Skip to content

Commit

Permalink
Backport 'OpenData Export breaks when handling deleted users' to v0.29 (
Browse files Browse the repository at this point in the history
decidim#13756)

Co-authored-by: andra-panaite <135139066+andra-panaite@users.noreply.github.com>
  • Loading branch information
alecslupu and andra-panaite authored Dec 12, 2024
1 parent 0a9b419 commit 74efe47
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
37 changes: 37 additions & 0 deletions decidim-meetings/lib/decidim/meetings/meeting_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def serialize
id: meeting.scope.try(:id),
name: meeting.scope.try(:name)
},
author: {
**author_fields
},
participatory_space: {
id: meeting.participatory_space.id,
url: Decidim::ResourceLocatorPresenter.new(meeting.participatory_space).url
Expand Down Expand Up @@ -57,6 +60,40 @@ def serialize
attr_reader :meeting
alias resource meeting

def author_fields
{
id: meeting.author.id,
name: author_name(meeting.author),
url: author_url(meeting.author)
}
end

def author_name(author)
translated_attribute(author.name)
end

def author_url(author)
if author.respond_to?(:nickname)
profile_url(author) # is a Decidim::User or Decidim::UserGroup
else
root_url # is a Decidim::Organization
end
end

def profile_url(author)
return "" if author.respond_to?(:deleted?) && author.deleted?

Decidim::Core::Engine.routes.url_helpers.profile_url(author.nickname, host:)
end

def root_url
Decidim::Core::Engine.routes.url_helpers.root_url(host:)
end

def host
resource.organization.host
end

def component
meeting.component
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,18 @@ def author_name(author)

def author_url(author)
if author.respond_to?(:nickname)
profile_url(author.nickname) # is a Decidim::User or Decidim::UserGroup
profile_url(author) # is a Decidim::User or Decidim::UserGroup
elsif author.respond_to?(:title)
meeting_url(author) # is a Decidim::Meetings::Meeting
else
root_url # is a Decidim::Organization
end
end

def profile_url(nickname)
Decidim::Core::Engine.routes.url_helpers.profile_url(nickname, host:)
def profile_url(author)
return "" if author.respond_to?(:deleted?) && author.deleted?

Decidim::Core::Engine.routes.url_helpers.profile_url(author.nickname, host:)
end

def meeting_url(meeting)
Expand Down

0 comments on commit 74efe47

Please sign in to comment.