Commit 6aa9c21a authored by James Lopez's avatar James Lopez

fix issue with adding members to project (spotted by test)

parent de990aa1
...@@ -73,7 +73,7 @@ class Member < ActiveRecord::Base ...@@ -73,7 +73,7 @@ class Member < ActiveRecord::Base
def add_user(members, user_id, access_level, current_user = nil) def add_user(members, user_id, access_level, current_user = nil)
user = user_for_id(user_id) user = user_for_id(user_id)
# `user` can be either a User object or an email to be invited # `user` can be either a User object or an email to be invited
if user.is_a?(User) if user.is_a?(User)
member = members.find_or_initialize_by(user_id: user.id) member = members.find_or_initialize_by(user_id: user.id)
...@@ -81,13 +81,22 @@ class Member < ActiveRecord::Base ...@@ -81,13 +81,22 @@ class Member < ActiveRecord::Base
member = members.build member = members.build
member.invite_email = user member.invite_email = user
end end
if !current_user || current_user.can?(:update_group_member, member)
project = members.first.respond_to?(:project)? members.first.project : nil
if can_update_member?(current_user, member, project)
member.created_by ||= current_user member.created_by ||= current_user
member.access_level = access_level member.access_level = access_level
member.save member.save
end end
end end
private
def can_update_member?(current_user, member, project)
!current_user || current_user.can?(:update_group_member, member) ||
(project && current_user.can?(:admin_project_member, project))
end
end end
def invite? def invite?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment