2013-08-20 12:59:26 +00:00
# Gitlab::Access module
#
# Define allowed roles that can be used
# in GitLab code to determine authorization level
#
module Gitlab
module Access
2016-06-17 16:59:33 +00:00
class AccessDeniedError < StandardError ; end
2016-07-20 04:52:31 +00:00
NO_ACCESS = 0
2013-08-20 12:59:26 +00:00
GUEST = 10
REPORTER = 20
DEVELOPER = 30
MASTER = 40
OWNER = 50
2015-01-25 15:33:54 +00:00
# Branch protection settings
2016-07-18 08:16:56 +00:00
PROTECTION_NONE = 0
PROTECTION_DEV_CAN_PUSH = 1
PROTECTION_FULL = 2
PROTECTION_DEV_CAN_MERGE = 3
2015-01-25 15:33:54 +00:00
2013-08-20 12:59:26 +00:00
class << self
def values
options . values
end
2014-09-14 16:32:51 +00:00
def all_values
options_with_owner . values
end
2013-08-20 12:59:26 +00:00
def options
{
" Guest " = > GUEST ,
" Reporter " = > REPORTER ,
" Developer " = > DEVELOPER ,
" Master " = > MASTER ,
}
end
def options_with_owner
options . merge (
" Owner " = > OWNER
)
end
def sym_options
{
guest : GUEST ,
reporter : REPORTER ,
developer : DEVELOPER ,
master : MASTER ,
}
end
2015-01-25 15:33:54 +00:00
def protection_options
2015-02-04 02:12:20 +00:00
{
2015-05-12 10:38:42 +00:00
" Not protected: Both developers and masters can push new commits, force push, or delete the branch. " = > PROTECTION_NONE ,
2016-07-18 08:16:56 +00:00
" Protected against pushes: Developers cannot push new commits, but are allowed to accept merge requests to the branch. " = > PROTECTION_DEV_CAN_MERGE ,
2015-05-12 10:38:42 +00:00
" Partially protected: Developers can push new commits, but cannot force push or delete the branch. Masters can do all of those. " = > PROTECTION_DEV_CAN_PUSH ,
" Fully protected: Developers cannot push new commits, force push, or delete the branch. Only masters can do any of those. " = > PROTECTION_FULL ,
2015-02-04 02:12:20 +00:00
}
2015-01-25 15:33:54 +00:00
end
2015-02-04 02:12:20 +00:00
2015-01-25 15:33:54 +00:00
def protection_values
protection_options . values
end
2013-08-20 12:59:26 +00:00
end
def human_access
Gitlab :: Access . options_with_owner . key ( access_field )
end
2013-08-27 18:35:41 +00:00
def owner?
access_field == OWNER
end
2013-08-20 12:59:26 +00:00
end
end