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 | 132 | rules = [] |
| 133 | 133 | |
| 134 | 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 | 136 | rules << [ |
| 137 | 137 | :manage_group, |
| 138 | 138 | :manage_namespace | ... | ... |
app/models/group.rb
| ... | ... | @@ -13,6 +13,8 @@ |
| 13 | 13 | # |
| 14 | 14 | |
| 15 | 15 | class Group < Namespace |
| 16 | + has_many :users_groups, dependent: :destroy | |
| 17 | + has_many :users, through: :users_groups | |
| 16 | 18 | |
| 17 | 19 | def add_users_to_project_teams(user_ids, project_access) |
| 18 | 20 | UsersProject.add_users_into_projects( |
| ... | ... | @@ -35,4 +37,8 @@ class Group < Namespace |
| 35 | 37 | def truncate_teams |
| 36 | 38 | UsersProject.truncate_teams(project_ids) |
| 37 | 39 | end |
| 40 | + | |
| 41 | + def owners | |
| 42 | + @owners ||= (users_groups.owners.map(&:user) << owner) | |
| 43 | + end | |
| 38 | 44 | end | ... | ... |
| ... | ... | @@ -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 | 53 | t.integer "assignee_id" |
| 54 | 54 | t.integer "author_id" |
| 55 | 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 | 58 | t.integer "position", :default => 0 |
| 59 | 59 | t.string "branch_name" |
| 60 | 60 | t.text "description" |
| ... | ... | @@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do |
| 71 | 71 | |
| 72 | 72 | create_table "keys", :force => true do |t| |
| 73 | 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 | 76 | t.text "key" |
| 77 | 77 | t.string "title" |
| 78 | 78 | t.string "identifier" |
| ... | ... | @@ -89,8 +89,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do |
| 89 | 89 | t.integer "author_id" |
| 90 | 90 | t.integer "assignee_id" |
| 91 | 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 | 94 | t.text "st_commits", :limit => 2147483647 |
| 95 | 95 | t.text "st_diffs", :limit => 2147483647 |
| 96 | 96 | t.integer "milestone_id" |
| ... | ... | @@ -139,8 +139,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do |
| 139 | 139 | t.text "note" |
| 140 | 140 | t.string "noteable_type" |
| 141 | 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 | 144 | t.integer "project_id" |
| 145 | 145 | t.string "attachment" |
| 146 | 146 | t.string "line_code" |
| ... | ... | @@ -158,8 +158,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do |
| 158 | 158 | t.string "name" |
| 159 | 159 | t.string "path" |
| 160 | 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 | 163 | t.integer "creator_id" |
| 164 | 164 | t.string "default_branch" |
| 165 | 165 | t.boolean "issues_enabled", :default => true, :null => false |
| ... | ... | @@ -206,8 +206,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do |
| 206 | 206 | t.text "content" |
| 207 | 207 | t.integer "author_id", :null => false |
| 208 | 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 | 211 | t.string "file_name" |
| 212 | 212 | t.datetime "expires_at" |
| 213 | 213 | t.boolean "private", :default => true, :null => false |
| ... | ... | @@ -228,9 +228,6 @@ ActiveRecord::Schema.define(:version => 20130614132337) do |
| 228 | 228 | t.datetime "created_at" |
| 229 | 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 | 231 | create_table "tags", :force => true do |t| |
| 235 | 232 | t.string "name" |
| 236 | 233 | end |
| ... | ... | @@ -262,44 +259,43 @@ ActiveRecord::Schema.define(:version => 20130614132337) do |
| 262 | 259 | end |
| 263 | 260 | |
| 264 | 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 | 264 | t.string "reset_password_token" |
| 268 | 265 | t.datetime "reset_password_sent_at" |
| 269 | 266 | t.datetime "remember_created_at" |
| 270 | - t.integer "sign_in_count", :default => 0 | |
| 267 | + t.integer "sign_in_count", :default => 0 | |
| 271 | 268 | t.datetime "current_sign_in_at" |
| 272 | 269 | t.datetime "last_sign_in_at" |
| 273 | 270 | t.string "current_sign_in_ip" |
| 274 | 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 | 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 | 280 | t.string "authentication_token" |
| 284 | - t.integer "theme_id", :default => 1, :null => false | |
| 281 | + t.integer "theme_id", :default => 1, :null => false | |
| 285 | 282 | t.string "bio" |
| 286 | - t.integer "failed_attempts", :default => 0 | |
| 283 | + t.integer "failed_attempts", :default => 0 | |
| 287 | 284 | t.datetime "locked_at" |
| 288 | 285 | t.string "extern_uid" |
| 289 | 286 | t.string "provider" |
| 290 | 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 | 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 | 293 | t.datetime "password_expires_at" |
| 297 | 294 | t.integer "created_by_id" |
| 298 | 295 | end |
| 299 | 296 | |
| 300 | 297 | add_index "users", ["admin"], :name => "index_users_on_admin" |
| 301 | 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 | 299 | add_index "users", ["name"], :name => "index_users_on_name" |
| 304 | 300 | add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true |
| 305 | 301 | add_index "users", ["username"], :name => "index_users_on_username" |
| ... | ... | @@ -307,8 +303,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do |
| 307 | 303 | create_table "users_projects", :force => true do |t| |
| 308 | 304 | t.integer "user_id", :null => false |
| 309 | 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 | 308 | t.integer "project_access", :default => 0, :null => false |
| 313 | 309 | t.integer "notification_level", :default => 3, :null => false |
| 314 | 310 | end |
| ... | ... | @@ -320,8 +316,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do |
| 320 | 316 | create_table "web_hooks", :force => true do |t| |
| 321 | 317 | t.string "url" |
| 322 | 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 | 321 | t.string "type", :default => "ProjectHook" |
| 326 | 322 | t.integer "service_id" |
| 327 | 323 | end | ... | ... |