Commit 9664424c authored by Douwe Maan's avatar Douwe Maan

Merge branch 'ci/api-projects' into 'master'

Extend projects API with CI data

Reference #4264 

See merge request !2303
parents bbc28428 fc4108b3
...@@ -76,7 +76,10 @@ Parameters: ...@@ -76,7 +76,10 @@ Parameters:
"updated_at": "2013-09-30T13: 46: 02Z" "updated_at": "2013-09-30T13: 46: 02Z"
}, },
"archived": false, "archived": false,
"avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png" "avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png",
"shared_runners_enabled": true,
"forks_count": 0,
"star_count": 0
}, },
{ {
"id": 6, "id": 6,
...@@ -129,7 +132,11 @@ Parameters: ...@@ -129,7 +132,11 @@ Parameters:
} }
}, },
"archived": false, "archived": false,
"avatar_url": null "avatar_url": null,
"shared_runners_enabled": true,
"forks_count": 0,
"star_count": 0,
"runners_token": "b8547b1dc37721d05889db52fa2f02"
} }
] ]
``` ```
...@@ -244,7 +251,11 @@ Parameters: ...@@ -244,7 +251,11 @@ Parameters:
} }
}, },
"archived": false, "archived": false,
"avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png" "avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png",
"shared_runners_enabled": true,
"forks_count": 0,
"star_count": 0,
"runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b"
} }
``` ```
......
...@@ -71,6 +71,7 @@ module API ...@@ -71,6 +71,7 @@ module API
expose :avatar_url expose :avatar_url
expose :star_count, :forks_count expose :star_count, :forks_count
expose :open_issues_count, if: lambda { |project, options| project.issues_enabled? && project.default_issues_tracker? } expose :open_issues_count, if: lambda { |project, options| project.issues_enabled? && project.default_issues_tracker? }
expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
end end
class ProjectMember < UserBasic class ProjectMember < UserBasic
......
...@@ -69,7 +69,8 @@ module API ...@@ -69,7 +69,8 @@ module API
# Example Request: # Example Request:
# GET /projects/:id # GET /projects/:id
get ":id" do get ":id" do
present user_project, with: Entities::ProjectWithAccess, user: current_user present user_project, with: Entities::ProjectWithAccess, user: current_user,
user_can_admin_project: can?(current_user, :admin_project, user_project)
end end
# Get events for a single project # Get events for a single project
...@@ -118,7 +119,8 @@ module API ...@@ -118,7 +119,8 @@ module API
attrs = map_public_to_visibility_level(attrs) attrs = map_public_to_visibility_level(attrs)
@project = ::Projects::CreateService.new(current_user, attrs).execute @project = ::Projects::CreateService.new(current_user, attrs).execute
if @project.saved? if @project.saved?
present @project, with: Entities::Project present @project, with: Entities::Project,
user_can_admin_project: can?(current_user, :admin_project, @project)
else else
if @project.errors[:limit_reached].present? if @project.errors[:limit_reached].present?
error!(@project.errors[:limit_reached], 403) error!(@project.errors[:limit_reached], 403)
...@@ -163,7 +165,8 @@ module API ...@@ -163,7 +165,8 @@ module API
attrs = map_public_to_visibility_level(attrs) attrs = map_public_to_visibility_level(attrs)
@project = ::Projects::CreateService.new(user, attrs).execute @project = ::Projects::CreateService.new(user, attrs).execute
if @project.saved? if @project.saved?
present @project, with: Entities::Project present @project, with: Entities::Project,
user_can_admin_project: can?(current_user, :admin_project, @project)
else else
render_validation_error!(@project) render_validation_error!(@project)
end end
...@@ -182,8 +185,9 @@ module API ...@@ -182,8 +185,9 @@ module API
if @forked_project.errors.any? if @forked_project.errors.any?
conflict!(@forked_project.errors.messages) conflict!(@forked_project.errors.messages)
else else
present @forked_project, with: Entities::Project present @forked_project, with: Entities::Project,
end user_can_admin_project: can?(current_user, :admin_project, @forked_project)
end
end end
# Update an existing project # Update an existing project
...@@ -229,7 +233,8 @@ module API ...@@ -229,7 +233,8 @@ module API
if user_project.errors.any? if user_project.errors.any?
render_validation_error!(user_project) render_validation_error!(user_project)
else else
present user_project, with: Entities::Project present user_project, with: Entities::Project,
user_can_admin_project: can?(current_user, :admin_project, user_project)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment