귀하의 데이터베이스에 일련의 사용자 그룹을 만들 것을 제안합니다. 각각의 사용자 계정 레벨에는 하나 이상의 사용자 계정 레벨이 있으며 그 다음 그룹에 계층 적 값으로 정수를 할당 한 다음 개별 계정에 대해 동일한 작업을 수행하십시오 그룹 내 수준이 같은 (이것은, 관계형 구조를 사용 이노) : 권한에 대한
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.
);
또한, 이것은 당신이 그렇게 한 사용자가 하나의 트리에서 상태 액세스 할 수 있지만, 다른 나무 만시 액세스, 다른 나무에 대해 서로 다른 권한 수준을 설정할 수 있습니다. – mopsyd