Skip to content

Commit 09fcea7

Browse files
OpenData Export breaks when handling deleted users (decidim#13592)
* Include deleted users to Open Data export * Run linter * Resolved comments * Run linter * Resolved comment * Added missing translation to fix tests * Normalize translations * Resolved comment --------- Co-authored-by: Alexandru Emil Lupu <contact@alecslupu.ro>
1 parent a7bc451 commit 09fcea7

File tree

7 files changed

+119
-6
lines changed

7 files changed

+119
-6
lines changed

decidim-debates/lib/decidim/debates/debate_serializer.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,16 @@ def author_name(author)
7373

7474
def author_url(author)
7575
if author.respond_to?(:nickname)
76-
profile_url(author.nickname) # is a Decidim::User or Decidim::UserGroup
76+
profile_url(author) # is a Decidim::User or Decidim::UserGroup
7777
else
7878
root_url # is a Decidim::Organization
7979
end
8080
end
8181

82-
def profile_url(nickname)
83-
Decidim::Core::Engine.routes.url_helpers.profile_url(nickname, host:)
82+
def profile_url(author)
83+
return "" if author.respond_to?(:deleted?) && author.deleted?
84+
85+
Decidim::Core::Engine.routes.url_helpers.profile_url(author.nickname, host:)
8486
end
8587

8688
def root_url

decidim-debates/spec/services/decidim/open_data_exporter_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@
3434
it_behaves_like "open data exporter"
3535
end
3636

37+
describe "debates by deleted user" do
38+
let(:resource_file_name) { "debates" }
39+
let(:component) do
40+
create(:debates_component, organization:, published_at: Time.current)
41+
end
42+
43+
let!(:deleted_user) { create(:user, :confirmed, :deleted, organization:) }
44+
let!(:resource) { create(:debate, component:, author: deleted_user) }
45+
46+
let(:second_component) do
47+
create(:debates_component, organization:, published_at: Time.current)
48+
end
49+
let!(:second_resource) { create(:debate, :closed, component: second_component, author: deleted_user) }
50+
51+
let(:resource_title) { "## debates" }
52+
let(:help_lines) do
53+
[
54+
"* id: The unique identifier of the debate",
55+
"* conclusions: The conclusions of the debate if it was closed"
56+
]
57+
end
58+
let(:unpublished_component) do
59+
create(:debates_component, organization:, published_at: nil)
60+
end
61+
let(:unpublished_resource) { create(:debate, component: unpublished_component) }
62+
63+
it_behaves_like "open data exporter"
64+
end
65+
3766
describe "debate_comments" do
3867
let(:resource_file_name) { "debate_comments" }
3968
let(:component) do

decidim-meetings/config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ en:
712712
address: The address of the meeting in case it is in person and has a physical location
713713
attachments: The number of attachments in this meeting
714714
attendees: The number of people attending this meeting
715+
author: The data for the author of this meeting
715716
comments: The number of comments made in this meeting
716717
component: The component that the meeting belongs to
717718
contributions: The number of contributions in this meeting made by the atteendes

decidim-meetings/lib/decidim/meetings/meeting_serializer.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def initialize(meeting)
1717
def serialize
1818
{
1919
id: meeting.id,
20+
author: {
21+
**author_fields
22+
},
2023
participatory_space: {
2124
id: meeting.participatory_space.id,
2225
url: Decidim::ResourceLocatorPresenter.new(meeting.participatory_space).url
@@ -53,6 +56,40 @@ def serialize
5356
attr_reader :meeting
5457
alias resource meeting
5558

59+
def author_fields
60+
{
61+
id: meeting.author.id,
62+
name: author_name(meeting.author),
63+
url: author_url(meeting.author)
64+
}
65+
end
66+
67+
def author_name(author)
68+
translated_attribute(author.name)
69+
end
70+
71+
def author_url(author)
72+
if author.respond_to?(:nickname)
73+
profile_url(author) # is a Decidim::User or Decidim::UserGroup
74+
else
75+
root_url # is a Decidim::Organization
76+
end
77+
end
78+
79+
def profile_url(author)
80+
return "" if author.respond_to?(:deleted?) && author.deleted?
81+
82+
Decidim::Core::Engine.routes.url_helpers.profile_url(author.nickname, host:)
83+
end
84+
85+
def root_url
86+
Decidim::Core::Engine.routes.url_helpers.root_url(host:)
87+
end
88+
89+
def host
90+
resource.organization.host
91+
end
92+
5693
def component
5794
meeting.component
5895
end

decidim-meetings/spec/services/decidim/open_data_exporter_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@
2727
it_behaves_like "open data exporter"
2828
end
2929

30+
describe "meeting created by deleted user" do
31+
let!(:deleted_user) { create(:user, :confirmed, :deleted, organization:) }
32+
let(:resource_file_name) { "meetings" }
33+
let(:component) do
34+
create(:meeting_component, organization:, published_at: Time.current)
35+
end
36+
let!(:resource) { create(:meeting, component:, author: deleted_user) }
37+
let(:resource_title) { "## meetings" }
38+
let(:help_lines) do
39+
[
40+
"* id: The unique identifier of the meeting"
41+
]
42+
end
43+
let(:unpublished_component) do
44+
create(:meeting_component, organization:, published_at: nil)
45+
end
46+
let(:unpublished_resource) { create(:meeting, component: unpublished_component, author: deleted_user) }
47+
48+
it_behaves_like "open data exporter"
49+
end
50+
3051
describe "meeting_comments" do
3152
let(:resource_file_name) { "meeting_comments" }
3253
let(:component) do

decidim-proposals/lib/decidim/proposals/proposal_serializer.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,18 @@ def author_name(author)
128128

129129
def author_url(author)
130130
if author.respond_to?(:nickname)
131-
profile_url(author.nickname) # is a Decidim::User or Decidim::UserGroup
131+
profile_url(author) # is a Decidim::User or Decidim::UserGroup
132132
elsif author.respond_to?(:title)
133133
meeting_url(author) # is a Decidim::Meetings::Meeting
134134
else
135135
root_url # is a Decidim::Organization
136136
end
137137
end
138138

139-
def profile_url(nickname)
140-
Decidim::Core::Engine.routes.url_helpers.profile_url(nickname, host:)
139+
def profile_url(author)
140+
return "" if author.respond_to?(:deleted?) && author.deleted?
141+
142+
Decidim::Core::Engine.routes.url_helpers.profile_url(author.nickname, host:)
141143
end
142144

143145
def meeting_url(meeting)

decidim-proposals/spec/services/decidim/open_data_exporter_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@
2727
it_behaves_like "open data exporter"
2828
end
2929

30+
describe "proposals by deleted user" do
31+
let(:resource_file_name) { "proposals" }
32+
let(:component) do
33+
create(:proposal_component, organization:, published_at: Time.current)
34+
end
35+
let!(:deleted_user) { create(:user, :confirmed, :deleted, organization:) }
36+
let!(:resource) { create(:proposal, component:, users: [deleted_user]) }
37+
let(:resource_title) { "## proposals" }
38+
let(:help_lines) do
39+
[
40+
"* id: The unique identifier for the proposal"
41+
]
42+
end
43+
let(:unpublished_component) do
44+
create(:proposal_component, organization:, published_at: nil)
45+
end
46+
let(:unpublished_resource) { create(:proposal, component: unpublished_component, users: [deleted_user]) }
47+
48+
it_behaves_like "open data exporter"
49+
end
50+
3051
describe "proposal_comments" do
3152
let(:resource_file_name) { "proposal_comments" }
3253
let(:component) do

0 commit comments

Comments
 (0)