2020-06-02 11:08:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
2020-11-13 07:09:03 -05:00
|
|
|
class UserMergeRequestsResolverBase < MergeRequestsResolver
|
2020-06-02 11:08:24 -04:00
|
|
|
include ResolvesProject
|
|
|
|
|
2021-03-23 23:09:04 -04:00
|
|
|
argument :project_path,
|
2021-07-22 08:10:04 -04:00
|
|
|
type: GraphQL::Types::String,
|
2021-03-23 23:09:04 -04:00
|
|
|
required: false,
|
|
|
|
description: <<~DESC
|
|
|
|
The full-path of the project the authored merge requests should be in.
|
|
|
|
Incompatible with projectId.
|
|
|
|
DESC
|
|
|
|
|
|
|
|
argument :project_id,
|
|
|
|
type: ::Types::GlobalIDType[::Project],
|
|
|
|
required: false,
|
|
|
|
description: <<~DESC
|
|
|
|
The global ID of the project the authored merge requests should be in.
|
|
|
|
Incompatible with projectPath.
|
|
|
|
DESC
|
2020-06-02 11:08:24 -04:00
|
|
|
|
|
|
|
attr_reader :project
|
2021-03-18 02:11:52 -04:00
|
|
|
alias_method :user, :object
|
2020-06-02 11:08:24 -04:00
|
|
|
|
|
|
|
def ready?(project_id: nil, project_path: nil, **args)
|
|
|
|
return early_return unless can_read_profile?
|
|
|
|
|
|
|
|
if project_id || project_path
|
|
|
|
load_project(project_path, project_id)
|
|
|
|
return early_return unless can_read_project?
|
|
|
|
elsif args[:iids].present?
|
2021-03-23 23:09:04 -04:00
|
|
|
raise ::Gitlab::Graphql::Errors::ArgumentError, 'iids requires projectPath or projectId'
|
2020-06-02 11:08:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
super(**args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve(**args)
|
|
|
|
prepare_args(args)
|
|
|
|
key = :"#{user_role}_id"
|
|
|
|
super(key => user.id, **args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_role
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def can_read_profile?
|
|
|
|
Ability.allowed?(current_user, :read_user_profile, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_read_project?
|
|
|
|
Ability.allowed?(current_user, :read_merge_request, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_project(project_path, project_id)
|
2020-10-30 20:09:08 -04:00
|
|
|
# TODO: remove this line when the compatibility layer is removed
|
|
|
|
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
|
|
|
|
project_id &&= ::Types::GlobalIDType[::Project].coerce_isolated_input(project_id)
|
|
|
|
@project = ::Gitlab::Graphql::Lazy.force(resolve_project(full_path: project_path, project_id: project_id))
|
2020-06-02 11:08:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def no_results_possible?(args)
|
|
|
|
some_argument_is_empty?(args)
|
|
|
|
end
|
|
|
|
|
|
|
|
# These arguments are handled in load_project, and should not be passed to
|
|
|
|
# the finder directly.
|
|
|
|
def prepare_args(args)
|
|
|
|
args.delete(:project_id)
|
|
|
|
args.delete(:project_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|