Skip to content

Commit

Permalink
Merge pull request #26 from PopulateTools/serialize_blocking_data
Browse files Browse the repository at this point in the history
Serialize blocking data
  • Loading branch information
entantoencuanto authored Feb 4, 2025
2 parents cb65da0 + 1b7b516 commit 196d782
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class UserExportSerializer < Decidim::DownloadYourDataSerializers::DownloadYourD
# Public: Exports a hash with the serialized data for the user including
# extra user fields
def serialize
super.merge(extra_user_fields)
super.merge(blocking_data).merge(extra_user_fields)
end

def extra_user_fields
Expand All @@ -18,6 +18,14 @@ def extra_user_fields
end
end

def blocking_data
{
blocked: resource.blocked,
blocked_at: resource.blocked_at,
blocking_justification: resource.blocking&.justification
}
end

def extra_fields
[
:gender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@
expect(serialized).to include(location: resource.extended_data["location"])
end

context "when users are blocked" do
let(:resource) { create(:user, :blocked, extended_data: registration_metadata, blocked_at:) }
let(:blocked_at) { Time.zone.now }
let(:blocking_user) { create(:user, :admin, :confirmed, organization: resource.organization) }
let(:blocking_justification) { "This is a spam user with suspicious activities" }
let(:user_block) { double(justification: blocking_justification) }

before do
allow(resource).to receive(:blocking).and_return(user_block)
end

it "includes the blocked status and justification" do
expect(serialized).to include(blocked: true)
expect(serialized).to include(blocked_at:)
expect(serialized).to include(blocking_justification:)
end
end

# Block ExtraUserFields IncludeExtraField

# EndBlock
Expand Down

0 comments on commit 196d782

Please sign in to comment.