debian-mirror-gitlab/app/graphql/resolvers/board_lists_resolver.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Resolvers
class BoardListsResolver < BaseResolver
2021-01-03 14:25:43 +05:30
include BoardIssueFilterable
2021-02-22 17:27:13 +05:30
prepend ManualAuthorization
2020-05-24 23:13:21 +05:30
include Gitlab::Graphql::Authorize::AuthorizeResource
type Types::BoardListType, null: true
2021-02-22 17:27:13 +05:30
extras [:lookahead]
authorize :read_list
2020-05-24 23:13:21 +05:30
2021-01-29 00:20:46 +05:30
argument :id, Types::GlobalIDType[List],
2020-10-24 23:57:45 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Find a list by its global ID.'
2020-10-24 23:57:45 +05:30
2021-01-03 14:25:43 +05:30
argument :issue_filters, Types::Boards::BoardIssueInputType,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Filters applied when getting issue metadata in the board list.'
2021-01-03 14:25:43 +05:30
2020-05-24 23:13:21 +05:30
alias_method :board, :object
2021-01-03 14:25:43 +05:30
def resolve(lookahead: nil, id: nil, issue_filters: {})
2020-05-24 23:13:21 +05:30
authorize!(board)
2020-10-24 23:57:45 +05:30
lists = board_lists(id)
2021-01-03 14:25:43 +05:30
context.scoped_set!(:issue_filters, issue_filters(issue_filters))
2020-05-24 23:13:21 +05:30
if load_preferences?(lookahead)
2021-03-11 19:13:27 +05:30
List.preload_preferences_for_user(lists, current_user)
2020-05-24 23:13:21 +05:30
end
2021-02-22 17:27:13 +05:30
offset_pagination(lists)
2020-05-24 23:13:21 +05:30
end
private
2020-10-24 23:57:45 +05:30
def board_lists(id)
2021-01-03 14:25:43 +05:30
service = ::Boards::Lists::ListService.new(
2020-10-24 23:57:45 +05:30
board.resource_parent,
2021-03-11 19:13:27 +05:30
current_user,
2020-10-24 23:57:45 +05:30
list_id: extract_list_id(id)
)
2020-05-24 23:13:21 +05:30
service.execute(board, create_default_lists: false)
end
def load_preferences?(lookahead)
2021-03-11 19:13:27 +05:30
lookahead&.selection(:edges)&.selection(:node)&.selects?(:collapsed) ||
lookahead&.selection(:nodes)&.selects?(:collapsed)
2020-05-24 23:13:21 +05:30
end
2020-10-24 23:57:45 +05:30
def extract_list_id(gid)
return unless gid.present?
GitlabSchema.parse_gid(gid, expected_type: ::List).model_id
end
2020-05-24 23:13:21 +05:30
end
end