2020-02-05 07:09:15 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
2020-08-10 14:09:54 -04:00
|
|
|
class MilestonesResolver < BaseResolver
|
2020-02-05 07:09:15 -05:00
|
|
|
include Gitlab::Graphql::Authorize::AuthorizeResource
|
|
|
|
include TimeFrameArguments
|
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
argument :ids, [GraphQL::ID_TYPE],
|
2020-08-10 14:09:54 -04:00
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'Array of global milestone IDs, e.g., "gid://gitlab/Milestone/1".'
|
2020-02-05 07:09:15 -05:00
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
argument :state, Types::MilestoneStateEnum,
|
2020-08-10 14:09:54 -04:00
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'Filter milestones by state.'
|
2020-05-14 05:07:53 -04:00
|
|
|
|
2020-10-13 23:08:32 -04:00
|
|
|
argument :title, GraphQL::STRING_TYPE,
|
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'The title of the milestone.'
|
2020-10-13 23:08:32 -04:00
|
|
|
|
|
|
|
argument :search_title, GraphQL::STRING_TYPE,
|
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'A search string for the title.'
|
2020-10-13 23:08:32 -04:00
|
|
|
|
|
|
|
argument :containing_date, Types::TimeType,
|
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'A date that the milestone contains.'
|
2020-10-13 23:08:32 -04:00
|
|
|
|
2020-11-13 10:09:24 -05:00
|
|
|
type Types::MilestoneType.connection_type, null: true
|
2020-02-05 07:09:15 -05:00
|
|
|
|
|
|
|
def resolve(**args)
|
|
|
|
validate_timeframe_params!(args)
|
|
|
|
|
|
|
|
authorize!
|
|
|
|
|
|
|
|
MilestonesFinder.new(milestones_finder_params(args)).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def milestones_finder_params(args)
|
|
|
|
{
|
2020-07-30 14:09:39 -04:00
|
|
|
ids: parse_gids(args[:ids]),
|
2020-02-05 07:09:15 -05:00
|
|
|
state: args[:state] || 'all',
|
2020-10-13 23:08:32 -04:00
|
|
|
title: args[:title],
|
|
|
|
search_title: args[:search_title],
|
|
|
|
containing_date: args[:containing_date]
|
|
|
|
}.merge!(timeframe_parameters(args)).merge!(parent_id_parameters(args))
|
|
|
|
end
|
|
|
|
|
|
|
|
def timeframe_parameters(args)
|
|
|
|
if args[:timeframe]
|
|
|
|
args[:timeframe].transform_keys { |k| :"#{k}_date" }
|
|
|
|
else
|
|
|
|
args.slice(:start_date, :end_date)
|
|
|
|
end
|
2020-02-05 07:09:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def parent
|
2020-08-10 14:09:54 -04:00
|
|
|
synchronized_object
|
2020-02-05 07:09:15 -05:00
|
|
|
end
|
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
def parent_id_parameters(args)
|
|
|
|
raise NotImplementedError
|
2020-02-05 07:09:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# MilestonesFinder does not check for current_user permissions,
|
|
|
|
# so for now we need to keep it here.
|
|
|
|
def authorize!
|
|
|
|
Ability.allowed?(context[:current_user], :read_milestone, parent) || raise_resource_not_available_error!
|
|
|
|
end
|
2020-05-14 05:07:53 -04:00
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
def parse_gids(gids)
|
|
|
|
gids&.map { |gid| GitlabSchema.parse_gid(gid, expected_type: Milestone).model_id }
|
2020-05-14 05:07:53 -04:00
|
|
|
end
|
2020-02-05 07:09:15 -05:00
|
|
|
end
|
|
|
|
end
|