From 949431fa02da18257c8b7c7a24c03faa04c02c5e Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 29 Mar 2016 22:19:00 +0200 Subject: Update API to use notification_level from notification_setting Signed-off-by: Dmitriy Zaporozhets --- lib/api/entities.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index f686c568bee..f414c1f9885 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -255,14 +255,19 @@ module API expose :id, :path, :kind end - class ProjectAccess < Grape::Entity + class Member < Grape::Entity expose :access_level - expose :notification_level + expose :notification_level do |member, options| + if member.notification_setting + NotificationSetting.levels[member.notification_setting.level] + end + end end - class GroupAccess < Grape::Entity - expose :access_level - expose :notification_level + class ProjectAccess < Member + end + + class GroupAccess < Member end class ProjectService < Grape::Entity -- cgit v1.2.1 From 82e92a0900f76d208faf94629c90309201d05914 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 14:32:36 +0200 Subject: API: Expose open_issues_count, closed_issues_count, open_merge_requests_count on labels --- lib/api/entities.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 340fc5452ab..cd0d16e5316 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -293,6 +293,7 @@ module API class Label < Grape::Entity expose :name, :color, :description + expose :open_issues_count, :closed_issues_count, :open_merge_requests_count end class Compare < Grape::Entity -- cgit v1.2.1 From 1d2429af9b0fd4ef1427c7676a50dae4e2cf0ff9 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Thu, 7 Apr 2016 16:45:33 -0500 Subject: Add missing proper nil and error handling to SAML login process. --- lib/gitlab/saml/user.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index c1072452abe..dd77216be48 100644 --- a/lib/gitlab/saml/user.rb +++ b/lib/gitlab/saml/user.rb @@ -26,13 +26,15 @@ module Gitlab @user ||= build_new_user end - if external_users_enabled? - # Check if there is overlap between the user's groups and the external groups - # setting then set user as external or internal. - if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? - @user.external = false - else - @user.external = true + unless @user.nil? + if external_users_enabled? + # Check if there is overlap between the user's groups and the external groups + # setting then set user as external or internal. + if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? + @user.external = false + else + @user.external = true + end end end @@ -48,7 +50,11 @@ module Gitlab end def changed? - gl_user.changed? || gl_user.identities.any?(&:changed?) + if gl_user + gl_user.changed? || gl_user.identities.any?(&:changed?) + else + true + end end protected -- cgit v1.2.1 From 1d1ca8b9c257f79ae75740cacad7d361635312b6 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Sat, 9 Apr 2016 13:29:37 +0100 Subject: fix emoji aliases not showing in autocomplete --- lib/tasks/gemojione.rake | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gemojione.rake b/lib/tasks/gemojione.rake index 7ec00a898fd..030ee8bafcb 100644 --- a/lib/tasks/gemojione.rake +++ b/lib/tasks/gemojione.rake @@ -5,12 +5,23 @@ namespace :gemojione do require 'json' dir = Gemojione.index.images_path + digests = [] + aliases = Hash.new { |hash, key| hash[key] = [] } + aliases_path = File.join(Rails.root, 'fixtures', 'emojis', 'aliases.json') - digests = AwardEmoji.emojis.map do |name, emoji_hash| + JSON.parse(File.read(aliases_path)).each do |alias_name, real_name| + aliases[real_name] << alias_name + end + + AwardEmoji.emojis.map do |name, emoji_hash| fpath = File.join(dir, "#{emoji_hash['unicode']}.png") digest = Digest::SHA256.file(fpath).hexdigest - { name: name, unicode: emoji_hash['unicode'], digest: digest } + digests << { name: name, unicode: emoji_hash['unicode'], digest: digest } + + aliases[name].each do |alias_name| + digests << { name: alias_name, unicode: emoji_hash['unicode'], digest: digest } + end end out = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json') -- cgit v1.2.1 From 12e6084667f8750c263b4a2e324e9a283697b52e Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 11 Apr 2016 10:16:15 -0500 Subject: Allow `external_providers` for Omniauth to be defined to mark these users as external --- lib/gitlab/o_auth/user.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/gitlab/o_auth/user.rb b/lib/gitlab/o_auth/user.rb index 832fb08a526..6e099c26d8c 100644 --- a/lib/gitlab/o_auth/user.rb +++ b/lib/gitlab/o_auth/user.rb @@ -54,6 +54,14 @@ module Gitlab @user ||= build_new_user end + unless @user.nil? + if external_provider? + @user.external = true + else + @user.external = false + end + end + @user end @@ -113,6 +121,10 @@ module Gitlab end end + def external_provider? + Gitlab.config.omniauth.external_providers.include?(auth_hash.provider) + end + def block_after_signup? if creating_linked_ldap_user? ldap_config.block_auto_created_users -- cgit v1.2.1 From 05a611a0918f9a39de4ea3a051c2192c327f778d Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 11 Apr 2016 17:25:18 -0500 Subject: Better control flow and added guard clause. --- lib/gitlab/saml/user.rb | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index dd77216be48..dba4bbfc899 100644 --- a/lib/gitlab/saml/user.rb +++ b/lib/gitlab/saml/user.rb @@ -26,15 +26,13 @@ module Gitlab @user ||= build_new_user end - unless @user.nil? - if external_users_enabled? - # Check if there is overlap between the user's groups and the external groups - # setting then set user as external or internal. - if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? - @user.external = false - else - @user.external = true - end + if external_users_enabled? && @user + # Check if there is overlap between the user's groups and the external groups + # setting then set user as external or internal. + if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? + @user.external = false + else + @user.external = true end end @@ -50,11 +48,8 @@ module Gitlab end def changed? - if gl_user - gl_user.changed? || gl_user.identities.any?(&:changed?) - else - true - end + return true unless gl_user + gl_user.changed? || gl_user.identities.any?(&:changed?) end protected -- cgit v1.2.1 From 61fc9aa87ea3752f3c7b853ab1cb102e53d392f2 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 11 Apr 2016 17:26:01 -0500 Subject: Better control flow. --- lib/gitlab/o_auth/user.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/o_auth/user.rb b/lib/gitlab/o_auth/user.rb index 6e099c26d8c..356e96fcbab 100644 --- a/lib/gitlab/o_auth/user.rb +++ b/lib/gitlab/o_auth/user.rb @@ -54,12 +54,10 @@ module Gitlab @user ||= build_new_user end - unless @user.nil? - if external_provider? - @user.external = true - else - @user.external = false - end + if external_provider? && @user + @user.external = true + elsif @user + @user.external = false end @user -- cgit v1.2.1 From 10080ce3624e199bd770a924d8d7f178008d4cb7 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 12:32:34 +0200 Subject: API: Expose updated_at for notes --- lib/api/entities.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 5ed9b7b1d9f..939469b3886 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -212,7 +212,7 @@ module API expose :note, as: :body expose :attachment_identifier, as: :attachment expose :author, using: Entities::UserBasic - expose :created_at + expose :created_at, :updated_at expose :system?, as: :system expose :noteable_id, :noteable_type # upvote? and downvote? are deprecated, always return false -- cgit v1.2.1 From 9d03e8fd5c564b20f3a1ef18583aa4c7c2b27cfc Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Thu, 7 Apr 2016 10:59:54 +0200 Subject: API: Add iid filter to milestones --- lib/api/milestones.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index 0f3f505fa05..84b4d4cdd6d 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -21,6 +21,7 @@ module API # state (optional) - Return "active" or "closed" milestones # Example Request: # GET /projects/:id/milestones + # GET /projects/:id/milestones?iid=42 # GET /projects/:id/milestones?state=active # GET /projects/:id/milestones?state=closed get ":id/milestones" do @@ -28,6 +29,7 @@ module API milestones = user_project.milestones milestones = filter_milestones_state(milestones, params[:state]) + milestones = filter_by_iid(milestones, params[:iid]) if params[:iid].present? present paginate(milestones), with: Entities::Milestone end -- cgit v1.2.1 From 20d4ca4cc3599b4335b73fd7c3bb0354efe397b4 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') 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 f81352f531b22d02b1b80cfbd6daed809ea8cf5d Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 12:50:21 +0200 Subject: Fix minor styling issues from code review --- lib/api/tags.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/api/tags.rb b/lib/api/tags.rb index 731a68082ba..d1a10479e44 100644 --- a/lib/api/tags.rb +++ b/lib/api/tags.rb @@ -19,15 +19,15 @@ module API # Get a single repository tag # # Parameters: - # id (required) - The ID of a project + # 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 + 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 + present tag, with: Entities::RepoTag, project: user_project end # Create tag -- cgit v1.2.1 From ba21c00f01bf4274d0e4cc3892293fc1e581b260 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 01:21:02 +0200 Subject: Delete notes via API --- lib/api/notes.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib') diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 174473f5371..fd1704d395c 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -112,6 +112,23 @@ module API end end + # Delete a +notable+ note + # + # Parameters: + # Parameters: + # id (required) - The ID of a project + # noteable_id (required) - The ID of an issue, MR, or snippet + # node_id (required) - The ID of a note + # Example Request: + # DELETE /projects/:id/issues/:noteable_id/notes/:note_id + # DELETE /projects/:id/snippets/:noteable_id/notes/:node_id + delete ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do + note = user_project.notes.find(params[:note_id]) + not_found!('Note') unless note + authorize! :admin_note, note + ::Notes::DeleteService.new(user_project, current_user).execute(note) + true + end end end end -- cgit v1.2.1 From 9aefaa41ab1442f81ffc15ad9a8279bd1e92c91a Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 19:04:17 +0200 Subject: Fix code review issues --- lib/api/notes.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/api/notes.rb b/lib/api/notes.rb index fd1704d395c..2ed986b9ec5 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -112,10 +112,9 @@ module API end end - # Delete a +notable+ note + # Delete a +noteable+ note # # Parameters: - # Parameters: # id (required) - The ID of a project # noteable_id (required) - The ID of an issue, MR, or snippet # node_id (required) - The ID of a note @@ -124,10 +123,9 @@ module API # DELETE /projects/:id/snippets/:noteable_id/notes/:node_id delete ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do note = user_project.notes.find(params[:note_id]) - not_found!('Note') unless note authorize! :admin_note, note ::Notes::DeleteService.new(user_project, current_user).execute(note) - true + present note, with: Entities::Note end end end -- cgit v1.2.1 From 6dbcb880cc72f7511358612bbc76e2ab9ded14c5 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Fri, 8 Apr 2016 12:41:37 +0200 Subject: Allow a project member to leave the projected through the API --- lib/api/project_members.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/api/project_members.rb b/lib/api/project_members.rb index c756bb479fc..4aefdf319c6 100644 --- a/lib/api/project_members.rb +++ b/lib/api/project_members.rb @@ -93,12 +93,17 @@ module API # Example Request: # DELETE /projects/:id/members/:user_id delete ":id/members/:user_id" do - authorize! :admin_project, user_project project_member = user_project.project_members.find_by(user_id: params[:user_id]) - unless project_member.nil? - project_member.destroy - else + + unless current_user.can?(:admin_project, user_project) || + current_user.can?(:destroy_project_member, project_member) + forbidden! + end + + if project_member.nil? { message: "Access revoked", id: params[:user_id].to_i } + else + project_member.destroy end end end -- cgit v1.2.1 From dc39c8372d760eceba50a35505dad8663b9e851e Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 15:43:29 +0200 Subject: Adapt tests to new testing guidelines --- lib/api/notes.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 2ed986b9ec5..a1c98f5e8ff 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -124,7 +124,9 @@ module API delete ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do note = user_project.notes.find(params[:note_id]) authorize! :admin_note, note + ::Notes::DeleteService.new(user_project, current_user).execute(note) + present note, with: Entities::Note end end -- cgit v1.2.1 From d0cdc2ee73c8421906fbd011d0f44d638616a864 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Thu, 7 Apr 2016 10:12:49 +0200 Subject: API: Ability to update a group --- lib/api/groups.rb | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/api/groups.rb b/lib/api/groups.rb index c165de21a75..964f691afcc 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -23,8 +23,10 @@ module API # Create group. Available only for users who can create groups. # # Parameters: - # name (required) - The name of the group - # path (required) - The path of the group + # name (required) - The name of the group + # path (required) - The path of the group + # description (optional) - The description of the group + # visibility_level (optional) - The visibility level of the group # Example Request: # POST /groups post do @@ -42,6 +44,30 @@ module API end end + # Update group. Available only for users who can administrate groups. + # + # Parameters: + # id (required) - The ID of a group + # path (optional) - The path of the group + # description (optional) - The description of the group + # visibility_level (optional) - The visibility level of the group + # Example Request: + # PUT /groups/:id + put ':id' do + group = find_group(params[:id]) + authorize! :admin_group, group + + attrs = attributes_for_keys [:name, :path, :description, :visibility_level] + + ::Groups::UpdateService.new(group, current_user, attrs).execute + + if group.errors.any? + render_validation_error!(group) + else + present group, with: Entities::GroupDetail + end + end + # Get a single group, with containing projects # # Parameters: -- cgit v1.2.1 From cba2c437e582dd5880ec45cc4ff2fccda2315ad5 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 11 Apr 2016 15:38:36 -0400 Subject: Move RepositoryArchiveCacheWorker to sidekiq-cron Closes #15105 --- lib/api/repositories.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index 0d0f0d4616d..62161aadb9a 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -98,7 +98,6 @@ module API authorize! :download_code, user_project begin - RepositoryArchiveCacheWorker.perform_async header *Gitlab::Workhorse.send_git_archive(user_project, params[:sha], params[:format]) rescue not_found!('File') -- cgit v1.2.1 From 5fb572417e0c331afb62c8bbaa561b0fe7836fc5 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 19:08:35 +0200 Subject: Fix minor issues according development guidelines --- lib/api/groups.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/api/groups.rb b/lib/api/groups.rb index 964f691afcc..91e420832f3 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -47,7 +47,7 @@ module API # Update group. Available only for users who can administrate groups. # # Parameters: - # id (required) - The ID of a group + # id (required) - The ID of a group # path (optional) - The path of the group # description (optional) - The description of the group # visibility_level (optional) - The visibility level of the group @@ -59,12 +59,10 @@ module API attrs = attributes_for_keys [:name, :path, :description, :visibility_level] - ::Groups::UpdateService.new(group, current_user, attrs).execute - - if group.errors.any? - render_validation_error!(group) - else + if ::Groups::UpdateService.new(group, current_user, attrs).execute present group, with: Entities::GroupDetail + else + render_validation_error!(group) end end -- cgit v1.2.1 From 2e13f6c326b920f1b78ca592dc1b938b62d5eef3 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 12 Apr 2016 14:39:08 -0400 Subject: Add `Gitlab.com?` method To be used as a feature flag for GitLab.com-only features, such as welcome emails. We will be careful to only use this to disable features or functionality that do not make sense for any installations that aren't GitLab.com. We will not use this to restrict features from other installations or keep them "exclusive" to GitLab.com. --- lib/gitlab.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/gitlab.rb b/lib/gitlab.rb index 6108697bc20..7479e729db1 100644 --- a/lib/gitlab.rb +++ b/lib/gitlab.rb @@ -1,4 +1,7 @@ require 'gitlab/git' module Gitlab + def self.com? + Gitlab.config.gitlab.url == 'https://gitlab.com' + end end -- cgit v1.2.1 From b2f48d8c46cebcf2a576c18b661c3481b3450f3b Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 21:34:24 +0200 Subject: API: Return 404 if user does not have access to group --- lib/api/helpers.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 4921ae99e78..96af7d7675c 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -91,8 +91,7 @@ module API if can?(current_user, :read_group, group) group else - forbidden!("#{current_user.username} lacks sufficient "\ - "access to #{group.name}") + not_found!('Group') end end -- cgit v1.2.1 From 3240ecfbefc7ae5994be6ef01b52c1cbdaa09057 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 12 Apr 2016 12:00:21 +0200 Subject: Added ability to add custom tags to transactions One use case for this is manually setting the "action" tag for Grape API calls. Due to Grape running blocks there are no human readable method names that can be used for the "action" tag, thus we have to set these manually on a case by case basis. --- lib/gitlab/metrics.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/gitlab/metrics.rb b/lib/gitlab/metrics.rb index 2a0a5629be5..484970c5a10 100644 --- a/lib/gitlab/metrics.rb +++ b/lib/gitlab/metrics.rb @@ -104,6 +104,16 @@ module Gitlab retval end + # Adds a tag to the current transaction (if any) + # + # name - The name of the tag to add. + # value - The value of the tag. + def self.tag_transaction(name, value) + trans = current_transaction + + trans.add_tag(name, value) if trans + end + # When enabled this should be set before being used as the usual pattern # "@foo ||= bar" is _not_ thread-safe. if enabled? -- cgit v1.2.1 From 482f67edb46423d4fc567e061d6546d8dfafc7bb Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Thu, 7 Apr 2016 14:07:17 +0200 Subject: API: Ability to move an issue --- lib/api/issues.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index c4ea05ee6cf..894d9794322 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -195,6 +195,29 @@ module API end end + # Move an existing issue + # + # Parameters: + # id (required) - The ID of a project + # issue_id (required) - The ID of a project issue + # new_project_id (required) - The ID of the new project + # Example Request: + # POST /projects/:id/issues/:issue_id/move + post ":id/issues/:issue_id/move" do + required_attributes! [:new_project_id] + + issue = user_project.issues.find(params[:issue_id]) + new_project = Project.find(params[:new_project_id]) + + begin + issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project) + present issue, with: Entities::Issue + rescue ::Issues::MoveService::MoveError => error + render_api_error!(error.message, 400) + end + end + + # # Delete a project issue # # Parameters: -- cgit v1.2.1 From 2b036025d619c51cff74e4eb430f50d43d1d8cdb Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 18:38:18 +0200 Subject: Update tests for moving issues via API --- lib/api/issues.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 894d9794322..850e99981ff 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -198,20 +198,20 @@ module API # Move an existing issue # # Parameters: - # id (required) - The ID of a project - # issue_id (required) - The ID of a project issue - # new_project_id (required) - The ID of the new project + # id (required) - The ID of a project + # issue_id (required) - The ID of a project issue + # to_project_id (required) - The ID of the new project # Example Request: # POST /projects/:id/issues/:issue_id/move - post ":id/issues/:issue_id/move" do - required_attributes! [:new_project_id] + post ':id/issues/:issue_id/move' do + required_attributes! [:to_project_id] issue = user_project.issues.find(params[:issue_id]) - new_project = Project.find(params[:new_project_id]) + new_project = Project.find(params[:to_project_id]) begin issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project) - present issue, with: Entities::Issue + present issue, with: Entities::Issue, current_user: current_user rescue ::Issues::MoveService::MoveError => error render_api_error!(error.message, 400) end -- cgit v1.2.1