1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Webcook security bundle. |
5
|
|
|
* |
6
|
|
|
* See LICENSE file in the root of the bundle. Webcook |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Webcook\Cms\SecurityBundle\Controller; |
10
|
|
|
|
11
|
|
|
use Webcook\Cms\CoreBundle\Base\BaseRestController; |
12
|
|
|
use Webcook\Cms\SecurityBundle\Entity\Role; |
13
|
|
|
use Webcook\Cms\SecurityBundle\Entity\Resource; |
14
|
|
|
use Webcook\Cms\SecurityBundle\Entity\RoleResource; |
15
|
|
|
use Webcook\Cms\SecurityBundle\Form\Type\RoleType; |
16
|
|
|
use Webcook\Cms\SecurityBundle\Form\Type\ResourcesType; |
17
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
18
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
19
|
|
|
use Webcook\Cms\SecurityBundle\Authorization\Voter\WebcookCmsVoter; |
20
|
|
|
use FOS\RestBundle\Controller\Annotations\Get; |
21
|
|
|
use FOS\RestBundle\Controller\Annotations\Post; |
22
|
|
|
use FOS\RestBundle\Controller\Annotations\Put; |
23
|
|
|
use FOS\RestBundle\Controller\Annotations\Delete; |
24
|
|
|
use Doctrine\DBAL\LockMode; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* REST api controller - role management. |
28
|
|
|
*/ |
29
|
|
|
class RoleController extends BaseRestController |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Update resources of the role. |
33
|
|
|
* |
34
|
|
|
* @param int $id Id of the desired role. |
35
|
|
|
* |
36
|
|
|
* @ApiDoc( |
37
|
|
|
* description="Update existing role.", |
38
|
|
|
* input="Webcook\Cms\SecurityBundle\Form\Type\ResourcesType" |
39
|
|
|
* ) |
40
|
1 |
|
* @Put(options={"i18n"=false}) |
41
|
|
|
*/ |
42
|
1 |
|
public function putRolesResourcesAction($id) |
|
|
|
|
43
|
|
|
{ |
44
|
1 |
|
$parameters = $this->getPutParameters('roleResources'); |
45
|
1 |
|
|
46
|
|
|
foreach ($parameters as $roleResourceArray) { |
47
|
1 |
|
$roleResource = $this->getEntityManager()->getRepository('Webcook\Cms\SecurityBundle\Entity\RoleResource')->find($roleResourceArray['id']); |
|
|
|
|
48
|
|
|
|
49
|
|
|
if ($roleResource) { |
50
|
|
|
$roleResource->setView($this->getValueFromArray($roleResourceArray, 'view')); |
51
|
|
|
$roleResource->setInsert($this->getValueFromArray($roleResourceArray, 'insert')); |
52
|
|
|
$roleResource->setEdit($this->getValueFromArray($roleResourceArray, 'edit')); |
53
|
|
|
$roleResource->setDelete($this->getValueFromArray($roleResourceArray, 'delete')); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->getEntityManager()->flush(); |
58
|
|
|
|
59
|
|
|
$view = $this->view(null, 204); |
60
|
|
|
|
61
|
|
|
return $this->handleView($view); |
62
|
|
|
} |
63
|
2 |
|
|
64
|
|
|
/** |
65
|
2 |
|
* Get specific value from an array. |
66
|
|
|
* |
67
|
2 |
|
* @param array $array array of values |
68
|
2 |
|
* @param string $key key of desired value |
69
|
|
|
* |
70
|
2 |
|
* @return bool|string Value or false. |
71
|
|
|
*/ |
72
|
|
|
private function getValueFromArray($array, $key) |
73
|
|
|
{ |
74
|
|
|
if (array_key_exists($key, $array)) { |
75
|
|
|
return filter_var($array[$key], FILTER_VALIDATE_BOOLEAN); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return false; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.