Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor malformed titles in admin logs (part 1) #12702

Merged
merged 43 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f39b9fc
Fix admin logs
alecslupu Apr 17, 2024
fb04f74
Properly escape log entries
alecslupu Apr 17, 2024
fbd9706
Add debates Presenter
alecslupu Apr 17, 2024
ed08779
Remove AdminLog::DebatePresenter
alecslupu Apr 17, 2024
f488500
Fix presenter usage
alecslupu Apr 17, 2024
e875100
More cleanup
alecslupu Apr 17, 2024
1502c0d
Running linters
alecslupu Apr 17, 2024
02f5927
Fix specs
alecslupu Apr 17, 2024
2754e8f
Running linters
alecslupu Apr 17, 2024
8be3c94
Merge branch 'develop' of github.com:decidim/decidim into fix/admin-logs
alecslupu May 10, 2024
9147a80
Add admin log entries
alecslupu May 10, 2024
468a80b
Add admin logs specs
alecslupu May 10, 2024
5b1725e
Fix specs
alecslupu May 10, 2024
08821c1
Proposals and sortitions
alecslupu May 10, 2024
b7d5c2d
Fix pipeline
alecslupu May 10, 2024
8c49d49
Fix pipeline
alecslupu May 10, 2024
b713423
Merge branch 'develop' of github.com:decidim/decidim into fix/admin-logs
alecslupu May 12, 2024
e305a3f
Add participatory process pages
alecslupu May 13, 2024
dea9b4d
More logs
alecslupu May 14, 2024
3ac8ef2
Refactor
alecslupu May 17, 2024
75522d0
lint
alecslupu May 17, 2024
9650781
Refactor
alecslupu May 18, 2024
1991ef8
Merge branch 'develop' of github.com:decidim/decidim into fix/admin-logs
alecslupu May 18, 2024
42cb9ad
Finalize the assembly types
alecslupu May 18, 2024
ce54d08
more refactor
alecslupu May 19, 2024
95721a2
Fix blogs
alecslupu May 19, 2024
86321f1
fix decidim-conferences
alecslupu May 19, 2024
cd3eeca
Reformat the code
alecslupu May 19, 2024
81f438d
update specs
alecslupu May 20, 2024
c4445c2
Refactor
alecslupu May 20, 2024
e1cb5d1
Running rubocops
alecslupu May 26, 2024
4ebb7dd
Merge branch 'develop' of github.com:decidim/decidim into fix/admin-logs
alecslupu May 28, 2024
ebf348a
Merge branch 'develop' of github.com:decidim/decidim into fix/admin-logs
alecslupu May 28, 2024
dbe1ebb
Fix meetings specs
alecslupu May 28, 2024
7d5ac34
Merge branch 'develop' of github.com:decidim/decidim into fix/admin-logs
alecslupu Jun 17, 2024
9b7aaa2
Apply suggestions from code review
alecslupu Jun 17, 2024
21f959b
Apply review recommendation
alecslupu Jun 17, 2024
ddaa1a8
Merge branch 'fix/admin-logs' of github.com:decidim/decidim into fix/…
alecslupu Jun 17, 2024
8ff656d
Fix spec
alecslupu Jun 17, 2024
d443137
Fix specs
alecslupu Jun 17, 2024
3ecb47d
Fix blogs specs
alecslupu Jun 17, 2024
8f97add
Apply suggestions from code review
alecslupu Jun 17, 2024
d00a76c
Lint
alecslupu Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module Log
# overwrite `BasePresenter#resource_presenter` to return your custom resource presenter.
# The only requirement for custom renderers is that they should respond to `present`.
class ResourcePresenter
include Decidim::SanitizeHelper

# Public: Initializes the presenter.
#
# resource - An instance of a model that can be located by
Expand Down Expand Up @@ -65,7 +67,11 @@ def resource_path
#
# Returns an HTML-safe String.
def present_resource_name
h.translated_attribute extra["title"]
if resource.present? && resource.respond_to?(:presenter) && resource.presenter.respond_to?(:title)
resource.presenter.title(html_escape: true)
else
decidim_escape_translated(extra["title"]).html_safe
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def generate_i18n_changeset(attribute, values, type)
locales.flat_map do |locale|
previous_value = values.first.try(:[], locale)
new_value = values.last.try(:[], locale)
if previous_value == new_value
if previous_value == new_value || (previous_value.nil? && new_value.blank?)
nil
else
label = generate_label(attribute, locale)
Expand Down
6 changes: 6 additions & 0 deletions decidim-debates/app/models/decidim/debates/debate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class Debate < Debates::ApplicationRecord
}
scope_search_multi :with_any_state, [:open, :closed]

# Returns the presenter for this author, to be used in the views.
alecslupu marked this conversation as resolved.
Show resolved Hide resolved
# Required by ResourceRenderer.
def presenter
Decidim::Debates::DebatePresenter.new(self)
end

def self.log_presenter_class_for(_log)
Decidim::Debates::AdminLog::DebatePresenter
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ module AdminLog
class DebatePresenter < Decidim::Log::BasePresenter
private

def resource_presenter
@resource_presenter ||= Decidim::Debates::Log::ResourcePresenter.new(action_log.resource, h, action_log.extra["resource"])
end

def diff_fields_mapping
{
description: "Decidim::Debates::AdminLog::ValueTypes::DebateTitleDescriptionPresenter",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ module AdminLog
class MeetingPresenter < Decidim::Log::BasePresenter
private

def resource_presenter
@resource_presenter ||= Decidim::Meetings::Log::ResourcePresenter.new(action_log.resource, h, action_log.extra["resource"])
end

def diff_fields_mapping
{
address: :string,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ module AdminLog
class ProposalPresenter < Decidim::Log::BasePresenter
private

def resource_presenter
@resource_presenter ||= Decidim::Proposals::Log::ResourcePresenter.new(action_log.resource, h, action_log.extra["resource"])
end

def diff_fields_mapping
{
title: "Decidim::Proposals::AdminLog::ValueTypes::ProposalTitleBodyPresenter",
title: :i18n,
body: "Decidim::Proposals::AdminLog::ValueTypes::ProposalTitleBodyPresenter",
state: "Decidim::Proposals::AdminLog::ValueTypes::ProposalStatePresenter",
answered_at: :date,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ValuationAssignmentPresenter < Decidim::Log::ResourcePresenter
# Returns an HTML-safe String.
def present_resource_name
if resource.present?
Decidim::Proposals::ProposalPresenter.new(resource.proposal).title
resource.proposal.presenter.title(html_escape: true)
else
super
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe Decidim::Proposals::Log::ResourcePresenter, type: :helper do
describe Decidim::Log::ResourcePresenter, type: :helper do
let(:presenter) { described_class.new(resource, helper, extra) }
let(:resource) { create(:proposal, title: Faker::Book.unique.title) }
let(:extra) do
Expand All @@ -12,11 +12,6 @@
end
let(:resource_path) { Decidim::ResourceLocatorPresenter.new(resource).path }

before do
helper.extend(Decidim::ApplicationHelper)
helper.extend(Decidim::TranslationsHelper)
end

context "when the resource exists" do
it "links to its public page with the name of the proposal" do
html = presenter.present
Expand Down