summaryrefslogtreecommitdiff
path: root/lib/api/projects.rb
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-12-07 13:44:09 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-12-07 13:44:09 +0000
commita2479aaa1be00416f952eb79fa444328266c16b6 (patch)
tree523250a25fc5b60ccd767bfc0a64f295a1c86b2e /lib/api/projects.rb
parent139ce1c44587f6920cdb1982c33714ff6cf910b7 (diff)
parent17542a7895f288b8e7bc92836039f4dcbb7c17d2 (diff)
downloadgitlab-ce-a2479aaa1be00416f952eb79fa444328266c16b6.tar.gz
Merge branch 'master' into 38869-datetime
* master: (82 commits) Docs: add EEU tier to the landing page CE backport of ProtectedBranches API changes Support uploads for groups Update pipeline create chain Prometheus metric Don't set timeago title to what was already there. Resolve "Display member role per project" The API isn't using the appropriate services for managing forks Add chevron to create dropdown on repository page Rename GKE as Kubernetes Engine Fix specs for MySQL Fix broken tests Refactor banzai to support referencing from group context Fix specs after rebase Prevent dups when using StringIO for binary reads Bump redis-rails to 5.0.2 to get redis-store security updates add note on deploying Pages to a private network Bump GITLAB_SHELL_VERSION Updates the dropdown to match the docs and remove old hack of stop event propagation Move invalid builds counter out of the transaction Add invalid builds counter metric to stage seeds class ...
Diffstat (limited to 'lib/api/projects.rb')
-rw-r--r--lib/api/projects.rb21
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