Skip to content

Instantly share code, notes, and snippets.

@thomsbg
Last active June 6, 2018 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomsbg/48074de233573cbbf607f7b28aa456d8 to your computer and use it in GitHub Desktop.
Save thomsbg/48074de233573cbbf607f7b28aa456d8 to your computer and use it in GitHub Desktop.
permissions query pseudocode
can user u perform operation o in scope s?
1. scopes = [s].concat(s.parents)
2. roles = RoleAssignment.where(user: u, scope: scopes).pluck(:role)
3. roles.any? { |role| ROLE_OPERATIONS_MAPPING[role].operations.include?(o) }
## or perhaps
1. scopes = [s].concat(s.parents)
3. roles = ROLES.select { |role| role.operations.include?(o) }
2. RoleAssignment.exist?(user: u, scope: scopes, role: roles)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment