diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-07-28 09:33:41 +0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-08-17 18:58:57 +0300 |
commit | 115fca13c3712c787f2a637e936cb1174483555a (patch) | |
tree | 41c57f8f27ad71ccafc62a8d9f77eb3af56b0cd1 /app/services | |
parent | 26ac0846408b21bd541f3c31f082f00e9422d9f4 (diff) |
Add service to move issues between lists
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/boards/issues/move_service.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/app/services/boards/issues/move_service.rb b/app/services/boards/issues/move_service.rb new file mode 100644 index 00000000000..d893a52cf9b --- /dev/null +++ b/app/services/boards/issues/move_service.rb @@ -0,0 +1,58 @@ +module Boards + module Issues + class MoveService + def initialize(project, user, params = {}) + @project = project + @user = user + @params = params.dup + end + + def execute + return false unless issue.present? + + update_service.execute(issue) + reopen_service.execute(issue) if moving_from.done? + close_service.execute(issue) if moving_to.done? + + true + end + + private + + attr_reader :project, :user, :params + + delegate :board, to: :project + + def issue + @issue ||= project.issues.visible_to_user(user).find_by!(iid: params[:id]) + end + + def moving_from + @moving_from ||= board.lists.find(params[:from]) + end + + def moving_to + @moving_to ||= board.lists.find(params[:to]) + end + + def close_service + ::Issues::CloseService.new(project, user) + end + + def reopen_service + ::Issues::ReopenService.new(project, user) + end + + def update_service + ::Issues::UpdateService.new(project, user, issue_params) + end + + def issue_params + { + add_label_ids: [moving_to.label_id].compact, + remove_label_ids: [moving_from.label_id].compact + } + end + end + end +end |