2020-04-21 11:21:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class BoardListsResolver < BaseResolver
|
|
|
|
include Gitlab::Graphql::Authorize::AuthorizeResource
|
|
|
|
|
|
|
|
type Types::BoardListType, null: true
|
|
|
|
|
2020-07-31 14:09:37 -04:00
|
|
|
argument :id, GraphQL::ID_TYPE,
|
|
|
|
required: false,
|
|
|
|
description: 'Find a list by its global ID'
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
alias_method :board, :object
|
|
|
|
|
2020-07-31 14:09:37 -04:00
|
|
|
def resolve(lookahead: nil, id: nil)
|
2020-04-21 11:21:10 -04:00
|
|
|
authorize!(board)
|
|
|
|
|
2020-07-31 14:09:37 -04:00
|
|
|
lists = board_lists(id)
|
2020-04-21 11:21:10 -04:00
|
|
|
|
|
|
|
if load_preferences?(lookahead)
|
|
|
|
List.preload_preferences_for_user(lists, context[:current_user])
|
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection.new(lists)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-07-31 14:09:37 -04:00
|
|
|
def board_lists(id)
|
2020-09-25 11:09:36 -04:00
|
|
|
service = ::Boards::Lists::ListService.new(
|
2020-07-31 14:09:37 -04:00
|
|
|
board.resource_parent,
|
|
|
|
context[:current_user],
|
|
|
|
list_id: extract_list_id(id)
|
|
|
|
)
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
service.execute(board, create_default_lists: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorized_resource?(board)
|
|
|
|
Ability.allowed?(context[:current_user], :read_list, board)
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_preferences?(lookahead)
|
|
|
|
lookahead&.selection(:edges)&.selection(:node)&.selects?(:collapsed)
|
|
|
|
end
|
2020-07-31 14:09:37 -04:00
|
|
|
|
|
|
|
def extract_list_id(gid)
|
|
|
|
return unless gid.present?
|
|
|
|
|
|
|
|
GitlabSchema.parse_gid(gid, expected_type: ::List).model_id
|
|
|
|
end
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
end
|