Commit 4400cf8d authored by Brandon Labuschagne's avatar Brandon Labuschagne

Merge branch...

Merge branch '324974-hide-new-merge-request-button-on-analytics-code_reviews-from-auditors' into 'master'

Hide "New merge request" button from Auditors on "Code review" page

See merge request gitlab-org/gitlab!56999
parents ada427b8 6d7b828a
......@@ -24,7 +24,8 @@ export default {
},
newMergeRequestUrl: {
type: String,
required: true,
required: false,
default: null,
},
emptyStateSvgPath: {
type: String,
......
# frozen_string_literal: true
module Analytics
module CodeReviewHelper
def code_review_app_data(project)
{
project_id: project.id,
project_path: project_path(project),
new_merge_request_url: merge_request_source_project_for_project(project) ? namespace_project_new_merge_request_path(project.namespace) : nil,
empty_state_svg_path: image_path('illustrations/merge_requests.svg'),
milestone_path: project_milestones_path(project),
labels_path: project_labels_path(project)
}
end
end
end
......@@ -5,4 +5,4 @@
%h3.mb-2
= _('Code Review')
%span.text-secondary= _('Review time is defined as the time it takes from first comment until merged.')
#js-code-review-analytics{ data: { project_id: @project.id, project_path: project_path(@project), new_merge_request_url: namespace_project_new_merge_request_path(@project.namespace), empty_state_svg_path: image_path('illustrations/merge_requests.svg'), milestone_path: project_milestones_path(@project), labels_path: project_labels_path(@project) } }
#js-code-review-analytics{ data: code_review_app_data(@project) }
---
title: Hide "New merge request" button from Auditors on Code Review Analytics page
merge_request: 56999
author:
type: fixed
......@@ -2,38 +2,89 @@
require 'spec_helper'
RSpec.describe 'CodeReviewAnalytics Filtered Search', :js do
RSpec.describe 'CodeReviewAnalytics', :js do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:project) { create(:project, :public) }
let_it_be(:auditor) { create(:user, auditor: true) }
before do
stub_licensed_features(code_review_analytics: true)
project.add_reporter(user)
project.add_developer(user)
end
context 'filtered search' do
before do
sign_in(user)
visit project_analytics_code_reviews_path(project)
end
it 'renders the filtered search bar correctly' do
page.within('.content-wrapper .content .vue-filtered-search-bar-container') do
expect(page).to have_selector('.gl-search-box-by-click')
expect(page.find('.gl-filtered-search-term-input')[:placeholder]).to eq('Filter results')
end
end
it 'displays label and milestone in search hint' do
page.within('.content-wrapper .content .vue-filtered-search-bar-container') do
page.find('.gl-search-box-by-click').click
expect(page).to have_selector('.gl-filtered-search-suggestion-list')
sign_in(user)
hints = page.find_all('.gl-filtered-search-suggestion-list > li')
visit project_analytics_code_reviews_path(project)
expect(hints.length).to eq(2)
expect(hints[0]).to have_content('Milestone')
expect(hints[1]).to have_content('Label')
end
end
end
it 'renders the filtered search bar correctly' do
page.within('.content-wrapper .content .vue-filtered-search-bar-container') do
expect(page).to have_selector('.gl-search-box-by-click')
expect(page.find('.gl-filtered-search-term-input')[:placeholder]).to eq('Filter results')
shared_examples 'empty state' do |expect_button:|
it "shows empty state #{expect_button ? 'with' : 'without'} \"New merge request\" button" do
visit project_analytics_code_reviews_path(project)
expect(page).to have_content("You don't have any open merge requests")
if expect_button
expect(page).to have_link('New merge request')
else
expect(page).not_to have_link('New merge request')
end
end
end
it 'displays label and milestone in search hint' do
page.within('.content-wrapper .content .vue-filtered-search-bar-container') do
page.find('.gl-search-box-by-click').click
context 'empty state' do
context 'when a regular user is signed in' do
before do
sign_in(user)
end
it_behaves_like 'empty state', expect_button: true
end
context 'when an "Auditor" is signed in' do
before do
sign_in(auditor)
end
expect(page).to have_selector('.gl-filtered-search-suggestion-list')
context 'when "Auditor" is a member of the project' do
before do
project.add_developer(auditor)
end
hints = page.find_all('.gl-filtered-search-suggestion-list > li')
it_behaves_like 'empty state', expect_button: true
end
context 'when "Auditor" is not a member of the project' do
it_behaves_like 'empty state', expect_button: false
end
end
expect(hints.length).to eq(2)
expect(hints[0]).to have_content('Milestone')
expect(hints[1]).to have_content('Label')
context 'when no user is signed in' do
it_behaves_like 'empty state', expect_button: false
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Analytics::CodeReviewHelper do
let_it_be(:project) { build(:project) }
describe '#code_review_app_data' do
using RSpec::Parameterized::TableSyntax
before do
allow(helper).to receive(:project_path).with(project).and_return('/mock/project')
allow(helper).to receive(:namespace_project_new_merge_request_path).with(project.namespace).and_return('/mock/project/-/merge_requests/new')
allow(helper).to receive(:image_path).with('illustrations/merge_requests.svg').and_return('/assets/illustrations/mock.svg')
allow(helper).to receive(:project_milestones_path).with(project).and_return('/mock/project/-/milestones')
allow(helper).to receive(:project_labels_path).with(project).and_return('/mock/project/-/labels')
end
where(:merge_request_source_project_for_project_return_value, :new_merge_request_url_expected) do
true | '/mock/project/-/merge_requests/new'
false | nil
end
with_them do
context "when `merge_request_source_project_for_project` is #{params[:merge_request_source_project_for_project_return_value]}" do
before do
allow(helper).to receive(:merge_request_source_project_for_project).with(project).and_return(merge_request_source_project_for_project_return_value)
end
it "returns expected hash with `new_merge_request_url` set to #{params[:new_merge_request_url_expected]}" do
expect(helper.code_review_app_data(project)).to match(
{
project_id: project.id,
project_path: '/mock/project',
empty_state_svg_path: '/assets/illustrations/mock.svg',
milestone_path: '/mock/project/-/milestones',
labels_path: '/mock/project/-/labels'
}.merge({ new_merge_request_url: new_merge_request_url_expected })
)
end
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