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

72 lines
1.5 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
module BoardsActions
include Gitlab::Utils::StrongMemoize
extend ActiveSupport::Concern
included do
2021-06-08 01:23:25 +05:30
before_action :authorize_read_board!, only: [:index, :show]
2022-11-25 23:54:43 +05:30
before_action :redirect_to_recent_board, only: [:index]
before_action :board, only: [:index, :show]
2021-01-03 14:25:43 +05:30
before_action :push_licensed_features, only: [:index, :show]
2019-07-07 11:18:12 +05:30
end
def index
2022-11-25 23:54:43 +05:30
# if no board exists, create one
@board = board_create_service.execute.payload unless board # rubocop:disable Gitlab/ModuleWithInstanceVariables
2019-07-07 11:18:12 +05:30
end
def show
2022-11-25 23:54:43 +05:30
return render_404 unless board
2019-07-07 11:18:12 +05:30
2022-11-25 23:54:43 +05:30
# Add / update the board in the recent visits table
board_visit_service.new(parent, current_user).execute(board)
2019-07-07 11:18:12 +05:30
end
private
2022-11-25 23:54:43 +05:30
def redirect_to_recent_board
return if !parent.multiple_issue_boards_available? || !latest_visited_board
redirect_to board_path(latest_visited_board.board)
2020-01-01 13:55:28 +05:30
end
2022-11-25 23:54:43 +05:30
def latest_visited_board
@latest_visited_board ||= Boards::VisitsFinder.new(parent, current_user).latest
end
# Noop on FOSS
def push_licensed_features
2019-07-07 11:18:12 +05:30
end
def board
strong_memoize(:board) do
2021-03-11 19:13:27 +05:30
board_finder.execute.first
2019-07-07 11:18:12 +05:30
end
end
2019-09-04 21:01:54 +05:30
2021-06-08 01:23:25 +05:30
def board_visit_service
Boards::Visits::CreateService
end
2022-11-25 23:54:43 +05:30
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
2019-09-04 21:01:54 +05:30
end
2022-11-25 23:54:43 +05:30
def group?
instance_variable_defined?(:@group)
2019-09-04 21:01:54 +05:30
end
2019-07-07 11:18:12 +05:30
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
BoardsActions.prepend_mod_with('BoardsActions')