debian-mirror-gitlab/app/controllers/projects/boards_controller.rb

61 lines
1.6 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
class Projects::BoardsController < Projects::ApplicationController
2018-03-17 18:26:18 +05:30
include BoardsResponses
2016-11-03 12:29:30 +05:30
include IssuableCollections
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
before_action :check_issues_available!
2016-11-03 12:29:30 +05:30
before_action :authorize_read_board!, only: [:index, :show]
2018-11-08 19:23:39 +05:30
before_action :boards, only: :index
2018-03-17 18:26:18 +05:30
before_action :assign_endpoint_vars
2018-12-13 13:39:08 +05:30
before_action :redirect_to_recent_board, only: :index
2016-11-03 12:29:30 +05:30
def index
2018-03-17 18:26:18 +05:30
respond_with_boards
2016-11-03 12:29:30 +05:30
end
2016-09-13 17:45:13 +05:30
def show
2018-11-08 19:23:39 +05:30
@board = boards.find(params[:id])
2016-11-03 12:29:30 +05:30
2018-12-13 13:39:08 +05:30
# add/update the board in the recent visited table
Boards::Visits::CreateService.new(@board.project, current_user).execute(@board) if request.format.html?
2018-03-17 18:26:18 +05:30
respond_with_board
2016-09-13 17:45:13 +05:30
end
private
2018-11-08 19:23:39 +05:30
def boards
@boards ||= Boards::ListService.new(project, current_user).execute
end
2018-03-17 18:26:18 +05:30
def assign_endpoint_vars
@boards_endpoint = project_boards_path(project)
@bulk_issues_path = bulk_update_project_issues_path(project)
@namespace_path = project.namespace.full_path
@labels_endpoint = project_labels_path(project)
end
2016-09-13 17:45:13 +05:30
def authorize_read_board!
2018-12-13 13:39:08 +05:30
access_denied! unless can?(current_user, :read_board, project)
2016-09-13 17:45:13 +05:30
end
2016-11-03 12:29:30 +05:30
def serialize_as_json(resource)
resource.as_json(only: [:id])
end
2018-12-13 13:39:08 +05:30
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-09-13 17:45:13 +05:30
end