내 Admin 클래스 내에 맞춤 동작이 있습니다. 내가하는 일은 관리자 클래스 내에서 이들을 "구성"하는 것입니다. 나는에 훅 어디 그
foreach ($admin->getSecurityInformation() as $role => $permissions) {
$role = sprintf($baseRole, $role);
if ($isMaster) {
// if the user has the MASTER permission, allow to grant access the admin roles to other users
$roles[$role] = $role;
} elseif ($this->securityContext->isGranted($role)) {
// although the user has no MASTER permission, allow the currently logged in user to view the role
$rolesReadOnly[$role] = $role;
}
}
: 표준 소나타 \ UserBundle \ 보안 \ EditableRolesBuilder는 소나타 BaseAdmin 클래스 "getSecurityInformation"의 공개 함수를 호출합니다.
을 : 그냥이 기능을 자신의 관리 클래스를 덮어 덮어에 의해
/**
* List here the customized roles actions which are used within the Admin class you have extended. (e.g. the
* CustomerAdmin uses a special function to login as the customer. In this case set the array to array('LOGIN') and
* use at certain points like ->isGranted('LOGIN'). This is also available in templates like
* admin.isGranted('LOGIN', object)).
* The actions you are listing here, will be appended to the standard actions: EDIT, LIST, CREATE, VIEW, DELETE,
* EXPORT, OPERATOR, MASTER.
*
* @see http://sonata-project.org/bundles/admin/master/doc/index.html
*
* @var array
*/
protected $customizedRoles = array();
/**
* {@inheritdoc}
*/
public function getSecurityInformation()
{
$standardAdminRoles = parent::getSecurityInformation();
$customizedAdminRoles = $this->getCustomizedAdminRoles();
$allAdminRoles = array_merge($standardAdminRoles, $customizedAdminRoles);
ksort($allAdminRoles);
return $allAdminRoles;
}
/**
* Get the customized roles set at property of the Admin class 'customizedRoles' prepared to append to the standard
* roles.
*
* @return array
*/
private function getCustomizedAdminRoles()
{
$customizedRoles = array();
if (is_array($this->customizedRoles) && !empty($this->customizedRoles)) {
foreach ($this->customizedRoles as $customizedRole) {
$customizedRole = strtoupper($customizedRole);
$customizedRoles[$customizedRole] = $customizedRole;
}
}
return $customizedRoles;
}
그리고 당신의 관리 클래스에서이 배열을 채우기 (나는 소나타 \ AdminBundle \ 관리자 \ 관리자에서 확장 내 BaseAdmin 클래스에서 이런 짓을했는지)
/** @{inheritdoc} */
protected $customizedRoles = array('LOGIN');
그게 전부입니다. 노력과 디자인이 나에게 꽤 공평한 것처럼 보인다. :-)
고마워, 난 내 역할을 ROLE_SUPER_ADMIN 및 ROLE_ADMIN 아래에 추가 할 수 있습니다. 이것은 소나타 파일을 변경하지 않기 때문에 매우 깨끗합니다. 내 소프트웨어의 새 버전에서는 이런 식으로 내 역할을 설정하려고합니다. –