BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
cef10ef7
Commit
cef10ef7
authored
Sep 14, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement review comments from @dbalexandre.
1. Don't have any EE-only code in CE. Ok to have CE-only code in EE. 2. Use `case` instead of `if/elsif`
parent
b116df7e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
37 deletions
+8
-37
api_update_service.rb
app/services/protected_branches/api_update_service.rb
+8
-37
No files found.
app/services/protected_branches/api_update_service.rb
View file @
cef10ef7
...
@@ -14,25 +14,19 @@ module ProtectedBranches
...
@@ -14,25 +14,19 @@ module ProtectedBranches
@protected_branch
=
protected_branch
@protected_branch
=
protected_branch
protected_branch
.
transaction
do
protected_branch
.
transaction
do
# If a protected branch can have only a single access level (CE), delete it to
delete_redundant_access_levels
# make room for the new access level. If a protected branch can have more than
# one access level (EE), only remove the relevant access levels. If we don't do this,
# we'll have a failed validation.
if
protected_branch_restricted_to_single_access_level?
delete_redundant_ce_access_levels
else
delete_redundant_ee_access_levels
end
if
@developers_can_push
case
@developers_can_push
when
true
params
.
merge!
(
push_access_levels_attributes:
[{
access_level:
Gitlab
::
Access
::
DEVELOPER
}])
params
.
merge!
(
push_access_levels_attributes:
[{
access_level:
Gitlab
::
Access
::
DEVELOPER
}])
elsif
@developers_can_push
==
false
when
false
params
.
merge!
(
push_access_levels_attributes:
[{
access_level:
Gitlab
::
Access
::
MASTER
}])
params
.
merge!
(
push_access_levels_attributes:
[{
access_level:
Gitlab
::
Access
::
MASTER
}])
end
end
if
@developers_can_merge
case
@developers_can_merge
when
true
params
.
merge!
(
merge_access_levels_attributes:
[{
access_level:
Gitlab
::
Access
::
DEVELOPER
}])
params
.
merge!
(
merge_access_levels_attributes:
[{
access_level:
Gitlab
::
Access
::
DEVELOPER
}])
elsif
@developers_can_merge
==
false
when
false
params
.
merge!
(
merge_access_levels_attributes:
[{
access_level:
Gitlab
::
Access
::
MASTER
}])
params
.
merge!
(
merge_access_levels_attributes:
[{
access_level:
Gitlab
::
Access
::
MASTER
}])
end
end
...
@@ -43,7 +37,7 @@ module ProtectedBranches
...
@@ -43,7 +37,7 @@ module ProtectedBranches
private
private
def
delete_redundant_
ce_
access_levels
def
delete_redundant_access_levels
if
@developers_can_merge
||
@developers_can_merge
==
false
if
@developers_can_merge
||
@developers_can_merge
==
false
@protected_branch
.
merge_access_levels
.
destroy_all
@protected_branch
.
merge_access_levels
.
destroy_all
end
end
...
@@ -52,28 +46,5 @@ module ProtectedBranches
...
@@ -52,28 +46,5 @@ module ProtectedBranches
@protected_branch
.
push_access_levels
.
destroy_all
@protected_branch
.
push_access_levels
.
destroy_all
end
end
end
end
def
delete_redundant_ee_access_levels
if
@developers_can_merge
@protected_branch
.
merge_access_levels
.
developer
.
destroy_all
elsif
@developers_can_merge
==
false
@protected_branch
.
merge_access_levels
.
developer
.
destroy_all
@protected_branch
.
merge_access_levels
.
master
.
destroy_all
end
if
@developers_can_push
@protected_branch
.
push_access_levels
.
developer
.
destroy_all
elsif
@developers_can_push
==
false
@protected_branch
.
push_access_levels
.
developer
.
destroy_all
@protected_branch
.
push_access_levels
.
master
.
destroy_all
end
end
def
protected_branch_restricted_to_single_access_level?
length_validator
=
ProtectedBranch
.
validators_on
(
:push_access_levels
).
find
do
|
validator
|
validator
.
is_a?
ActiveModel
::
Validations
::
LengthValidator
end
length_validator
.
options
[
:is
]
==
1
if
length_validator
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment