Commit 81697850eb16d66615fb072e7c288b3b3dc70758
1 parent
cc5440e8
Exists in
master
and in
4 other branches
create UsersGroup entity. Modify ability to check group owners instead one owner
Showing
7 changed files
with
85 additions
and
37 deletions
Show diff stats
app/models/ability.rb
@@ -132,7 +132,7 @@ class Ability | @@ -132,7 +132,7 @@ class Ability | ||
132 | rules = [] | 132 | rules = [] |
133 | 133 | ||
134 | # Only group owner and administrators can manage group | 134 | # Only group owner and administrators can manage group |
135 | - if group.owner == user || user.admin? | 135 | + if group.owners.include?(user) || user.admin? |
136 | rules << [ | 136 | rules << [ |
137 | :manage_group, | 137 | :manage_group, |
138 | :manage_namespace | 138 | :manage_namespace |
app/models/group.rb
@@ -13,6 +13,8 @@ | @@ -13,6 +13,8 @@ | ||
13 | # | 13 | # |
14 | 14 | ||
15 | class Group < Namespace | 15 | class Group < Namespace |
16 | + has_many :users_groups, dependent: :destroy | ||
17 | + has_many :users, through: :users_groups | ||
16 | 18 | ||
17 | def add_users_to_project_teams(user_ids, project_access) | 19 | def add_users_to_project_teams(user_ids, project_access) |
18 | UsersProject.add_users_into_projects( | 20 | UsersProject.add_users_into_projects( |
@@ -35,4 +37,8 @@ class Group < Namespace | @@ -35,4 +37,8 @@ class Group < Namespace | ||
35 | def truncate_teams | 37 | def truncate_teams |
36 | UsersProject.truncate_teams(project_ids) | 38 | UsersProject.truncate_teams(project_ids) |
37 | end | 39 | end |
40 | + | ||
41 | + def owners | ||
42 | + @owners ||= (users_groups.owners.map(&:user) << owner) | ||
43 | + end | ||
38 | end | 44 | end |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +class UsersGroup < ActiveRecord::Base | ||
2 | + GUEST = 10 | ||
3 | + REPORTER = 20 | ||
4 | + DEVELOPER = 30 | ||
5 | + MASTER = 40 | ||
6 | + OWNER = 50 | ||
7 | + | ||
8 | + attr_accessible :group_access, :group_id, :user_id | ||
9 | + | ||
10 | + belongs_to :user | ||
11 | + belongs_to :project | ||
12 | + | ||
13 | + scope :guests, -> { where(group_access: GUEST) } | ||
14 | + scope :reporters, -> { where(group_access: REPORTER) } | ||
15 | + scope :developers, -> { where(group_access: DEVELOPER) } | ||
16 | + scope :masters, -> { where(group_access: MASTER) } | ||
17 | + scope :owners, -> { where(group_access: OWNER) } | ||
18 | + | ||
19 | + scope :with_group, ->(group) { where(group_id: group.id) } | ||
20 | + scope :with_user, ->(user) { where(user_id: user.id) } | ||
21 | +end |
db/schema.rb
@@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | @@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | ||
53 | t.integer "assignee_id" | 53 | t.integer "assignee_id" |
54 | t.integer "author_id" | 54 | t.integer "author_id" |
55 | t.integer "project_id" | 55 | t.integer "project_id" |
56 | - t.datetime "created_at", :null => false | ||
57 | - t.datetime "updated_at", :null => false | 56 | + t.datetime "created_at" |
57 | + t.datetime "updated_at" | ||
58 | t.integer "position", :default => 0 | 58 | t.integer "position", :default => 0 |
59 | t.string "branch_name" | 59 | t.string "branch_name" |
60 | t.text "description" | 60 | t.text "description" |
@@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | @@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | ||
71 | 71 | ||
72 | create_table "keys", :force => true do |t| | 72 | create_table "keys", :force => true do |t| |
73 | t.integer "user_id" | 73 | t.integer "user_id" |
74 | - t.datetime "created_at", :null => false | ||
75 | - t.datetime "updated_at", :null => false | 74 | + t.datetime "created_at" |
75 | + t.datetime "updated_at" | ||
76 | t.text "key" | 76 | t.text "key" |
77 | t.string "title" | 77 | t.string "title" |
78 | t.string "identifier" | 78 | t.string "identifier" |
@@ -89,8 +89,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | @@ -89,8 +89,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | ||
89 | t.integer "author_id" | 89 | t.integer "author_id" |
90 | t.integer "assignee_id" | 90 | t.integer "assignee_id" |
91 | t.string "title" | 91 | t.string "title" |
92 | - t.datetime "created_at", :null => false | ||
93 | - t.datetime "updated_at", :null => false | 92 | + t.datetime "created_at" |
93 | + t.datetime "updated_at" | ||
94 | t.text "st_commits", :limit => 2147483647 | 94 | t.text "st_commits", :limit => 2147483647 |
95 | t.text "st_diffs", :limit => 2147483647 | 95 | t.text "st_diffs", :limit => 2147483647 |
96 | t.integer "milestone_id" | 96 | t.integer "milestone_id" |
@@ -139,8 +139,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | @@ -139,8 +139,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | ||
139 | t.text "note" | 139 | t.text "note" |
140 | t.string "noteable_type" | 140 | t.string "noteable_type" |
141 | t.integer "author_id" | 141 | t.integer "author_id" |
142 | - t.datetime "created_at", :null => false | ||
143 | - t.datetime "updated_at", :null => false | 142 | + t.datetime "created_at" |
143 | + t.datetime "updated_at" | ||
144 | t.integer "project_id" | 144 | t.integer "project_id" |
145 | t.string "attachment" | 145 | t.string "attachment" |
146 | t.string "line_code" | 146 | t.string "line_code" |
@@ -158,8 +158,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | @@ -158,8 +158,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | ||
158 | t.string "name" | 158 | t.string "name" |
159 | t.string "path" | 159 | t.string "path" |
160 | t.text "description" | 160 | t.text "description" |
161 | - t.datetime "created_at", :null => false | ||
162 | - t.datetime "updated_at", :null => false | 161 | + t.datetime "created_at" |
162 | + t.datetime "updated_at" | ||
163 | t.integer "creator_id" | 163 | t.integer "creator_id" |
164 | t.string "default_branch" | 164 | t.string "default_branch" |
165 | t.boolean "issues_enabled", :default => true, :null => false | 165 | t.boolean "issues_enabled", :default => true, :null => false |
@@ -206,8 +206,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | @@ -206,8 +206,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | ||
206 | t.text "content" | 206 | t.text "content" |
207 | t.integer "author_id", :null => false | 207 | t.integer "author_id", :null => false |
208 | t.integer "project_id" | 208 | t.integer "project_id" |
209 | - t.datetime "created_at", :null => false | ||
210 | - t.datetime "updated_at", :null => false | 209 | + t.datetime "created_at" |
210 | + t.datetime "updated_at" | ||
211 | t.string "file_name" | 211 | t.string "file_name" |
212 | t.datetime "expires_at" | 212 | t.datetime "expires_at" |
213 | t.boolean "private", :default => true, :null => false | 213 | t.boolean "private", :default => true, :null => false |
@@ -228,9 +228,6 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | @@ -228,9 +228,6 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | ||
228 | t.datetime "created_at" | 228 | t.datetime "created_at" |
229 | end | 229 | end |
230 | 230 | ||
231 | - add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" | ||
232 | - add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context" | ||
233 | - | ||
234 | create_table "tags", :force => true do |t| | 231 | create_table "tags", :force => true do |t| |
235 | t.string "name" | 232 | t.string "name" |
236 | end | 233 | end |
@@ -262,44 +259,43 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | @@ -262,44 +259,43 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | ||
262 | end | 259 | end |
263 | 260 | ||
264 | create_table "users", :force => true do |t| | 261 | create_table "users", :force => true do |t| |
265 | - t.string "email", :default => "", :null => false | ||
266 | - t.string "encrypted_password", :default => "", :null => false | 262 | + t.string "email", :default => "", :null => false |
263 | + t.string "encrypted_password", :limit => 128, :default => "", :null => false | ||
267 | t.string "reset_password_token" | 264 | t.string "reset_password_token" |
268 | t.datetime "reset_password_sent_at" | 265 | t.datetime "reset_password_sent_at" |
269 | t.datetime "remember_created_at" | 266 | t.datetime "remember_created_at" |
270 | - t.integer "sign_in_count", :default => 0 | 267 | + t.integer "sign_in_count", :default => 0 |
271 | t.datetime "current_sign_in_at" | 268 | t.datetime "current_sign_in_at" |
272 | t.datetime "last_sign_in_at" | 269 | t.datetime "last_sign_in_at" |
273 | t.string "current_sign_in_ip" | 270 | t.string "current_sign_in_ip" |
274 | t.string "last_sign_in_ip" | 271 | t.string "last_sign_in_ip" |
275 | - t.datetime "created_at", :null => false | ||
276 | - t.datetime "updated_at", :null => false | 272 | + t.datetime "created_at" |
273 | + t.datetime "updated_at" | ||
277 | t.string "name" | 274 | t.string "name" |
278 | - t.boolean "admin", :default => false, :null => false | ||
279 | - t.integer "projects_limit", :default => 10 | ||
280 | - t.string "skype", :default => "", :null => false | ||
281 | - t.string "linkedin", :default => "", :null => false | ||
282 | - t.string "twitter", :default => "", :null => false | 275 | + t.boolean "admin", :default => false, :null => false |
276 | + t.integer "projects_limit", :default => 10 | ||
277 | + t.string "skype", :default => "", :null => false | ||
278 | + t.string "linkedin", :default => "", :null => false | ||
279 | + t.string "twitter", :default => "", :null => false | ||
283 | t.string "authentication_token" | 280 | t.string "authentication_token" |
284 | - t.integer "theme_id", :default => 1, :null => false | 281 | + t.integer "theme_id", :default => 1, :null => false |
285 | t.string "bio" | 282 | t.string "bio" |
286 | - t.integer "failed_attempts", :default => 0 | 283 | + t.integer "failed_attempts", :default => 0 |
287 | t.datetime "locked_at" | 284 | t.datetime "locked_at" |
288 | t.string "extern_uid" | 285 | t.string "extern_uid" |
289 | t.string "provider" | 286 | t.string "provider" |
290 | t.string "username" | 287 | t.string "username" |
291 | - t.boolean "can_create_group", :default => true, :null => false | ||
292 | - t.boolean "can_create_team", :default => true, :null => false | 288 | + t.boolean "can_create_group", :default => true, :null => false |
289 | + t.boolean "can_create_team", :default => true, :null => false | ||
293 | t.string "state" | 290 | t.string "state" |
294 | - t.integer "color_scheme_id", :default => 1, :null => false | ||
295 | - t.integer "notification_level", :default => 1, :null => false | 291 | + t.integer "color_scheme_id", :default => 1, :null => false |
292 | + t.integer "notification_level", :default => 1, :null => false | ||
296 | t.datetime "password_expires_at" | 293 | t.datetime "password_expires_at" |
297 | t.integer "created_by_id" | 294 | t.integer "created_by_id" |
298 | end | 295 | end |
299 | 296 | ||
300 | add_index "users", ["admin"], :name => "index_users_on_admin" | 297 | add_index "users", ["admin"], :name => "index_users_on_admin" |
301 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true | 298 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true |
302 | - add_index "users", ["extern_uid", "provider"], :name => "index_users_on_extern_uid_and_provider", :unique => true | ||
303 | add_index "users", ["name"], :name => "index_users_on_name" | 299 | add_index "users", ["name"], :name => "index_users_on_name" |
304 | add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true | 300 | add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true |
305 | add_index "users", ["username"], :name => "index_users_on_username" | 301 | add_index "users", ["username"], :name => "index_users_on_username" |
@@ -307,8 +303,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | @@ -307,8 +303,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | ||
307 | create_table "users_projects", :force => true do |t| | 303 | create_table "users_projects", :force => true do |t| |
308 | t.integer "user_id", :null => false | 304 | t.integer "user_id", :null => false |
309 | t.integer "project_id", :null => false | 305 | t.integer "project_id", :null => false |
310 | - t.datetime "created_at", :null => false | ||
311 | - t.datetime "updated_at", :null => false | 306 | + t.datetime "created_at" |
307 | + t.datetime "updated_at" | ||
312 | t.integer "project_access", :default => 0, :null => false | 308 | t.integer "project_access", :default => 0, :null => false |
313 | t.integer "notification_level", :default => 3, :null => false | 309 | t.integer "notification_level", :default => 3, :null => false |
314 | end | 310 | end |
@@ -320,8 +316,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | @@ -320,8 +316,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do | ||
320 | create_table "web_hooks", :force => true do |t| | 316 | create_table "web_hooks", :force => true do |t| |
321 | t.string "url" | 317 | t.string "url" |
322 | t.integer "project_id" | 318 | t.integer "project_id" |
323 | - t.datetime "created_at", :null => false | ||
324 | - t.datetime "updated_at", :null => false | 319 | + t.datetime "created_at" |
320 | + t.datetime "updated_at" | ||
325 | t.string "type", :default => "ProjectHook" | 321 | t.string "type", :default => "ProjectHook" |
326 | t.integer "service_id" | 322 | t.integer "service_id" |
327 | end | 323 | end |