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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
88781783
Commit
88781783
authored
May 22, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete branch service with permission checks
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
9f80ab8e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
app/services/delete_branch_service.rb
app/services/delete_branch_service.rb
+42
-0
No files found.
app/services/delete_branch_service.rb
0 → 100644
View file @
88781783
class
DeleteBranchService
def
execute
(
project
,
branch_name
,
current_user
)
repository
=
project
.
repository
branch
=
repository
.
find_branch
(
branch_name
)
# No such branch
unless
branch
return
error
(
'No such branch'
)
end
# Dont allow remove of protected branch
if
project
.
protected_branch?
(
branch_name
)
return
error
(
'Protected branch cant be removed'
)
end
# Dont allow user to remove branch if he is not allowed to push
unless
current_user
.
can?
(
:push_code
,
project
)
return
error
(
'You dont have push access to repo'
)
end
if
repository
.
rm_branch
(
branch_name
)
Event
.
create_ref_event
(
project
,
current_user
,
branch
,
'rm'
)
success
(
'Branch was removed'
)
else
return
error
(
'Failed to remove branch'
)
end
end
def
error
(
message
)
{
message:
message
,
state: :error
}
end
def
success
(
message
)
{
message:
message
,
state: :success
}
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