Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_merge_requests_resolver.rb « resolvers « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b0d6e159f73d99d737c59a32e810bfbc8059a913 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true

module Resolvers
  class UserMergeRequestsResolver < MergeRequestsResolver
    include ResolvesProject

    argument :project_path, GraphQL::STRING_TYPE,
          required: false,
          description: 'The full-path of the project the authored merge requests should be in. Incompatible with projectId.'

    argument :project_id, GraphQL::ID_TYPE,
          required: false,
          description: 'The global ID of the project the authored merge requests should be in. Incompatible with projectPath.'

    attr_reader :project
    alias_method :user, :synchronized_object

    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?
        raise ::Gitlab::Graphql::Errors::ArgumentError,
          'iids requires projectPath or projectId'
      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)
      @project = resolve_project(full_path: project_path, project_id: project_id)
      @project = @project.sync if @project.respond_to?(:sync)
    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