2018-11-06 04:45:35 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-21 09:48:07 +00:00
|
|
|
module Gitlab
|
|
|
|
module CycleAnalytics
|
|
|
|
class Permissions
|
|
|
|
STAGE_PERMISSIONS = {
|
2016-11-21 13:09:26 +00:00
|
|
|
issue: :read_issue,
|
|
|
|
code: :read_merge_request,
|
|
|
|
test: :read_build,
|
|
|
|
review: :read_merge_request,
|
|
|
|
staging: :read_build,
|
2017-05-03 11:22:03 +00:00
|
|
|
production: :read_issue
|
2016-11-21 09:48:07 +00:00
|
|
|
}.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)
|
|
|
|
|
2016-11-21 13:09:26 +00:00
|
|
|
STAGE_PERMISSIONS[stage] ? authorize_project(STAGE_PERMISSIONS[stage]) : true
|
2016-11-21 09:48:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_project(permission)
|
|
|
|
Ability.allowed?(@user, permission, @project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|