Skip to content

Commit 857b730

Browse files
author
gdgate
authored
Merge pull request #1092 from kubamahnert/TMA-732
TMA-732: fix edge cases for user input sanitized MUFs Reviewed-by: https://github.com/kubamahnert
2 parents 2f082f2 + b652d7c commit 857b730

3 files changed

Lines changed: 41 additions & 11 deletions

File tree

lib/gooddata/lcm/actions/synchronize_user_filters.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def call(params)
139139
CSV.foreach(File.open(data_source.realize(params), 'r:UTF-8'), headers: csv_with_headers, return_headers: false, encoding: 'utf-8') do |row|
140140
filters << row.to_hash
141141
end
142+
fail 'The filter set can not be empty when using sync_multiple_projects_based_on_custom_id mode' if filters.empty?
142143
filters.group_by { |u| u[multiple_projects_column] }.flat_map do |client_id, new_filters|
143144
fail "Client id cannot be empty" if client_id.blank?
144145
project = domain.clients(client_id, data_product).project

lib/gooddata/models/user_filters/user_filter_builder.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,13 +539,16 @@ def self.normalize_filters(filters)
539539
end
540540

541541
# Removes MUFs from to_delete unless in user is in users_brick_input
542+
# if this does not happen, users that are about to be deleted by users_brick
543+
# would have all their filters removed now, which is not desirable
542544
def self.sanitize_filters_to_delete(to_delete, users_brick_input, project_users)
543545
return to_delete unless users_brick_input && users_brick_input.any?
544546
user_profiles = users_brick_input.map do |user|
545547
result = project_users.find { |u| u.login == user['login'] }
546548
next unless result
547549
result.profile_url
548550
end.compact
551+
return to_delete unless user_profiles.any?
549552
to_delete.reject do |_, value|
550553
user_profiles.none? { |profile| profile == value.first.json[:related] }
551554
end

spec/unit/actions/synchronize_user_filters_spec.rb

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33

44
require_relative 'shared_examples_for_user_actions'
55

6+
shared_context 'using mode with custom_id' do
7+
let(:CSV) { double('CSV') }
8+
9+
before do
10+
allow(project).to receive(:metadata).and_return(
11+
'GOODOT_CUSTOM_PROJECT_ID' => 'project-123'
12+
)
13+
allow(project).to receive(:uri).and_return('project-uri')
14+
allow(project).to receive(:add_data_permissions)
15+
allow(domain).to receive(:clients).and_return([])
16+
allow(data_source).to receive(:realize).and_return('filepath')
17+
end
18+
end
19+
620
describe GoodData::LCM2::SynchronizeUserFilters do
721
let(:client) { double('client') }
822
let(:user) { double('user') }
@@ -76,6 +90,7 @@
7690
end
7791

7892
context 'when using sync_one_project_based_on_custom_id mode with multiple_projects_column' do
93+
include_context 'using mode with custom_id'
7994
let(:params) do
8095
params = {
8196
GDC_GD_CLIENT: client,
@@ -88,17 +103,6 @@
88103
}
89104
GoodData::LCM2.convert_to_smart_hash(params)
90105
end
91-
let(:CSV) { double('CSV') }
92-
93-
before do
94-
allow(project).to receive(:metadata).and_return(
95-
'GOODOT_CUSTOM_PROJECT_ID' => 'project-123'
96-
)
97-
allow(project).to receive(:uri).and_return('project-uri')
98-
allow(project).to receive(:add_data_permissions)
99-
allow(domain).to receive(:clients).and_return([])
100-
allow(data_source).to receive(:realize).and_return('filepath')
101-
end
102106

103107
context 'when params do not match client data in domain' do
104108
before do
@@ -143,4 +147,26 @@
143147
end
144148
end
145149
end
150+
151+
context 'when using sync_multiple_projects_based_on_custom_id mode' do
152+
include_context 'using mode with custom_id'
153+
let(:params) do
154+
params = {
155+
input_source: 'foo',
156+
domain: 'bar',
157+
multiple_projects_column: 'id_column',
158+
sync_mode: 'sync_multiple_projects_based_on_custom_id',
159+
gdc_logger: logger,
160+
GDC_GD_CLIENT: client,
161+
filters_config: { labels: [] }
162+
}
163+
GoodData::LCM2.convert_to_smart_hash(params)
164+
end
165+
166+
it 'fails if the MUF set is empty' do
167+
expect(File).to receive(:open)
168+
expect(CSV).to receive(:foreach)
169+
expect { subject.class.call(params) }.to raise_error(/The filter set can not be empty/)
170+
end
171+
end
146172
end

0 commit comments

Comments
 (0)