Skip to content

Commit

Permalink
Merge branch 'release-7.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed May 27, 2022
2 parents b5d936b + 90c48ed commit 6a319af
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 19 deletions.
34 changes: 17 additions & 17 deletions composer.json
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\\": ""
}
}
}
6 changes: 5 additions & 1 deletion manifest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use oat\taoDacSimple\model\Copy\ServiceProvider\CopyServiceProvider;
use oat\taoDacSimple\scripts\install\AttachEventHandler;
use oat\taoDacSimple\scripts\update\Updater;

Expand All @@ -18,7 +19,7 @@
* 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) 2014-2020 (original work) Open Assessment Technologies SA;
* Copyright (c) 2014-2022 (original work) Open Assessment Technologies SA;
*/

use oat\taoDacSimple\scripts\install\SetupDataAccess;
Expand Down Expand Up @@ -63,5 +64,8 @@

#BASE URL (usually the domain root)
'BASE_URL' => ROOT_URL . 'taoDacSimple/',
],
'containerServiceProviders' => [
CopyServiceProvider::class
]
];
53 changes: 53 additions & 0 deletions model/Copy/Service/DacSimplePermissionCopier.php
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);
}
}
}
68 changes: 68 additions & 0 deletions model/Copy/ServiceProvider/CopyServiceProvider.php
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),
]
);
}
}
2 changes: 1 addition & 1 deletion model/DataBaseAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public function removeAllPermissions($resourceIds)

$this->getPersistence()->exec($query, $resourceIds);
foreach ($resourceIds as $resourceId) {
$this->getEventManager()->trigger(new DacRemovedEvent('-', $resourceId, '-'));
$this->getEventManager()->trigger(new DacRemovedEvent('-', $resourceId, ['-']));
}
return true;
}
Expand Down
105 changes: 105 additions & 0 deletions test/unit/model/Copy/Service/DacSimplePermissionCopierTest.php
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);
}
}

0 comments on commit 6a319af

Please sign in to comment.