Skip to content

Commit 196d782

Browse files
Merge pull request #26 from PopulateTools/serialize_blocking_data
Serialize blocking data
2 parents cb65da0 + 1b7b516 commit 196d782

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

app/serializers/decidim/extra_user_fields/user_export_serializer.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class UserExportSerializer < Decidim::DownloadYourDataSerializers::DownloadYourD
77
# Public: Exports a hash with the serialized data for the user including
88
# extra user fields
99
def serialize
10-
super.merge(extra_user_fields)
10+
super.merge(blocking_data).merge(extra_user_fields)
1111
end
1212

1313
def extra_user_fields
@@ -18,6 +18,14 @@ def extra_user_fields
1818
end
1919
end
2020

21+
def blocking_data
22+
{
23+
blocked: resource.blocked,
24+
blocked_at: resource.blocked_at,
25+
blocking_justification: resource.blocking&.justification
26+
}
27+
end
28+
2129
def extra_fields
2230
[
2331
:gender,

spec/serializers/decidim/extra_user_fields/user_export_serializer_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@
6767
expect(serialized).to include(location: resource.extended_data["location"])
6868
end
6969

70+
context "when users are blocked" do
71+
let(:resource) { create(:user, :blocked, extended_data: registration_metadata, blocked_at:) }
72+
let(:blocked_at) { Time.zone.now }
73+
let(:blocking_user) { create(:user, :admin, :confirmed, organization: resource.organization) }
74+
let(:blocking_justification) { "This is a spam user with suspicious activities" }
75+
let(:user_block) { double(justification: blocking_justification) }
76+
77+
before do
78+
allow(resource).to receive(:blocking).and_return(user_block)
79+
end
80+
81+
it "includes the blocked status and justification" do
82+
expect(serialized).to include(blocked: true)
83+
expect(serialized).to include(blocked_at:)
84+
expect(serialized).to include(blocking_justification:)
85+
end
86+
end
87+
7088
# Block ExtraUserFields IncludeExtraField
7189

7290
# EndBlock

0 commit comments

Comments
 (0)