Update user access level when adding to group.
This commit is contained in:
parent
2c0c9e26e8
commit
97cf31c4cb
2 changed files with 14 additions and 1 deletions
|
@ -26,7 +26,8 @@ class Group < Namespace
|
|||
|
||||
def add_users(user_ids, group_access)
|
||||
user_ids.compact.each do |user_id|
|
||||
self.users_groups.create(user_id: user_id, group_access: group_access)
|
||||
user = self.users_groups.find_or_initialize_by_user_id(user_id)
|
||||
user.update_attributes(group_access: group_access)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -42,4 +42,16 @@ describe Group do
|
|||
|
||||
it { group.users_groups.masters.map(&:user).should include(user) }
|
||||
end
|
||||
|
||||
describe :add_users do
|
||||
let(:user) { create(:user) }
|
||||
before { group.add_users([user.id], UsersGroup::GUEST) }
|
||||
|
||||
it "should update the group permission" do
|
||||
group.users_groups.guests.map(&:user).should include(user)
|
||||
group.add_users([user.id], UsersGroup::DEVELOPER)
|
||||
group.users_groups.developers.map(&:user).should include(user)
|
||||
group.users_groups.guests.map(&:user).should_not include(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue