2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-31 13:48:57 -04:00
|
|
|
module BoardsResponses
|
2018-02-19 14:06:16 -05:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
# Overridden on EE module
|
2018-02-19 14:06:16 -05:00
|
|
|
def board_params
|
2019-06-17 08:58:48 -04:00
|
|
|
params.require(:board).permit(:name)
|
2018-02-19 14:06:16 -05:00
|
|
|
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
|
|
|
|
|
2017-08-31 13:48:57 -04:00
|
|
|
def authorize_read_list
|
2019-01-17 12:40:37 -05:00
|
|
|
authorize_action_for!(board, :read_list)
|
2017-08-31 13:48:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_read_issue
|
2019-01-17 12:40:37 -05:00
|
|
|
authorize_action_for!(board, :read_issue)
|
2017-08-31 13:48:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_update_issue
|
|
|
|
authorize_action_for!(issue, :admin_issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_create_issue
|
2018-10-24 23:38:02 -04:00
|
|
|
list = List.find(issue_params[:list_id])
|
|
|
|
action = list.backlog? ? :create_issue : :admin_issue
|
2018-10-24 05:58:34 -04:00
|
|
|
|
2018-10-24 23:38:02 -04:00
|
|
|
authorize_action_for!(project, action)
|
2017-08-31 13:48:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_admin_list
|
2019-01-17 12:40:37 -05:00
|
|
|
authorize_action_for!(board, :admin_list)
|
2017-08-31 13:48:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_action_for!(resource, ability)
|
|
|
|
return render_403 unless can?(current_user, ability, resource)
|
|
|
|
end
|
|
|
|
|
|
|
|
def respond_with_boards
|
2017-11-22 02:50:36 -05:00
|
|
|
respond_with(@boards) # rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2017-08-31 13:48:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def respond_with_board
|
2017-11-22 02:50:36 -05:00
|
|
|
respond_with(@board) # rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2017-08-31 13:48:57 -04:00
|
|
|
end
|
|
|
|
|
2018-02-19 14:06:16 -05:00
|
|
|
def serialize_as_json(resource)
|
2019-06-10 06:30:00 -04:00
|
|
|
serializer.represent(resource).as_json
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
|
2017-08-31 13:48:57 -04:00
|
|
|
def respond_with(resource)
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
render json: serialize_as_json(resource)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-06-06 04:13:18 -04:00
|
|
|
|
|
|
|
def serializer
|
|
|
|
BoardSerializer.new
|
|
|
|
end
|
2017-08-31 13:48:57 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
BoardsResponses.prepend_if_ee('EE::BoardsResponses')
|