Commit fe4f5d6e authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '194160-code-review-api-mock' into 'master'

Code Review analytics skeleton

See merge request gitlab-org/gitlab!22480
parents 9c1b7a18 daeb5e92
......@@ -290,6 +290,8 @@
= render_if_exists 'layouts/nav/sidebar/project_packages_link'
= render_if_exists 'layouts/nav/sidebar/project_analytics_link' # EE-specific
- if project_nav_tab? :wiki
- wiki_url = project_wiki_path(@project, :home)
= nav_link(controller: :wikis) do
......
# frozen_string_literal: true
module Projects
module Analytics
class CodeReviewsController < Projects::ApplicationController
before_action :authorize_read_code_review_analytics!
def index
end
end
end
end
......@@ -59,6 +59,10 @@ module EE
nav_tabs << :packages
end
if ::Feature.enabled?(:code_review_analytics, project)
nav_tabs << :code_review
end
if can?(current_user, :read_feature_flag, project) && !nav_tabs.include?(:operations)
nav_tabs << :operations
end
......
......@@ -12,6 +12,7 @@ class License < ApplicationRecord
audit_events
burndown_charts
code_owners
code_review_analytics
contribution_analytics
description_diffs
elastic_search
......
......@@ -95,6 +95,11 @@ module EE
!@subject.design_management_enabled?
end
with_scope :subject
condition(:code_review_analytics_enabled) do
@subject.feature_available?(:code_review_analytics, @user)
end
condition(:group_timelogs_available) do
@subject.feature_available?(:group_timelogs)
end
......@@ -304,6 +309,8 @@ module EE
end
rule { build_service_proxy_enabled }.enable :build_service_proxy_enabled
rule { can?(:read_merge_request) & code_review_analytics_enabled }.enable :read_code_review_analytics
end
override :lookup_access_level!
......
- if Feature.enabled?(:code_review_analytics) && can?(current_user, :read_code_review_analytics, @project)
- project_analytics_link = namespace_project_analytics_code_reviews_path(@project.namespace, @project)
= nav_link controller: :code_review do
= link_to project_analytics_link, data: { qa_selector: 'project_analytics_link' } do
.nav-icon-container
= sprite_icon('chart')
%span.nav-item-name
= _('Project Analytics')
%ul.sidebar-sub-level-items
= nav_link(controller: :code_review, html_options: { class: "fly-out-top-item" } ) do
= link_to project_analytics_link do
%strong.fly-out-top-item-name
= _('Project Analytics')
%li.divider.fly-out-top-item
- if project_nav_tab?(:code_review)
= nav_link controller: :code_review do
= link_to project_analytics_link, title: _('Code Review') do
%span= _('Code Review')
- breadcrumb_title _("Code Review")
- page_title _("Code Review")
.d-flex.align-items-center
%h1.page-title
= _('Code Review')
.text-secondary= _('Review time is defined as the time it takes from first comment until merged.')
#js-code-review-analytics{ data: { project: @project } }
......@@ -77,6 +77,12 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end
resources :audit_events, only: [:index]
namespace :analytics do
constraints(::Constraints::FeatureConstrainer.new(:code_review_analytics)) do
resources :code_reviews, only: [:index]
end
end
end
# End of the /-/ scope.
......
......@@ -1188,4 +1188,41 @@ describe ProjectPolicy do
it { is_expected.to be_disallowed(:read_group_timelogs) }
end
describe ':read_code_review_analytics' do
let(:project) { create(:project, namespace: owner.namespace) }
using RSpec::Parameterized::TableSyntax
where(:role, :allowed) do
:guest | false
:reporter | true
:developer | true
:maintainer | true
:owner | true
:admin | true
end
with_them do
let(:current_user) { public_send(role) }
before do
stub_licensed_features(code_review_analytics: true)
end
it do
is_expected.to(allowed ? be_allowed(:read_code_review_analytics) : be_disallowed(:read_code_review_analytics))
end
end
context 'with code review analytics is not available in license' do
let(:current_user) { owner }
before do
stub_licensed_features(code_review_analytics: false)
end
it { is_expected.to be_disallowed(:read_code_review_analytics) }
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Projects::Analytics::CodeReviewsController, type: :request do
let(:user) { create :user }
let(:project) { create(:project) }
before do
login_as user
stub_feature_flags(code_review_analytics: true)
end
describe 'GET /*namespace_id/:project_id/analytics/code_reviews' do
context 'for reporter+' do
before do
project.add_reporter(user)
end
context 'with code_review_analytics included in plan' do
it 'is success' do
get project_analytics_code_reviews_path(project)
expect(response).to have_gitlab_http_status(200)
end
end
context 'without code_review_analytics in plan' do
before do
stub_licensed_features(code_review_analytics: false)
end
it 'is not found' do
get project_analytics_code_reviews_path(project)
expect(response).to have_gitlab_http_status(404)
end
end
end
context 'for guests' do
before do
project.add_guest(user)
end
it 'is not found' do
get project_analytics_code_reviews_path(project)
expect(response).to have_gitlab_http_status(404)
end
end
end
end
......@@ -4514,6 +4514,9 @@ msgstr ""
msgid "Code Owners to the merge request changes."
msgstr ""
msgid "Code Review"
msgstr ""
msgid "Code owner approval is required"
msgstr ""
......@@ -13905,6 +13908,9 @@ msgstr ""
msgid "Project '%{project_name}' will be deleted on %{date}"
msgstr ""
msgid "Project Analytics"
msgstr ""
msgid "Project Badges"
msgstr ""
......@@ -15568,6 +15574,9 @@ msgstr ""
msgid "Review the process for configuring service providers in your identity provider — in this case, GitLab is the \"service provider\" or \"relying party\"."
msgstr ""
msgid "Review time is defined as the time it takes from first comment until merged."
msgstr ""
msgid "Reviewing"
msgstr ""
......
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