diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 2c43b1a2067..91d15e0e4ea 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -315,6 +315,10 @@ module ProjectsHelper ) % { default_label: default_label } end + def can_import_members? + Ability.allowed?(current_user, :admin_project_member, @project) + end + private def get_project_nav_tabs(project, current_user) diff --git a/app/views/projects/project_members/_new_project_member.html.haml b/app/views/projects/project_members/_new_project_member.html.haml index 0590578c3fe..efabb7f7b19 100644 --- a/app/views/projects/project_members/_new_project_member.html.haml +++ b/app/views/projects/project_members/_new_project_member.html.haml @@ -19,4 +19,5 @@ = text_field_tag :expires_at, nil, class: 'form-control js-access-expiration-date', placeholder: 'Expiration date' %i.clear-icon.js-clear-input = f.submit _("Add to project"), class: "btn btn-success qa-add-member-button" - = link_to _("Import"), import_project_project_members_path(@project), class: "btn btn-default", title: _("Import members from another project") + - if can_import_members? + = link_to _("Import"), import_project_project_members_path(@project), class: "btn btn-default", title: _("Import members from another project") diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 554cb861563..83271aa24a3 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -799,4 +799,24 @@ describe ProjectsHelper do it { is_expected.to eq(result) } 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