gitlab-org--gitlab-foss/lib/gitlab/access.rb

85 lines
2.1 KiB
Ruby
Raw Normal View History

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
AccessDeniedError = Class.new(StandardError)
NO_ACCESS = 0
2013-08-20 08:59:26 -04:00
GUEST = 10
REPORTER = 20
DEVELOPER = 30
MASTER = 40
OWNER = 50
# Branch protection settings
PROTECTION_NONE = 0
PROTECTION_DEV_CAN_PUSH = 1
PROTECTION_FULL = 2
PROTECTION_DEV_CAN_MERGE = 3
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
def all_values
options_with_owner.values
end
2013-08-20 08:59:26 -04:00
def options
{
"Guest" => GUEST,
"Reporter" => REPORTER,
"Developer" => DEVELOPER,
"Master" => MASTER
2013-08-20 08:59:26 -04:00
}
end
def options_with_owner
options.merge(
"Owner" => OWNER
)
end
def sym_options
{
guest: GUEST,
reporter: REPORTER,
developer: DEVELOPER,
master: MASTER
2013-08-20 08:59:26 -04:00
}
end
def sym_options_with_owner
sym_options.merge(owner: OWNER)
end
def protection_options
{
"Not protected: Both developers and masters 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. Masters can push to the branch." => PROTECTION_DEV_CAN_MERGE,
"Partially protected: Both developers and masters can push new commits, but cannot force push or delete the branch." => PROTECTION_DEV_CAN_PUSH,
"Fully protected: Developers cannot push new commits, but masters can. No-one can force push or delete the branch." => PROTECTION_FULL
}
end
def protection_values
protection_options.values
end
def human_access(access)
options_with_owner.key(access)
end
2013-08-20 08:59:26 -04:00
end
def human_access
Gitlab::Access.human_access(access_field)
2013-08-20 08:59:26 -04:00
end
def owner?
access_field == OWNER
end
2013-08-20 08:59:26 -04:00
end
end