Verified Commit 5dd35c17 authored by Aakriti Gupta's avatar Aakriti Gupta Committed by Douglas Barbosa Alexandre

Re-factor auth related before_actions into parent controller

parent 767b5d77
......@@ -15,5 +15,26 @@ 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 render_403 if @group && !@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