Commit 8f3caa15 authored by Michael Lunøe's avatar Michael Lunøe Committed by Dmytro Zaporozhets

Add embeddable charts feature flag

feat(Analytics/insights): add embeddable charts feature flag
This will prepare us for future work in this area

Ref. https://gitlab.com/gitlab-org/gitlab/-/issues/224174
parent 1b4d6d6f
......@@ -5,11 +5,18 @@ module InsightsActions
module Embeddable
extend ActiveSupport::Concern
included do
before_action do
push_frontend_feature_flag(:embed_analytics_report, insights_entity)
end
end
def embedded
response.set_header('X-Frame-Options', 'SAMEORIGIN')
return render_404 unless Feature.enabled?(:embed_analytics_report, insights_entity)
return render_404 unless can?(current_user, :embed_analytics_report, insights_entity)
return render_404 unless can?(current_user, :view_embedded_analytics_report, insights_entity)
render :embedded, layout: false
end
......
......@@ -12,10 +12,6 @@ class Projects::InsightsController < Projects::ApplicationController
private
def authorize_read_project!
render_404 unless can?(current_user, :read_project, project)
end
def insights_entity
project
end
......
......@@ -251,7 +251,7 @@ module EE
rule { admin & is_gitlab_com }.enable :update_subscription_limit
rule { public_group }.enable :embed_analytics_report
rule { public_group }.enable :view_embedded_analytics_report
end
override :lookup_access_level!
......
......@@ -424,7 +424,7 @@ module EE
rule { status_page_available & can?(:owner_access) }.enable :mark_issue_for_publication
rule { status_page_available & can?(:developer_access) }.enable :publish_status_page
rule { public_project }.enable :embed_analytics_report
rule { public_project }.enable :view_embedded_analytics_report
end
override :lookup_access_level!
......
......@@ -106,7 +106,7 @@ RSpec.describe Groups::InsightsController do
it_behaves_like '200 status'
end
describe 'GET #show.sjon' do
describe 'GET #show.json' do
subject { get :show, params: params.merge(group_id: parent_group.to_param), format: :json }
it_behaves_like '200 status'
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::InsightsController do
let_it_be(:group) { create(:group, :private) }
let_it_be(:project) { create(:project, :private, namespace: group) }
let_it_be(:insight) { create(:insight, group: group, project: project) }
let_it_be(:user) { create(:user) }
let(:query_params) { { type: 'bar', query: { issuable_type: 'issue', collection_labels: ['bug'] }, projects: projects_params } }
let(:projects_params) { { only: [project.id, project.full_path] } }
let(:params) { { trailing_slash: true, project_id: project, namespace_id: group } }
before do
stub_licensed_features(insights: true)
sign_in(user)
end
shared_examples '404 status' do
it 'returns 404 status' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
shared_examples '200 status' do
it 'returns 200 status' do
subject
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'when insights configuration project cannot be read by current user' do
describe 'GET #show.html' do
subject { get :show, params: params }
it_behaves_like '404 status'
end
describe 'GET #show.json' do
subject { get :show, params: params, format: :json }
it_behaves_like '404 status'
end
describe 'POST #query' do
subject { post :query, params: params.merge(query_params) }
it_behaves_like '404 status'
end
end
context 'when insights configuration project can be read by current user' do
before do
project.add_reporter(user)
end
describe 'GET #show.html' do
subject { get :show, params: params }
it_behaves_like '200 status'
end
describe 'GET #show.json' do
subject { get :show, params: params, format: :json }
it_behaves_like '200 status'
end
describe 'POST #query.json' do
subject { post :query, params: params.merge(query_params), format: :json }
it_behaves_like '200 status'
end
describe 'GET #show' do
it_behaves_like 'tracking unique visits', :show do
let(:request_params) { params }
let(:target_id) { 'p_analytics_insights' }
end
end
end
end
......@@ -76,6 +76,24 @@ RSpec.shared_examples 'Insights page' do
expect(page).to have_gitlab_http_status(:not_found)
end
end
context 'when embeddable charts feature flag is turned on for insights configuration project' do
before do
stub_feature_flags(embed_analytics_report: false)
end
it 'returns enabled feature flag for enabled entity' do
stub_feature_flags(embed_analytics_report: entity)
visit route
expect(page).to have_pushed_frontend_feature_flags(embedAnalyticsReport: true)
end
it 'returns disabled feature flag for disabled entity' do
visit route
expect(page).to have_pushed_frontend_feature_flags(embedAnalyticsReport: false)
end
end
end
context 'without correct license' do
......
......@@ -8,7 +8,7 @@ RSpec.shared_examples 'analytics report embedding' do
allow(subject.subject).to receive(:public?).and_return(false)
end
it { is_expected.to be_disallowed(:embed_analytics_report) }
it { is_expected.to be_disallowed(:view_embedded_analytics_report) }
end
context 'when subject is public' do
......@@ -16,6 +16,6 @@ RSpec.shared_examples 'analytics report embedding' do
allow(subject.subject).to receive(:public?).and_return(true)
end
it { is_expected.to be_allowed(:embed_analytics_report) }
it { is_expected.to be_allowed(:view_embedded_analytics_report) }
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