Commit 1b4bb74d authored by James Lopez's avatar James Lopez

Merge branch 'eliminate-code-duplication-in-vsa-controller' into 'master'

Eliminate code duplication in group VSA controller

See merge request gitlab-org/gitlab!33147
parents a36c4a49 6192c61f
# frozen_string_literal: true
class Groups::Analytics::CycleAnalyticsController < Groups::Analytics::ApplicationController
include CycleAnalyticsParams
class Groups::Analytics::CycleAnalyticsController < Analytics::CycleAnalyticsController
layout 'group'
check_feature_flag Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG
increment_usage_counter Gitlab::UsageDataCounters::CycleAnalyticsCounter, :views, only: :show
before_action do
push_frontend_feature_flag(:cycle_analytics_scatterplot_enabled, default_enabled: true)
push_frontend_feature_flag(:cycle_analytics_scatterplot_median_enabled, default_enabled: true)
push_frontend_feature_flag(:value_stream_analytics_path_navigation, @group)
end
before_action :load_group, only: :show
before_action :load_project, only: :show
before_action :build_request_params, only: :show
def build_request_params
@request_params ||= Gitlab::Analytics::CycleAnalytics::RequestParams.new(allowed_params.merge(group: @group), current_user: current_user)
end
def allowed_params
params.permit(
:created_after,
:created_before,
project_ids: []
)
render_403 unless can?(current_user, :read_group_cycle_analytics, @group)
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Groups::Analytics::CycleAnalyticsController do
let(:group) { create(:group) }
let(:user) { create(:user) }
before do
group.add_maintainer(user)
sign_in(user)
end
context 'when the license is available' do
before do
stub_licensed_features(cycle_analytics_for_groups: true)
end
it 'succeeds' do
get(:show, params: { group_id: group })
expect(response).to be_successful
end
end
context 'when the license is missing' do
it 'renders 403 error' do
get(:show, params: { group_id: group })
expect(response).to have_gitlab_http_status(:forbidden)
end
end
context 'when non-existent group is given' do
it 'renders 403 error' do
get(:show, params: { group_id: 'unknown' })
expect(response).to have_gitlab_http_status(:not_found)
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