Module: Gitlab::Access

Included in:
Git::BranchPushService, Member
Defined in:
lib/gitlab/access.rb,
lib/gitlab/access/branch_protection.rb

Defined Under Namespace

Classes: BranchProtection

Constant Summary collapse

AccessDeniedError =
Class.new(StandardError)
NO_ACCESS =
0
MINIMAL_ACCESS =
5
GUEST =
10
REPORTER =
20
DEVELOPER =
30
MAINTAINER =
40
OWNER =
50
ADMIN =
60
PROTECTION_NONE =

Branch protection settings

0
PROTECTION_DEV_CAN_PUSH =
1
PROTECTION_FULL =
2
PROTECTION_DEV_CAN_MERGE =
3
PROTECTION_DEV_CAN_INITIAL_PUSH =
4
NO_ONE_PROJECT_ACCESS =

Default project creation level

0
MAINTAINER_PROJECT_ACCESS =
1
DEVELOPER_MAINTAINER_PROJECT_ACCESS =
2
OWNER_SUBGROUP_ACCESS =

Default subgroup creation level

0
MAINTAINER_SUBGROUP_ACCESS =
1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_valuesObject



40
41
42
# File 'lib/gitlab/access.rb', line 40

def all_values
  options_with_owner.values
end

.human_access(access) ⇒ Object



112
113
114
# File 'lib/gitlab/access.rb', line 112

def human_access(access)
  options_with_owner.key(access)
end

.human_access_with_none(access) ⇒ Object



116
117
118
# File 'lib/gitlab/access.rb', line 116

def human_access_with_none(access)
  options_with_none.key(access)
end

.optionsObject



44
45
46
47
48
49
50
51
# File 'lib/gitlab/access.rb', line 44

def options
  {
    "Guest" => GUEST,
    "Reporter" => REPORTER,
    "Developer" => DEVELOPER,
    "Maintainer" => MAINTAINER
  }
end

.options_with_noneObject



59
60
61
62
63
# File 'lib/gitlab/access.rb', line 59

def options_with_none
  options_with_owner.merge(
    "None" => NO_ACCESS
  )
end

.options_with_ownerObject



53
54
55
56
57
# File 'lib/gitlab/access.rb', line 53

def options_with_owner
  options.merge(
    "Owner" => OWNER
  )
end

.project_creation_level_name(name) ⇒ Object



144
145
146
# File 'lib/gitlab/access.rb', line 144

def project_creation_level_name(name)
  project_creation_options.key(name)
end

.project_creation_optionsObject



120
121
122
123
124
125
126
# File 'lib/gitlab/access.rb', line 120

def project_creation_options
  {
    s_('ProjectCreationLevel|No one') => NO_ONE_PROJECT_ACCESS,
    s_('ProjectCreationLevel|Maintainers') => MAINTAINER_PROJECT_ACCESS,
    s_('ProjectCreationLevel|Developers + Maintainers') => DEVELOPER_MAINTAINER_PROJECT_ACCESS
  }
end

.project_creation_string_optionsObject



128
129
130
131
132
133
134
# File 'lib/gitlab/access.rb', line 128

def project_creation_string_options
  {
    'noone' => NO_ONE_PROJECT_ACCESS,
    'maintainer' => MAINTAINER_PROJECT_ACCESS,
    'developer' => DEVELOPER_MAINTAINER_PROJECT_ACCESS
  }
end

.project_creation_string_valuesObject



140
141
142
# File 'lib/gitlab/access.rb', line 140

def project_creation_string_values
  project_creation_string_options.keys
end

.project_creation_valuesObject



136
137
138
# File 'lib/gitlab/access.rb', line 136

def project_creation_values
  project_creation_options.values
end

.protection_optionsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/gitlab/access.rb', line 78

def protection_options
  [
    {
      label: s_('DefaultBranchProtection|Not protected'),
      help_text: s_('DefaultBranchProtection|Both developers and maintainers can push new commits, force push, or delete the branch.'),
      value: PROTECTION_NONE
    },
    {
      label: s_('DefaultBranchProtection|Protected against pushes'),
      help_text: s_('DefaultBranchProtection|Developers cannot push new commits, but are allowed to accept merge requests to the branch. Maintainers can push to the branch.'),
      value: PROTECTION_DEV_CAN_MERGE
    },
    {
      label: s_('DefaultBranchProtection|Partially protected'),
      help_text: s_('DefaultBranchProtection|Both developers and maintainers can push new commits, but cannot force push.'),
      value: PROTECTION_DEV_CAN_PUSH
    },
    {
      label: s_('DefaultBranchProtection|Fully protected'),
      help_text: s_('DefaultBranchProtection|Developers cannot push new commits, but maintainers can. No one can force push.'),
      value: PROTECTION_FULL
    },
    {
      label: s_('DefaultBranchProtection|Fully protected after initial push'),
      help_text: s_('DefaultBranchProtection|Developers can push the initial commit to a repository, but none afterward. Maintainers can always push. No one can force push.'),
      value: PROTECTION_DEV_CAN_INITIAL_PUSH
    }
  ]
end

.protection_valuesObject



108
109
110
# File 'lib/gitlab/access.rb', line 108

def protection_values
  protection_options.map { |option| option[:value] }
end

.subgroup_creation_optionsObject



148
149
150
151
152
153
# File 'lib/gitlab/access.rb', line 148

def subgroup_creation_options
  {
    s_('SubgroupCreationlevel|Owners') => OWNER_SUBGROUP_ACCESS,
    s_('SubgroupCreationlevel|Maintainers') => MAINTAINER_SUBGROUP_ACCESS
  }
end

.subgroup_creation_string_optionsObject



155
156
157
158
159
160
# File 'lib/gitlab/access.rb', line 155

def subgroup_creation_string_options
  {
    'owner' => OWNER_SUBGROUP_ACCESS,
    'maintainer' => MAINTAINER_SUBGROUP_ACCESS
  }
end

.subgroup_creation_string_valuesObject



166
167
168
# File 'lib/gitlab/access.rb', line 166

def subgroup_creation_string_values
  subgroup_creation_string_options.keys
end

.subgroup_creation_valuesObject



162
163
164
# File 'lib/gitlab/access.rb', line 162

def subgroup_creation_values
  subgroup_creation_options.values
end

.sym_optionsObject



65
66
67
68
69
70
71
72
# File 'lib/gitlab/access.rb', line 65

def sym_options
  {
    guest: GUEST,
    reporter: REPORTER,
    developer: DEVELOPER,
    maintainer: MAINTAINER
  }
end

.sym_options_with_ownerObject



74
75
76
# File 'lib/gitlab/access.rb', line 74

def sym_options_with_owner
  sym_options.merge(owner: OWNER)
end

Instance Method Details

#human_accessObject



171
172
173
# File 'lib/gitlab/access.rb', line 171

def human_access
  Gitlab::Access.human_access(access_field)
end

#human_access_with_noneObject



175
176
177
# File 'lib/gitlab/access.rb', line 175

def human_access_with_none
  Gitlab::Access.human_access_with_none(access_field)
end

#owner?Boolean

Returns:

  • (Boolean)


179
180
181
# File 'lib/gitlab/access.rb', line 179

def owner?
  access_field == OWNER
end