2

ROLE_ERECTA_TASK_ADMIN (으)로 새 역할을 만들어야하지만 어떻게해야할지 모르겠지만, 소나타에서 선언해야합니다. 관리자 인터페이스? 소나타 번들을 사용하여 사용자 그룹 역할을 관리합니다. 이제 일부 롤 만 갖지만 다른 번들을 내 번들로 만들고 싶습니다.symfony 2에 새로운 사용자 정의 역할을 추가하여 SONATA 번들의 권한을 관리해야합니다.

내 security.yml

role_hierarchy: 
     ROLE_ADMIN:  [ROLE_USER, ROLE_SONATA_ADMIN] 
     ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] 
     # PROTEZIONE MODULO TASK 
     ROLE_ERECTA_TASK_ADMIN: [ROLE_ERECTA_TASK_USER] 
     ROLE_ERECTA_TASK_SA: [ROLE_ERECTA_TASK_ADMIN, ROLE_ALLOWED_TO_SWITCH] 
     SONATA: 
      - ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT # if you are using acl then this line must be commented 

소나타 관리자 사용자 관리자 : 사전에 enter image description here

감사합니다.

답변

1

는 역할을 추가하는 또 다른 빠른 해결 방법이 있습니다. security.yml을 편집하고 ROLE_SUPER_ADMIN에 역할을 추가하십시오.

role_hierarchy: 
    ... 
    ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH, ROLE_FOO, ROLE_BAR, ...] 
+0

고마워, 난 내 역할을 ROLE_SUPER_ADMIN 및 ROLE_ADMIN 아래에 추가 할 수 있습니다. 이것은 소나타 파일을 변경하지 않기 때문에 매우 깨끗합니다. 내 소프트웨어의 새 버전에서는 이런 식으로 내 역할을 설정하려고합니다. –

2

나는 당신이 그와 같은 formMapper에서 수동으로 역할을 설정하는 것이 좋습니다 :

$formMapper->with('Roles') 
       ->add('roles', 'choice', 
        array('choices'=> 
        array('ROLE_SUPER_ADMIN' => 'ROLE_SUPER_ADMIN', 'ROLE_...' => 'ROLE_...'), 
         'expanded'=> true, 
         'multiple'=> true)) 
       ->end(); 

은 또한 당신의 역할에 ROLE_ADMINROLE_SONATA_ADMIN를 추가합니다.

-2

나는 :) Rpg600에, 덕분에 다른 방법을 발견했다

나는 SecurityRolesType.php

공공 기능 getDefaultOptions (배열 $ 옵션/공급 업체/번들/소나타/UserBundle/양식/형식에이 코드를 작성) { $ options = parent :: getDefaultOptions ($ options); 응용 프로그램에서 이제

$roles = array(); 
//== MY-CODE ============================================================================================================ 
$Role_to_add= array(); 
foreach ($this->pool->getContainer()->getParameter('security.role_hierarchy.roles') as $key => $value_roles_group_array) 
    if('_ALL'== substr($key,-4,4)) 
      foreach ($value_roles_group_array as $key => $new_roles_string) 
       $roles[$new_roles_string]=$new_roles_string; 
//======================================================================================================================     
$rolesReadOnly = array(); 

... 

/설정/security.yml

role_hierarchy: 
    ROLE_ADMIN:  [ROLE_USER, ROLE_SONATA_ADMIN] 
    ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] 
    # PROTEZIONE MODULO TASK 
    ROLE_ERECTA_TASK_ALL: [ROLE_ERECTA_TASK_USER, ROLE_ERECTA_TASK_ADMIN, ROLE_ERECTA_TASK_SA] 
    ROLE_ERECTA_TASK_ADMIN: [ROLE_ERECTA_TASK_USER] 
    ROLE_ERECTA_TASK_SA: [ROLE_ERECTA_TASK_ADMIN, ROLE_ALLOWED_TO_SWITCH] 
    SONATA: 
     - ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT # if you are using acl then this line must be commented 

내가 계층 구조 역할에 추가

새 역할 문자열을 보여주는 내부 "_ALL"내 코드로드 모든 하위 요소에 의해 끝난 역할 소나타 관리 양식 사용자.

Sonata Form Admin with the roles added by my code

지금 나는 나의 새로운 역할을 볼 수 있습니다 로그인을 수행 할 때.

Symfony System account info

+9

공급 업체 디렉토리 아래에서 아무 것도 편집하지 않는 것이 좋습니다. – pestaa

+0

그래, 그게 절대적으로 당신이하고 싶은 모든 일이 있다면 – Prof83

0

보다 유연한 구현을 위해 vendor/sonata-project/user-bundle/Security/EditableRolesBuilder.php를 재정의 할 수도 있습니다.

이 파일을 직접 편집하지 말고 번들 상속을 통해 수행하거나 sonata.user.editable_role_builder 서비스를 재정 의하여 사용자 정의 클래스를 주입하십시오.

0

내 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'); 

그게 전부입니다. 노력과 디자인이 나에게 꽤 공평한 것처럼 보인다. :-)