-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
249 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
{ | ||
|
||
"name": "oat-sa/extension-tao-dac-simple", | ||
"description" : "extension that allows admin to give access to some resources to other people", | ||
"type" : "tao-extension", | ||
"authors" : [ | ||
"description": "extension that allows admin to give access to some resources to other people", | ||
"type": "tao-extension", | ||
"authors": [ | ||
{ | ||
"name": "Open Assessment Technologies SA" | ||
"name": "Open Assessment Technologies SA" | ||
} | ||
], | ||
"keywords" : [ | ||
"keywords": [ | ||
"tao", | ||
"computer-based-assessment" | ||
], | ||
"homepage" : "http://www.taotesting.com", | ||
"license" : [ | ||
"homepage": "http://www.taotesting.com", | ||
"license": [ | ||
"GPL-2.0-only" | ||
], | ||
"extra" : { | ||
"tao-extension-name" : "taoDacSimple" | ||
"extra": { | ||
"tao-extension-name": "taoDacSimple" | ||
}, | ||
"minimum-stability" : "dev", | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": ">=7.1", | ||
"oat-sa/oatbox-extension-installer": "~1.1||dev-master", | ||
"oat-sa/generis" : ">=14.0.0", | ||
"oat-sa/tao-core" : ">=48.0.0", | ||
"oat-sa/extension-tao-backoffice" : ">=6.0.0" | ||
"oat-sa/generis": ">=14.0.0", | ||
"oat-sa/tao-core": ">=50.15.0", | ||
"oat-sa/extension-tao-backoffice": ">=6.0.0", | ||
"oat-sa/extension-tao-item": ">=11.29.0" | ||
}, | ||
"autoload" : { | ||
"psr-4" : { | ||
"oat\\taoDacSimple\\" : "" | ||
"autoload": { | ||
"psr-4": { | ||
"oat\\taoDacSimple\\": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2022 (original work) Open Assessment Technologies SA; | ||
* | ||
* @author Gabriel Felipe Soares <gabriel.felipe.soares@taotesting.com> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\taoDacSimple\model\Copy\Service; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use core_kernel_classes_Resource; | ||
use oat\taoDacSimple\model\DataBaseAccess; | ||
use oat\tao\model\resources\Contract\PermissionCopierInterface; | ||
|
||
class DacSimplePermissionCopier implements PermissionCopierInterface | ||
{ | ||
/** @var DataBaseAccess */ | ||
private $dataBaseAccess; | ||
|
||
public function __construct(DataBaseAccess $dataBaseAccess) | ||
{ | ||
$this->dataBaseAccess = $dataBaseAccess; | ||
} | ||
|
||
public function copy( | ||
core_kernel_classes_Resource $from, | ||
core_kernel_classes_Resource $to | ||
): void { | ||
$permissions = $this->dataBaseAccess->getResourcePermissions($from->getUri()); | ||
$this->dataBaseAccess->removeAllPermissions([$to->getUri()]); | ||
|
||
foreach ($permissions as $userId => $rights) { | ||
$this->dataBaseAccess->addPermissions($userId, $to->getUri(), $rights); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2022 (original work) Open Assessment Technologies SA; | ||
* | ||
* @author Gabriel Felipe Soares <gabriel.felipe.soares@taotesting.com> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\taoDacSimple\model\Copy\ServiceProvider; | ||
|
||
use oat\tao\model\resources\Service\ClassCopier; | ||
use oat\tao\model\resources\Service\InstanceCopier; | ||
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface; | ||
use oat\taoDacSimple\model\Copy\Service\DacSimplePermissionCopier; | ||
use oat\taoDacSimple\model\DataBaseAccess; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
use function Symfony\Component\DependencyInjection\Loader\Configurator\service; | ||
|
||
class CopyServiceProvider implements ContainerServiceProviderInterface | ||
{ | ||
public function __invoke(ContainerConfigurator $configurator): void | ||
{ | ||
$services = $configurator->services(); | ||
|
||
$services | ||
->set(DacSimplePermissionCopier::class, DacSimplePermissionCopier::class) | ||
->args( | ||
[ | ||
service(DataBaseAccess::SERVICE_ID), | ||
] | ||
); | ||
|
||
$services | ||
->get(ClassCopier::class . '::ITEMS') | ||
->call( | ||
'withPermissionCopier', | ||
[ | ||
service(DacSimplePermissionCopier::class), | ||
] | ||
); | ||
|
||
$services | ||
->get(InstanceCopier::class . '::ITEMS') | ||
->call( | ||
'withPermissionCopier', | ||
[ | ||
service(DacSimplePermissionCopier::class), | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
test/unit/model/Copy/Service/DacSimplePermissionCopierTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2022 (original work) Open Assessment Technologies SA; | ||
* | ||
* @author Gabriel Felipe Soares <gabriel.felipe.soares@taotesting.com | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\taoDacSimple\test\unit\model\Copy\Service; | ||
|
||
use core_kernel_classes_Resource; | ||
use oat\taoDacSimple\model\Copy\Service\DacSimplePermissionCopier; | ||
use oat\taoDacSimple\model\DataBaseAccess; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DacSimplePermissionCopierTest extends TestCase | ||
{ | ||
/** @var DacSimplePermissionCopier */ | ||
private $sut; | ||
|
||
/** @var DataBaseAccess|MockObject */ | ||
private $dataBaseAccess; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->dataBaseAccess = $this->createMock(DataBaseAccess::class); | ||
$this->sut = new DacSimplePermissionCopier($this->dataBaseAccess); | ||
} | ||
|
||
public function testCopy(): void | ||
{ | ||
$from = $this->createMock(core_kernel_classes_Resource::class); | ||
$from->method('getUri') | ||
->willReturn('fromUri'); | ||
|
||
$to = $this->createMock(core_kernel_classes_Resource::class); | ||
$to->method('getUri') | ||
->willReturn('toUri'); | ||
|
||
$this->dataBaseAccess | ||
->expects($this->once()) | ||
->method('removeAllPermissions') | ||
->with( | ||
[ | ||
'toUri' | ||
] | ||
); | ||
|
||
$this->dataBaseAccess | ||
->expects($this->once()) | ||
->method('getResourcePermissions') | ||
->with('fromUri') | ||
->willReturn( | ||
[ | ||
'user1' => [ | ||
'WRITE' | ||
], | ||
'user2' => [ | ||
'READ' | ||
] | ||
] | ||
); | ||
|
||
$this->dataBaseAccess | ||
->expects($this->at(2)) | ||
->method('addPermissions') | ||
->with( | ||
'user1', | ||
'toUri', | ||
[ | ||
'WRITE' | ||
] | ||
); | ||
|
||
$this->dataBaseAccess | ||
->expects($this->at(3)) | ||
->method('addPermissions') | ||
->with( | ||
'user2', | ||
'toUri', | ||
[ | ||
'READ' | ||
] | ||
); | ||
|
||
$this->sut->copy($from, $to); | ||
} | ||
} |