2019-02-26 17:26:26 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module BoardsActions
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2021-05-05 00:10:41 +00:00
|
|
|
before_action :authorize_read_board!, only: [:index, :show]
|
2022-09-28 15:09:17 +00:00
|
|
|
before_action :redirect_to_recent_board, only: [:index]
|
|
|
|
before_action :board, only: [:index, :show]
|
2020-09-21 21:09:27 +00:00
|
|
|
before_action :push_licensed_features, only: [:index, :show]
|
2019-02-26 17:26:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
2022-09-28 15:09:17 +00:00
|
|
|
# if no board exists, create one
|
|
|
|
@board = board_create_service.execute.payload unless board # rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2019-02-26 17:26:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2022-09-28 15:09:17 +00:00
|
|
|
return render_404 unless board
|
2019-02-26 17:26:26 +00:00
|
|
|
|
2022-09-28 15:09:17 +00:00
|
|
|
# Add / update the board in the recent visits table
|
|
|
|
board_visit_service.new(parent, current_user).execute(board)
|
2019-02-26 17:26:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-09-28 15:09:17 +00:00
|
|
|
def redirect_to_recent_board
|
|
|
|
return if !parent.multiple_issue_boards_available? || !latest_visited_board
|
|
|
|
|
|
|
|
redirect_to board_path(latest_visited_board.board)
|
2019-11-21 06:06:32 +00:00
|
|
|
end
|
|
|
|
|
2022-09-28 15:09:17 +00:00
|
|
|
def latest_visited_board
|
|
|
|
@latest_visited_board ||= Boards::VisitsFinder.new(parent, current_user).latest
|
|
|
|
end
|
|
|
|
|
|
|
|
# Noop on FOSS
|
|
|
|
def push_licensed_features
|
2019-02-26 17:26:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def board
|
|
|
|
strong_memoize(:board) do
|
2021-02-12 09:08:48 +00:00
|
|
|
board_finder.execute.first
|
2019-02-26 17:26:26 +00:00
|
|
|
end
|
|
|
|
end
|
2019-06-06 08:13:18 +00:00
|
|
|
|
2021-05-11 15:10:20 +00:00
|
|
|
def board_visit_service
|
|
|
|
Boards::Visits::CreateService
|
|
|
|
end
|
2022-10-14 21:09:20 +00:00
|
|
|
|
|
|
|
def parent
|
|
|
|
strong_memoize(:parent) do
|
|
|
|
group? ? group : project
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def board_path(board)
|
|
|
|
if group?
|
|
|
|
group_board_path(parent, board)
|
|
|
|
else
|
|
|
|
project_board_path(parent, board)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def group?
|
|
|
|
instance_variable_defined?(:@group)
|
|
|
|
end
|
2019-02-26 17:26:26 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
BoardsActions.prepend_mod_with('BoardsActions')
|