diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2017-12-07 08:44:55 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-12-07 08:44:55 +0000 |
commit | c9871e84e4b605922689aee5957d206516dca8e8 (patch) | |
tree | 6b4818c767b6e87cbe21f4808411f00db0d593d6 /lib | |
parent | af09fb858e0588d4d246ffa55bdd653e05d97b63 (diff) | |
download | gitlab-ce-c9871e84e4b605922689aee5957d206516dca8e8.tar.gz |
The API isn't using the appropriate services for managing forks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/projects.rb | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 14a4fc6f025..fa222bf2b1c 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -367,15 +367,16 @@ module API post ":id/fork/:forked_from_id" do authenticated_as_admin! - forked_from_project = find_project!(params[:forked_from_id]) - not_found!("Source Project") unless forked_from_project + fork_from_project = find_project!(params[:forked_from_id]) - if user_project.forked_from_project.nil? - user_project.create_forked_project_link(forked_to_project_id: user_project.id, forked_from_project_id: forked_from_project.id) + not_found!("Source Project") unless fork_from_project - ::Projects::ForksCountService.new(forked_from_project).refresh_cache + result = ::Projects::ForkService.new(fork_from_project, current_user).execute(user_project) + + if result + present user_project.reload, with: Entities::Project else - render_api_error!("Project already forked", 409) + render_api_error!("Project already forked", 409) if user_project.forked? end end @@ -383,11 +384,11 @@ module API delete ":id/fork" do authorize! :remove_fork_project, user_project - if user_project.forked? - destroy_conditionally!(user_project.forked_project_link) - else - not_modified! + result = destroy_conditionally!(user_project) do + ::Projects::UnlinkForkService.new(user_project, current_user).execute end + + result ? status(204) : not_modified! end desc 'Share the project with a group' do |