public function deletePolicy($roleId, $policyId, Request $request)
    {
        try {
            // First try to treat $roleId as a role draft ID.
            $roleDraft = $this->roleService->loadRoleDraft($roleId);

            $policy = null;
            foreach ($roleDraft->getPolicies() as $rolePolicy) {
                if ($rolePolicy->id == $policyId) {
                    $policy = $rolePolicy;
                    break;
                }
            }

            if ($policy !== null) {
                $this->roleService->removePolicyByRoleDraft($roleDraft, $policy);

                return new Values\NoContent();
            }
        } catch (NotFoundException $e) {
            // Then try to treat $roleId as a role ID.
            $role = $this->roleService->loadRole($roleId);

            $policy = null;
            foreach ($role->getPolicies() as $rolePolicy) {
                if ($rolePolicy->id == $policyId) {
                    $policy = $rolePolicy;
                    break;
                }
            }

            if ($policy !== null) {
                $this->roleService->deletePolicy($policy);

                return new Values\NoContent();
            }
        }

        throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
    }
public function deletePolicy($roleId, $policyId, Request $request)
    {
        try {
            // First try to treat $roleId as a role draft ID.
            $roleDraft = $this->roleService->loadRoleDraft($roleId);

            $policy = null;
            foreach ($roleDraft->getPolicies() as $rolePolicy) {
                if ($rolePolicy->id == $policyId) {
                    $policy = $rolePolicy;
                    break;
                }
            }

            if ($policy !== null) {
                $this->roleService->removePolicyByRoleDraft($roleDraft, $policy);

                return new Values\NoContent();
            }
        } catch (NotFoundException $e) {
            // Then try to treat $roleId as a role ID.
            $role = $this->roleService->loadRole($roleId);

            $policy = null;
            foreach ($role->getPolicies() as $rolePolicy) {
                if ($rolePolicy->id == $policyId) {
                    $policy = $rolePolicy;
                    break;
                }
            }

            if ($policy !== null) {
                $this->roleService->deletePolicy($policy);

                return new Values\NoContent();
            }
        }

        throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
    }
public function deletePolicy ( $ roleId , $ policyId , Request $ request ) { try { // First try to treat $roleId as a role draft ID. $ roleDraft = $ this -> roleService -> loadRoleDraft ( $ roleId ) ; $ policy = null ; foreach ( $ roleDraft -> getPolicies ( ) as $ rolePolicy ) { if ( $ rolePolicy -> id == $ policyId ) { $ policy = $ rolePolicy ; break ; } } if ( $ policy !== null ) { $ this -> roleService -> removePolicyByRoleDraft ( $ roleDraft , $ policy ) ; return new Values \ NoContent ( ) ; } } catch ( NotFoundException $ e ) { // Then try to treat $roleId as a role ID. $ role = $ this -> roleService -> loadRole ( $ roleId ) ; $ policy = null ; foreach ( $ role -> getPolicies ( ) as $ rolePolicy ) { if ( $ rolePolicy -> id == $ policyId ) { $ policy = $ rolePolicy ; break ; } } if ( $ policy !== null ) { $ this -> roleService -> deletePolicy ( $ policy ) ; return new Values \ NoContent ( ) ; } } throw new Exceptions \ NotFoundException ( "Policy not found: '{$request->getPathInfo()}'." ) ; }
Delete a policy from role.

@param $roleId int ID of a role or a role draft
@param $policyId int ID of a policy

@throws \eZ\Publish\Core\REST\Common\Exceptions\NotFoundException

@return \eZ\Publish\Core\REST\Server\Values\NoContent
Delete a policy from role .