From 2c5bcf2e1b5b5574238555657296a8831b989d1e Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Wed, 23 Mar 2016 22:36:35 +0100 Subject: Add endpoints for archiving and unarchiving --- lib/api/projects.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/api') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 6fcb5261e40..aa60a39f341 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -244,6 +244,34 @@ module API end end + # Archive project + # + # Parameters: + # id (required) - The ID of a project + # Example Request: + # PUT /projects/:id/archive + put ':id/archive' do + authorize!(:archive_project, user_project) + + user_project.archive! + + present @project, with: Entities::Project + end + + # Unarchive project + # + # Parameters: + # id (required) - The ID of a project + # Example Request: + # PUT /projects/:id/unarchive + put ':id/unarchive' do + authorize!(:archive_project, user_project) + + user_project.unarchive! + + present @project, with: Entities::Project + end + # Remove project # # Parameters: -- cgit v1.2.1 From 3549d7c1d402c10c567c239b006132c45b0c0d1e Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Thu, 24 Mar 2016 13:36:45 +0100 Subject: PUT becomes POST on archiving endpoints Also the specs have a minor improvement. Mainly the access right spec. Changes are reflected in the docs --- lib/api/projects.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/api') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index aa60a39f341..24b31005475 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -250,12 +250,12 @@ module API # id (required) - The ID of a project # Example Request: # PUT /projects/:id/archive - put ':id/archive' do + post ':id/archive' do authorize!(:archive_project, user_project) user_project.archive! - present @project, with: Entities::Project + present user_project, with: Entities::Project end # Unarchive project @@ -264,12 +264,12 @@ module API # id (required) - The ID of a project # Example Request: # PUT /projects/:id/unarchive - put ':id/unarchive' do + post ':id/unarchive' do authorize!(:archive_project, user_project) user_project.unarchive! - present @project, with: Entities::Project + present user_project, with: Entities::Project end # Remove project -- cgit v1.2.1 From 85cc1729596ac1e5b31d8cfa1daa07477db6033d Mon Sep 17 00:00:00 2001 From: connorshea Date: Thu, 31 Mar 2016 16:40:39 -0600 Subject: Remove "Congratulations!" tweet button on newly-created project. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’ve removed everything related to the feature based on this commit: ce08f919f34fd8849834365 Resolves #10857. --- lib/api/entities.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index f686c568bee..b7de575cdcd 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -334,7 +334,6 @@ module API expose :updated_at expose :home_page_url expose :default_branch_protection - expose :twitter_sharing_enabled expose :restricted_visibility_levels expose :max_attachment_size expose :session_expire_delay -- cgit v1.2.1 From 84b0ab77667b85a42db8a5a02d9758657af66f16 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 24 Mar 2016 17:00:26 +0100 Subject: Added & use Gitlab::Routing for URL helpers Rails' "url_helpers" method creates an anonymous Module (which a bunch of methods) on every call. By caching the output of this method in a dedicated method we can shave off about 10 seconds of loading time for an issue with around 200 comments. --- lib/api/entities.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index f686c568bee..c452aed27df 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -8,7 +8,7 @@ module API expose :id, :state, :avatar_url expose :web_url do |user, options| - Gitlab::Application.routes.url_helpers.user_url(user) + Gitlab::Routing.url_helpers.user_url(user) end end @@ -89,7 +89,7 @@ module API expose :avatar_url expose :web_url do |group, options| - Gitlab::Application.routes.url_helpers.group_url(group) + Gitlab::Routing.url_helpers.group_url(group) end end -- cgit v1.2.1 From d023a8528713ab9ffd8a9fc034f752ab91442b24 Mon Sep 17 00:00:00 2001 From: Yasser Hussain Date: Wed, 6 Apr 2016 15:07:31 +0530 Subject: Changed the argument of not_found for 'unprotect' not_found appends string "Not Found" to the argument causing the resulting message to be "Branch does not exist Not Found" which is an incorrect error message. Changed the argument of not_found! for 'unprotect' command to "Branch" from "Branch does not exist". This makes the final error message to appear as "Branch Not Found" which is correct and same as error messages for other commands like 'protect'. --- lib/api/branches.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/branches.rb b/lib/api/branches.rb index 592100a7045..231840148d9 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -64,7 +64,7 @@ module API authorize_admin_project @branch = user_project.repository.find_branch(params[:branch]) - not_found!("Branch does not exist") unless @branch + not_found!("Branch") unless @branch protected_branch = user_project.protected_branches.find_by(name: @branch.name) protected_branch.destroy if protected_branch -- cgit v1.2.1 From 7f287c9136d5d1cdda8df170c6e772ca82aad1e9 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 13:59:50 +0200 Subject: API: Ability to retrieve a single tag --- lib/api/tags.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/api') diff --git a/lib/api/tags.rb b/lib/api/tags.rb index 2d8a9e51bb9..731a68082ba 100644 --- a/lib/api/tags.rb +++ b/lib/api/tags.rb @@ -16,6 +16,20 @@ module API with: Entities::RepoTag, project: user_project end + # Get a single repository tag + # + # Parameters: + # id (required) - The ID of a project + # tag_name (required) - The name of the tag + # Example Request: + # GET /projects/:id/repository/tags/:tag_name + get ":id/repository/tags/:tag_name", requirements: { tag_name: /.*/ } do + tag = user_project.repository.find_tag(params[:tag_name]) + not_found!('Tag') unless tag + + present tag, with: Entities::RepoTag, project: user_project + end + # Create tag # # Parameters: -- cgit v1.2.1 From 62b6963255696192a015bbc28cb21de159572c1d Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 01:57:21 +0200 Subject: Expose user location in API --- lib/api/entities.rb | 2 +- lib/api/users.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 340fc5452ab..4c49442bf8b 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -15,7 +15,7 @@ module API class User < UserBasic expose :created_at expose :is_admin?, as: :is_admin - expose :bio, :skype, :linkedin, :twitter, :website_url + expose :bio, :location, :skype, :linkedin, :twitter, :website_url end class Identity < Grape::Entity diff --git a/lib/api/users.rb b/lib/api/users.rb index 13ab17c6904..0a14bac07c0 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -58,6 +58,7 @@ module API # extern_uid - External authentication provider UID # provider - External provider # bio - Bio + # location - Location of the user # admin - User is admin - true or false (default) # can_create_group - User can create groups - true or false # confirm - Require user confirmation - true (default) or false @@ -67,7 +68,7 @@ module API post do authenticated_as_admin! required_attributes! [:email, :password, :name, :username] - attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :bio, :can_create_group, :admin, :confirm, :external] + attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :bio, :location, :can_create_group, :admin, :confirm, :external] admin = attrs.delete(:admin) confirm = !(attrs.delete(:confirm) =~ (/(false|f|no|0)$/i)) user = User.build_user(attrs) @@ -106,6 +107,7 @@ module API # website_url - Website url # projects_limit - Limit projects each user can create # bio - Bio + # location - Location of the user # admin - User is admin - true or false (default) # can_create_group - User can create groups - true or false # external - Flags the user as external - true or false(default) @@ -114,7 +116,7 @@ module API put ":id" do authenticated_as_admin! - attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :website_url, :projects_limit, :username, :bio, :can_create_group, :admin, :external] + attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :website_url, :projects_limit, :username, :bio, :location, :can_create_group, :admin, :external] user = User.find(params[:id]) not_found!('User') unless user -- cgit v1.2.1 From 0728588c3424fd7e75ca3c45ad1ea84063437311 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 13:03:07 +0200 Subject: API: Ability to filter milestones by state --- lib/api/milestones.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'lib/api') diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index c5cd73943fb..39efa1b176b 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -3,17 +3,33 @@ module API class Milestones < Grape::API before { authenticate! } + helpers do + def filter_milestones_state(milestones, state) + case state + when 'active' then milestones.active + when 'closed' then milestones.closed + else milestones + end + end + end + resource :projects do # Get a list of project milestones # # Parameters: - # id (required) - The ID of a project + # id (required) - The ID of a project + # state (optional) - Return "active" or "closed" milestones # Example Request: # GET /projects/:id/milestones + # GET /projects/:id/milestones?state=active + # GET /projects/:id/milestones?state=closed get ":id/milestones" do authorize! :read_milestone, user_project - present paginate(user_project.milestones), with: Entities::Milestone + milestones = user_project.milestones + milestones = filter_milestones_state(milestones, params[:state]) unless params[:state].nil? + + present paginate(milestones), with: Entities::Milestone end # Get a single project milestone -- cgit v1.2.1 From e6215a9a8ed20354782120a7ce6368c7e8aab9a5 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 20:53:17 +0200 Subject: Improve coding and doc style --- lib/api/milestones.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index 39efa1b176b..afb6ffa3609 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -27,7 +27,7 @@ module API authorize! :read_milestone, user_project milestones = user_project.milestones - milestones = filter_milestones_state(milestones, params[:state]) unless params[:state].nil? + milestones = filter_milestones_state(milestones, params[:state]) present paginate(milestones), with: Entities::Milestone end -- cgit v1.2.1 From dc3272dccbf2462ad8a7ee8f677086ffabae3afb Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 21:03:24 +0200 Subject: Revert "API: Ability to retrieve a single tag" This reverts commit 7f287c9136d5d1cdda8df170c6e772ca82aad1e9. --- lib/api/tags.rb | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'lib/api') diff --git a/lib/api/tags.rb b/lib/api/tags.rb index 731a68082ba..2d8a9e51bb9 100644 --- a/lib/api/tags.rb +++ b/lib/api/tags.rb @@ -16,20 +16,6 @@ module API with: Entities::RepoTag, project: user_project end - # Get a single repository tag - # - # Parameters: - # id (required) - The ID of a project - # tag_name (required) - The name of the tag - # Example Request: - # GET /projects/:id/repository/tags/:tag_name - get ":id/repository/tags/:tag_name", requirements: { tag_name: /.*/ } do - tag = user_project.repository.find_tag(params[:tag_name]) - not_found!('Tag') unless tag - - present tag, with: Entities::RepoTag, project: user_project - end - # Create tag # # Parameters: -- cgit v1.2.1 From fb2fde9d62a599f08c065c54de236eacb6558d60 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Fri, 8 Apr 2016 08:41:10 +0200 Subject: API: Expose subscribed? on issues --- lib/api/entities.rb | 8 ++++++++ lib/api/issues.rb | 10 +++++----- lib/api/merge_requests.rb | 14 +++++++------- lib/api/milestones.rb | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 4c49442bf8b..d76b46b8836 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -170,6 +170,10 @@ module API expose :label_names, as: :labels expose :milestone, using: Entities::Milestone expose :assignee, :author, using: Entities::UserBasic + + expose :subscribed do |issue, options| + issue.subscribed?(options[:current_user]) + end end class MergeRequest < ProjectEntity @@ -183,6 +187,10 @@ module API expose :milestone, using: Entities::Milestone expose :merge_when_build_succeeds expose :merge_status + + expose :subscribed do |merge_request, options| + merge_request.subscribed?(options[:current_user]) + end end class MergeRequestChanges < MergeRequest diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 1fee1dee1a6..c4ea05ee6cf 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -55,7 +55,7 @@ module API issues = filter_issues_state(issues, params[:state]) unless params[:state].nil? issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? issues.reorder(issuable_order_by => issuable_sort) - present paginate(issues), with: Entities::Issue + present paginate(issues), with: Entities::Issue, current_user: current_user end end @@ -92,7 +92,7 @@ module API end issues.reorder(issuable_order_by => issuable_sort) - present paginate(issues), with: Entities::Issue + present paginate(issues), with: Entities::Issue, current_user: current_user end # Get a single project issue @@ -105,7 +105,7 @@ module API get ":id/issues/:issue_id" do @issue = user_project.issues.find(params[:issue_id]) not_found! unless can?(current_user, :read_issue, @issue) - present @issue, with: Entities::Issue + present @issue, with: Entities::Issue, current_user: current_user end # Create a new project issue @@ -149,7 +149,7 @@ module API issue.add_labels_by_names(params[:labels].split(',')) end - present issue, with: Entities::Issue + present issue, with: Entities::Issue, current_user: current_user else render_validation_error!(issue) end @@ -189,7 +189,7 @@ module API issue.add_labels_by_names(params[:labels].split(',')) end - present issue, with: Entities::Issue + present issue, with: Entities::Issue, current_user: current_user else render_validation_error!(issue) end diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 93052fba06b..4e7de8867b4 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -56,7 +56,7 @@ module API end merge_requests = merge_requests.reorder(issuable_order_by => issuable_sort) - present paginate(merge_requests), with: Entities::MergeRequest + present paginate(merge_requests), with: Entities::MergeRequest, current_user: current_user end # Create MR @@ -94,7 +94,7 @@ module API merge_request.add_labels_by_names(params[:labels].split(",")) end - present merge_request, with: Entities::MergeRequest + present merge_request, with: Entities::MergeRequest, current_user: current_user else handle_merge_request_errors! merge_request.errors end @@ -130,7 +130,7 @@ module API authorize! :read_merge_request, merge_request - present merge_request, with: Entities::MergeRequest + present merge_request, with: Entities::MergeRequest, current_user: current_user end # Show MR commits @@ -162,7 +162,7 @@ module API merge_request = user_project.merge_requests. find(params[:merge_request_id]) authorize! :read_merge_request, merge_request - present merge_request, with: Entities::MergeRequestChanges + present merge_request, with: Entities::MergeRequestChanges, current_user: current_user end # Update MR @@ -204,7 +204,7 @@ module API merge_request.add_labels_by_names(params[:labels].split(",")) end - present merge_request, with: Entities::MergeRequest + present merge_request, with: Entities::MergeRequest, current_user: current_user else handle_merge_request_errors! merge_request.errors end @@ -246,7 +246,7 @@ module API execute(merge_request) end - present merge_request, with: Entities::MergeRequest + present merge_request, with: Entities::MergeRequest, current_user: current_user end # Cancel Merge if Merge When build succeeds is enabled @@ -325,7 +325,7 @@ module API get "#{path}/closes_issues" do merge_request = user_project.merge_requests.find(params[:merge_request_id]) issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user)) - present paginate(issues), with: Entities::Issue + present paginate(issues), with: Entities::Issue, current_user: current_user end end end diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index afb6ffa3609..0f3f505fa05 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -103,7 +103,7 @@ module API authorize! :read_milestone, user_project @milestone = user_project.milestones.find(params[:milestone_id]) - present paginate(@milestone.issues), with: Entities::Issue + present paginate(@milestone.issues), with: Entities::Issue, current_user: current_user end end -- cgit v1.2.1