Commit a5dbe353549ad71ce2868d67dee5226ad8d46e63
1 parent
db03bfa8
Exists in
master
and in
4 other branches
Improve change group ownership logic
Showing
2 changed files
with
12 additions
and
1 deletions
Show diff stats
app/controllers/admin/groups_controller.rb
@@ -34,7 +34,7 @@ class Admin::GroupsController < Admin::ApplicationController | @@ -34,7 +34,7 @@ class Admin::GroupsController < Admin::ApplicationController | ||
34 | owner_id =group_params.delete(:owner_id) | 34 | owner_id =group_params.delete(:owner_id) |
35 | 35 | ||
36 | if owner_id | 36 | if owner_id |
37 | - @group.owner = User.find(owner_id) | 37 | + @group.change_owner(User.find(owner_id)) |
38 | end | 38 | end |
39 | 39 | ||
40 | if @group.update_attributes(group_params) | 40 | if @group.update_attributes(group_params) |
app/models/group.rb
@@ -32,6 +32,17 @@ class Group < Namespace | @@ -32,6 +32,17 @@ class Group < Namespace | ||
32 | end | 32 | end |
33 | end | 33 | end |
34 | 34 | ||
35 | + def change_owner(user) | ||
36 | + self.owner = user | ||
37 | + membership = users_groups.where(user_id: user.id).first | ||
38 | + | ||
39 | + if membership | ||
40 | + membership.update_attributes(group_access: UsersGroup::OWNER) | ||
41 | + else | ||
42 | + add_owner | ||
43 | + end | ||
44 | + end | ||
45 | + | ||
35 | private | 46 | private |
36 | 47 | ||
37 | def add_owner | 48 | def add_owner |