diff options
author | Baldinof <baldinof@gmail.com> | 2016-03-22 15:34:35 +0100 |
---|---|---|
committer | Baldinof <baldinof@gmail.com> | 2016-03-22 15:34:35 +0100 |
commit | fa4126acffdfe13741e05a60ad5ed7fd407b4f16 (patch) | |
tree | b7f7e6e49d851c947426684def13c593896f0c70 /app | |
parent | 436caf4e8b7beb8cb61bb1045273488477841880 (diff) | |
download | gitlab-ce-fa4126acffdfe13741e05a60ad5ed7fd407b4f16.tar.gz |
Move unlink fork logic to a service
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects_controller.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 20 | ||||
-rw-r--r-- | app/services/projects/unlink_fork_service.rb | 19 |
3 files changed, 20 insertions, 21 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 94789702d65..87657e4e3d2 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -71,7 +71,7 @@ class ProjectsController < ApplicationController def remove_fork return access_denied! unless can?(current_user, :remove_fork_project, @project) - if @project.unlink_fork(current_user) + if ::Projects::UnlinkForkService.new(@project, current_user).execute flash[:notice] = 'The fork relationship has been removed.' end end diff --git a/app/models/project.rb b/app/models/project.rb index 8d9908128e2..691b706ea40 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -917,26 +917,6 @@ class Project < ActiveRecord::Base self.builds_enabled = true end - def unlink_fork(user) - if forked? - forked_from_project.lfs_objects.find_each do |lfs_object| - lfs_object.projects << self - end - - merge_requests = forked_from_project.merge_requests.opened.from_project(self) - - unless merge_requests.empty? - close_service = MergeRequests::CloseService.new(self, user) - - merge_requests.each do |mr| - close_service.execute(mr) - end - end - - forked_project_link.destroy - end - end - def any_runners?(&block) if runners.active.any?(&block) return true diff --git a/app/services/projects/unlink_fork_service.rb b/app/services/projects/unlink_fork_service.rb new file mode 100644 index 00000000000..d0703effa1d --- /dev/null +++ b/app/services/projects/unlink_fork_service.rb @@ -0,0 +1,19 @@ +module Projects + class UnlinkForkService < BaseService + def execute + return unless @project.forked? + + @project.forked_from_project.lfs_objects.find_each do |lfs_object| + lfs_object.projects << self + end + + merge_requests = @project.forked_from_project.merge_requests.opened.from_project(@project) + + merge_requests.each do |mr| + MergeRequests::CloseService.new(@project, @current_user).execute(mr) + end + + @project.forked_project_link.destroy + end + end +end |