diff options
author | Alexandru Croitor <acroitor@gitlab.com> | 2019-06-17 15:58:48 +0300 |
---|---|---|
committer | Alexandru Croitor <acroitor@gitlab.com> | 2019-06-26 12:28:00 +0300 |
commit | 0f6c42c5ce165dadf1976ae15a043b87ca533618 (patch) | |
tree | 9220ed5a8eb628ca3c5170a0d5f9400870538797 /app/controllers | |
parent | 2b9ddc2f99bc0a49967c9ccc5b79ccc53e7559b4 (diff) | |
download | gitlab-ce-0f6c42c5ce165dadf1976ae15a043b87ca533618.tar.gz |
Move Multiple Issue Boards for Projects to Core53811-issue-boards-to-core-projects-backend-ce
Refactor code to allow multiple issue boards management for projects
in CE
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/concerns/boards_responses.rb | 3 | ||||
-rw-r--r-- | app/controllers/concerns/multiple_boards_actions.rb | 90 | ||||
-rw-r--r-- | app/controllers/projects/boards_controller.rb | 2 |
3 files changed, 93 insertions, 2 deletions
diff --git a/app/controllers/concerns/boards_responses.rb b/app/controllers/concerns/boards_responses.rb index 7625600e452..9da2f888ead 100644 --- a/app/controllers/concerns/boards_responses.rb +++ b/app/controllers/concerns/boards_responses.rb @@ -3,8 +3,9 @@ module BoardsResponses include Gitlab::Utils::StrongMemoize + # Overridden on EE module def board_params - params.require(:board).permit(:name, :weight, :milestone_id, :assignee_id, label_ids: []) + params.require(:board).permit(:name) end def parent diff --git a/app/controllers/concerns/multiple_boards_actions.rb b/app/controllers/concerns/multiple_boards_actions.rb new file mode 100644 index 00000000000..95a6800f55c --- /dev/null +++ b/app/controllers/concerns/multiple_boards_actions.rb @@ -0,0 +1,90 @@ +# frozen_string_literal: true + +module MultipleBoardsActions + include Gitlab::Utils::StrongMemoize + extend ActiveSupport::Concern + + included do + include BoardsActions + + before_action :redirect_to_recent_board, only: [:index] + before_action :authenticate_user!, only: [:recent] + before_action :authorize_create_board!, only: [:create] + before_action :authorize_admin_board!, only: [:create, :update, :destroy] + end + + def recent + recent_visits = ::Boards::VisitsFinder.new(parent, current_user).latest(4) + recent_boards = recent_visits.map(&:board) + + render json: serialize_as_json(recent_boards) + end + + def create + board = Boards::CreateService.new(parent, current_user, board_params).execute + + respond_to do |format| + format.json do + if board.persisted? + extra_json = { board_path: board_path(board) } + render json: serialize_as_json(board).merge(extra_json) + else + render json: board.errors, status: :unprocessable_entity + end + end + end + end + + def update + service = Boards::UpdateService.new(parent, current_user, board_params) + + respond_to do |format| + format.json do + if service.execute(board) + extra_json = { board_path: board_path(board) } + render json: serialize_as_json(board).merge(extra_json) + else + render json: board.errors, status: :unprocessable_entity + end + end + end + end + + def destroy + service = Boards::DestroyService.new(parent, current_user) + service.execute(board) + + respond_to do |format| + format.json { head :ok } + format.html { redirect_to boards_path, status: :found } + end + end + + private + + def redirect_to_recent_board + return if request.format.json? || !parent.multiple_issue_boards_available? || !latest_visited_board + + redirect_to board_path(latest_visited_board.board) + end + + def latest_visited_board + @latest_visited_board ||= Boards::VisitsFinder.new(parent, current_user).latest + end + + def authorize_create_board! + check_multiple_group_issue_boards_available! if group? + end + + def authorize_admin_board! + return render_404 unless can?(current_user, :admin_board, parent) + end + + def serializer + BoardSerializer.new(current_user: current_user) + end + + def serialize_as_json(resource) + serializer.represent(resource, serializer: 'board', include_full_project_path: board.group_board?) + end +end diff --git a/app/controllers/projects/boards_controller.rb b/app/controllers/projects/boards_controller.rb index 95897aaf980..14b02993e6e 100644 --- a/app/controllers/projects/boards_controller.rb +++ b/app/controllers/projects/boards_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Projects::BoardsController < Projects::ApplicationController - include BoardsActions + include MultipleBoardsActions include IssuableCollections before_action :check_issues_available! |