diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-02-01 12:41:01 -0600 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-02-17 11:29:16 +0000 |
commit | ac868482a7780a332045ef270a409ff70bcf8efd (patch) | |
tree | 99ff605262028f08718f04ac0c9e42c516d38693 /app/services | |
parent | 5d8f5328baca93b9134f10ae593e71834578a9f8 (diff) | |
download | gitlab-ce-ac868482a7780a332045ef270a409ff70bcf8efd.tar.gz |
Allow issues in boards to be ordered
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/boards/issues/list_service.rb | 7 | ||||
-rw-r--r-- | app/services/boards/issues/move_service.rb | 29 | ||||
-rw-r--r-- | app/services/issuable_base_service.rb | 2 | ||||
-rw-r--r-- | app/services/issues/update_service.rb | 21 |
4 files changed, 45 insertions, 14 deletions
diff --git a/app/services/boards/issues/list_service.rb b/app/services/boards/issues/list_service.rb index 8a94c54b6ab..185838764c1 100644 --- a/app/services/boards/issues/list_service.rb +++ b/app/services/boards/issues/list_service.rb @@ -5,7 +5,7 @@ module Boards issues = IssuesFinder.new(current_user, filter_params).execute issues = without_board_labels(issues) unless movable_list? issues = with_list_label(issues) if movable_list? - issues + issues.reorder(Gitlab::Database.nulls_last_order('relative_position', 'ASC')) end private @@ -26,7 +26,6 @@ module Boards def filter_params set_default_scope - set_default_sort set_project set_state @@ -37,10 +36,6 @@ module Boards params[:scope] = 'all' end - def set_default_sort - params[:sort] = 'priority' - end - def set_project params[:project_id] = project.id end diff --git a/app/services/boards/issues/move_service.rb b/app/services/boards/issues/move_service.rb index 96554a92a02..7c0df55e9b6 100644 --- a/app/services/boards/issues/move_service.rb +++ b/app/services/boards/issues/move_service.rb @@ -3,7 +3,7 @@ module Boards class MoveService < BaseService def execute(issue) return false unless can?(current_user, :update_issue, issue) - return false unless valid_move? + return false if issue_params.empty? update_service.execute(issue) end @@ -14,7 +14,7 @@ module Boards @board ||= project.boards.find(params[:board_id]) end - def valid_move? + def move_between_lists? moving_from_list.present? && moving_to_list.present? && moving_from_list != moving_to_list end @@ -32,11 +32,19 @@ module Boards end def issue_params - { - add_label_ids: add_label_ids, - remove_label_ids: remove_label_ids, - state_event: issue_state - } + attrs = {} + + if move_between_lists? + attrs.merge!( + add_label_ids: add_label_ids, + remove_label_ids: remove_label_ids, + state_event: issue_state, + ) + end + + attrs[:move_between_iids] = move_between_iids if move_between_iids + + attrs end def issue_state @@ -58,6 +66,13 @@ module Boards Array(label_ids).compact end + + def move_between_iids + move_after_iid = params[:move_after_iid] + move_before_iid = params[:move_before_iid] + return unless move_after_iid || move_before_iid + [move_after_iid, move_before_iid] + end end end end diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index 5f3ced49665..2256d7db008 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -212,7 +212,7 @@ class IssuableBaseService < BaseService label_ids = process_label_ids(params, existing_label_ids: issuable.label_ids) params[:label_ids] = label_ids if labels_changing?(issuable.label_ids, label_ids) - if params.present? && update_issuable(issuable, params) + if (issuable.changed? || params.present?) && update_issuable(issuable, params) # We do not touch as it will affect a update on updated_at field ActiveRecord::Base.no_touching do handle_common_system_notes(issuable, old_labels: old_labels) diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb index 78cbf94ec69..ba06f208dbc 100644 --- a/app/services/issues/update_service.rb +++ b/app/services/issues/update_service.rb @@ -1,6 +1,7 @@ module Issues class UpdateService < Issues::BaseService def execute(issue) + handle_move_between_iids(issue) update(issue) end @@ -47,6 +48,26 @@ module Issues Issues::CloseService end + def handle_move_between_iids(issue) + if move_between_iids = params.delete(:move_between_iids) + before_iid, after_iid = move_between_iids + + issue_before = nil + if before_iid + issue_before = issue.project.issues.find_by(iid: before_iid) + issue_before = nil unless can?(current_user, :update_issue, issue_before) + end + + issue_after = nil + if after_iid + issue_after = issue.project.issues.find_by(iid: after_iid) + issue_after = nil unless can?(current_user, :update_issue, issue_after) + end + + issue.move_between(issue_before, issue_after) + end + end + private def create_confidentiality_note(issue) |