Class: Group
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Group
- Defined in:
- backend/app/model/group.rb
Class Method Summary collapse
-
.ADMIN_GROUP_CODE ⇒ Object
-
.broadcast_changes ⇒ Object
-
.create_from_json(json, opts = {}) ⇒ Object
-
.PUBLIC_GROUP_CODE ⇒ Object
-
.SEARCHINDEX_GROUP_CODE ⇒ Object
-
.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
-
.set_members(obj, json) ⇒ Object
-
.set_permissions(obj, json) ⇒ Object
-
.STAFF_GROUP_CODE ⇒ Object
-
.transfer_all(source_repository, target_repository) ⇒ Object
Instance Method Summary collapse
-
#before_save ⇒ Object
-
#delete ⇒ Object
-
#grant(permission_code) ⇒ Object
-
#update_from_json(json, opts = {}, apply_nested_records = true) ⇒ Object
-
#validate ⇒ Object
Class Method Details
.ADMIN_GROUP_CODE ⇒ Object
13 14 15 |
# File 'backend/app/model/group.rb', line 13 def self.ADMIN_GROUP_CODE 'administrators' end |
.broadcast_changes ⇒ Object
141 142 143 |
# File 'backend/app/model/group.rb', line 141 def self.broadcast_changes Notifications.notify("REFRESH_ACLS") end |
.create_from_json(json, opts = {}) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'backend/app/model/group.rb', line 86 def self.create_from_json(json, opts = {}) obj = super set_members(obj, json) (obj, json) broadcast_changes obj end |
.PUBLIC_GROUP_CODE ⇒ Object
23 24 25 |
# File 'backend/app/model/group.rb', line 23 def self.PUBLIC_GROUP_CODE 'publicanonymous' end |
.SEARCHINDEX_GROUP_CODE ⇒ Object
18 19 20 |
# File 'backend/app/model/group.rb', line 18 def self.SEARCHINDEX_GROUP_CODE 'searchindex' end |
.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'backend/app/model/group.rb', line 117 def self.sequel_to_jsonmodel(objs, opts = {}) jsons = super jsons.zip(objs).each do |json, obj| if opts[:with_members] json.member_usernames = obj.user.map {|user| user[:username]} end json. = obj..map {|| [:permission_code]} end jsons end |
.set_members(obj, json) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'backend/app/model/group.rb', line 39 def self.set_members(obj, json) nonusers = [] (json.member_usernames or []).map {|username| user = User[:username => username] if not user nonusers << username end } if nonusers.length > 0 if nonusers.length == 1 raise UserNotFoundException.new("User #{nonusers[0]} does not exist") else raise UserNotFoundException.new("Users #{nonusers.join(', ')} do not exist") end end obj.remove_all_user (json.member_usernames or []).map {|username| user = User[:username => username] obj.add_user(user) if user } end |
.set_permissions(obj, json) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'backend/app/model/group.rb', line 64 def self.(obj, json) obj. (json. or []).each do || next if Permission.derived?() = Permission[:permission_code => ] if .nil? raise "Unknown permission code: #{permission_code}" end if [:level] == 'global' Log.error("You can't assign a global permission to a repository") raise AccessDeniedException.new("You can't assign a global permission to a repository") end obj.() end end |
.STAFF_GROUP_CODE ⇒ Object
27 28 29 |
# File 'backend/app/model/group.rb', line 27 def self.STAFF_GROUP_CODE 'staffsystem' end |
.transfer_all(source_repository, target_repository) ⇒ Object
155 156 157 |
# File 'backend/app/model/group.rb', line 155 def self.transfer_all(source_repository, target_repository) # Groups aren't candidates for being transferred, so we don't call super. end |
Instance Method Details
#before_save ⇒ Object
32 33 34 35 36 |
# File 'backend/app/model/group.rb', line 32 def before_save super self.group_code_norm = self.group_code.downcase end |
#delete ⇒ Object
146 147 148 149 150 151 152 |
# File 'backend/app/model/group.rb', line 146 def delete remove_all_user super self.class.broadcast_changes end |
#grant(permission_code) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'backend/app/model/group.rb', line 106 def grant() = Permission[:permission_code => .to_s] if self.class.db[:group_permission].filter(:group_id => self.id, :permission_id => .id).empty? () end end |
#update_from_json(json, opts = {}, apply_nested_records = true) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'backend/app/model/group.rb', line 96 def update_from_json(json, opts = {}, apply_nested_records = true) super self.class.set_members(self, json) if opts[:with_members] self.class.(self, json) self.class.broadcast_changes self.id end |
#validate ⇒ Object
132 133 134 135 136 137 138 |
# File 'backend/app/model/group.rb', line 132 def validate super self.group_code_norm = self.group_code.downcase validates_unique([:repo_id, :group_code_norm], :message => "Group code must be unique within a repository") map_validation_to_json_property([:repo_id, :group_code_norm], :group_code) end |