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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# frozen_string_literal: true
module Mutations
module Members
class BulkUpdateBase < BaseMutation
include ::API::Helpers::MembersHelpers
argument :user_ids,
[::Types::GlobalIDType[::User]],
required: true,
description: 'Global IDs of the members.'
argument :access_level,
::Types::MemberAccessLevelEnum,
required: true,
description: 'Access level to update the members to.'
argument :expires_at,
Types::TimeType,
required: false,
description: 'Date and time the membership expires.'
MAX_MEMBERS_UPDATE_LIMIT = 50
MAX_MEMBERS_UPDATE_ERROR = "Count of members to be updated should be less than #{MAX_MEMBERS_UPDATE_LIMIT}."
.freeze
INVALID_MEMBERS_ERROR = 'Only access level of direct members can be updated.'
def resolve(**args)
result = ::Members::UpdateService
.new(current_user, args.except(:user_ids, source_id_param_name))
.execute(@updatable_members)
{
source_members_key => result[:members],
errors: Array.wrap(result[:message])
}
rescue Gitlab::Access::AccessDeniedError
{
errors: ["Unable to update members, please check user permissions."]
}
end
private
def ready?(**args)
source = authorized_find!(source_id: args[source_id_param_name])
user_ids = args.fetch(:user_ids, {}).map(&:model_id)
@updatable_members = only_direct_members(source, user_ids)
if @updatable_members.size > MAX_MEMBERS_UPDATE_LIMIT
raise Gitlab::Graphql::Errors::InvalidMemberCountError, MAX_MEMBERS_UPDATE_ERROR
end
if @updatable_members.size != user_ids.size
raise Gitlab::Graphql::Errors::InvalidMembersError, INVALID_MEMBERS_ERROR
end
super
end
def find_object(source_id:)
GitlabSchema.object_from_id(source_id, expected_type: source_type)
end
def only_direct_members(source, user_ids)
source_members(source)
.with_user(user_ids)
.to_a
end
def source_id_param_name
"#{source_name}_id".to_sym
end
def source_members_key
"#{source_name}_members".to_sym
end
def source_name
source_type.name.downcase
end
def source_type
raise NotImplementedError
end
end
end
end
|