Class: Gitlab::Triage::Filters::MemberConditionsFilter
Constant Summary
collapse
- SOURCES =
%w[project group].freeze
- CONDITIONS =
%w[member_of not_member_of].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
all_params_filter_names, params_check_for_field, params_checking_condition_type, params_checking_condition_value, params_filter_names, #validate_condition
Constructor Details
#initialize(resource, condition, network = nil) ⇒ MemberConditionsFilter
Returns a new instance of MemberConditionsFilter.
11
12
13
14
|
# File 'lib/gitlab/triage/filters/member_conditions_filter.rb', line 11
def initialize(resource, condition, network = nil)
@network = network
super(resource, condition)
end
|
Class Method Details
.filter_parameters ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/gitlab/triage/filters/member_conditions_filter.rb', line 16
def self.filter_parameters
[
{
name: :source,
type: String,
values: SOURCES
},
{
name: :condition,
type: String,
values: CONDITIONS
},
{
name: :source_id,
type: [Numeric, String]
}
]
end
|
Instance Method Details
#calculate ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/gitlab/triage/filters/member_conditions_filter.rb', line 51
def calculate
return false unless resource_value
case @condition
when :member_of
condition_value.include?(resource_value)
when :not_member_of
!condition_value.include?(resource_value)
end
end
|
#condition_value ⇒ Object
45
46
47
48
49
|
# File 'lib/gitlab/triage/filters/member_conditions_filter.rb', line 45
def condition_value
members.map do |member|
member[:username]
end
end
|
#initialize_variables(condition) ⇒ Object
35
36
37
38
39
|
# File 'lib/gitlab/triage/filters/member_conditions_filter.rb', line 35
def initialize_variables(condition)
@source = condition[:source].to_sym
@condition = condition[:condition].to_sym
@source_id = condition[:source_id]
end
|
#members ⇒ Object
62
63
64
|
# File 'lib/gitlab/triage/filters/member_conditions_filter.rb', line 62
def members
@members ||= @network.query_api_cached(member_url)
end
|
#resource_value ⇒ Object
41
42
43
|
# File 'lib/gitlab/triage/filters/member_conditions_filter.rb', line 41
def resource_value
@resource[member_field][:username] if @resource[member_field]
end
|
#url_opts ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/gitlab/triage/filters/member_conditions_filter.rb', line 72
def url_opts
{
network_options: @network.options,
resource_type: 'members',
source: @source == :group ? 'groups' : 'projects',
source_id: @source_id,
params: { per_page: 100 }
}
end
|