2018-10-22 03:00:50 -04:00
# frozen_string_literal: true
2013-08-20 08:59:26 -04:00
# Gitlab::Access module
#
# Define allowed roles that can be used
# in GitLab code to determine authorization level
#
module Gitlab
module Access
2017-03-01 06:00:37 -05:00
AccessDeniedError = Class . new ( StandardError )
2016-06-17 12:59:33 -04:00
2018-07-11 10:36:08 -04:00
NO_ACCESS = 0
GUEST = 10
REPORTER = 20
DEVELOPER = 30
MAINTAINER = 40
# @deprecated
MASTER = MAINTAINER
OWNER = 50
2013-08-20 08:59:26 -04:00
2015-01-25 10:33:54 -05:00
# Branch protection settings
2016-07-18 04:16:56 -04:00
PROTECTION_NONE = 0
PROTECTION_DEV_CAN_PUSH = 1
PROTECTION_FULL = 2
PROTECTION_DEV_CAN_MERGE = 3
2015-01-25 10:33:54 -05:00
2013-08-20 08:59:26 -04:00
class << self
2017-02-22 12:51:46 -05:00
delegate :values , to : :options
2013-08-20 08:59:26 -04:00
2014-09-14 12:32:51 -04:00
def all_values
options_with_owner . values
end
2013-08-20 08:59:26 -04:00
def options
{
2018-05-22 04:51:45 -04:00
" Guest " = > GUEST ,
" Reporter " = > REPORTER ,
" Developer " = > DEVELOPER ,
2018-07-11 10:36:08 -04:00
" Maintainer " = > MAINTAINER
2013-08-20 08:59:26 -04:00
}
end
def options_with_owner
options . merge (
" Owner " = > OWNER
)
end
def sym_options
{
2018-07-11 10:36:08 -04:00
guest : GUEST ,
reporter : REPORTER ,
developer : DEVELOPER ,
maintainer : MAINTAINER
2013-08-20 08:59:26 -04:00
}
end
2015-01-25 10:33:54 -05:00
2016-09-16 11:54:21 -04:00
def sym_options_with_owner
sym_options . merge ( owner : OWNER )
end
2015-01-25 10:33:54 -05:00
def protection_options
2015-02-03 21:12:20 -05:00
{
2018-05-22 04:51:45 -04:00
" Not protected: Both developers and maintainers can push new commits, force push, or delete the branch. " = > PROTECTION_NONE ,
" Protected against pushes: Developers cannot push new commits, but are allowed to accept merge requests to the branch. Maintainers can push to the branch. " = > PROTECTION_DEV_CAN_MERGE ,
" Partially protected: Both developers and maintainers can push new commits, but cannot force push or delete the branch. " = > PROTECTION_DEV_CAN_PUSH ,
" Fully protected: Developers cannot push new commits, but maintainers can. No-one can force push or delete the branch. " = > PROTECTION_FULL
2015-02-03 21:12:20 -05:00
}
2015-01-25 10:33:54 -05:00
end
2015-02-03 21:12:20 -05:00
2015-01-25 10:33:54 -05:00
def protection_values
protection_options . values
end
2017-07-29 11:04:42 -04:00
def human_access ( access )
options_with_owner . key ( access )
end
2013-08-20 08:59:26 -04:00
end
def human_access
2017-07-29 11:04:42 -04:00
Gitlab :: Access . human_access ( access_field )
2013-08-20 08:59:26 -04:00
end
2013-08-27 14:35:41 -04:00
def owner?
access_field == OWNER
end
2013-08-20 08:59:26 -04:00
end
end