From 7532c012c26fc116f7c39f7c88ac3b08d818955c Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Mon, 8 Aug 2016 17:25:39 +0100 Subject: user is now notified when creating an issue through the api --- lib/api/issues.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'lib/api/issues.rb') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 077258faee1..1121285f0af 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -154,6 +154,20 @@ module API render_api_error!({ labels: errors }, 400) end + if params[:labels].present? + params[:labels] = params[:labels].split(",").each { |word| word.strip! } + attrs[:label_ids] = [] + + params[:labels].each do |label| + existing_label = user_project.labels.where(title: label).first + + unless existing_label.nil? + attrs[:label_ids] << existing_label.id + params[:labels].delete(label) + end + end + end + project = user_project issue = ::Issues::CreateService.new(project, current_user, attrs.merge(request: request, api: true)).execute @@ -163,10 +177,10 @@ module API end if issue.valid? - # Find or create labels and attach to issue. Labels are valid because + # create new labels and attach to issue. Labels are valid because # we already checked its name, so there can't be an error here if params[:labels].present? - issue.add_labels_by_names(params[:labels].split(',')) + issue.add_labels_by_names(params[:labels]) end present issue, with: Entities::Issue, current_user: current_user -- cgit v1.2.1 From b7d29ce659412e9a2acc411c841420eb13d115ba Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Tue, 9 Aug 2016 23:08:59 +0100 Subject: adds test to check whether or not an email is sent to label subscribers after creating a new issue through the api --- lib/api/issues.rb | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'lib/api/issues.rb') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 1121285f0af..9a042e6e70d 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -154,35 +154,22 @@ module API render_api_error!({ labels: errors }, 400) end + # Find or create labels if params[:labels].present? - params[:labels] = params[:labels].split(",").each { |word| word.strip! } - attrs[:label_ids] = [] - - params[:labels].each do |label| - existing_label = user_project.labels.where(title: label).first - - unless existing_label.nil? - attrs[:label_ids] << existing_label.id - params[:labels].delete(label) - end + attrs[:label_ids] = params[:labels].split(",").map do |label_name| + user_project.labels.create_with(color: Label::DEFAULT_COLOR) + .find_or_create_by(title: label_name.strip) + .id end end - project = user_project - - issue = ::Issues::CreateService.new(project, current_user, attrs.merge(request: request, api: true)).execute + issue = ::Issues::CreateService.new(user_project, current_user, attrs.merge(request: request, api: true)).execute if issue.spam? render_api_error!({ error: 'Spam detected' }, 400) end if issue.valid? - # create new labels and attach to issue. Labels are valid because - # we already checked its name, so there can't be an error here - if params[:labels].present? - issue.add_labels_by_names(params[:labels]) - end - present issue, with: Entities::Issue, current_user: current_user else render_validation_error!(issue) -- cgit v1.2.1 From 7f0bcf04323ad69b64a90112896971ea8d1a5f99 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Mon, 15 Aug 2016 17:50:41 +0100 Subject: refactors update issue api request and some minor comments --- lib/api/issues.rb | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'lib/api/issues.rb') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 9a042e6e70d..39a46f69f16 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -154,14 +154,9 @@ module API render_api_error!({ labels: errors }, 400) end - # Find or create labels - if params[:labels].present? - attrs[:label_ids] = params[:labels].split(",").map do |label_name| - user_project.labels.create_with(color: Label::DEFAULT_COLOR) - .find_or_create_by(title: label_name.strip) - .id - end - end + # Find or create labels to attach to the issue. Labels are vaild + # because we already checked its name, so there can't be an error here + attrs[:label_ids] = get_label_ids(params[:labels]) if params[:labels].present? issue = ::Issues::CreateService.new(user_project, current_user, attrs.merge(request: request, api: true)).execute @@ -203,17 +198,16 @@ module API render_api_error!({ labels: errors }, 400) end + # Find or create labels and attach to issue. Labels are valid because + # we already checked its name, so there can't be an error here + if params[:labels] && can?(current_user, :admin_issue, user_project) + issue.remove_labels + attrs[:label_ids] = get_label_ids(params[:labels]) + end + issue = ::Issues::UpdateService.new(user_project, current_user, attrs).execute(issue) if issue.valid? - # Find or create labels and attach to issue. Labels are valid because - # we already checked its name, so there can't be an error here - if params[:labels] && can?(current_user, :admin_issue, user_project) - issue.remove_labels - # Create and add labels to the new created issue - issue.add_labels_by_names(params[:labels].split(',')) - end - present issue, with: Entities::Issue, current_user: current_user else render_validation_error!(issue) -- cgit v1.2.1 From 76c2901eac89b1b3a9975ec0f91fb929fbed2e70 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Thu, 18 Aug 2016 11:24:44 +0100 Subject: if issue is not valid we revert back to the old labels when updating --- lib/api/issues.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'lib/api/issues.rb') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 39a46f69f16..d0bc7243e54 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -154,9 +154,7 @@ module API render_api_error!({ labels: errors }, 400) end - # Find or create labels to attach to the issue. Labels are vaild - # because we already checked its name, so there can't be an error here - attrs[:label_ids] = get_label_ids(params[:labels]) if params[:labels].present? + attrs[:labels] = params[:labels] if params[:labels] issue = ::Issues::CreateService.new(user_project, current_user, attrs.merge(request: request, api: true)).execute @@ -198,12 +196,7 @@ module API render_api_error!({ labels: errors }, 400) end - # Find or create labels and attach to issue. Labels are valid because - # we already checked its name, so there can't be an error here - if params[:labels] && can?(current_user, :admin_issue, user_project) - issue.remove_labels - attrs[:label_ids] = get_label_ids(params[:labels]) - end + attrs[:labels] = params[:labels] if params[:labels] issue = ::Issues::UpdateService.new(user_project, current_user, attrs).execute(issue) -- cgit v1.2.1 From 036cc8c27e8340a3eed63444bd3f42f86037f350 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Fri, 15 Jul 2016 16:21:53 +0200 Subject: API: Expose issue#confidential --- lib/api/issues.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/api/issues.rb') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index d0bc7243e54..556684187d8 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -140,12 +140,13 @@ module API # labels (optional) - The labels of an issue # created_at (optional) - Date time string, ISO 8601 formatted # due_date (optional) - Date time string in the format YEAR-MONTH-DAY + # confidential (optional) - Boolean parameter if the issue should be confidential # Example Request: # POST /projects/:id/issues post ':id/issues' do required_attributes! [:title] - keys = [:title, :description, :assignee_id, :milestone_id, :due_date] + keys = [:title, :description, :assignee_id, :milestone_id, :due_date, :confidential] keys << :created_at if current_user.admin? || user_project.owner == current_user attrs = attributes_for_keys(keys) @@ -156,6 +157,10 @@ module API attrs[:labels] = params[:labels] if params[:labels] + # Convert and filter out invalid confidential flags + attrs['confidential'] = to_boolean(attrs['confidential']) + attrs.delete('confidential') if attrs['confidential'].nil? + issue = ::Issues::CreateService.new(user_project, current_user, attrs.merge(request: request, api: true)).execute if issue.spam? @@ -182,12 +187,13 @@ module API # state_event (optional) - The state event of an issue (close|reopen) # updated_at (optional) - Date time string, ISO 8601 formatted # due_date (optional) - Date time string in the format YEAR-MONTH-DAY + # confidential (optional) - Boolean parameter if the issue should be confidential # Example Request: # PUT /projects/:id/issues/:issue_id put ':id/issues/:issue_id' do issue = user_project.issues.find(params[:issue_id]) authorize! :update_issue, issue - keys = [:title, :description, :assignee_id, :milestone_id, :state_event, :due_date] + keys = [:title, :description, :assignee_id, :milestone_id, :state_event, :due_date, :confidential] keys << :updated_at if current_user.admin? || user_project.owner == current_user attrs = attributes_for_keys(keys) @@ -198,6 +204,10 @@ module API attrs[:labels] = params[:labels] if params[:labels] + # Convert and filter out invalid confidential flags + attrs['confidential'] = to_boolean(attrs['confidential']) + attrs.delete('confidential') if attrs['confidential'].nil? + issue = ::Issues::UpdateService.new(user_project, current_user, attrs).execute(issue) if issue.valid? -- cgit v1.2.1