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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
e7061396
Commit
e7061396
authored
Mar 24, 2018
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DestroyService for protected tags/branches used from controller
parent
1f7328f8
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
122 additions
and
14 deletions
+122
-14
app/controllers/projects/protected_branches_controller.rb
app/controllers/projects/protected_branches_controller.rb
+2
-6
app/controllers/projects/protected_refs_controller.rb
app/controllers/projects/protected_refs_controller.rb
+13
-1
app/controllers/projects/protected_tags_controller.rb
app/controllers/projects/protected_tags_controller.rb
+2
-6
app/services/protected_branches/destroy_service.rb
app/services/protected_branches/destroy_service.rb
+7
-0
app/services/protected_tags/destroy_service.rb
app/services/protected_tags/destroy_service.rb
+7
-0
spec/controllers/projects/protected_branches_controller_spec.rb
...ontrollers/projects/protected_branches_controller_spec.rb
+56
-0
spec/policies/protected_branch_policy_spec.rb
spec/policies/protected_branch_policy_spec.rb
+1
-1
spec/services/protected_branches/destroy_service_spec.rb
spec/services/protected_branches/destroy_service_spec.rb
+17
-0
spec/services/protected_tags/destroy_service_spec.rb
spec/services/protected_tags/destroy_service_spec.rb
+17
-0
No files found.
app/controllers/projects/protected_branches_controller.rb
View file @
e7061396
...
...
@@ -5,12 +5,8 @@ class Projects::ProtectedBranchesController < Projects::ProtectedRefsController
@project
.
repository
.
branches
end
def
create_service_class
::
ProtectedBranches
::
CreateService
end
def
update_service_class
::
ProtectedBranches
::
UpdateService
def
service_namespace
::
ProtectedBranches
end
def
load_protected_ref
...
...
app/controllers/projects/protected_refs_controller.rb
View file @
e7061396
...
...
@@ -37,7 +37,7 @@ class Projects::ProtectedRefsController < Projects::ApplicationController
end
def
destroy
@protected_ref
.
destroy
destroy_service_class
.
new
(
@project
,
current_user
).
execute
(
@protected_ref
)
respond_to
do
|
format
|
format
.
html
{
redirect_to_repository_settings
(
@project
)
}
...
...
@@ -47,6 +47,18 @@ class Projects::ProtectedRefsController < Projects::ApplicationController
protected
def
create_service_class
service_namespace
::
CreateService
end
def
update_service_class
service_namespace
::
UpdateService
end
def
destroy_service_class
service_namespace
::
DestroyService
end
def
access_level_attributes
%i(access_level id)
end
...
...
app/controllers/projects/protected_tags_controller.rb
View file @
e7061396
...
...
@@ -5,12 +5,8 @@ class Projects::ProtectedTagsController < Projects::ProtectedRefsController
@project
.
repository
.
tags
end
def
create_service_class
::
ProtectedTags
::
CreateService
end
def
update_service_class
::
ProtectedTags
::
UpdateService
def
service_namespace
::
ProtectedTags
end
def
load_protected_ref
...
...
app/services/protected_branches/destroy_service.rb
0 → 100644
View file @
e7061396
module
ProtectedBranches
class
DestroyService
<
BaseService
def
execute
(
protected_branch
)
protected_branch
.
destroy
end
end
end
app/services/protected_tags/destroy_service.rb
0 → 100644
View file @
e7061396
module
ProtectedTags
class
DestroyService
<
BaseService
def
execute
(
protected_tag
)
protected_tag
.
destroy
end
end
end
spec/controllers/projects/protected_branches_controller_spec.rb
View file @
e7061396
require
(
'spec_helper'
)
describe
Projects
::
ProtectedBranchesController
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:protected_branch
)
{
create
(
:protected_branch
,
project:
project
)
}
let
(
:project_params
)
{
{
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
}
}
let
(
:base_params
)
{
project_params
.
merge
(
id:
protected_branch
.
id
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
end
describe
"GET #index"
do
let
(
:project
)
{
create
(
:project_empty_repo
,
:public
)
}
...
...
@@ -8,4 +18,50 @@ describe Projects::ProtectedBranchesController do
get
(
:index
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
)
end
end
describe
"POST #create"
do
let
(
:master_access_level
)
{
[{
access_level:
Gitlab
::
Access
::
MASTER
}]
}
let
(
:access_level_params
)
do
{
merge_access_levels_attributes:
master_access_level
,
push_access_levels_attributes:
master_access_level
}
end
let
(
:create_params
)
{
attributes_for
(
:protected_branch
).
merge
(
access_level_params
)
}
before
do
sign_in
(
user
)
end
it
'creates the protected branch rule'
do
expect
do
post
(
:create
,
project_params
.
merge
(
protected_branch:
create_params
))
end
.
to
change
(
ProtectedBranch
,
:count
).
by
(
1
)
end
end
describe
"PUT #update"
do
let
(
:update_params
)
{
{
name:
'new_name'
}
}
before
do
sign_in
(
user
)
end
it
'updates the protected branch rule'
do
put
(
:update
,
base_params
.
merge
(
protected_branch:
update_params
))
expect
(
protected_branch
.
reload
.
name
).
to
eq
(
'new_name'
)
expect
(
json_response
[
"name"
]).
to
eq
(
'new_name'
)
end
end
describe
"DELETE #destroy"
do
before
do
sign_in
(
user
)
end
it
"deletes the protected branch rule"
do
delete
(
:destroy
,
base_params
)
expect
{
ProtectedBranch
.
find
(
protected_branch
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
end
end
spec/policies/protected_branch_policy_spec.rb
View file @
e7061396
...
...
@@ -29,7 +29,7 @@ describe ProtectedBranchPolicy do
context
'and unprotection is limited to admins'
do
#TODO: remove this is temporary exploration
before
do
stub_
ee_
application_setting
(
only_admins_can_unprotect_master_branch:
true
)
stub_application_setting
(
only_admins_can_unprotect_master_branch:
true
)
end
context
'and the protection is for master'
do
...
...
spec/services/protected_branches/destroy_service_spec.rb
0 → 100644
View file @
e7061396
require
'spec_helper'
describe
ProtectedBranches
::
DestroyService
do
let
(
:protected_branch
)
{
create
(
:protected_branch
)
}
let
(
:project
)
{
protected_branch
.
project
}
let
(
:user
)
{
project
.
owner
}
describe
'#execute'
do
subject
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
it
'destroys a protected branch'
do
service
.
execute
(
protected_branch
)
expect
(
protected_branch
).
to
be_destroyed
end
end
end
spec/services/protected_tags/destroy_service_spec.rb
0 → 100644
View file @
e7061396
require
'spec_helper'
describe
ProtectedTags
::
DestroyService
do
let
(
:protected_tag
)
{
create
(
:protected_tag
)
}
let
(
:project
)
{
protected_tag
.
project
}
let
(
:user
)
{
project
.
owner
}
describe
'#execute'
do
subject
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
it
'destroy a protected tag'
do
service
.
execute
(
protected_tag
)
expect
(
protected_tag
).
to
be_destroyed
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