Commit 7de75920 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor controller code that creates project/group members

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent eeaeb275
module MembershipActions module MembershipActions
extend ActiveSupport::Concern extend ActiveSupport::Concern
def create
status = Members::CreateService.new(membershipable, current_user, params).execute
redirect_url = polymorphic_url([membershipable, :members])
if status
redirect_to redirect_url, notice: 'Users were successfully added.'
else
redirect_to redirect_url, alert: 'No users specified.'
end
end
def request_access def request_access
membershipable.request_access(current_user) membershipable.request_access(current_user)
......
...@@ -21,21 +21,6 @@ class Groups::GroupMembersController < Groups::ApplicationController ...@@ -21,21 +21,6 @@ class Groups::GroupMembersController < Groups::ApplicationController
@group_member = @group.group_members.new @group_member = @group.group_members.new
end end
def create
if params[:user_ids].blank?
return redirect_to(group_group_members_path(@group), alert: 'No users specified.')
end
@group.add_users(
params[:user_ids].split(','),
params[:access_level],
current_user: current_user,
expires_at: params[:expires_at]
)
redirect_to group_group_members_path(@group), notice: 'Users were successfully added.'
end
def update def update
@group_member = @group.group_members.find(params[:id]) @group_member = @group.group_members.find(params[:id])
......
...@@ -10,18 +10,6 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -10,18 +10,6 @@ class Projects::ProjectMembersController < Projects::ApplicationController
redirect_to namespace_project_settings_members_path(@project.namespace, @project, sort: sort) redirect_to namespace_project_settings_members_path(@project.namespace, @project, sort: sort)
end end
def create
status = Members::CreateService.new(@project, current_user, params).execute
redirect_url = namespace_project_settings_members_path(@project.namespace, @project)
if status
redirect_to redirect_url, notice: 'Users were successfully added.'
else
redirect_to redirect_url, alert: 'No users or groups specified.'
end
end
def update def update
@project_member = @project.project_members.find(params[:id]) @project_member = @project.project_members.find(params[:id])
......
...@@ -181,7 +181,7 @@ class Project < ActiveRecord::Base ...@@ -181,7 +181,7 @@ class Project < ActiveRecord::Base
delegate :name, to: :owner, allow_nil: true, prefix: true delegate :name, to: :owner, allow_nil: true, prefix: true
delegate :count, to: :forks, prefix: true delegate :count, to: :forks, prefix: true
delegate :members, to: :team, prefix: true delegate :members, to: :team, prefix: true
delegate :add_user, to: :team delegate :add_user, :add_users, to: :team
delegate :add_guest, :add_reporter, :add_developer, :add_master, to: :team delegate :add_guest, :add_reporter, :add_developer, :add_master, to: :team
delegate :empty_repo?, to: :repository delegate :empty_repo?, to: :repository
......
module Members module Members
class CreateService < BaseService class CreateService < BaseService
def initialize(source, current_user, params = {})
@source = source
@current_user = current_user
@params = params
end
def execute def execute
return false if params[:user_ids].blank? return false if params[:user_ids].blank?
project.team.add_users( @source.add_users(
params[:user_ids].split(','), params[:user_ids].split(','),
params[:access_level], params[:access_level],
expires_at: params[:expires_at], expires_at: params[:expires_at],
......
---
title: Refactor code that creates project/group members
merge_request: 10735
author:
...@@ -55,7 +55,7 @@ describe Projects::ProjectMembersController do ...@@ -55,7 +55,7 @@ describe Projects::ProjectMembersController do
user_ids: '', user_ids: '',
access_level: Gitlab::Access::GUEST access_level: Gitlab::Access::GUEST
expect(response).to set_flash.to 'No users or groups specified.' expect(response).to set_flash.to 'No users specified.'
expect(response).to redirect_to(namespace_project_settings_members_path(project.namespace, project)) expect(response).to redirect_to(namespace_project_settings_members_path(project.namespace, project))
end end
end end
......
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