2011-09-20 4 views
5

조직에서 비즈니스와 관련된 정보를 입력하는 시스템을 구축 중입니다. 일부 사용자는 자신의 조직 통계에 액세스 할 수있는 수준 이상의 사용자가보고 할 수 있어야하며 상위 사용자는 개별 조직 통계뿐만 아니라 상위 수준의 엔티티에 대한 집계 통계에 액세스 할 수 있어야합니다. 계층 구조). 계층 구조로 사용자 권한 관리

Example hierarchy

  • 는 지방 자치 단체 내에서 하나 개 이상의 조직이 될 것입니다.
  • 하나 이상의 상태
  • 는 조직, 지방 자치 단체, 카운티, 그리고 국가가 추가 될 수있을 것입니다 상태에서 하나 개 이상의 카운티가있을 것입니다 카운티에있는 하나 개 이상의 지방 자치 단체가있을 것입니다 언제든지
  • 조직에 자치 단체를 추가하면 해당 주를 볼 수있는 권한이있는 사용자는 관리자가 명시 적으로 필요없이 새 조직/자치 단체/카운티에 대한 보고서를 자동으로 볼 수 있어야합니다 그들에게 허락을 준다. 동일한 계층 구조 아래의 새 항목이 시스템에 추가 될 때마다시/군 차원에서 보고서를 볼 수있는 권한이있는 사용자에게도 마찬가지입니다.

몇 가지 예 :

사용자 1 :은 조직 #에 대한 보고서를 볼 수 1

사용자 2 :는 자치제 번호 아래의 모든 조직에 대한 보고서를 볼 수 2

사용자 3 : 시정촌의 모든 조직에 대한 보고서를 볼 수 있습니다. # 1 & # 2

사용자 4 : 카운티 번호 아래의 모든 조직에 대한 보고서를 볼 수 3

사용자 5 : 내 질문에 내가이 어떻게 구성 할 3

주 # 아래의 모든 카운티에 대한 보고서를 볼 수 있습니까? 개별 조직에 권한을 할당하지 않고 보고서에 사용 권한을 할당하는 가장 좋은 방법을 확신하지 못합니다. 분명히 실용적이지 않습니다.

ACL에 대해 다루는 몇 가지 질문을 보았지만 여기에는 해당 사항이 없습니다. 그렇다면 ACL과 어떻게 관련되는지에 대한 설명도 만족스런 대답이 될 것입니다.

답변

1

내가 (oranisation, 지방 자치 단체, 카운티, 주)

하나의 방법은 각 개체에 고유 한 권한 ID를 assing 있다는 것을 생각하고 그래서 테이블이 새 열은 다음과 같은 형태로 permission_id이 있어야합니다 기구 1은 권한 ID M1 시정촌이 권한 아이디 M2

등이있을 것이다 것입니다 권한 ID O2

지방 자치 단체 일이있을 것이다 O1 기구 2 permission_id 것입니다.

그런 다음 권한 열은 같은 것 사용 권한 테이블 (ID, id_user, 권한) 을 할 수 O1 - permisssion에만 조직 1 M1에 대한 - 지방 자치 단체의 모든 조직에 허가 한 M1M2 - 허가 지방 자치 단체 1, 2

S1의 모든 조직 - 주 1

허가 이건 그냥 제 의견입니다. 사용자가 지방 자치 단체에 액세스 할 수 있다는 것을 알고있는 한, 해당 자치 단체의 모든 정보에 액세스 할 수 있어야합니다. 현재 엔티티에서 경로를 가져올 수있는 일부 PHP 함수는 사용자 권한과 일치 할 수 있습니다.

예.

당신은 시정촌 페이지입니다. M2. S2에 대한 권한을 가진 사용자와 함께 당신의 기능이 인수로 주어지면 지방 자치 단체의 ID와 기능이 M2, C3, S1 경로를 생성합니다. S2와 S1을 비교하면 사용 권한이 거부됩니다. 이 방법으로 복잡성은 O (n)입니다. 여기서 n은 엔티티 (조직, 지자체, 카운티 및 주 4 개)의 수입니다.

4

귀하의 데이터베이스에 일련의 사용자 그룹을 만들 것을 제안합니다. 각각의 사용자 계정 레벨에는 하나 이상의 사용자 계정 레벨이 있으며 그 다음 그룹에 계층 적 값으로 정수를 할당 한 다음 개별 계정에 대해 동일한 작업을 수행하십시오 그룹 내 수준이 같은 (이것은, 관계형 구조를 사용 이노) : 권한에 대한

table: account_groups (Broader account groupings) 
Fields: 
-id_key - primary key, auto number 
-group - unique index 
-parent - index, foreign key=account_groups.group (this allows you to create group trees, so you can specify that a county group belongs to a state, and a municipality belongs to a county group, etc.) 
-group_hierarchy - integer (0 is highest permission group, each subsequent one step lower) 

table: account_levels (Account levels within a group) 
Fields: 
-id_key - primary key, auto number 
-account_level - unique index 
-group - index, foreign key=account_groups.group 
-account_heirarchy - integer (same as other table but denotes heirarchy within the group 

table: user_accounts (Individual user accounts) 
Fields: 
-id_key - primary key, auto number 
-account_id - unique index, user account name 
-account_level - index, foreign key=account_levels.account_level 

table: user_groups (denotes which tree(s) the user has access to) 
Fields: 
-id_key - primary key, auto number 
-account_id - index, foreign key=user_accounts.account_id 
-group - index, foreign key=account_groups.group 

: 그리고 당신은 다음에 대한 사용 권한을 반복하는 PHP를 사용할 수 있습니다

table: permissions (directory of permissions that could be applied) 
Fields: 
-id_key - primary key, auto number 
-permission - unique index, permission identifier 
-other stuff you need associated with the individual permissions, based on how you want them to hook into your program 

table: permissions_group_permissions (permissions applied at group level) 
Fields: 
-id_key - primary key, auto number 
-group - index, foreign key=account_groups.group 
-permission - index, foreign key= permissions.permission 

table: permissions_account_permissions (permissions applied at account level) 
Fields: 
-id_key - primary key, auto number 
-account_type - index, foreign key=account_levels.account_level 
-permission - index, foreign key=permissions.permission 

table: permissions_individual_permissions (permissions applied to individual accounts, if neccessary) 
Fields: 
-id_key - primary key, auto number 
-account_id - index, foreign key=user_accounts.account_id 
-permission - index, foreign key=permissions.permission 
-allow_or_deny - boolean (TRUE means permission is granted, FALSE means permission if revoked. This allows you to fine tune individual accounts, either granting custom elevated permissions, or revoking individual permissions for troublesome accounts without demoting them from the group. This can be useful in some special circumstances) 
-expiration - timestamp (allows you to set expiration dates for permissions, like if you want to temporarily suspend a specific action. Programmatically set default value of 00/00/00 00:00:00 as indefinite. You can do this at the account and group levels too by adding this field to those tables.) 

fi에 의한 개인 계좌 먼저 계정 수준과 관련된 그룹을 가져오고, 계층 순서로 각 후속 그룹의 배열을 만든 다음 그룹 내의 현재 계정 수준에서 현재 그룹의 계층 순서 (그룹 배열에 다차원 배열로 추가)를 반복합니다. 그룹 내의 마지막 기존 계정 수준까지 다음으로 각 후속 그룹에 대한 모든 계정 레벨을 가져오고 마지막으로 배열에 추가 된 각 계정 레벨에 대한 모든 관련 권한을 가져옵니다. 개별 사용자 권한을 구현하는 경우 개별적으로 적용된 권한을 사용하여 권한 배열을 추가하고 마지막으로 allow_or_deny 필드가 FALSE로 설정된 사용 권한을 배열에서 제거해야합니다. 사용자가 여러 트리에 액세스해야하는 경우 계정 ID와 일치하는 account_groups 테이블에 레코드를 추가하고 액세스 할 수있는 트리의 최상위 수준을 나타내는 레코드를 추가 한 다음 트리의 모든 후속 그룹을 반복합니다. 모든 적용 가능한 사용 권한을 계정에 부여하려면 user_groups에서 account_id에 대한 모든 그룹 연결을 가져온 다음 앞에서 설명한 트리별로 프로세스를 실행하십시오. 사용자가 하나의 트리에만 액세스 할 수있는 경우 user_groups 테이블을 사용할 필요조차 없습니다.

an example of how the structure fits your model: 
group: USA, hierarchy = 0 
group: California, parent-> USA, hierarchy = 1 
group: Los Angeles, parent->California, hierarchy = 2 
group: Texas, parent->USA, hierarchy = 1 
group: Dallas, parent->Texas, hierarchy = 2 

미국의 회원은 모든 것을 액세스 할 수 있습니다. 캘리포니아의 구성원은 각 계정의 레벨이 모두가

account levels: 
admin, hierarchy=0 
manager, hierarchy=1 
analyst, hierarchy=2 
staff member, hierarchy=3 

(서로 다른 부모 지점이기 때문에)가 같은 계층 적 가치를 가지고 있더라도, 텍사스 그룹을 캘리포니아의 계층 구조에서 이후의 모든 그룹에 액세스 할 수는 없지만 각 후속 계정 수준에 대한 사용 권한

user accounts: 
Bob, manager (likes to spam junk email to everyone) 

는 여전히 permissions_individual_permissions에 이메일 권한을 추가하고 FALSE로 allow_or_deny 값을 설정하여 밥의 이메일을 보내는 허가를 취소 할 수 있습니다. 이렇게하면 Bob을 관리에서 강등시키지 않고 스팸으로부터 막을 수 있습니다.

example PHP array: 
$account=array(
    groups=>array(), //Step 1: array_push each group the account is a member of here. Repeat for each tree from user_groups. 
    account_levels=>array(), //Step 2: loop through $account[groups], array_push each level here 
    permissions=>array(), //Step 3: loop through $account[account_levels], array_push each permission here. Then do the same for individual permissions applied to the account 
    restrictions=>array() //Step 4: loop through individual permissions where allow_or_deny=FALSE, array_push here (do the same for group and account level if you implemented restrictions for those tables as well). Tell your program to ignore permissions from this array, even if the account would otherwise have them. 
); 
+0

또한, 이것은 당신이 그렇게 한 사용자가 하나의 트리에서 상태 액세스 할 수 있지만, 다른 나무 만시 액세스, 다른 나무에 대해 서로 다른 권한 수준을 설정할 수 있습니다. – mopsyd

관련 문제