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


89
90
91
# File 'lib/gitlab/access.rb', line 89

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

.human_access_with_none(access) ⇒ Object


93
94
95
# File 'lib/gitlab/access.rb', line 93

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


121
122
123
# File 'lib/gitlab/access.rb', line 121

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

.project_creation_optionsObject


97
98
99
100
101
102
103
# File 'lib/gitlab/access.rb', line 97

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


105
106
107
108
109
110
111
# File 'lib/gitlab/access.rb', line 105

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

.project_creation_string_valuesObject


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

def project_creation_string_values
  project_creation_string_options.keys
end

.project_creation_valuesObject


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

def project_creation_values
  project_creation_options.values
end

.protection_optionsObject


76
77
78
79
80
81
82
83
# File 'lib/gitlab/access.rb', line 76

def protection_options
  {
    "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
  }
end

.protection_valuesObject


85
86
87
# File 'lib/gitlab/access.rb', line 85

def protection_values
  protection_options.values
end

.subgroup_creation_optionsObject


125
126
127
128
129
130
# File 'lib/gitlab/access.rb', line 125

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

.subgroup_creation_string_optionsObject


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

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

.subgroup_creation_string_valuesObject


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

def subgroup_creation_string_values
  subgroup_creation_string_options.keys
end

.subgroup_creation_valuesObject


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

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


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

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

#human_access_with_noneObject


152
153
154
# File 'lib/gitlab/access.rb', line 152

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

#owner?Boolean

Returns:

  • (Boolean)

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

def owner?
  access_field == OWNER
end