gitlab-org--gitlab-foss/app/controllers/projects/boards_controller.rb

61 lines
1.6 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-08-01 12:09:41 -04:00
class Projects::BoardsController < Projects::ApplicationController
2017-08-28 17:56:49 -04:00
include BoardsResponses
2017-08-31 13:48:57 -04:00
include IssuableCollections
before_action :check_issues_available!
before_action :authorize_read_board!, only: [:index, :show]
before_action :boards, only: :index
2017-08-28 17:56:49 -04:00
before_action :assign_endpoint_vars
before_action :redirect_to_recent_board, only: :index
def index
2017-08-28 17:56:49 -04:00
respond_with_boards
end
2016-08-01 12:09:41 -04:00
def show
@board = boards.find(params[:id])
# add/update the board in the recent visited table
Boards::Visits::CreateService.new(@board.project, current_user).execute(@board) if request.format.html?
2017-08-28 17:56:49 -04:00
respond_with_board
2016-08-01 12:09:41 -04:00
end
private
def boards
@boards ||= Boards::ListService.new(project, current_user).execute
end
2017-08-28 17:56:49 -04:00
def assign_endpoint_vars
2017-12-03 13:46:07 -05:00
@boards_endpoint = project_boards_path(project)
2017-08-28 17:56:49 -04:00
@bulk_issues_path = bulk_update_project_issues_path(project)
2017-09-04 15:55:29 -04:00
@namespace_path = project.namespace.full_path
2017-08-28 17:56:49 -04:00
@labels_endpoint = project_labels_path(project)
end
def authorize_read_board!
access_denied! unless can?(current_user, :read_board, project)
end
def serialize_as_json(resource)
2016-10-10 22:29:20 -04:00
resource.as_json(only: [:id])
end
def includes_board?(board_id)
boards.any? { |board| board.id == board_id }
end
def redirect_to_recent_board
return if request.format.json?
recently_visited = Boards::Visits::LatestService.new(project, current_user).execute
if recently_visited && includes_board?(recently_visited.board_id)
redirect_to(namespace_project_board_path(id: recently_visited.board_id), status: :found)
end
end
2016-08-01 12:09:41 -04:00
end