Commit d47c9e8f authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'ag-re-factor-analytics-controllers' into 'master'

Re-factor: Move auth related `before_actions` into parent controller

See merge request gitlab-org/gitlab!16644
parents 371032d9 5ac7286c
......@@ -15,5 +15,27 @@ class Analytics::ApplicationController < ApplicationController
before_action(*args) { counter_klass.count(counter) }
end
def authorize_view_productivity_analytics!(action)
return render_403 unless can?(current_user, action, @group || :global)
end
def check_feature_availability!(feature)
return render_403 unless ::License.feature_available?(feature)
return unless @group
return render_403 unless @group.root_ancestor.feature_available?(feature)
end
def load_group
return unless params['group_id']
@group = find_routable!(Group, params['group_id'])
end
def load_project
return unless @group && params['project_id']
@project = find_routable!(@group.projects, params['project_id'])
end
private_class_method :check_feature_flag, :increment_usage_counter
end
......@@ -7,8 +7,12 @@ class Analytics::ProductivityAnalyticsController < Analytics::ApplicationControl
before_action :load_group
before_action :load_project
before_action :check_feature_availability!
before_action :authorize_view_productivity_analytics!
before_action -> {
check_feature_availability!(:productivity_analytics)
}
before_action -> {
authorize_view_productivity_analytics!(:view_productivity_analytics)
}
include IssuableCollections
......@@ -47,27 +51,6 @@ class Analytics::ProductivityAnalyticsController < Analytics::ApplicationControl
end
end
def authorize_view_productivity_analytics!
return render_403 unless can?(current_user, :view_productivity_analytics, @group || :global)
end
def check_feature_availability!
return render_403 unless ::License.feature_available?(:productivity_analytics)
return render_403 if @group && !@group.root_ancestor.feature_available?(:productivity_analytics)
end
def load_group
return unless params['group_id']
@group = find_routable!(Group, params['group_id'])
end
def load_project
return unless @group && params['project_id']
@project = find_routable!(@group.projects, params['project_id'])
end
def serializer
@serializer ||= BaseSerializer.new(current_user: current_user)
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