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

95 lines
1.9 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module BoardsResponses
2018-03-27 19:54:05 +05:30
include Gitlab::Utils::StrongMemoize
2019-09-30 21:07:59 +05:30
# Overridden on EE module
2018-03-27 19:54:05 +05:30
def board_params
2019-09-30 21:07:59 +05:30
params.require(:board).permit(:name)
2018-03-27 19:54:05 +05:30
end
def parent
strong_memoize(:parent) do
group? ? group : project
end
end
def boards_path
if group?
group_boards_path(parent)
else
project_boards_path(parent)
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
2018-03-17 18:26:18 +05:30
def authorize_read_list
2021-04-17 20:07:23 +05:30
authorize_action_for!(board, :read_issue_board_list)
2018-03-17 18:26:18 +05:30
end
def authorize_read_issue
2019-03-02 22:35:43 +05:30
authorize_action_for!(board, :read_issue)
2018-03-17 18:26:18 +05:30
end
def authorize_update_issue
authorize_action_for!(issue, :admin_issue)
end
def authorize_create_issue
2018-12-13 13:39:08 +05:30
list = List.find(issue_params[:list_id])
action = list.backlog? ? :create_issue : :admin_issue
authorize_action_for!(project, action)
2018-03-17 18:26:18 +05:30
end
def authorize_admin_list
2021-04-17 20:07:23 +05:30
authorize_action_for!(board, :admin_issue_board_list)
2018-03-17 18:26:18 +05:30
end
def authorize_action_for!(resource, ability)
return render_403 unless can?(current_user, ability, resource)
end
def respond_with_boards
respond_with(@boards) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end
def respond_with_board
2021-03-11 19:13:27 +05:30
# rubocop:disable Gitlab/ModuleWithInstanceVariables
return render_404 unless @board
respond_with(@board)
# rubocop:enable Gitlab/ModuleWithInstanceVariables
2018-03-17 18:26:18 +05:30
end
2018-03-27 19:54:05 +05:30
def serialize_as_json(resource)
2019-09-04 21:01:54 +05:30
serializer.represent(resource).as_json
2018-03-27 19:54:05 +05:30
end
2018-03-17 18:26:18 +05:30
def respond_with(resource)
respond_to do |format|
format.html
format.json do
render json: serialize_as_json(resource)
end
end
end
2019-09-04 21:01:54 +05:30
def serializer
BoardSerializer.new
end
2018-03-17 18:26:18 +05:30
end
2019-12-04 20:38:33 +05:30
BoardsResponses.prepend_if_ee('EE::BoardsResponses')