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
PROTECTION_NONE =

Branch protection settings

0
PROTECTION_DEV_CAN_PUSH =
1
PROTECTION_FULL =
2
PROTECTION_DEV_CAN_MERGE =
3
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


38
39
40
# File 'lib/gitlab/access.rb', line 38

def all_values
  options_with_owner.values
end

.human_access(access) ⇒ Object


105
106
107
# File 'lib/gitlab/access.rb', line 105

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

.human_access_with_none(access) ⇒ Object


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

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

.optionsObject


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

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

.options_with_noneObject


57
58
59
60
61
# File 'lib/gitlab/access.rb', line 57

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

.options_with_ownerObject


51
52
53
54
55
# File 'lib/gitlab/access.rb', line 51

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

.project_creation_level_name(name) ⇒ Object


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

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

.project_creation_optionsObject


113
114
115
116
117
118
119
# File 'lib/gitlab/access.rb', line 113

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


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

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

.project_creation_string_valuesObject


133
134
135
# File 'lib/gitlab/access.rb', line 133

def project_creation_string_values
  project_creation_string_options.keys
end

.project_creation_valuesObject


129
130
131
# File 'lib/gitlab/access.rb', line 129

def project_creation_values
  project_creation_options.values
end

.protection_optionsObject


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/gitlab/access.rb', line 76

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
    }
  ]
end

.protection_valuesObject


101
102
103
# File 'lib/gitlab/access.rb', line 101

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

.subgroup_creation_optionsObject


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

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

.subgroup_creation_string_optionsObject


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

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

.subgroup_creation_string_valuesObject


159
160
161
# File 'lib/gitlab/access.rb', line 159

def subgroup_creation_string_values
  subgroup_creation_string_options.keys
end

.subgroup_creation_valuesObject


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

def subgroup_creation_values
  subgroup_creation_options.values
end

.sym_optionsObject


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

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

.sym_options_with_ownerObject


72
73
74
# File 'lib/gitlab/access.rb', line 72

def sym_options_with_owner
  sym_options.merge(owner: OWNER)
end

Instance Method Details

#human_accessObject


164
165
166
# File 'lib/gitlab/access.rb', line 164

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

#human_access_with_noneObject


168
169
170
# File 'lib/gitlab/access.rb', line 168

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

#owner?Boolean

Returns:

  • (Boolean)

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

def owner?
  access_field == OWNER
end