Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b6a4c018
Commit
b6a4c018
authored
Mar 25, 2018
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API uses ProtectedBranchPolicy for destroy/create
parent
973bd462
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
4 deletions
+35
-4
lib/api/protected_branches.rb
lib/api/protected_branches.rb
+4
-1
spec/requests/api/protected_branches_spec.rb
spec/requests/api/protected_branches_spec.rb
+31
-3
No files found.
lib/api/protected_branches.rb
View file @
b6a4c018
...
@@ -74,7 +74,10 @@ module API
...
@@ -74,7 +74,10 @@ module API
delete
':id/protected_branches/:name'
,
requirements:
BRANCH_ENDPOINT_REQUIREMENTS
do
delete
':id/protected_branches/:name'
,
requirements:
BRANCH_ENDPOINT_REQUIREMENTS
do
protected_branch
=
user_project
.
protected_branches
.
find_by!
(
name:
params
[
:name
])
protected_branch
=
user_project
.
protected_branches
.
find_by!
(
name:
params
[
:name
])
destroy_conditionally!
(
protected_branch
)
destroy_conditionally!
(
protected_branch
)
do
destroy_service
=
::
ProtectedBranches
::
DestroyService
.
new
(
user_project
,
current_user
)
destroy_service
.
execute
(
protected_branch
)
end
end
end
end
end
end
end
...
...
spec/requests/api/protected_branches_spec.rb
View file @
b6a4c018
...
@@ -193,6 +193,19 @@ describe API::ProtectedBranches do
...
@@ -193,6 +193,19 @@ describe API::ProtectedBranches do
expect
(
json_response
[
'merge_access_levels'
][
0
][
'access_level'
]).
to
eq
(
Gitlab
::
Access
::
MASTER
)
expect
(
json_response
[
'merge_access_levels'
][
0
][
'access_level'
]).
to
eq
(
Gitlab
::
Access
::
MASTER
)
end
end
end
end
context
'when a policy restricts rule deletion'
do
before
do
policy
=
instance_double
(
ProtectedBranchPolicy
,
can?:
false
)
expect
(
ProtectedBranchPolicy
).
to
receive
(
:new
).
and_return
(
policy
)
end
it
"prevents deletion of the protected branch rule"
do
post
post_endpoint
,
name:
branch_name
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
end
end
context
'when authenticated as a guest'
do
context
'when authenticated as a guest'
do
...
@@ -209,18 +222,20 @@ describe API::ProtectedBranches do
...
@@ -209,18 +222,20 @@ describe API::ProtectedBranches do
end
end
describe
"DELETE /projects/:id/protected_branches/unprotect/:branch"
do
describe
"DELETE /projects/:id/protected_branches/unprotect/:branch"
do
let
(
:delete_endpoint
)
{
api
(
"/projects/
#{
project
.
id
}
/protected_branches/
#{
branch_name
}
"
,
user
)
}
before
do
before
do
project
.
add_master
(
user
)
project
.
add_master
(
user
)
end
end
it
"unprotects a single branch"
do
it
"unprotects a single branch"
do
delete
api
(
"/projects/
#{
project
.
id
}
/protected_branches/
#{
branch_name
}
"
,
user
)
delete
delete_endpoint
expect
(
response
).
to
have_gitlab_http_status
(
204
)
expect
(
response
).
to
have_gitlab_http_status
(
204
)
end
end
it_behaves_like
'412 response'
do
it_behaves_like
'412 response'
do
let
(
:request
)
{
api
(
"/projects/
#{
project
.
id
}
/protected_branches/
#{
branch_name
}
"
,
user
)
}
let
(
:request
)
{
delete_endpoint
}
end
end
it
"returns 404 if branch does not exist"
do
it
"returns 404 if branch does not exist"
do
...
@@ -229,11 +244,24 @@ describe API::ProtectedBranches do
...
@@ -229,11 +244,24 @@ describe API::ProtectedBranches do
expect
(
response
).
to
have_gitlab_http_status
(
404
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
context
'when a policy restricts rule deletion'
do
before
do
policy
=
instance_double
(
ProtectedBranchPolicy
,
can?:
false
)
expect
(
ProtectedBranchPolicy
).
to
receive
(
:new
).
and_return
(
policy
)
end
it
"prevents deletion of the protected branch rule"
do
delete
delete_endpoint
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'when branch has a wildcard in its name'
do
context
'when branch has a wildcard in its name'
do
let
(
:protected_name
)
{
'feature*'
}
let
(
:protected_name
)
{
'feature*'
}
it
"unprotects a wildcard branch"
do
it
"unprotects a wildcard branch"
do
delete
api
(
"/projects/
#{
project
.
id
}
/protected_branches/
#{
branch_name
}
"
,
user
)
delete
delete_endpoint
expect
(
response
).
to
have_gitlab_http_status
(
204
)
expect
(
response
).
to
have_gitlab_http_status
(
204
)
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