From c59d513128b10dd4ee1fee6f6978fd0085dd9665 Mon Sep 17 00:00:00 2001 From: Brandon Labuschagne <blabuschagne@gitlab.com> Date: Wed, 24 Jun 2020 21:57:07 +0000 Subject: [PATCH] Introduces base generic reporting route Also includes the controller and a view which can be used for bootstrapping the vue application. https://gitlab.com/gitlab-org/gitlab/-/issues/220494 --- .../analytics/reports/pages_controller.rb | 21 +++++++++ .../analytics/reports/pages/show.html.haml | 2 + ee/app/views/layouts/report_pages.html.haml | 3 ++ ee/config/routes/analytics.rb | 4 ++ ee/lib/gitlab/analytics.rb | 11 ++++- .../reports/pages_controller_spec.rb | 46 +++++++++++++++++++ locale/gitlab.pot | 3 ++ 7 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 ee/app/controllers/analytics/reports/pages_controller.rb create mode 100644 ee/app/views/analytics/reports/pages/show.html.haml create mode 100644 ee/app/views/layouts/report_pages.html.haml create mode 100644 ee/spec/controllers/analytics/reports/pages_controller_spec.rb diff --git a/ee/app/controllers/analytics/reports/pages_controller.rb b/ee/app/controllers/analytics/reports/pages_controller.rb new file mode 100644 index 0000000000000..b316c5c6117ca --- /dev/null +++ b/ee/app/controllers/analytics/reports/pages_controller.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Analytics + module Reports + class PagesController < ::ApplicationController + layout 'report_pages' + + before_action do + render_404 unless feature_enabled? && feature_available? + end + + def feature_enabled? + Feature.enabled?(Gitlab::Analytics::REPORT_PAGES_FEATURE_FLAG) + end + + def feature_available? + ::License.feature_available?(:group_activity_analytics) + end + end + end +end diff --git a/ee/app/views/analytics/reports/pages/show.html.haml b/ee/app/views/analytics/reports/pages/show.html.haml new file mode 100644 index 0000000000000..1becb885af075 --- /dev/null +++ b/ee/app/views/analytics/reports/pages/show.html.haml @@ -0,0 +1,2 @@ +- page_title _("Reports") + diff --git a/ee/app/views/layouts/report_pages.html.haml b/ee/app/views/layouts/report_pages.html.haml new file mode 100644 index 0000000000000..e042ea2e501a5 --- /dev/null +++ b/ee/app/views/layouts/report_pages.html.haml @@ -0,0 +1,3 @@ +- page_title _('Reports') + += render template: 'layouts/application' diff --git a/ee/config/routes/analytics.rb b/ee/config/routes/analytics.rb index ff0d1d3cf8aad..2d24dc2882db6 100644 --- a/ee/config/routes/analytics.rb +++ b/ee/config/routes/analytics.rb @@ -3,6 +3,10 @@ namespace :analytics do root to: 'analytics#index' + constraints(::Constraints::FeatureConstrainer.new(Gitlab::Analytics::REPORT_PAGES_FEATURE_FLAG)) do + get :report_pages, to: 'reports/pages#show' + end + constraints(-> (req) { Gitlab::Analytics.cycle_analytics_enabled? }) do resource :cycle_analytics, only: :show, path: 'value_stream_analytics' scope module: :cycle_analytics, as: 'cycle_analytics', path: 'value_stream_analytics' do diff --git a/ee/lib/gitlab/analytics.rb b/ee/lib/gitlab/analytics.rb index a1617f0521f9f..733126340d5a0 100644 --- a/ee/lib/gitlab/analytics.rb +++ b/ee/lib/gitlab/analytics.rb @@ -5,15 +5,18 @@ module Analytics # Normally each analytics feature should be guarded with a feature flag. CYCLE_ANALYTICS_FEATURE_FLAG = :cycle_analytics PRODUCTIVITY_ANALYTICS_FEATURE_FLAG = :productivity_analytics + REPORT_PAGES_FEATURE_FLAG = :report_pages FEATURE_FLAGS = [ CYCLE_ANALYTICS_FEATURE_FLAG, - PRODUCTIVITY_ANALYTICS_FEATURE_FLAG + PRODUCTIVITY_ANALYTICS_FEATURE_FLAG, + REPORT_PAGES_FEATURE_FLAG ].freeze FEATURE_FLAG_DEFAULTS = { PRODUCTIVITY_ANALYTICS_FEATURE_FLAG => true, - CYCLE_ANALYTICS_FEATURE_FLAG => true + CYCLE_ANALYTICS_FEATURE_FLAG => true, + REPORT_PAGES_FEATURE_FLAG => false }.freeze def self.any_features_enabled? @@ -28,6 +31,10 @@ def self.productivity_analytics_enabled? feature_enabled?(PRODUCTIVITY_ANALYTICS_FEATURE_FLAG) end + def self.report_pages_enabled? + feature_enabled?(REPORT_PAGES_FEATURE_FLAG) + end + def self.feature_enabled_by_default?(flag) !!FEATURE_FLAG_DEFAULTS[flag] end diff --git a/ee/spec/controllers/analytics/reports/pages_controller_spec.rb b/ee/spec/controllers/analytics/reports/pages_controller_spec.rb new file mode 100644 index 0000000000000..734d624a940ad --- /dev/null +++ b/ee/spec/controllers/analytics/reports/pages_controller_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Analytics::Reports::PagesController do + let(:user) { create(:user) } + + before do + sign_in(user) + + stub_licensed_features(group_activity_analytics: true) + stub_feature_flags(Gitlab::Analytics::REPORT_PAGES_FEATURE_FLAG => true) + end + + describe 'GET show' do + it 'renders the report page' do + get :show + + expect(response).to render_template :show + end + + context 'when the feature flag is false' do + before do + stub_feature_flags(Gitlab::Analytics::REPORT_PAGES_FEATURE_FLAG => false) + end + + it 'renders 404, not found' do + get :show + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'when the feature is not available' do + before do + stub_licensed_features(group_activity_analytics: false) + end + + it 'renders 404, not found' do + get :show + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end +end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index e791fd771d7ba..cc705334d2962 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -19049,6 +19049,9 @@ msgstr "" msgid "Reporting" msgstr "" +msgid "Reports" +msgstr "" + msgid "Reports|%{combinedString} and %{resolvedString}" msgstr "" -- GitLab