Commit fc4108b3 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Modify CI features in projects API

parent ba9799b4
...@@ -79,11 +79,7 @@ Parameters: ...@@ -79,11 +79,7 @@ Parameters:
"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, "shared_runners_enabled": true,
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0
"build_allow_git_fetch": true,
"build_coverage_regex": null,
"build_timeout": 3600,
"runners_token": "4f9e77be0eed5ef29548fccda3b371"
}, },
{ {
"id": 6, "id": 6,
...@@ -140,9 +136,6 @@ Parameters: ...@@ -140,9 +136,6 @@ Parameters:
"shared_runners_enabled": true, "shared_runners_enabled": true,
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0,
"build_allow_git_fetch": true,
"build_coverage_regex": null,
"build_timeout": 3600,
"runners_token": "b8547b1dc37721d05889db52fa2f02" "runners_token": "b8547b1dc37721d05889db52fa2f02"
} }
] ]
...@@ -262,9 +255,6 @@ Parameters: ...@@ -262,9 +255,6 @@ Parameters:
"shared_runners_enabled": true, "shared_runners_enabled": true,
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0,
"build_allow_git_fetch": true,
"build_coverage_regex": null,
"build_timeout": 3600,
"runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b" "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b"
} }
``` ```
...@@ -430,9 +420,6 @@ Parameters: ...@@ -430,9 +420,6 @@ Parameters:
- `public` (optional) - if `true` same as setting visibility_level = 20 - `public` (optional) - if `true` same as setting visibility_level = 20
- `visibility_level` (optional) - `visibility_level` (optional)
- `import_url` (optional) - `import_url` (optional)
- `build_allow_git_fetch` (optional)
- `build_timeout` (optional)
- `build_coverage_regex` (optional)
### Create project for user ### Create project for user
...@@ -455,9 +442,6 @@ Parameters: ...@@ -455,9 +442,6 @@ Parameters:
- `public` (optional) - if `true` same as setting visibility_level = 20 - `public` (optional) - if `true` same as setting visibility_level = 20
- `visibility_level` (optional) - `visibility_level` (optional)
- `import_url` (optional) - `import_url` (optional)
- `build_allow_git_fetch` (optional)
- `build_timeout` (optional)
- `build_coverage_regex` (optional)
### Edit project ### Edit project
...@@ -481,9 +465,6 @@ Parameters: ...@@ -481,9 +465,6 @@ Parameters:
- `snippets_enabled` (optional) - `snippets_enabled` (optional)
- `public` (optional) - if `true` same as setting visibility_level = 20 - `public` (optional) - if `true` same as setting visibility_level = 20
- `visibility_level` (optional) - `visibility_level` (optional)
- `build_allow_git_fetch` (optional)
- `build_timeout` (optional)
- `build_coverage_regex` (optional)
On success, method returns 200 with the updated project. If parameters are On success, method returns 200 with the updated project. If parameters are
invalid, 400 is returned. invalid, 400 is returned.
......
...@@ -71,9 +71,7 @@ module API ...@@ -71,9 +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] }
expose :build_allow_git_fetch, :build_timeout, :build_coverage_regex
expose :runners_token
end end
class ProjectMember < UserBasic class ProjectMember < UserBasic
......
...@@ -157,7 +157,7 @@ module API ...@@ -157,7 +157,7 @@ module API
def attributes_for_keys(keys, custom_params = nil) def attributes_for_keys(keys, custom_params = nil)
attrs = {} attrs = {}
keys.each do |key| keys.each do |key|
if params[key].present? or (params.has_key?(key) and (params[key].empty? or params[key] == false)) if params[key].present? or (params.has_key?(key) and params[key] == false)
attrs[key] = params[key] attrs[key] = params[key]
end end
end end
......
...@@ -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
...@@ -98,9 +99,6 @@ module API ...@@ -98,9 +99,6 @@ module API
# public (optional) - if true same as setting visibility_level = 20 # public (optional) - if true same as setting visibility_level = 20
# visibility_level (optional) - 0 by default # visibility_level (optional) - 0 by default
# import_url (optional) # import_url (optional)
# build_allow_git_fetch (optional)
# build_timeout (optional)
# build_coverage_regex (optional)
# Example Request # Example Request
# POST /projects # POST /projects
post do post do
...@@ -117,14 +115,12 @@ module API ...@@ -117,14 +115,12 @@ module API
:namespace_id, :namespace_id,
:public, :public,
:visibility_level, :visibility_level,
:import_url, :import_url]
:build_allow_git_fetch,
:build_timeout,
:build_coverage_regex]
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)
...@@ -149,9 +145,6 @@ module API ...@@ -149,9 +145,6 @@ module API
# public (optional) - if true same as setting visibility_level = 20 # public (optional) - if true same as setting visibility_level = 20
# visibility_level (optional) # visibility_level (optional)
# import_url (optional) # import_url (optional)
# build_allow_git_fetch (optional)
# build_timeout (optional)
# build_coverage_regex (optional)
# Example Request # Example Request
# POST /projects/user/:user_id # POST /projects/user/:user_id
post "user/:user_id" do post "user/:user_id" do
...@@ -168,14 +161,12 @@ module API ...@@ -168,14 +161,12 @@ module API
:shared_runners_enabled, :shared_runners_enabled,
:public, :public,
:visibility_level, :visibility_level,
:import_url, :import_url]
:build_allow_git_fetch,
:build_timeout,
:build_coverage_regex]
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
...@@ -194,7 +185,8 @@ module API ...@@ -194,7 +185,8 @@ 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,
user_can_admin_project: can?(current_user, :admin_project, @forked_project)
end end
end end
...@@ -213,9 +205,6 @@ module API ...@@ -213,9 +205,6 @@ module API
# shared_runners_enabled (optional) # shared_runners_enabled (optional)
# public (optional) - if true same as setting visibility_level = 20 # public (optional) - if true same as setting visibility_level = 20
# visibility_level (optional) - visibility level of a project # visibility_level (optional) - visibility level of a project
# build_allow_git_fetch (optional)
# build_timeout (optional)
# build_coverage_regex (optional)
# Example Request # Example Request
# PUT /projects/:id # PUT /projects/:id
put ':id' do put ':id' do
...@@ -230,10 +219,7 @@ module API ...@@ -230,10 +219,7 @@ module API
:snippets_enabled, :snippets_enabled,
:shared_runners_enabled, :shared_runners_enabled,
:public, :public,
:visibility_level, :visibility_level]
:build_allow_git_fetch,
:build_timeout,
:build_coverage_regex]
attrs = map_public_to_visibility_level(attrs) attrs = map_public_to_visibility_level(attrs)
authorize_admin_project authorize_admin_project
authorize! :rename_project, user_project if attrs[:name].present? authorize! :rename_project, user_project if attrs[:name].present?
...@@ -247,7 +233,8 @@ module API ...@@ -247,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