7e6f6e1603
Enables frozens string for the following: * lib/gitlab/conflict/**/*.rb * lib/gitlab/cross_project_access/**/*.rb * lib/gitlab/cycle_analytics/**/*.rb * lib/gitlab/data_builder/**/*.rb * lib/gitlab/database/**/*.rb * lib/gitlab/dependency_linker/**/*.rb * lib/gitlab/diff/**/*.rb * lib/gitlab/downtime_check/**/*.rb * lib/gitlab/email/**/*.rb * lib/gitlab/etag_caching/**/*.rb Partially addresses gitlab-org/gitlab-ce#47424.
46 lines
1 KiB
Ruby
46 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
module CycleAnalytics
|
|
class Permissions
|
|
STAGE_PERMISSIONS = {
|
|
issue: :read_issue,
|
|
code: :read_merge_request,
|
|
test: :read_build,
|
|
review: :read_merge_request,
|
|
staging: :read_build,
|
|
production: :read_issue
|
|
}.freeze
|
|
|
|
def self.get(*args)
|
|
new(*args).get
|
|
end
|
|
|
|
def initialize(user:, project:)
|
|
@user = user
|
|
@project = project
|
|
@stage_permission_hash = {}
|
|
end
|
|
|
|
def get
|
|
::CycleAnalytics::STAGES.each do |stage|
|
|
@stage_permission_hash[stage] = authorized_stage?(stage)
|
|
end
|
|
|
|
@stage_permission_hash
|
|
end
|
|
|
|
private
|
|
|
|
def authorized_stage?(stage)
|
|
return false unless authorize_project(:read_cycle_analytics)
|
|
|
|
STAGE_PERMISSIONS[stage] ? authorize_project(STAGE_PERMISSIONS[stage]) : true
|
|
end
|
|
|
|
def authorize_project(permission)
|
|
Ability.allowed?(@user, permission, @project)
|
|
end
|
|
end
|
|
end
|
|
end
|