debian-mirror-gitlab/app/controllers/concerns/multiple_boards_actions.rb

94 lines
2.5 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# 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
2022-04-04 11:22:00 +05:30
recent_visits = ::Boards::VisitsFinder.new(parent, current_user).latest(Board::RECENT_BOARDS_SIZE)
2019-09-30 21:07:59 +05:30
recent_boards = recent_visits.map(&:board)
render json: serialize_as_json(recent_boards)
end
def create
2021-01-03 14:25:43 +05:30
response = Boards::CreateService.new(parent, current_user, board_params).execute
2019-09-30 21:07:59 +05:30
respond_to do |format|
format.json do
2021-01-03 14:25:43 +05:30
board = response.payload
if response.success?
2019-09-30 21:07:59 +05:30
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
2021-03-11 19:13:27 +05:30
return unless board_type == Board.to_type
2019-09-30 21:07:59 +05:30
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!
2021-04-17 20:07:23 +05:30
return render_404 unless can?(current_user, :admin_issue_board, parent)
2019-09-30 21:07:59 +05:30
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