Commit b2c8dc6f authored by Adam Niedzielski's avatar Adam Niedzielski

Replace optional parameters with keyword arguments.

parent 420e5903
...@@ -36,7 +36,12 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -36,7 +36,12 @@ class Projects::ProjectMembersController < Projects::ApplicationController
end end
def create def create
@project.team.add_users(params[:user_ids].split(','), params[:access_level], current_user, params[:expires_at]) @project.team.add_users(
params[:user_ids].split(','),
params[:access_level],
expires_at: params[:expires_at],
current_user: current_user
)
redirect_to namespace_project_project_members_path(@project.namespace, @project) redirect_to namespace_project_project_members_path(@project.namespace, @project)
end end
......
...@@ -97,7 +97,7 @@ class Group < Namespace ...@@ -97,7 +97,7 @@ class Group < Namespace
def add_users(user_ids, access_level, current_user = nil) def add_users(user_ids, access_level, current_user = nil)
user_ids.each do |user_id| user_ids.each do |user_id|
Member.add_user(self.group_members, user_id, access_level, current_user) Member.add_user(self.group_members, user_id, access_level, current_user: current_user)
end end
end end
......
...@@ -74,7 +74,7 @@ class Member < ActiveRecord::Base ...@@ -74,7 +74,7 @@ class Member < ActiveRecord::Base
user user
end end
def add_user(members, user_id, access_level, current_user = nil, expires_at = nil) def add_user(members, user_id, access_level, current_user: nil, expires_at: 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
......
...@@ -33,7 +33,7 @@ class ProjectMember < Member ...@@ -33,7 +33,7 @@ class ProjectMember < Member
# :master # :master
# ) # )
# #
def add_users_into_projects(project_ids, user_ids, access, current_user = nil, expires_at = nil) def add_users_into_projects(project_ids, user_ids, access, current_user: nil, expires_at: nil)
access_level = if roles_hash.has_key?(access) access_level = if roles_hash.has_key?(access)
roles_hash[access] roles_hash[access]
elsif roles_hash.values.include?(access.to_i) elsif roles_hash.values.include?(access.to_i)
...@@ -49,7 +49,13 @@ class ProjectMember < Member ...@@ -49,7 +49,13 @@ class ProjectMember < Member
project = Project.find(project_id) project = Project.find(project_id)
users.each do |user| users.each do |user|
Member.add_user(project.project_members, user, access_level, current_user, expires_at) Member.add_user(
project.project_members,
user,
access_level,
current_user: current_user,
expires_at: expires_at
)
end end
end end
end end
......
...@@ -15,7 +15,7 @@ class ProjectTeam ...@@ -15,7 +15,7 @@ class ProjectTeam
users, access, current_user = *args users, access, current_user = *args
if users.respond_to?(:each) if users.respond_to?(:each)
add_users(users, access, current_user) add_users(users, access, current_user: current_user)
else else
add_user(users, access, current_user) add_user(users, access, current_user)
end end
...@@ -33,18 +33,18 @@ class ProjectTeam ...@@ -33,18 +33,18 @@ class ProjectTeam
member member
end end
def add_users(users, access, current_user = nil, expires_at = nil) def add_users(users, access, current_user: nil, expires_at: nil)
ProjectMember.add_users_into_projects( ProjectMember.add_users_into_projects(
[project.id], [project.id],
users, users,
access, access,
current_user, current_user: current_user,
expires_at expires_at: expires_at
) )
end end
def add_user(user, access, current_user = nil) def add_user(user, access, current_user = nil)
add_users([user], access, current_user) add_users([user], access, current_user: current_user)
end end
# Remove all users from project team # Remove all users from project team
......
...@@ -493,7 +493,12 @@ describe Notify do ...@@ -493,7 +493,12 @@ describe Notify do
end end
def invite_to_project(project:, email:, inviter:) def invite_to_project(project:, email:, inviter:)
ProjectMember.add_user(project.project_members, 'toto@example.com', Gitlab::Access::DEVELOPER, inviter) Member.add_user(
project.project_members,
'toto@example.com',
Gitlab::Access::DEVELOPER,
current_user: inviter
)
project.project_members.invite.last project.project_members.invite.last
end end
...@@ -740,7 +745,12 @@ describe Notify do ...@@ -740,7 +745,12 @@ describe Notify do
end end
def invite_to_group(group:, email:, inviter:) def invite_to_group(group:, email:, inviter:)
GroupMember.add_user(group.group_members, 'toto@example.com', Gitlab::Access::DEVELOPER, inviter) Member.add_user(
group.group_members,
'toto@example.com',
Gitlab::Access::DEVELOPER,
current_user: inviter
)
group.group_members.invite.last group.group_members.invite.last
end end
......
...@@ -65,11 +65,21 @@ describe Member, models: true do ...@@ -65,11 +65,21 @@ describe Member, models: true do
@master_user = create(:user).tap { |u| project.team << [u, :master] } @master_user = create(:user).tap { |u| project.team << [u, :master] }
@master = project.members.find_by(user_id: @master_user.id) @master = project.members.find_by(user_id: @master_user.id)
ProjectMember.add_user(project.members, 'toto1@example.com', Gitlab::Access::DEVELOPER, @master_user) Member.add_user(
project.members,
'toto1@example.com',
Gitlab::Access::DEVELOPER,
current_user: @master_user
)
@invited_member = project.members.invite.find_by_invite_email('toto1@example.com') @invited_member = project.members.invite.find_by_invite_email('toto1@example.com')
accepted_invite_user = build(:user) accepted_invite_user = build(:user)
ProjectMember.add_user(project.members, 'toto2@example.com', Gitlab::Access::DEVELOPER, @master_user) Member.add_user(
project.members,
'toto2@example.com',
Gitlab::Access::DEVELOPER,
current_user: @master_user
)
@accepted_invite_member = project.members.invite.find_by_invite_email('toto2@example.com').tap { |u| u.accept_invite!(accepted_invite_user) } @accepted_invite_member = project.members.invite.find_by_invite_email('toto2@example.com').tap { |u| u.accept_invite!(accepted_invite_user) }
requested_user = create(:user).tap { |u| project.request_access(u) } requested_user = create(:user).tap { |u| project.request_access(u) }
......
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