-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update policy to use static admin data
The mapping from admin groups to which beamlines they refer to allows the access functions to be greatly simplified. Also adds functions to differentiate between users that are on a proposal/session and those that can access it due to being an admin for that beamline.
- Loading branch information
Showing
6 changed files
with
103 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package diamond.policy.admin | ||
|
||
import rego.v1 | ||
|
||
is_admin(subject) if { | ||
"super_admin" in data.diamond.data.subjects[subject].permissions # regal ignore:external-reference | ||
} | ||
|
||
is_beamline_admin(subject, beamline) if { | ||
some admin in data.diamond.data.subjects[subject].permissions | ||
beamline in data.diamond.data.admin[admin] # regal ignore:external-reference | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package diamond.policy.admin_test | ||
|
||
import data.diamond.policy.admin | ||
import rego.v1 | ||
|
||
diamond_data := { | ||
"subjects": { | ||
"alice": { | ||
"permissions": [], | ||
"proposals": [], | ||
"sessions": [], | ||
}, | ||
"bob": { | ||
"permissions": ["b07_admin"], | ||
"proposals": [], | ||
"sessions": [], | ||
}, | ||
"carol": { | ||
"permissions": ["super_admin"], | ||
"proposals": [], | ||
"sessions": [], | ||
}, | ||
"oscar": { | ||
"permissions": ["group_admin"], | ||
"proposals": [], | ||
"sessions": [], | ||
}, | ||
}, | ||
"sessions": {}, | ||
"proposals": {}, | ||
"beamlines": {}, | ||
"admin": {"b07_admin": ["b07"], "group_admin": ["b07", "i07"]}, | ||
} | ||
|
||
test_super_admin_subject if { | ||
admin.is_admin("carol") with data.diamond.data as diamond_data | ||
} | ||
|
||
test_beamline_admin_subject_beamline if { | ||
admin.is_beamline_admin("bob", "b07") with data.diamond.data as diamond_data | ||
} | ||
|
||
test_group_admin_subject_beamline if { | ||
admin.is_beamline_admin("oscar", "b07") with data.diamond.data as diamond_data | ||
} | ||
|
||
test_non_admin if { | ||
not admin.is_admin("alice") with data.diamond.data as diamond_data | ||
} | ||
|
||
test_beamline_admin_not_admin if { | ||
not admin.is_admin("bob") with data.diamond.data as diamond_data | ||
} | ||
|
||
test_non_beamline_admin if { | ||
not admin.is_beamline_admin("alice", "b07") with data.diamond.data as diamond_data | ||
} | ||
|
||
test_super_admin_not_beamline_admin if { | ||
not admin.is_beamline_admin("carol", "b07") with data.diamond.data as diamond_data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package diamond.policy.proposal | ||
|
||
import data.diamond.policy.admin | ||
import rego.v1 | ||
|
||
# Allow if subject has super_admin permission | ||
access_proposal(subject, proposal_number) if { | ||
"super_admin" in data.diamond.data.subjects[subject].permissions # regal ignore:external-reference | ||
on_proposal(subject, proposal_number) if { | ||
proposal_number in data.diamond.data.subjects[subject].proposals # regal ignore:external-reference | ||
} | ||
|
||
# Allow if subject has super_admin permission | ||
access_proposal(subject, proposal_number) if admin.is_admin(subject) | ||
|
||
# Allow if subject is on proposal | ||
access_proposal(subject, proposal_number) if { | ||
proposal_number in data.diamond.data.subjects[subject].proposals # regal ignore:external-reference | ||
} | ||
access_proposal(subject, proposal_number) if on_proposal(subject, proposal_number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters