Commit ab93ca0f authored by Małgorzata Ksionek's avatar Małgorzata Ksionek

Add new scope to gather data properly

Add basic spec

Fix variable name

Refactor compliance controller

Add specs and try to order things as they should be ordered

Add empty state

Add menu link

Add specs to the empty state
parent e3574e79
# frozen_string_literal: true
class Groups::Security::ComplianceDashboardController < Groups::ApplicationController
include SortingHelper
include Gitlab::IssuableMetadata
layout 'group'
......@@ -12,13 +11,17 @@ class Groups::Security::ComplianceDashboardController < Groups::ApplicationContr
finder_options = {
scope: :all,
state: :merged,
sort: sort_value_recently_updated
sort: :by_merge_date,
include_subgroups: true,
attempt_group_search_optimizations: true
}
finder_options[:group_id] = @group.id
finder_options[:include_subgroups] = true
finder_options[:attempt_group_search_optimizations] = true
@merge_requests = MergeRequestsFinder.new(current_user, finder_options).execute.preload(preload_for_collection).page(params[:page])
@issuable_meta_data = issuable_meta_data(@merge_requests, 'MergeRequest', current_user)
@merge_requests = MergeRequestsFinder.new(current_user, finder_options).execute
.select('DISTINCT ON (merge_requests.target_project_id) merge_requests.*')
.preload(preload_for_collection)
@merge_requests = @merge_requests.order('merge_request_metrics.merged_at').page(params[:page])
end
private
......
......@@ -53,6 +53,7 @@ module EE
end
end
<<<<<<< HEAD
scope :order_review_time_desc, -> do
joins(:metrics).reorder(::Gitlab::Database.nulls_last_order('merge_request_metrics.first_comment_at'))
end
......@@ -62,6 +63,9 @@ module EE
:author, :approved_by_users, :metrics,
latest_merge_request_diff: :merge_request_diff_files, target_project: :namespace, milestone: :project)
end
=======
scope :by_merge_date, -> { joins(:metrics).order("merge_requests.target_project_id, merge_request_metrics.merged_at DESC") }
>>>>>>> Add new scope to gather data properly
end
class_methods do
......
- max_render = 4
- max_render = 2
- approvers_rendering_overflow = merge_request.approved_by_users.size > max_render
- render_count = approvers_rendering_overflow ? max_render - 1 : max_render
- more_approvers_count = merge_request.approved_by_users.size - render_count
......@@ -8,4 +8,4 @@
= link_to_member(project, approver, name: true, title: "Approved by :name")
- if more_approvers_count.positive?
%span{ class: 'avatar-counter has-tooltip', data: { container: 'body', placement: 'bottom', 'line-type' => 'old', 'original-title' => "+#{more_assignees_count} more approvers", qa_selector: 'avatar_counter' } } +#{more_approvers_count}
%span{ class: 'avatar-counter has-tooltip', data: { container: 'body', placement: 'bottom', 'line-type' => 'old', 'original-title' => "+#{more_approvers_count} more approvers", qa_selector: 'avatar_counter' } } +#{more_approvers_count}
.row.empty-state.merge-requests
.col-12
.svg-content
= image_tag 'illustrations/merge_requests.svg'
.col-12
.text-content
%h4
= _("Merge requests are a place to propose changes you've made to a project and discuss those changes with others")
%p
= _("Interested parties can even contribute by pushing commits if they want to.")
......@@ -6,4 +6,4 @@
= paginate @merge_requests, theme: "gitlab"
- else
= render 'shared/empty_states/merge_requests'
= render 'empty_state'
- breadcrumb_title _("Compliance Dashboard")
- page_title _("Compliance Dashboard")
= render "merge_requests"
- if @group.feature_available?(:security_dashboard)
= nav_link(path: 'groups/security/dashboard#show') do
= link_to group_security_dashboard_path(@group), data: { qa_selector: 'security_dashboard_link' } do
- if @group.feature_available?(:group_level_compliance_dashboard)
= nav_link(path: 'groups/security/compliance_dashboard#show') do
= link_to group_security_compliance_dashboard_path(@group), data: { qa_selector: 'security_dashboard_link' } do
.nav-icon-container
= sprite_icon('shield')
%span.nav-item-name
= _('Security')
%ul.sidebar-sub-level-items.is-fly-out-only
= nav_link(path: 'groups/security/dashboard#show') do
= link_to group_security_dashboard_path(@group), title: _('Security') do
%strong.fly-out-top-item-name
= _('Security')
= _('Security & Compliance')
%ul.sidebar-sub-level-items
- if @group.feature_available?(:security_dashboard)
= nav_link(path: 'groups/security/dashboard#show') do
= link_to group_security_dashboard_path(@group), title: _('Security') do
%span= _('Security')
= nav_link(path: 'groups/security/compliance_dashboard#show') do
= link_to group_security_compliance_dashboard_path(@group), title: _('Security') do
%span= _('Compliance')
# frozen_string_literal: true
require 'spec_helper'
describe Groups::Security::ComplianceDashboardController do
let(:user) { create(:user) }
let(:group) { create(:group) }
before do
sign_in(user)
end
describe 'GET show' do
subject { get :show, params: { group_id: group.to_param } }
context 'when compliance dashboard feature is enabled' do
before do
stub_licensed_features(group_level_compliance_dashboard: true)
end
context 'and user is allowed to access group compliance dashboard' do
before do
group.add_owner(user)
end
it { is_expected.to have_gitlab_http_status(200) }
context 'when there are no merge requests' do
render_views
it 'renders empty state' do
subject
expect(response.body).to have_css("div.empty-state")
end
end
context 'when there are merge requests from projects in group' do
let(:project) { create(:project, namespace: group) }
let(:project_2) { create(:project, namespace: group) }
let(:mr_1) { create(:merge_request, source_project: project, state: :merged) }
let(:mr_2) { create(:merge_request, source_project: project_2, state: :merged) }
let(:mr_3) { create(:merge_request, source_project: project, source_branch: 'A', state: :merged) }
let(:mr_4) { create(:merge_request, source_project: project_2, source_branch: 'A', state: :merged) }
before do
mr_1.metrics.update!(merged_at: 20.minutes.ago)
mr_2.metrics.update!(merged_at: 40.minutes.ago)
mr_3.metrics.update!(merged_at: 30.minutes.ago)
mr_4.metrics.update!(merged_at: 50.minutes.ago)
end
it 'shows only most recent Merge Request from each project' do
subject
expect(assigns(:merge_requests)).to contain_exactly(mr_1, mr_2)
end
context 'when there are merge requests from projects in group and subgroups' do
let(:subgroup) { create(:group, parent: group) }
let(:sub_project) { create(:project, namespace: subgroup) }
let(:mr_5) { create(:merge_request, source_project: sub_project, state: :merged) }
let(:mr_6) { create(:merge_request, source_project: sub_project, state: :merged) }
before do
mr_5.metrics.update!(merged_at: 10.minutes.ago)
mr_6.metrics.update!(merged_at: 30.minutes.ago)
end
xit 'shows only most recent Merge Request from each project' do
subject
expect(assigns(:merge_requests)).to eq([mr_5, mr_1, mr_2])
end
end
end
end
context 'when user is not allowed to access group compliance dashboard' do
it { is_expected.to have_gitlab_http_status(403) }
end
end
context 'when security compliance feature is disabled' do
it { is_expected.to have_gitlab_http_status(403) }
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