Class: Permissions
- Inherits:
-
Object
- Object
- Permissions
- Defined in:
- frontend/app/models/permissions.rb
Class Method Summary collapse
-
.pack(repo_permissions_map) ⇒ Object
-
.user_can?(packed_permission_map, repo_uri, permission) ⇒ Boolean
Class Method Details
.pack(repo_permissions_map) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'frontend/app/models/permissions.rb', line 3 def self.pack() = .values.flatten.uniq result = {} result['key'] = result['perms'] = Hash[.map do |repo_uri, | = .map {|| .include?() ? "1" : "0" }.join("") [repo_uri, ] end] result end |
.user_can?(packed_permission_map, repo_uri, permission) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'frontend/app/models/permissions.rb', line 22 def self.user_can?(, repo_uri, ) position = ['key'].index() if !position # Any permission not in our key list isn't granted in any repo return false end # Otherwise, the permission is granted if there's a "1" in the appropriate # position = ['perms'][repo_uri] && [position] == "1" end |