diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-10 14:03:00 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-10 14:03:00 +0300 |
commit | 6a9aed1e878bc8651243d645d0a9d2f7da33f248 (patch) | |
tree | b70a5bb88b89676130271207029df4eaba0dc573 /lib/api | |
parent | 223d26405128a64f624b78e7d4b03565d1e85a69 (diff) | |
parent | 381638b77f68004dd9b5607eacceb3cee5b2bf3c (diff) | |
download | gitlab-ce-6a9aed1e878bc8651243d645d0a9d2f7da33f248.tar.gz |
Merge branch 'master' into 6-0-dev
Conflicts:
CHANGELOG
VERSION
app/views/admin/teams/projects/new.html.haml
app/views/projects/teams/available.html.haml
doc/install/installation.md
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 7 | ||||
-rw-r--r-- | lib/api/helpers.rb | 6 | ||||
-rw-r--r-- | lib/api/projects.rb | 36 |
3 files changed, 46 insertions, 3 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 14d6c0f9353..7fcc7eba9d2 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -25,6 +25,12 @@ module API expose :id, :url, :created_at end + class ForkedFromProject < Grape::Entity + expose :id + expose :name, :name_with_namespace + expose :path, :path_with_namespace + end + class Project < Grape::Entity expose :id, :description, :default_branch, :public, :ssh_url_to_repo, :http_url_to_repo, :web_url expose :owner, using: Entities::UserBasic @@ -32,6 +38,7 @@ module API expose :path, :path_with_namespace expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :created_at, :last_activity_at expose :namespace + expose :forked_from_project, using: Entities::ForkedFromProject, :if => lambda{ | project, options | project.forked? } end class ProjectMember < UserBasic diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 94cf4f2e69f..f857d4133b2 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -5,12 +5,12 @@ module API end def user_project - @project ||= find_project + @project ||= find_project(params[:id]) @project || not_found! end - def find_project - project = Project.find_by_id(params[:id]) || Project.find_with_namespace(params[:id]) + def find_project(id) + project = Project.find_by_id(id) || Project.find_with_namespace(id) if project && can?(current_user, :read_project, project) project diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 6dc051e4ba2..d5709f5cb59 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -121,6 +121,42 @@ module API end + # Mark this project as forked from another + # + # Parameters: + # id: (required) - The ID of the project being marked as a fork + # forked_from_id: (required) - The ID of the project it was forked from + # Example Request: + # POST /projects/:id/fork/:forked_from_id + post ":id/fork/:forked_from_id" do + authenticated_as_admin! + forked_from_project = find_project(params[:forked_from_id]) + unless forked_from_project.nil? + 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) + else + render_api_error!("Project already forked", 409) + end + else + not_found! + end + + end + + # Remove a forked_from relationship + # + # Parameters: + # id: (required) - The ID of the project being marked as a fork + # Example Request: + # DELETE /projects/:id/fork + delete ":id/fork" do + authenticated_as_admin! + unless user_project.forked_project_link.nil? + user_project.forked_project_link.destroy + end + end + + # Get a project team members # # Parameters: |