Commit d48130c3 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'new-proj-member-scb' into 'master'

Resolve CE/EE diffs in new proj member import

Closes #6358

See merge request gitlab-org/gitlab-ee!12607
parents 3deeb6ba 31d20b97
...@@ -317,6 +317,10 @@ module ProjectsHelper ...@@ -317,6 +317,10 @@ module ProjectsHelper
) % { default_label: default_label } ) % { default_label: default_label }
end end
def can_import_members?
Ability.allowed?(current_user, :admin_project_member, @project)
end
private private
def get_project_nav_tabs(project, current_user) def get_project_nav_tabs(project, current_user)
......
...@@ -19,5 +19,5 @@ ...@@ -19,5 +19,5 @@
= text_field_tag :expires_at, nil, class: 'form-control js-access-expiration-date', placeholder: 'Expiration date' = text_field_tag :expires_at, nil, class: 'form-control js-access-expiration-date', placeholder: 'Expiration date'
%i.clear-icon.js-clear-input %i.clear-icon.js-clear-input
= f.submit _("Add to project"), class: "btn btn-success qa-add-member-button" = f.submit _("Add to project"), class: "btn btn-success qa-add-member-button"
- if can?(current_user, :admin_project_member, @project) && !membership_locked? - if can_import_members?
= link_to _("Import"), import_project_project_members_path(@project), class: "btn btn-default", title: _("Import members from another project") = link_to _("Import"), import_project_project_members_path(@project), class: "btn btn-default", title: _("Import members from another project")
...@@ -244,5 +244,10 @@ module EE ...@@ -244,5 +244,10 @@ module EE
@project_incident_management_setting ||= @project.incident_management_setting || @project_incident_management_setting ||= @project.incident_management_setting ||
@project.build_incident_management_setting @project.build_incident_management_setting
end end
override :can_import_members?
def can_import_members?
super && !membership_locked?
end
end end
end end
...@@ -43,4 +43,24 @@ describe ProjectsHelper do ...@@ -43,4 +43,24 @@ describe ProjectsHelper do
end end
end end
end end
describe '#can_import_members?' do
let(:project) { create(:project) }
let(:owner) { project.owner }
before do
helper.instance_variable_set(:@project, project)
allow(helper).to receive(:current_user) { owner }
end
it 'returns false if membership is locked' do
allow(helper).to receive(:membership_locked?) { true }
expect(helper.can_import_members?).to eq false
end
it 'returns true if membership is not locked' do
allow(helper).to receive(:membership_locked?) { false }
expect(helper.can_import_members?).to eq true
end
end
end end
...@@ -799,4 +799,24 @@ describe ProjectsHelper do ...@@ -799,4 +799,24 @@ describe ProjectsHelper do
it { is_expected.to eq(result) } it { is_expected.to eq(result) }
end end
end end
describe '#can_import_members?' do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:owner) { project.owner }
before do
helper.instance_variable_set(:@project, project)
end
it 'returns false if user cannot admin_project_member' do
allow(helper).to receive(:current_user) { user }
expect(helper.can_import_members?).to eq false
end
it 'returns true if user can admin_project_member' do
allow(helper).to receive(:current_user) { owner }
expect(helper.can_import_members?).to eq true
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