From 026f8a14c660732ddbc8f683c84655ddabb95a77 Mon Sep 17 00:00:00 2001 From: Vera Rojman Date: Tue, 2 Mar 2021 14:37:33 +0100 Subject: [PATCH 1/8] Add css selectors to emails to improve design customization (#7493) --- .../invite_join_conference_mailer/invite.html.erb | 8 ++++---- .../confirmation.html.erb | 6 +++--- .../pending_validation.html.erb | 6 +++--- .../app/views/devise/mailer/join_conference.html.erb | 10 +++++----- .../mailers/conference_registration_mailer_spec.rb | 2 +- .../views/decidim/block_user_mailer/notify.html.erb | 8 ++++---- .../export_mailer/data_portability_export.html.erb | 9 +++++++-- .../app/views/decidim/export_mailer/export.html.erb | 4 +++- .../comanagers_new_conversation.html.erb | 10 +++++----- .../comanagers_new_message.html.erb | 10 +++++----- .../conversation_mailer/new_conversation.html.erb | 8 ++++---- .../new_group_conversation.html.erb | 10 +++++----- .../conversation_mailer/new_group_message.html.erb | 10 +++++----- .../conversation_mailer/new_message.html.erb | 8 ++++---- .../newsletters_opt_in_mailer/notify.html.erb | 12 ++++++------ .../notification_mailer/event_received.html.erb | 8 ++++---- .../app/views/decidim/reported_mailer/hide.html.erb | 6 +++--- .../views/decidim/reported_mailer/report.html.erb | 6 +++--- .../views/decidim/user_report_mailer/notify.html.erb | 8 ++++---- .../devise/mailer/confirmation_instructions.html.erb | 7 ++++--- .../devise/mailer/invitation_instructions.html.erb | 10 +++++----- .../app/views/devise/mailer/invite_admin.html.erb | 10 +++++----- .../views/devise/mailer/invite_collaborator.html.erb | 10 +++++----- .../views/devise/mailer/invite_private_user.html.erb | 10 +++++----- ...ganization_admin_invitation_instructions.html.erb | 11 ++++++----- .../app/views/devise/mailer/password_change.html.erb | 4 ++-- .../mailer/reset_password_instructions.html.erb | 11 ++++++----- .../views/devise/mailer/unlock_instructions.html.erb | 8 ++++---- .../admin/invite_join_meeting_mailer/invite.html.erb | 8 ++++---- .../registration_mailer/confirmation.html.erb | 4 ++-- .../app/views/devise/mailer/join_meeting.html.erb | 12 ++++++------ .../spec/mailers/registration_mailer_spec.rb | 4 ++-- 32 files changed, 134 insertions(+), 124 deletions(-) diff --git a/decidim-conferences/app/views/decidim/conferences/admin/invite_join_conference_mailer/invite.html.erb b/decidim-conferences/app/views/decidim/conferences/admin/invite_join_conference_mailer/invite.html.erb index c4c5942d559e..34fd0a15e1eb 100644 --- a/decidim-conferences/app/views/decidim/conferences/admin/invite_join_conference_mailer/invite.html.erb +++ b/decidim-conferences/app/views/decidim/conferences/admin/invite_join_conference_mailer/invite.html.erb @@ -1,12 +1,12 @@ -

<%= t("devise.mailer.invitation_instructions.hello", email: @user.name) %>

+

<%= t("devise.mailer.invitation_instructions.hello", email: @user.name) %>

-

+

<%= t ".invited_you_to_join_a_conference", invited_by: @invited_by.name, application: @user.organization.name %>

-

+

<%= link_to t(".decline", conference_title: translated_attribute(@conference.title)),routes.decline_invitation_conference_registration_type_conference_registration_path(conference_slug: @conference.slug, registration_type_id: @registration_type.id) %>

-

+

<%= link_to t(".registration", conference_title: translated_attribute(@conference.title)),routes.conference_registration_type_conference_registration_url(conference_slug: @conference.slug, registration_type_id: @registration_type.id) %>

diff --git a/decidim-conferences/app/views/decidim/conferences/conference_registration_mailer/confirmation.html.erb b/decidim-conferences/app/views/decidim/conferences/conference_registration_mailer/confirmation.html.erb index b47583325833..f3037ca64822 100644 --- a/decidim-conferences/app/views/decidim/conferences/conference_registration_mailer/confirmation.html.erb +++ b/decidim-conferences/app/views/decidim/conferences/conference_registration_mailer/confirmation.html.erb @@ -1,6 +1,6 @@ -

<%= t(".confirmed_html", title: translated_attribute(@conference.title), url: @locator.url) %>

+

<%= t(".confirmed_html", title: translated_attribute(@conference.title), url: @locator.url) %>

-

<%= t(".details_1", registration_type: translated_attribute(@registration_type.title), price: number_to_currency((@registration_type.price || 0), locale: I18n.locale, unit: Decidim.currency_unit)) %>

+

<%= t(".details_1", registration_type: translated_attribute(@registration_type.title), price: number_to_currency((@registration_type.price || 0), locale: I18n.locale, unit: Decidim.currency_unit)) %>

-

<%= t(".details_2") %>

+

<%= t(".details_2") %>

diff --git a/decidim-conferences/app/views/decidim/conferences/conference_registration_mailer/pending_validation.html.erb b/decidim-conferences/app/views/decidim/conferences/conference_registration_mailer/pending_validation.html.erb index 209a29d28c1e..59aedf9a0590 100644 --- a/decidim-conferences/app/views/decidim/conferences/conference_registration_mailer/pending_validation.html.erb +++ b/decidim-conferences/app/views/decidim/conferences/conference_registration_mailer/pending_validation.html.erb @@ -1,6 +1,6 @@ -

<%= t(".pending_html", title: translated_attribute(@conference.title), url: @locator.url) %>

+

<%= t(".pending_html", title: translated_attribute(@conference.title), url: @locator.url) %>

-

<%= t(".details", registration_type: translated_attribute(@registration_type.title), price: number_to_currency((@registration_type.price || 0), locale: I18n.locale, unit: Decidim.currency_unit)) %>

+

<%= t(".details", registration_type: translated_attribute(@registration_type.title), price: number_to_currency((@registration_type.price || 0), locale: I18n.locale, unit: Decidim.currency_unit)) %>

-

<%= t(".confirmation_pending") %>

+

<%= t(".confirmation_pending") %>

diff --git a/decidim-conferences/app/views/devise/mailer/join_conference.html.erb b/decidim-conferences/app/views/devise/mailer/join_conference.html.erb index b8c600a7c020..cb3edb920dcd 100644 --- a/decidim-conferences/app/views/devise/mailer/join_conference.html.erb +++ b/decidim-conferences/app/views/devise/mailer/join_conference.html.erb @@ -1,13 +1,13 @@ -

<%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %>

+

<%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %>

-

+

<%= t("decidim.conferences.admin.invite_join_conference_mailer.invite.invited_you_to_join_a_conference", invited_by: @resource.invited_by.name, application: @resource.organization.name) %>

-

<%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: Decidim::EngineRouter.main_proxy(@opts[:conference]).conference_conference_registration_path(conference_slug: @opts[:conference]), host: @resource.organization.host) %>

+

<%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: Decidim::EngineRouter.main_proxy(@opts[:conference]).conference_conference_registration_path(conference_slug: @opts[:conference]), host: @resource.organization.host) %>

<% if @resource.invitation_due_at %> -

<%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :long)) %>

+

<%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :long)) %>

<% end %> -

<%= t("devise.mailer.invitation_instructions.ignore").html_safe %>

+

<%= t("devise.mailer.invitation_instructions.ignore").html_safe %>

diff --git a/decidim-conferences/spec/mailers/conference_registration_mailer_spec.rb b/decidim-conferences/spec/mailers/conference_registration_mailer_spec.rb index 104903c011d5..688a1b1caeeb 100644 --- a/decidim-conferences/spec/mailers/conference_registration_mailer_spec.rb +++ b/decidim-conferences/spec/mailers/conference_registration_mailer_spec.rb @@ -29,7 +29,7 @@ module Decidim::Conferences describe "confirmation" do let(:default_subject) { "Your conference's registration has been confirmed" } - let(:default_body) { "details in the attachment" } + let(:default_body) { "You will find the conference" } it "expect subject and body" do expect(mail.subject).to eq(default_subject) diff --git a/decidim-core/app/views/decidim/block_user_mailer/notify.html.erb b/decidim-core/app/views/decidim/block_user_mailer/notify.html.erb index 245a0442c1da..230a4e9b5ad1 100644 --- a/decidim-core/app/views/decidim/block_user_mailer/notify.html.erb +++ b/decidim-core/app/views/decidim/block_user_mailer/notify.html.erb @@ -1,7 +1,7 @@ -

<%= t ".hello" %>

+

<%= t ".hello" %>

-

<%= t ".body_1", organization_name: h(@organization.name) %>

+

<%= t ".body_1", organization_name: h(@organization.name) %>

-

<%= t ".body_2", justification: h(@justification) %>

+

<%= t ".body_2", justification: h(@justification) %>

-

<%= t(".greetings", organization_name: h(@organization.name), organization_url: decidim.root_url(host: @organization.host)).html_safe %>

+

<%= t(".greetings", organization_name: h(@organization.name), organization_url: decidim.root_url(host: @organization.host)).html_safe %>

diff --git a/decidim-core/app/views/decidim/export_mailer/data_portability_export.html.erb b/decidim-core/app/views/decidim/export_mailer/data_portability_export.html.erb index 348092590d1e..8132ea4b73bb 100644 --- a/decidim-core/app/views/decidim/export_mailer/data_portability_export.html.erb +++ b/decidim-core/app/views/decidim/export_mailer/data_portability_export.html.erb @@ -1,2 +1,7 @@ -<%= t(".click_button", password: @password, date: l(Decidim.data_portability_expiry_time.from_now, format: :decidim_short) ).html_safe %>
-<%= link_to t(".download"), download_file_data_portability_url(host: @organization.host, filename: @filename), class: "button expanded hollow button--sc" %> +

+ <%= t(".click_button", password: @password, date: l(Decidim.data_portability_expiry_time.from_now, format: :decidim_short) ).html_safe %>
+

+ +

+ <%= link_to t(".download"), download_file_data_portability_url(host: @organization.host, filename: @filename), class: "button expanded hollow button--sc" %> +

diff --git a/decidim-core/app/views/decidim/export_mailer/export.html.erb b/decidim-core/app/views/decidim/export_mailer/export.html.erb index 99da8884c7c5..2c01abff4695 100644 --- a/decidim-core/app/views/decidim/export_mailer/export.html.erb +++ b/decidim-core/app/views/decidim/export_mailer/export.html.erb @@ -1 +1,3 @@ -<%= t(".ready") %> +

+ <%= t(".ready") %> +

diff --git a/decidim-core/app/views/decidim/messaging/conversation_mailer/comanagers_new_conversation.html.erb b/decidim-core/app/views/decidim/messaging/conversation_mailer/comanagers_new_conversation.html.erb index 65cb880ce439..4828626da16d 100644 --- a/decidim-core/app/views/decidim/messaging/conversation_mailer/comanagers_new_conversation.html.erb +++ b/decidim-core/app/views/decidim/messaging/conversation_mailer/comanagers_new_conversation.html.erb @@ -1,8 +1,8 @@ -

<%= t(".greeting", recipient: @recipient.name) %>

+

<%= t(".greeting", recipient: @recipient.name) %>

-

<%= t(".admin_in_group", group: @sender.name) %>

+

<%= t(".admin_in_group", group: @sender.name) %>

-

<%= t(".intro", group: @sender.name, manager: @third_party.name) %>

+

<%= t(".intro", group: @sender.name, manager: @third_party.name) %>

@@ -10,8 +10,8 @@

-

+

<%= link_to decidim.profile_conversation_url(nickname: @sender.nickname, id: @conversation.id, host: @host), decidim.profile_conversation_url(nickname: @sender.nickname, id: @conversation.id, host: @host) %>

-

<%= t(".outro") %>

+

<%= t(".outro") %>

diff --git a/decidim-core/app/views/decidim/messaging/conversation_mailer/comanagers_new_message.html.erb b/decidim-core/app/views/decidim/messaging/conversation_mailer/comanagers_new_message.html.erb index 65cb880ce439..4828626da16d 100644 --- a/decidim-core/app/views/decidim/messaging/conversation_mailer/comanagers_new_message.html.erb +++ b/decidim-core/app/views/decidim/messaging/conversation_mailer/comanagers_new_message.html.erb @@ -1,8 +1,8 @@ -

<%= t(".greeting", recipient: @recipient.name) %>

+

<%= t(".greeting", recipient: @recipient.name) %>

-

<%= t(".admin_in_group", group: @sender.name) %>

+

<%= t(".admin_in_group", group: @sender.name) %>

-

<%= t(".intro", group: @sender.name, manager: @third_party.name) %>

+

<%= t(".intro", group: @sender.name, manager: @third_party.name) %>

@@ -10,8 +10,8 @@

-

+

<%= link_to decidim.profile_conversation_url(nickname: @sender.nickname, id: @conversation.id, host: @host), decidim.profile_conversation_url(nickname: @sender.nickname, id: @conversation.id, host: @host) %>

-

<%= t(".outro") %>

+

<%= t(".outro") %>

diff --git a/decidim-core/app/views/decidim/messaging/conversation_mailer/new_conversation.html.erb b/decidim-core/app/views/decidim/messaging/conversation_mailer/new_conversation.html.erb index baf61eba164f..cca7e21e2f8b 100644 --- a/decidim-core/app/views/decidim/messaging/conversation_mailer/new_conversation.html.erb +++ b/decidim-core/app/views/decidim/messaging/conversation_mailer/new_conversation.html.erb @@ -1,6 +1,6 @@ -

<%= t(".greeting", recipient: @recipient.name) %>

+

<%= t(".greeting", recipient: @recipient.name) %>

-

<%= t(".intro", sender: @sender.name) %>

+

<%= t(".intro", sender: @sender.name) %>

@@ -8,8 +8,8 @@

-

+

<%= link_to decidim.conversation_url(@conversation, host: @host), decidim.conversation_url(@conversation, host: @host) %>

-

<%= t(".outro") %>

+

<%= t(".outro") %>

diff --git a/decidim-core/app/views/decidim/messaging/conversation_mailer/new_group_conversation.html.erb b/decidim-core/app/views/decidim/messaging/conversation_mailer/new_group_conversation.html.erb index acdf8fbef97f..7c73a9ec2048 100644 --- a/decidim-core/app/views/decidim/messaging/conversation_mailer/new_group_conversation.html.erb +++ b/decidim-core/app/views/decidim/messaging/conversation_mailer/new_group_conversation.html.erb @@ -1,8 +1,8 @@ -

<%= t(".greeting", recipient: @recipient.name) %>

+

<%= t(".greeting", recipient: @recipient.name) %>

-

<%= t(".admin_in_group", group: @third_party.name) %>

+

<%= t(".admin_in_group", group: @third_party.name) %>

-

<%= t(".intro", sender: @sender.name, group: @third_party.name) %>

+

<%= t(".intro", sender: @sender.name, group: @third_party.name) %>

@@ -10,8 +10,8 @@

-

+

<%= link_to decidim.profile_conversation_url(nickname: @third_party.nickname, id: @conversation.id, host: @host), decidim.profile_conversation_url(nickname: @third_party.nickname, id: @conversation.id, host: @host) %>

-

<%= t(".outro") %>

+

<%= t(".outro") %>

diff --git a/decidim-core/app/views/decidim/messaging/conversation_mailer/new_group_message.html.erb b/decidim-core/app/views/decidim/messaging/conversation_mailer/new_group_message.html.erb index acdf8fbef97f..7c73a9ec2048 100644 --- a/decidim-core/app/views/decidim/messaging/conversation_mailer/new_group_message.html.erb +++ b/decidim-core/app/views/decidim/messaging/conversation_mailer/new_group_message.html.erb @@ -1,8 +1,8 @@ -

<%= t(".greeting", recipient: @recipient.name) %>

+

<%= t(".greeting", recipient: @recipient.name) %>

-

<%= t(".admin_in_group", group: @third_party.name) %>

+

<%= t(".admin_in_group", group: @third_party.name) %>

-

<%= t(".intro", sender: @sender.name, group: @third_party.name) %>

+

<%= t(".intro", sender: @sender.name, group: @third_party.name) %>

@@ -10,8 +10,8 @@

-

+

<%= link_to decidim.profile_conversation_url(nickname: @third_party.nickname, id: @conversation.id, host: @host), decidim.profile_conversation_url(nickname: @third_party.nickname, id: @conversation.id, host: @host) %>

-

<%= t(".outro") %>

+

<%= t(".outro") %>

diff --git a/decidim-core/app/views/decidim/messaging/conversation_mailer/new_message.html.erb b/decidim-core/app/views/decidim/messaging/conversation_mailer/new_message.html.erb index baf61eba164f..cca7e21e2f8b 100644 --- a/decidim-core/app/views/decidim/messaging/conversation_mailer/new_message.html.erb +++ b/decidim-core/app/views/decidim/messaging/conversation_mailer/new_message.html.erb @@ -1,6 +1,6 @@ -

<%= t(".greeting", recipient: @recipient.name) %>

+

<%= t(".greeting", recipient: @recipient.name) %>

-

<%= t(".intro", sender: @sender.name) %>

+

<%= t(".intro", sender: @sender.name) %>

@@ -8,8 +8,8 @@

-

+

<%= link_to decidim.conversation_url(@conversation, host: @host), decidim.conversation_url(@conversation, host: @host) %>

-

<%= t(".outro") %>

+

<%= t(".outro") %>

diff --git a/decidim-core/app/views/decidim/newsletters_opt_in_mailer/notify.html.erb b/decidim-core/app/views/decidim/newsletters_opt_in_mailer/notify.html.erb index 231fba193dfc..c15792918de0 100644 --- a/decidim-core/app/views/decidim/newsletters_opt_in_mailer/notify.html.erb +++ b/decidim-core/app/views/decidim/newsletters_opt_in_mailer/notify.html.erb @@ -1,8 +1,8 @@ -

<%= t ".hello" %>

+

<%= t ".hello" %>

-

<%= t ".body_1", organization_name: h(@organization.name) %>

+

<%= t ".body_1", organization_name: h(@organization.name) %>

-

<%= t ".body_2" %>

+

<%= t ".body_2" %>

@@ -10,7 +10,7 @@
- <%= link_to t(".button"), decidim.newsletters_opt_in_url(token: @token, host: @organization.host), method: "PUT", class: "button", target: "_blank" %> + <%= link_to t(".button"), decidim.newsletters_opt_in_url(token: @token, host: @organization.host), method: "PUT", class: "button email-button email-button__cta", target: "_blank" %>
@@ -18,6 +18,6 @@ -

<%= t ".body_3" %>

+

<%= t ".body_3" %>

-

<%= t(".greetings", organization_name: h(@organization.name), organization_url: decidim.root_url(host: @organization.host)).html_safe %>

+

<%= t(".greetings", organization_name: h(@organization.name), organization_url: decidim.root_url(host: @organization.host)).html_safe %>

diff --git a/decidim-core/app/views/decidim/notification_mailer/event_received.html.erb b/decidim-core/app/views/decidim/notification_mailer/event_received.html.erb index ea517d219cc3..bf7f755827e1 100644 --- a/decidim-core/app/views/decidim/notification_mailer/event_received.html.erb +++ b/decidim-core/app/views/decidim/notification_mailer/event_received.html.erb @@ -1,6 +1,6 @@ -

<%= @event_instance.email_greeting %>

+

<%= @event_instance.email_greeting %>

-

<%= @event_instance.email_intro %>

+

<%= @event_instance.email_intro %>

<% if @event_instance.try(:safe_resource_text).present? %>
@@ -11,9 +11,9 @@ <% end %> <% if @event_instance.resource_path.present? && @event_instance.resource_title.present? %> -

+

<% end %> -

<%= @event_instance.email_outro %>

+ diff --git a/decidim-core/app/views/decidim/reported_mailer/hide.html.erb b/decidim-core/app/views/decidim/reported_mailer/hide.html.erb index 1178821e928f..3d7fbb9e4c72 100644 --- a/decidim-core/app/views/decidim/reported_mailer/hide.html.erb +++ b/decidim-core/app/views/decidim/reported_mailer/hide.html.erb @@ -1,9 +1,9 @@ -

<%= t(".hello", name: @user.name) %>

+ -

+

-

+

diff --git a/decidim-core/app/views/decidim/reported_mailer/report.html.erb b/decidim-core/app/views/decidim/reported_mailer/report.html.erb index 4783bd046540..009a570c87ce 100644 --- a/decidim-core/app/views/decidim/reported_mailer/report.html.erb +++ b/decidim-core/app/views/decidim/reported_mailer/report.html.erb @@ -1,6 +1,6 @@ -

<%= t(".hello", name: @user.name) %>

+ -

+

@@ -54,7 +54,7 @@
- <%= link_to t(".see_report"), report_url, class: "button", target: "_blank" %> + <%= link_to t(".see_report"), report_url, class: "button email-button email-button__cta", target: "_blank" %>
diff --git a/decidim-core/app/views/decidim/user_report_mailer/notify.html.erb b/decidim-core/app/views/decidim/user_report_mailer/notify.html.erb index e2701482e856..252526db2a3a 100644 --- a/decidim-core/app/views/decidim/user_report_mailer/notify.html.erb +++ b/decidim-core/app/views/decidim/user_report_mailer/notify.html.erb @@ -1,7 +1,7 @@ -

<%= t ".hello", admin: h(@admin.name) %>

+ -

<%= t ".body_1", user: h(@user.name), token: h(@token.name) %>

+ -

<%= t ".body_2", reason: h(@reason) %>

+ -

<%= t(".greetings", organization_name: h(@organization.name), organization_url: decidim.root_url(host: @organization.host)).html_safe %>

+ diff --git a/decidim-core/app/views/devise/mailer/confirmation_instructions.html.erb b/decidim-core/app/views/devise/mailer/confirmation_instructions.html.erb index 4920db95e1e8..120656c714c3 100644 --- a/decidim-core/app/views/devise/mailer/confirmation_instructions.html.erb +++ b/decidim-core/app/views/devise/mailer/confirmation_instructions.html.erb @@ -1,4 +1,5 @@ -

<%= t(".greeting", recipient: @resource.email) %>

+ -

<%= t(".instruction") %>

-

<%= link_to t(".action"), confirmation_url(@resource, confirmation_token: @token, host: @resource.organization.host) %>

+ + + diff --git a/decidim-core/app/views/devise/mailer/invitation_instructions.html.erb b/decidim-core/app/views/devise/mailer/invitation_instructions.html.erb index 3f37da2c51a0..e518af3508f8 100644 --- a/decidim-core/app/views/devise/mailer/invitation_instructions.html.erb +++ b/decidim-core/app/views/devise/mailer/invitation_instructions.html.erb @@ -1,13 +1,13 @@ -

<%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %>

+ -

+

-

<%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim.root_path, host: @resource.organization.host) %>

+ <% if @resource.invitation_due_at %> -

<%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :long)) %>

+ <% end %> -

<%= t("devise.mailer.invitation_instructions.ignore").html_safe %>

+ diff --git a/decidim-core/app/views/devise/mailer/invite_admin.html.erb b/decidim-core/app/views/devise/mailer/invite_admin.html.erb index f924b24175ac..d0733210c7e4 100644 --- a/decidim-core/app/views/devise/mailer/invite_admin.html.erb +++ b/decidim-core/app/views/devise/mailer/invite_admin.html.erb @@ -1,6 +1,6 @@ -

<%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %>

+ -

+

-

<%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %>

+ <% if @resource.invitation_due_at %> -

<%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :long)) %>

+ <% end %> -

<%= t("devise.mailer.invitation_instructions.ignore").html_safe %>

+ diff --git a/decidim-core/app/views/devise/mailer/invite_collaborator.html.erb b/decidim-core/app/views/devise/mailer/invite_collaborator.html.erb index f924b24175ac..d0733210c7e4 100644 --- a/decidim-core/app/views/devise/mailer/invite_collaborator.html.erb +++ b/decidim-core/app/views/devise/mailer/invite_collaborator.html.erb @@ -1,6 +1,6 @@ -

<%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %>

+ -

+

-

<%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %>

+ <% if @resource.invitation_due_at %> -

<%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :long)) %>

+ <% end %> -

<%= t("devise.mailer.invitation_instructions.ignore").html_safe %>

+ diff --git a/decidim-core/app/views/devise/mailer/invite_private_user.html.erb b/decidim-core/app/views/devise/mailer/invite_private_user.html.erb index b9f49338a99b..3b5e9029e09c 100644 --- a/decidim-core/app/views/devise/mailer/invite_private_user.html.erb +++ b/decidim-core/app/views/devise/mailer/invite_private_user.html.erb @@ -1,6 +1,6 @@ -

<%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %>

+ -

+

-

<%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, host: @resource.organization.host) %>

+ <% if @resource.invitation_due_at %> -

<%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :long)) %>

+ <% end %> -

<%= t("devise.mailer.invitation_instructions.ignore").html_safe %>

+ diff --git a/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.html.erb b/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.html.erb index b4a18361b47e..68198d936fb5 100644 --- a/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.html.erb +++ b/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.html.erb @@ -1,10 +1,11 @@ -

<%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %>

+ -

<%= t("devise.mailer.invitation_instructions.someone_invited_you", application: @resource.organization.name) %>

-

<%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %>

+ + + <% if @resource.invitation_due_at %> -

<%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :long)) %>

+ <% end %> -

<%= t("devise.mailer.invitation_instructions.ignore").html_safe %>

+ diff --git a/decidim-core/app/views/devise/mailer/password_change.html.erb b/decidim-core/app/views/devise/mailer/password_change.html.erb index 689c723551b9..d9f038548c4b 100644 --- a/decidim-core/app/views/devise/mailer/password_change.html.erb +++ b/decidim-core/app/views/devise/mailer/password_change.html.erb @@ -1,3 +1,3 @@ -

<%= t(".greeting", recipient: @resource.email) %>

+ -

<%= t(".message") %>

+ diff --git a/decidim-core/app/views/devise/mailer/reset_password_instructions.html.erb b/decidim-core/app/views/devise/mailer/reset_password_instructions.html.erb index a90beb25e5f9..b753d52ec67a 100644 --- a/decidim-core/app/views/devise/mailer/reset_password_instructions.html.erb +++ b/decidim-core/app/views/devise/mailer/reset_password_instructions.html.erb @@ -1,8 +1,9 @@ -

<%= t(".greeting", recipient: @resource.email) %>

+ -

<%= t(".instruction") %>

+ -

<%= link_to t(".action"), edit_password_url(@resource, reset_password_token: @token, host: @resource.organization.host) %>

+ -

<%= t(".instruction_2") %>

-

<%= t(".instruction_3") %>

+ + + diff --git a/decidim-core/app/views/devise/mailer/unlock_instructions.html.erb b/decidim-core/app/views/devise/mailer/unlock_instructions.html.erb index 72ea9dec0fd6..cfd02b8241f8 100644 --- a/decidim-core/app/views/devise/mailer/unlock_instructions.html.erb +++ b/decidim-core/app/views/devise/mailer/unlock_instructions.html.erb @@ -1,7 +1,7 @@ -

<%= t(".greeting", recipient: @resource.email) %>

+ -

<%= t(".message") %>

+ -

<%= t(".instruction") %>

+ -

<%= link_to t(".action"), unlock_url(@resource, unlock_token: @token, host: @resource.organization.host) %>

+ diff --git a/decidim-meetings/app/views/decidim/meetings/admin/invite_join_meeting_mailer/invite.html.erb b/decidim-meetings/app/views/decidim/meetings/admin/invite_join_meeting_mailer/invite.html.erb index ceee6046f4ad..8e9039a9b490 100644 --- a/decidim-meetings/app/views/decidim/meetings/admin/invite_join_meeting_mailer/invite.html.erb +++ b/decidim-meetings/app/views/decidim/meetings/admin/invite_join_meeting_mailer/invite.html.erb @@ -1,8 +1,8 @@ -

<%= t("devise.mailer.invitation_instructions.hello", email: @user.name) %>

+ -

+

-

<%= link_to t(".decline", meeting_title: present(@meeting).title),routes.decline_invitation_meeting_registration_url(meeting_id: @meeting, participatory_space_id: @meeting.component.participatory_space) %> -

<%= link_to t(".join", meeting_title: present(@meeting).title),routes.meeting_registration_url(meeting_id: @meeting, participatory_space_id: @meeting.component.participatory_space) %> +

<%= t(".confirmed_html", title: present(@meeting).title, url: @locator.url) %>

+ <% if @registration.meeting.component.settings.registration_code_enabled %>

<%= t(".registration_code", code: @registration.code) %>

<% end %> -

<%= t(".details") %>

+ diff --git a/decidim-meetings/app/views/devise/mailer/join_meeting.html.erb b/decidim-meetings/app/views/devise/mailer/join_meeting.html.erb index 596cadf4a548..78a4967549fe 100644 --- a/decidim-meetings/app/views/devise/mailer/join_meeting.html.erb +++ b/decidim-meetings/app/views/devise/mailer/join_meeting.html.erb @@ -1,14 +1,14 @@ -

<%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %>

+ -

+

-

<%= link_to t("devise.mailer.invitation_instructions.decline"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: Decidim::EngineRouter.main_proxy(@opts[:meeting].component).decline_invitation_meeting_registration_path(meeting_id: @opts[:meeting], participatory_space_id: @opts[:meeting].component.participatory_space), host: @resource.organization.host) %>

-

<%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: Decidim::EngineRouter.main_proxy(@opts[:meeting].component).meeting_registration_path(meeting_id: @opts[:meeting], participatory_space_id: @opts[:meeting].component.participatory_space), host: @resource.organization.host) %>

+ + <% if @resource.invitation_due_at %> -

<%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :long)) %>

+ <% end %> -

<%= t("devise.mailer.invitation_instructions.ignore").html_safe %>

+ diff --git a/decidim-meetings/spec/mailers/registration_mailer_spec.rb b/decidim-meetings/spec/mailers/registration_mailer_spec.rb index 8e2afc8ea3da..eb714a80d157 100644 --- a/decidim-meetings/spec/mailers/registration_mailer_spec.rb +++ b/decidim-meetings/spec/mailers/registration_mailer_spec.rb @@ -18,8 +18,8 @@ module Decidim::Meetings let(:subject) { "La teva inscripció a la trobada ha estat confirmada" } let(:default_subject) { "Your meeting's registration has been confirmed" } - let(:body) { "detalls de la" } - let(:default_body) { "details in the attachment" } + let(:body) { "arxiu adjunt" } + let(:default_body) { "You will find the meeting" } include_examples "localised email" end From 50bb0309e77ce0e6262fcd439731cc9e17bbe8ed Mon Sep 17 00:00:00 2001 From: Vera Rojman Date: Wed, 10 Mar 2021 15:36:00 +0100 Subject: [PATCH 2/8] Use first photo attachment as card image for meetings --- .../app/cells/decidim/meetings/meeting_m_cell.rb | 8 ++++++++ .../spec/cells/decidim/meetings/meeting_m_cell_spec.rb | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/decidim-meetings/app/cells/decidim/meetings/meeting_m_cell.rb b/decidim-meetings/app/cells/decidim/meetings/meeting_m_cell.rb index 738815b64629..2519e2822fd3 100644 --- a/decidim-meetings/app/cells/decidim/meetings/meeting_m_cell.rb +++ b/decidim-meetings/app/cells/decidim/meetings/meeting_m_cell.rb @@ -31,6 +31,14 @@ def title private + def resource_image_path + model.photo&.url + end + + def has_image? + true + end + def spans_multiple_dates? start_date != end_date end diff --git a/decidim-meetings/spec/cells/decidim/meetings/meeting_m_cell_spec.rb b/decidim-meetings/spec/cells/decidim/meetings/meeting_m_cell_spec.rb index d6e6ef23d8a7..02a26c4ecaf9 100644 --- a/decidim-meetings/spec/cells/decidim/meetings/meeting_m_cell_spec.rb +++ b/decidim-meetings/spec/cells/decidim/meetings/meeting_m_cell_spec.rb @@ -19,6 +19,14 @@ module Decidim::Meetings it "renders the card" do expect(cell_html).to have_css(".card--meeting") end + + context "when an image is attached to the meeting" do + let!(:attachment) { create(:attachment, attached_to: meeting) } + + it "renders the picture" do + expect(cell_html).to have_css(".card__image") + end + end end context "when title contains special html entities" do From 7b72d1c13952a7f2dafbd99ae48e3ffc09cd5455 Mon Sep 17 00:00:00 2001 From: Vera Rojman Date: Wed, 10 Mar 2021 15:24:11 +0100 Subject: [PATCH 3/8] Use first photo attachment as card image for blog posts # Conflicts: # decidim-blogs/spec/system/explore_posts_spec.rb --- .../app/views/decidim/blogs/posts/_posts.html.erb | 3 +++ decidim-blogs/spec/system/explore_posts_spec.rb | 7 +++++++ decidim-core/lib/decidim/has_attachments.rb | 15 +++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/decidim-blogs/app/views/decidim/blogs/posts/_posts.html.erb b/decidim-blogs/app/views/decidim/blogs/posts/_posts.html.erb index e63a799443c7..8687f62a049c 100644 --- a/decidim-blogs/app/views/decidim/blogs/posts/_posts.html.erb +++ b/decidim-blogs/app/views/decidim/blogs/posts/_posts.html.erb @@ -1,6 +1,9 @@
<% paginate_posts.each do |post| %>
+ <% if post.photo.present? %> + <%= image_tag post.photo.url, class: "card__image" %> + <% end %>
<%= link_to post, class: "card__link" do %> diff --git a/decidim-blogs/spec/system/explore_posts_spec.rb b/decidim-blogs/spec/system/explore_posts_spec.rb index a38c0e4aa5da..6c1831e48b91 100644 --- a/decidim-blogs/spec/system/explore_posts_spec.rb +++ b/decidim-blogs/spec/system/explore_posts_spec.rb @@ -9,6 +9,8 @@ let!(:old_post) { create(:post, component: component, created_at: Time.current - 2.days) } let!(:new_post) { create(:post, component: component, created_at: Time.current) } + let!(:image) { create(:attachment, attached_to: old_post) } + describe "index" do it "shows all posts for the given process" do visit_component @@ -17,6 +19,11 @@ expect(page).to have_selector(".card--post", text: translated(old_post.title)) end + it "shows images" do + visit_component + expect(page).to have_selector(".card--post img.card__image") + end + context "when paginating" do let(:collection_size) { 10 } let!(:collection) { create_list :post, collection_size, component: component } diff --git a/decidim-core/lib/decidim/has_attachments.rb b/decidim-core/lib/decidim/has_attachments.rb index 93c3cc1ffcab..860800333668 100644 --- a/decidim-core/lib/decidim/has_attachments.rb +++ b/decidim-core/lib/decidim/has_attachments.rb @@ -15,28 +15,35 @@ module HasAttachments inverse_of: :attached_to, as: :attached_to - # All the attachments that are photos for this process. + # The first attachment that is a photo for this model. + # + # Returns an Attachment + def photo + @photo ||= photos.first + end + + # All the attachments that are photos for this model. # # Returns an Array def photos @photos ||= attachments.select(&:photo?) end - # All the attachments that are documents for this process. + # All the attachments that are documents for this model. # # Returns an Array def documents @documents ||= attachments.includes(:attachment_collection).select(&:document?) end - # All the attachments that are documents for this process that has a collection. + # All the attachments that are documents for this model that has a collection. # # Returns an Array def documents_with_collection documents.select(&:attachment_collection_id?) end - # All the attachments that are documents for this process that not has a collection. + # All the attachments that are documents for this model that not has a collection. # # Returns an Array def documents_without_collection From e2050008bbd4d8f74ee54419d449334681ec9f16 Mon Sep 17 00:00:00 2001 From: Vera Rojman Date: Mon, 19 Apr 2021 14:22:21 +0200 Subject: [PATCH 4/8] Improve proposals import options (#7669) --- .../proposals/admin/import_proposals.rb | 25 +++++- .../proposals/admin/proposals_import_form.rb | 6 ++ .../admin/proposals_imports/new.html.erb | 6 ++ decidim-proposals/config/locales/en.yml | 1 + .../proposals/admin/import_proposals_spec.rb | 88 ++++++++++++++++--- 5 files changed, 111 insertions(+), 15 deletions(-) diff --git a/decidim-proposals/app/commands/decidim/proposals/admin/import_proposals.rb b/decidim-proposals/app/commands/decidim/proposals/admin/import_proposals.rb index 71cad3d0effc..1b86753fbbf5 100644 --- a/decidim-proposals/app/commands/decidim/proposals/admin/import_proposals.rb +++ b/decidim-proposals/app/commands/decidim/proposals/admin/import_proposals.rb @@ -39,15 +39,17 @@ def import_proposals action_user: form.current_user, extra_attributes: { "component" => target_component - } + }.merge(proposal_answer_attributes(original_proposal)) ) end.compact end def proposals - Decidim::Proposals::Proposal - .where(component: origin_component) - .where(state: proposal_states) + @proposals = Decidim::Proposals::Proposal + .where(component: origin_component) + .where(state: proposal_states) + @proposals = @proposals.where(scope: proposal_scopes) unless proposal_scopes.empty? + @proposals end def proposal_states @@ -61,6 +63,10 @@ def proposal_states @proposal_states end + def proposal_scopes + @form.scopes + end + def origin_component @form.origin_component end @@ -78,6 +84,17 @@ def proposal_already_copied?(original_proposal, target_component) def proposal_author form.keep_authors ? nil : @form.current_organization end + + def proposal_answer_attributes(original_proposal) + return {} unless form.keep_answers + + { + answer: original_proposal.answer, + answered_at: original_proposal.answered_at, + state: original_proposal.state, + state_published_at: original_proposal.state_published_at + } + end end end end diff --git a/decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb b/decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb index 08970569736a..4807be757e72 100644 --- a/decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb +++ b/decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb @@ -10,8 +10,10 @@ class ProposalsImportForm < Decidim::Form attribute :origin_component_id, Integer attribute :import_proposals, Boolean + attribute :keep_answers, Boolean attribute :keep_authors, Boolean attribute :states, Array + attribute :scope_ids, Array validates :origin_component_id, :origin_component, :states, :current_component, presence: true validates :import_proposals, allow_nil: false, acceptance: true @@ -32,6 +34,10 @@ def states super.reject(&:blank?) end + def scopes + Decidim::Scope.where(organization: current_organization, id: scope_ids) + end + def origin_component @origin_component ||= origin_components.find_by(id: origin_component_id) end diff --git a/decidim-proposals/app/views/decidim/proposals/admin/proposals_imports/new.html.erb b/decidim-proposals/app/views/decidim/proposals/admin/proposals_imports/new.html.erb index ffdb923f1224..389ed67abffd 100644 --- a/decidim-proposals/app/views/decidim/proposals/admin/proposals_imports/new.html.erb +++ b/decidim-proposals/app/views/decidim/proposals/admin/proposals_imports/new.html.erb @@ -16,6 +16,12 @@
<%= f.check_box :keep_authors %>
+
+ <%= f.check_box :keep_answers %> +
+
+ <%= scopes_picker_filter f, :scope_ids %> +
<%= f.check_box :import_proposals %>
diff --git a/decidim-proposals/config/locales/en.yml b/decidim-proposals/config/locales/en.yml index 40dbd00ba25f..986ecda9517e 100644 --- a/decidim-proposals/config/locales/en.yml +++ b/decidim-proposals/config/locales/en.yml @@ -36,6 +36,7 @@ en: origin_component_id: Component to copy the proposals from proposals_import: import_proposals: Import proposals + keep_answers: Keep state and answers keep_authors: Keep original authors valuation_assignment: admin_log: diff --git a/decidim-proposals/spec/commands/decidim/proposals/admin/import_proposals_spec.rb b/decidim-proposals/spec/commands/decidim/proposals/admin/import_proposals_spec.rb index a69969825a51..d6718b954402 100644 --- a/decidim-proposals/spec/commands/decidim/proposals/admin/import_proposals_spec.rb +++ b/decidim-proposals/spec/commands/decidim/proposals/admin/import_proposals_spec.rb @@ -7,27 +7,42 @@ module Proposals module Admin describe ImportProposals do describe "call" do - let!(:proposal) { create(:proposal, :accepted) } - let(:keep_authors) { false } - let(:current_component) do + let!(:organization) { create(:organization) } + let!(:proposal) { create(:proposal, :accepted, component: proposal_component) } + let!(:proposal_component) do + create( + :proposal_component, + organization: organization + ) + end + let!(:current_component) do create( :proposal_component, - participatory_space: proposal.component.participatory_space + participatory_space: proposal_component.participatory_space, + organization: organization ) end + let(:form) do instance_double( ProposalsImportForm, - origin_component: proposal.component, + origin_component: proposal_component, current_component: current_component, - current_organization: current_component.organization, + current_organization: organization, keep_authors: keep_authors, + keep_answers: keep_answers, states: states, - current_user: create(:user), + scopes: scopes, + scope_ids: scope_ids, + current_user: create(:user, organization: organization), valid?: valid ) end + let(:keep_authors) { false } + let(:keep_answers) { false } let(:states) { ["accepted"] } + let(:scopes) { [] } + let(:scope_ids) { scopes.map(&:id) } let(:command) { described_class.new(form) } describe "when the form is not valid" do @@ -58,7 +73,7 @@ module Admin end context "when a proposal was already imported" do - let(:second_proposal) { create(:proposal, :accepted, component: proposal.component) } + let(:second_proposal) { create(:proposal, :accepted, component: proposal_component) } before do command.call @@ -90,7 +105,7 @@ module Admin new_proposal = Proposal.where(component: current_component).last expect(new_proposal.title).to eq(proposal.title) expect(new_proposal.body).to eq(proposal.body) - expect(new_proposal.creator_author).to eq(current_component.organization) + expect(new_proposal.creator_author).to eq(organization) expect(new_proposal.category).to eq(proposal.category) expect(new_proposal.state).to be_nil @@ -117,12 +132,26 @@ module Admin end end + describe "when keep_answers is true" do + let(:keep_answers) { true } + + it "keeps the proposal state and answers" do + command.call + + new_proposal = Proposal.where(component: current_component).last + expect(new_proposal.answer).to eq(proposal.answer) + expect(new_proposal.answered_at).to be_within(1.second).of(proposal.answered_at) + expect(new_proposal.state).to eq(proposal.state) + expect(new_proposal.state_published_at).to be_within(1.second).of(proposal.state_published_at) + end + end + describe "proposal states" do let(:states) { %w(not_answered rejected) } before do - create(:proposal, :rejected, component: proposal.component) - create(:proposal, component: proposal.component) + create(:proposal, :rejected, component: proposal_component) + create(:proposal, component: proposal_component) end it "only imports proposals from the selected states" do @@ -134,6 +163,43 @@ module Admin end end + describe "proposal scopes" do + let(:states) { ProposalsImportForm::VALID_STATES.dup } + let(:scope) { create(:scope, organization: organization) } + let(:other_scope) { create(:scope, organization: organization) } + + let(:scopes) { [scope] } + let(:scope_ids) { [scope.id] } + + let!(:proposals) do + [ + create(:proposal, component: proposal_component, scope: scope), + create(:proposal, component: proposal_component, scope: other_scope) + ] + end + + it "only imports proposals from the selected scope" do + expect do + command.call + end.to change { Proposal.where(component: current_component).count }.by(1) + + expect(Proposal.where(component: current_component).pluck(:decidim_scope_id)).to eq([scope.id]) + end + + context "when the global scope is selected" do + let(:scope) { nil } + let(:scope_ids) { [nil] } + + it "only imports proposals from the global scope" do + expect do + command.call + end.to change { Proposal.where(component: current_component).count }.by(2) + + expect(Proposal.where(component: current_component).pluck(:decidim_scope_id)).to eq([nil, nil]) + end + end + end + describe "when the proposal has attachments" do let!(:attachment) do create(:attachment, attached_to: proposal) From a173dda7f0486f51c2f6bfaf7976578eda3259ac Mon Sep 17 00:00:00 2001 From: Vera Rojman Date: Wed, 28 Apr 2021 14:05:21 +0200 Subject: [PATCH 5/8] Authorizable comment action for proposals (#6916) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ivan Vergés Co-authored-by: Aitor Lopez Beltran --- .../cells/decidim/comments/comment/votes.erb | 4 +- .../cells/decidim/comments/comment_cell.rb | 14 ++ .../user_comments_blocked_warning.erb | 6 +- .../cells/decidim/comments/comments_cell.rb | 17 +++ .../decidim/comments/comments_controller.rb | 2 +- .../forms/decidim/comments/comment_form.rb | 2 +- .../decidim/comments/permissions.rb | 2 +- decidim-comments/config/locales/en.yml | 1 + .../lib/decidim/comments/commentable.rb | 5 + .../decidim/comments/comment_cell_spec.rb | 34 +++++ .../decidim/comments/comments_cell_spec.rb | 28 +++- .../dev/test/rspec_support/component.rb | 5 + decidim-proposals/config/locales/en.yml | 2 + .../decidim/proposals/commentable_proposal.rb | 10 +- .../lib/decidim/proposals/component.rb | 4 +- .../spec/system/authorized_comments_spec.rb | 136 ++++++++++++++++++ .../spec/system/comments_spec.rb | 11 ++ 17 files changed, 273 insertions(+), 10 deletions(-) create mode 100644 decidim-proposals/spec/system/authorized_comments_spec.rb diff --git a/decidim-comments/app/cells/decidim/comments/comment/votes.erb b/decidim-comments/app/cells/decidim/comments/comment/votes.erb index 41cc5107d8e4..489d11c8ea4c 100644 --- a/decidim-comments/app/cells/decidim/comments/comment/votes.erb +++ b/decidim-comments/app/cells/decidim/comments/comment/votes.erb @@ -1,11 +1,11 @@
<% if user_signed_in? %> - <%= button_to decidim_comments.comment_votes_path(model, weight: 1), remote: true, disabled: voted_down?, class: votes_up_classes, title: t("decidim.components.up_vote_button.text") do %> + <%= vote_button_to decidim_comments.comment_votes_path(model, weight: 1), remote: true, disabled: voted_down?, class: votes_up_classes, title: t("decidim.components.up_vote_button.text") do %> <%= t("decidim.components.up_vote_button.text") %> <%= icon "chevron-top", class: "icon--small", role: "none presentation" %> <%= up_votes_count %> <% end %> - <%= button_to decidim_comments.comment_votes_path(model, weight: -1), remote: true, disabled: voted_up?, class: votes_down_classes, title: t("decidim.components.down_vote_button.text") do %> + <%= vote_button_to decidim_comments.comment_votes_path(model, weight: -1), remote: true, disabled: voted_up?, class: votes_down_classes, title: t("decidim.components.down_vote_button.text") do %> <%= t("decidim.components.down_vote_button.text") %> <%= icon "chevron-bottom", class: "icon--small", role: "none presentation" %> <%= down_votes_count %> diff --git a/decidim-comments/app/cells/decidim/comments/comment_cell.rb b/decidim-comments/app/cells/decidim/comments/comment_cell.rb index f21a684d479e..8e80b4006756 100644 --- a/decidim-comments/app/cells/decidim/comments/comment_cell.rb +++ b/decidim-comments/app/cells/decidim/comments/comment_cell.rb @@ -151,6 +151,20 @@ def nested_level_even? def has_replies? model.comment_threads.any? end + + # action_authorization_button expects current_component to be available + def current_component + root_commentable.try(:component) + end + + def vote_button_to(path, params, &block) + # actions are linked to objects belonging to a component + # In consultations, a question belong to a participatory_space but it has comments + # To apply :comment permission, the modal authorizer should be refactored to allow participatory spaces-level comments + return button_to(path, params, &block) unless current_component + + action_authorized_button_to(:vote_comment, path, params.merge(resource: root_commentable), &block) + end end end end diff --git a/decidim-comments/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb b/decidim-comments/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb index c1fd3da8e947..cebed3c18879 100644 --- a/decidim-comments/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb +++ b/decidim-comments/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb @@ -1,3 +1,7 @@
-

<%= t("decidim.components.comments.blocked_comments_for_user_warning") %>

+ <% if comment_permissions? %> +

<%= blocked_comments_for_unauthorized_user_warning_link %>

+ <% else %> +

<%= t("decidim.components.comments.blocked_comments_for_user_warning") %>

+ <% end %>
diff --git a/decidim-comments/app/cells/decidim/comments/comments_cell.rb b/decidim-comments/app/cells/decidim/comments/comments_cell.rb index 9b7079478a54..bdf639c2a4a3 100644 --- a/decidim-comments/app/cells/decidim/comments/comments_cell.rb +++ b/decidim-comments/app/cells/decidim/comments/comments_cell.rb @@ -129,6 +129,23 @@ def user_comments_blocked? !model.user_allowed_to_comment?(current_user) end + + def comment_permissions? + [model, current_component].any? do |resource| + resource.try(:permissions).try(:[], "comment") + end + end + + # action_authorization_link expects current_component to be available + def current_component + model.try(:component) + end + + def blocked_comments_for_unauthorized_user_warning_link + action_authorized_link_to(:comment, commentable_path, { resource: model }) do + t("decidim.components.comments.blocked_comments_for_unauthorized_user_warning") + end + end end end end diff --git a/decidim-comments/app/controllers/decidim/comments/comments_controller.rb b/decidim-comments/app/controllers/decidim/comments/comments_controller.rb index 8e3fb995b3ad..bf0ba00161fb 100644 --- a/decidim-comments/app/controllers/decidim/comments/comments_controller.rb +++ b/decidim-comments/app/controllers/decidim/comments/comments_controller.rb @@ -44,7 +44,7 @@ def create params.merge(commentable: commentable) ).with_context( current_organization: current_organization, - current_component: commentable.component + current_component: commentable.try(:component) || commentable.participatory_space ) Decidim::Comments::CreateComment.call(form, current_user) do on(:ok) do |comment| diff --git a/decidim-comments/app/forms/decidim/comments/comment_form.rb b/decidim-comments/app/forms/decidim/comments/comment_form.rb index 8d77b84212a8..53bc05317161 100644 --- a/decidim-comments/app/forms/decidim/comments/comment_form.rb +++ b/decidim-comments/app/forms/decidim/comments/comment_form.rb @@ -19,7 +19,7 @@ class CommentForm < Form validate :max_depth def max_length - if current_component&.settings.respond_to?(:comments_max_length) + if current_component.try(:settings).respond_to?(:comments_max_length) component_length = current_component.try { settings.comments_max_length.positive? } return current_component.settings.comments_max_length if component_length end diff --git a/decidim-comments/app/permissions/decidim/comments/permissions.rb b/decidim-comments/app/permissions/decidim/comments/permissions.rb index 8d440afd5267..5b8c092031f6 100644 --- a/decidim-comments/app/permissions/decidim/comments/permissions.rb +++ b/decidim-comments/app/permissions/decidim/comments/permissions.rb @@ -36,7 +36,7 @@ def can_create_comment? def can_vote_comment? return disallow! unless user - return disallow! unless commentable&.user_allowed_to_comment?(user) + return disallow! unless commentable&.user_allowed_to_vote_comment?(user) allow! end diff --git a/decidim-comments/config/locales/en.yml b/decidim-comments/config/locales/en.yml index 18b47adbf604..a62e48a6dbfb 100644 --- a/decidim-comments/config/locales/en.yml +++ b/decidim-comments/config/locales/en.yml @@ -74,6 +74,7 @@ en: comment_thread: title: Conversation with %{authorName} comments: + blocked_comments_for_unauthorized_user_warning: You need to be verified to comment at this moment, but you can read the previous ones. blocked_comments_for_user_warning: You are not able to comment at this moment, but you can read the previous ones. blocked_comments_warning: Comments are disabled at this time, but you can read the previous ones. comment_details_title: Comment details diff --git a/decidim-comments/lib/decidim/comments/commentable.rb b/decidim-comments/lib/decidim/comments/commentable.rb index 7f9a1fd961f5..d7aa379ad514 100644 --- a/decidim-comments/lib/decidim/comments/commentable.rb +++ b/decidim-comments/lib/decidim/comments/commentable.rb @@ -52,6 +52,11 @@ def user_allowed_to_comment?(_user) true end + # Public: Whether the object can have new comment votes or not. + def user_allowed_to_vote_comment?(_user) + true + end + # Public: Updates the comments counter cache. We have to do it these # way in order to properly calculate the coutner with hidden # comments. diff --git a/decidim-comments/spec/cells/decidim/comments/comment_cell_spec.rb b/decidim-comments/spec/cells/decidim/comments/comment_cell_spec.rb index 256986b53530..73240c35bfaa 100644 --- a/decidim-comments/spec/cells/decidim/comments/comment_cell_spec.rb +++ b/decidim-comments/spec/cells/decidim/comments/comment_cell_spec.rb @@ -124,5 +124,39 @@ module Decidim::Comments end end end + + describe "#vote_button_to" do + context "when commentable has permissions set for the vote_comment action" do + let(:permissions) do + { + vote_comment: { + authorization_handlers: { + "dummy_authorization_handler" => { "options" => {} } + } + } + } + end + + let(:user) { create(:user, :confirmed, organization: organization) } + + before do + organization.available_authorizations = ["dummy_authorization_handler"] + organization.save! + commentable.create_resource_permission(permissions: permissions) + allow(commentable).to receive(:comments_have_votes?).and_return(true) + allow(subject).to receive(:current_user).and_return(user) + end + + it "renders an action_authorized button" do + expect(subject).to have_css("[data-open=\"authorizationModal\"]") + end + end + + context "when commentable has no permissions set for the vote_comment action" do + it "renders a plain button" do + expect(subject).to have_no_css("[data-open=\"authorizationModal\"]") + end + end + end end end diff --git a/decidim-comments/spec/cells/decidim/comments/comments_cell_spec.rb b/decidim-comments/spec/cells/decidim/comments/comments_cell_spec.rb index 8e0916093e0c..b619e7fcada7 100644 --- a/decidim-comments/spec/cells/decidim/comments/comments_cell_spec.rb +++ b/decidim-comments/spec/cells/decidim/comments/comments_cell_spec.rb @@ -92,13 +92,39 @@ module Decidim::Comments context "when user comments are blocked" do before do allow(commentable).to receive(:user_allowed_to_comment?).with(current_user).and_return(false) + allow(commentable).to receive(:user_authorized_to_comment?).with(current_user).and_return(true) end it "renders the user comments blocked warning" do - expect(subject).not_to have_css(".callout.warning", text: I18n.t("decidim.components.comments.blocked_comments_warning")) + expect(subject).not_to have_css(".callout.warning", text: I18n.t("decidim.components.comments.blocked_comments_for_unauthorized_user_warning")) expect(subject).to have_css(".callout.warning", text: I18n.t("decidim.components.comments.blocked_comments_for_user_warning")) end end + + context "when user is not authorized to comment" do + let(:permissions) do + { + comment: { + authorization_handlers: { + "dummy_authorization_handler" => { "options" => {} } + } + } + } + end + + before do + organization.available_authorizations = ["dummy_authorization_handler"] + organization.save! + commentable.create_resource_permission(permissions: permissions) + allow(commentable).to receive(:user_allowed_to_comment?).with(current_user).and_return(false) + allow(commentable).to receive(:user_authorized_to_comment?).with(current_user).and_return(false) + end + + it "renders the user not authorized to comment warning" do + expect(subject).to have_css(".callout.warning", text: I18n.t("decidim.components.comments.blocked_comments_for_unauthorized_user_warning")) + expect(subject).not_to have_css(".callout.warning", text: I18n.t("decidim.components.comments.blocked_comments_for_user_warning")) + end + end end end end diff --git a/decidim-dev/lib/decidim/dev/test/rspec_support/component.rb b/decidim-dev/lib/decidim/dev/test/rspec_support/component.rb index 0d2dd5f30ac9..befe5689a68c 100644 --- a/decidim-dev/lib/decidim/dev/test/rspec_support/component.rb +++ b/decidim-dev/lib/decidim/dev/test/rspec_support/component.rb @@ -115,6 +115,11 @@ def user_allowed_to_comment?(user) component.can_participate_in_space?(user) end + # Public: Whether the object can have new comment votes or not. + def user_allowed_to_vote_comment?(user) + component.can_participate_in_space?(user) + end + def self.user_collection(user) where(decidim_author_id: user.id, decidim_author_type: "Decidim::User") end diff --git a/decidim-proposals/config/locales/en.yml b/decidim-proposals/config/locales/en.yml index 986ecda9517e..19949d650f6e 100644 --- a/decidim-proposals/config/locales/en.yml +++ b/decidim-proposals/config/locales/en.yml @@ -115,9 +115,11 @@ en: proposals: actions: amend: Amend + comment: Comment create: Create endorse: Endorse vote: Support + vote_comment: Vote comment withdraw: Withdraw name: Proposals settings: diff --git a/decidim-proposals/lib/decidim/proposals/commentable_proposal.rb b/decidim-proposals/lib/decidim/proposals/commentable_proposal.rb index 0bcfe5b81229..8a3f918c6b7f 100644 --- a/decidim-proposals/lib/decidim/proposals/commentable_proposal.rb +++ b/decidim-proposals/lib/decidim/proposals/commentable_proposal.rb @@ -36,7 +36,15 @@ def users_to_notify_on_comment_created end def user_allowed_to_comment?(user) - can_participate_in_space?(user) + return unless can_participate_in_space?(user) + + ActionAuthorizer.new(user, "comment", component, self).authorize.ok? + end + + def user_allowed_to_vote_comment?(user) + return unless can_participate_in_space?(user) + + ActionAuthorizer.new(user, "vote_comment", component, self).authorize.ok? end end end diff --git a/decidim-proposals/lib/decidim/proposals/component.rb b/decidim-proposals/lib/decidim/proposals/component.rb index 289373dee279..990f5bd1194b 100644 --- a/decidim-proposals/lib/decidim/proposals/component.rb +++ b/decidim-proposals/lib/decidim/proposals/component.rb @@ -16,7 +16,7 @@ component.newsletter_participant_entities = ["Decidim::Proposals::Proposal"] - component.actions = %w(endorse vote create withdraw amend) + component.actions = %w(endorse vote create withdraw amend comment vote_comment) component.query_type = "Decidim::Proposals::ProposalsType" @@ -83,7 +83,7 @@ resource.template = "decidim/proposals/proposals/linked_proposals" resource.card = "decidim/proposals/proposal" resource.reported_content_cell = "decidim/proposals/reported_content" - resource.actions = %w(endorse vote amend) + resource.actions = %w(endorse vote amend comment vote_comment) resource.searchable = true end diff --git a/decidim-proposals/spec/system/authorized_comments_spec.rb b/decidim-proposals/spec/system/authorized_comments_spec.rb new file mode 100644 index 000000000000..583c2dd857ba --- /dev/null +++ b/decidim-proposals/spec/system/authorized_comments_spec.rb @@ -0,0 +1,136 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "Authorized comments", type: :system do + let!(:commentable) { create(:proposal, component: component, users: [author]) } + let!(:author) { create(:user, :confirmed, organization: organization) } + let!(:component) { create(:proposal_component, organization: organization) } + let!(:user) { create(:user, :confirmed, organization: organization) } + let!(:comments) { create_list(:comment, 3, commentable: commentable) } + let!(:authorization_handler_name) { "dummy_authorization_handler" } + let!(:organization) { create(:organization, available_authorizations: available_authorizations) } + let!(:available_authorizations) { [authorization_handler_name] } + + let(:resource_path) { resource_locator(commentable).path } + + after do + expect_no_js_errors + end + + before do + switch_to_host(organization.host) + sign_in user + end + + shared_examples_for "allowed to comment" do + it do + expect(page).not_to have_content("You need to be verified to comment at this moment") + expect(page).to have_selector("form.new_comment") + end + end + + shared_examples_for "not allowed to comment" do + it do + expect(page).to have_content("You need to be verified to comment at this moment") + end + end + + shared_examples_for "allowed to vote a comment" do + it do + within "#comment_#{comments[0].id}" do + page.find(".comment__votes--up").click + end + + expect(page).to have_selector(".comment__votes--up", text: /1/) + end + end + + shared_examples_for "not allowed to vote a comment" do + it do + within "#comment_#{comments[0].id}" do + page.find(".comment__votes--up").click + end + + expect(page).to have_selector(".comment__votes--up", text: /0/) + expect(page).to have_content("Authorization required") + end + end + + context "when the proposal has no restriction on commenting and voting comments" do + before do + visit resource_path + end + + it_behaves_like "allowed to comment" + it_behaves_like "allowed to vote a comment" + end + + context "when the proposal has restrictions on commenting and/or voting comments" do + let!(:resource_permission) { commentable.create_resource_permission(permissions: permissions) } + let(:comment_permission) do + { comment: authorization_handlers } + end + let(:vote_comment_permission) do + { vote_comment: authorization_handlers } + end + let(:authorization_handlers) do + { authorization_handlers: { authorization_handler_name => { "options" => {} } } } + end + + before do + authorization + visit resource_path + end + + context "and user is not verified" do + let(:authorization) { nil } + + describe "restricted comment action" do + let(:permissions) { comment_permission } + + it_behaves_like "not allowed to comment" + it_behaves_like "allowed to vote a comment" + end + + describe "restricted vote_comment action" do + let(:permissions) { vote_comment_permission } + + it_behaves_like "allowed to comment" + it_behaves_like "not allowed to vote a comment" + end + + describe "restricted comment and vote_comment action" do + let(:permissions) { comment_permission.merge(vote_comment_permission) } + + it_behaves_like "not allowed to comment" + it_behaves_like "not allowed to vote a comment" + end + end + + context "and user is verified" do + let(:authorization) { create(:authorization, user: user, name: "dummy_authorization_handler") } + + describe "restricted comment action" do + let(:permissions) { comment_permission } + + it_behaves_like "allowed to comment" + it_behaves_like "allowed to vote a comment" + end + + describe "restricted vote_comment action" do + let(:permissions) { vote_comment_permission } + + it_behaves_like "allowed to comment" + it_behaves_like "allowed to vote a comment" + end + + describe "restricted comment and vote_comment action" do + let(:permissions) { comment_permission.merge(vote_comment_permission) } + + it_behaves_like "allowed to comment" + it_behaves_like "allowed to vote a comment" + end + end + end +end diff --git a/decidim-proposals/spec/system/comments_spec.rb b/decidim-proposals/spec/system/comments_spec.rb index e5628ffff553..777fdfa8824d 100644 --- a/decidim-proposals/spec/system/comments_spec.rb +++ b/decidim-proposals/spec/system/comments_spec.rb @@ -6,8 +6,19 @@ let!(:component) { create(:proposal_component, organization: organization) } let!(:author) { create(:user, :confirmed, organization: organization) } let!(:commentable) { create(:proposal, component: component, users: [author]) } + let!(:organization) { create(:organization) } + let!(:user) { create(:user, :confirmed, organization: organization) } + let!(:comments) { create_list(:comment, 3, commentable: commentable) } let(:resource_path) { resource_locator(commentable).path } + after do + expect_no_js_errors + end + + before do + switch_to_host(organization.host) + end + include_examples "comments" end From 55fa532cd6ff1e3cab1f6a655d95ca6f14ee8fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Wed, 26 Jan 2022 15:11:11 +0100 Subject: [PATCH 6/8] Fix participatory groups leaks on other organizations/tenants (#8651) --- ...participatory_processes_shared_examples.rb | 5 +++ ...participatory_process_groups_controller.rb | 2 +- .../participatory_processes_controller.rb | 6 ++-- ...n_promoted_participatory_process_groups.rb | 16 +++++++++ ...cipatory_process_groups_controller_spec.rb | 36 +++++++++++++++++++ ...participatory_processes_controller_spec.rb | 5 +++ .../system/participatory_processes_spec.rb | 12 ++++++- 7 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 decidim-participatory_processes/app/queries/decidim/participatory_processes/organization_promoted_participatory_process_groups.rb create mode 100644 decidim-participatory_processes/spec/controllers/participatory_process_groups_controller_spec.rb diff --git a/decidim-dev/lib/decidim/dev/test/promoted_participatory_processes_shared_examples.rb b/decidim-dev/lib/decidim/dev/test/promoted_participatory_processes_shared_examples.rb index 2e0fc2da73e2..aad48666ac81 100644 --- a/decidim-dev/lib/decidim/dev/test/promoted_participatory_processes_shared_examples.rb +++ b/decidim-dev/lib/decidim/dev/test/promoted_participatory_processes_shared_examples.rb @@ -35,6 +35,11 @@ organization: organization ) + _external_promoted_group = create( + :participatory_process_group, + :promoted + ) + expect(controller.helpers.promoted_collection).to( match_array([promoted_group, promoted_process]) ) diff --git a/decidim-participatory_processes/app/controllers/decidim/participatory_processes/participatory_process_groups_controller.rb b/decidim-participatory_processes/app/controllers/decidim/participatory_processes/participatory_process_groups_controller.rb index d256050306a3..f02a49ff1561 100644 --- a/decidim-participatory_processes/app/controllers/decidim/participatory_processes/participatory_process_groups_controller.rb +++ b/decidim-participatory_processes/app/controllers/decidim/participatory_processes/participatory_process_groups_controller.rb @@ -29,7 +29,7 @@ def participatory_processes end def set_group - @group = Decidim::ParticipatoryProcessGroup.find(params[:id]) + @group = Decidim::ParticipatoryProcessGroup.where(organization: current_organization).find(params[:id]) end attr_reader :group diff --git a/decidim-participatory_processes/app/controllers/decidim/participatory_processes/participatory_processes_controller.rb b/decidim-participatory_processes/app/controllers/decidim/participatory_processes/participatory_processes_controller.rb index cdbc3a4a725a..7da345643a11 100644 --- a/decidim-participatory_processes/app/controllers/decidim/participatory_processes/participatory_processes_controller.rb +++ b/decidim-participatory_processes/app/controllers/decidim/participatory_processes/participatory_processes_controller.rb @@ -73,7 +73,7 @@ def promoted_participatory_processes end def promoted_participatory_process_groups - @promoted_participatory_process_groups ||= PromotedParticipatoryProcessGroups.new + @promoted_participatory_process_groups ||= OrganizationPromotedParticipatoryProcessGroups.new(current_organization) end def promoted_collection @@ -93,8 +93,8 @@ def participatory_processes end def participatory_process_groups - @participatory_process_groups ||= Decidim::ParticipatoryProcessGroup - .where(id: filtered_processes.grouped.group_ids) + @participatory_process_groups ||= OrganizationParticipatoryProcessGroups.new(current_organization).query + .where(id: filtered_processes.grouped.group_ids) end def stats diff --git a/decidim-participatory_processes/app/queries/decidim/participatory_processes/organization_promoted_participatory_process_groups.rb b/decidim-participatory_processes/app/queries/decidim/participatory_processes/organization_promoted_participatory_process_groups.rb new file mode 100644 index 000000000000..7c99523e8424 --- /dev/null +++ b/decidim-participatory_processes/app/queries/decidim/participatory_processes/organization_promoted_participatory_process_groups.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Decidim + module ParticipatoryProcesses + # This query class filters participatory process groups given an organization. + class OrganizationPromotedParticipatoryProcessGroups < Rectify::Query + def initialize(organization) + @organization = organization + end + + def query + PromotedParticipatoryProcessGroups.new.query.where(organization: @organization) + end + end + end +end diff --git a/decidim-participatory_processes/spec/controllers/participatory_process_groups_controller_spec.rb b/decidim-participatory_processes/spec/controllers/participatory_process_groups_controller_spec.rb new file mode 100644 index 000000000000..4cb66d747162 --- /dev/null +++ b/decidim-participatory_processes/spec/controllers/participatory_process_groups_controller_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module ParticipatoryProcesses + describe ParticipatoryProcessGroupsController, type: :controller do + routes { Decidim::ParticipatoryProcesses::Engine.routes } + + let(:organization) { create(:organization) } + let!(:process_group) { create :participatory_process_group, organization: organization } + + describe "GET show" do + before do + request.env["decidim.current_organization"] = organization + end + + context "when the process group belongs to the organization" do + it "shows the content" do + get :show, params: { id: process_group.id } + + expect(response).to be_successful + end + end + + context "when the process group do not belong to the organization" do + let!(:process_group) { create :participatory_process_group } + + it "redirects to 404 if there aren't any" do + expect { get :show, params: { id: process_group.id } }.to raise_error(ActiveRecord::RecordNotFound) + end + end + end + end + end +end diff --git a/decidim-participatory_processes/spec/controllers/participatory_processes_controller_spec.rb b/decidim-participatory_processes/spec/controllers/participatory_processes_controller_spec.rb index 27ea10f9efec..b3609be69765 100644 --- a/decidim-participatory_processes/spec/controllers/participatory_processes_controller_spec.rb +++ b/decidim-participatory_processes/spec/controllers/participatory_processes_controller_spec.rb @@ -79,6 +79,11 @@ module ParticipatoryProcesses organization: other_organization ) + _manipulated_other_groups = create( + :participatory_process_group, + participatory_processes: [create(:participatory_process, organization: organization)] + ) + expect(controller.helpers.collection) .to match_array([*published, *organization_groups]) end diff --git a/decidim-participatory_processes/spec/system/participatory_processes_spec.rb b/decidim-participatory_processes/spec/system/participatory_processes_spec.rb index f618c3ef6d16..38ed3b4c1174 100644 --- a/decidim-participatory_processes/spec/system/participatory_processes_spec.rb +++ b/decidim-participatory_processes/spec/system/participatory_processes_spec.rb @@ -228,7 +228,7 @@ end context "when there are promoted participatory process groups" do - let!(:promoted_group) { create(:participatory_process_group, :promoted, :with_participatory_processes) } + let!(:promoted_group) { create(:participatory_process_group, :promoted, :with_participatory_processes, organization: organization) } let(:promoted_items_titles) { page.all("#highlighted-processes .card__title").map(&:text) } before do @@ -270,6 +270,16 @@ expect(page).to have_link(cta_settings[:button_text_en], href: cta_settings[:button_url]) end end + + context "and promoted group belongs to another organization" do + let!(:promoted_group) { create(:participatory_process_group, :promoted, :with_participatory_processes) } + + it "shows a CTA button inside group card" do + within("#highlighted-processes") do + expect(page).not_to have_link(cta_settings[:button_text_en], href: cta_settings[:button_url]) + end + end + end end end end From a532a7e8fc66140ef23ae5d4c90d4435327700d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Mon, 21 Feb 2022 12:27:46 +0100 Subject: [PATCH 7/8] Fix report moderation for all the spaces (#8813) # Conflicts: # decidim-comments/app/models/decidim/comments/comment.rb --- .../app/permissions/decidim/assemblies/permissions.rb | 8 -------- .../permissions/decidim/assemblies/permissions_spec.rb | 8 -------- decidim-comments/app/models/decidim/comments/comment.rb | 2 +- .../app/permissions/decidim/conferences/permissions.rb | 8 -------- .../permissions/decidim/conferences/permissions_spec.rb | 8 -------- .../app/models/decidim/consultations/question.rb | 1 + decidim-core/app/permissions/decidim/permissions.rb | 9 +++++++++ .../spec/permissions/decidim/permissions_spec.rb | 8 ++++++++ .../app/permissions/decidim/initiatives/permissions.rb | 8 -------- .../decidim/participatory_processes/permissions.rb | 8 -------- .../decidim/participatory_processes/permissions_spec.rb | 8 -------- 11 files changed, 19 insertions(+), 57 deletions(-) diff --git a/decidim-assemblies/app/permissions/decidim/assemblies/permissions.rb b/decidim-assemblies/app/permissions/decidim/assemblies/permissions.rb index 12ab4a536f9f..24e6d9a4efee 100644 --- a/decidim-assemblies/app/permissions/decidim/assemblies/permissions.rb +++ b/decidim-assemblies/app/permissions/decidim/assemblies/permissions.rb @@ -17,7 +17,6 @@ def permissions public_list_assemblies_action? public_read_assembly_action? public_list_members_action? - public_report_content_action? return permission_action end @@ -125,13 +124,6 @@ def public_list_members_action? allow! end - def public_report_content_action? - return unless permission_action.action == :create && - permission_action.subject == :moderation - - allow! - end - # All users with a relation to a assembly and organization admins can enter # the space area. The sapce area is considered to be the assemblies zone, # not the assembly groups one. diff --git a/decidim-assemblies/spec/permissions/decidim/assemblies/permissions_spec.rb b/decidim-assemblies/spec/permissions/decidim/assemblies/permissions_spec.rb index d763feb3aefd..f14464a86f1b 100644 --- a/decidim-assemblies/spec/permissions/decidim/assemblies/permissions_spec.rb +++ b/decidim-assemblies/spec/permissions/decidim/assemblies/permissions_spec.rb @@ -126,14 +126,6 @@ it { is_expected.to eq true } end - context "when reporting a resource" do - let(:action) do - { scope: :public, action: :create, subject: :moderation } - end - - it { is_expected.to eq true } - end - context "when any other action" do let(:action) do { scope: :public, action: :foo, subject: :bar } diff --git a/decidim-comments/app/models/decidim/comments/comment.rb b/decidim-comments/app/models/decidim/comments/comment.rb index a66eb280b0f3..b9998875979e 100644 --- a/decidim-comments/app/models/decidim/comments/comment.rb +++ b/decidim-comments/app/models/decidim/comments/comment.rb @@ -80,7 +80,7 @@ def visible? end def participatory_space - return root_commentable if root_commentable.is_a?(Decidim::Participable) + return root_commentable unless root_commentable.respond_to?(:participatory_space) root_commentable.participatory_space end diff --git a/decidim-conferences/app/permissions/decidim/conferences/permissions.rb b/decidim-conferences/app/permissions/decidim/conferences/permissions.rb index d8abc3fd7adb..d00b6cbbf82f 100644 --- a/decidim-conferences/app/permissions/decidim/conferences/permissions.rb +++ b/decidim-conferences/app/permissions/decidim/conferences/permissions.rb @@ -20,7 +20,6 @@ def permissions public_list_program_action? public_list_media_links_action? public_list_registration_types_action? - public_report_content_action? can_join_conference? can_leave_conference? @@ -159,13 +158,6 @@ def public_list_registration_types_action? allow! end - def public_report_content_action? - return unless permission_action.action == :create && - permission_action.subject == :moderation - - allow! - end - # All users with a relation to a conference and organization admins can enter # the space area. The sapce area is considered to be the conferences zone, # not the conference groups one. diff --git a/decidim-conferences/spec/permissions/decidim/conferences/permissions_spec.rb b/decidim-conferences/spec/permissions/decidim/conferences/permissions_spec.rb index d1fc558f05e1..e999b4ef98bb 100644 --- a/decidim-conferences/spec/permissions/decidim/conferences/permissions_spec.rb +++ b/decidim-conferences/spec/permissions/decidim/conferences/permissions_spec.rb @@ -140,14 +140,6 @@ it { is_expected.to eq true } end - context "when reporting a resource" do - let(:action) do - { scope: :public, action: :create, subject: :moderation } - end - - it { is_expected.to eq true } - end - context "when any other action" do let(:action) do { scope: :public, action: :foo, subject: :bar } diff --git a/decidim-consultations/app/models/decidim/consultations/question.rb b/decidim-consultations/app/models/decidim/consultations/question.rb index 9fd45fd27a26..c177e0fc19a1 100644 --- a/decidim-consultations/app/models/decidim/consultations/question.rb +++ b/decidim-consultations/app/models/decidim/consultations/question.rb @@ -66,6 +66,7 @@ class Question < ApplicationRecord delegate :start_voting_date, to: :consultation delegate :end_voting_date, to: :consultation delegate :results_published?, to: :consultation + delegate :moderators, to: :consultation alias participatory_space consultation diff --git a/decidim-core/app/permissions/decidim/permissions.rb b/decidim-core/app/permissions/decidim/permissions.rb index dee69831c345..73ab21062e8f 100644 --- a/decidim-core/app/permissions/decidim/permissions.rb +++ b/decidim-core/app/permissions/decidim/permissions.rb @@ -10,6 +10,8 @@ def permissions component_public_action? search_scope_action? + public_report_content_action? + return permission_action unless user user_manager_permissions @@ -28,6 +30,13 @@ def permissions private + def public_report_content_action? + return unless permission_action.action == :create && + permission_action.subject == :moderation + + allow! + end + def read_public_pages_action? return unless permission_action.subject == :public_page && permission_action.action == :read diff --git a/decidim-core/spec/permissions/decidim/permissions_spec.rb b/decidim-core/spec/permissions/decidim/permissions_spec.rb index f6d3e95ebf37..540a28ff4976 100644 --- a/decidim-core/spec/permissions/decidim/permissions_spec.rb +++ b/decidim-core/spec/permissions/decidim/permissions_spec.rb @@ -32,6 +32,14 @@ it { is_expected.to eq true } end + context "when reporting a resource" do + let(:action) do + { scope: :public, action: :create, subject: :moderation } + end + + it { is_expected.to eq true } + end + context "when reading a component" do let(:action) do { scope: :public, action: :read, subject: :component } diff --git a/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb b/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb index 3a656bb852e5..1041aa8be0fb 100644 --- a/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb +++ b/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb @@ -9,7 +9,6 @@ def permissions return permission_action if permission_action.scope != :public # Non-logged users permissions - public_report_content_action? list_public_initiatives? read_public_initiative? search_initiative_types_and_scopes? @@ -154,13 +153,6 @@ def initiative_attachment? toggle_allow(initiative_type.attachments_enabled?) end - def public_report_content_action? - return unless permission_action.action == :create && - permission_action.subject == :moderation - - allow! - end - def sign_initiative? return unless permission_action.action == :sign_initiative && permission_action.subject == :initiative diff --git a/decidim-participatory_processes/app/permissions/decidim/participatory_processes/permissions.rb b/decidim-participatory_processes/app/permissions/decidim/participatory_processes/permissions.rb index 0b7e303644b2..dbdcd74a2c52 100644 --- a/decidim-participatory_processes/app/permissions/decidim/participatory_processes/permissions.rb +++ b/decidim-participatory_processes/app/permissions/decidim/participatory_processes/permissions.rb @@ -19,7 +19,6 @@ def permissions public_list_process_groups_action? public_read_process_group_action? public_read_process_action? - public_report_content_action? return permission_action end @@ -119,13 +118,6 @@ def can_view_private_space? user.admin || process.users.include?(user) end - def public_report_content_action? - return unless permission_action.action == :create && - permission_action.subject == :moderation - - allow! - end - # Only organization admins can enter the process groups space area. def user_can_enter_process_groups_space_area? return unless permission_action.action == :enter && diff --git a/decidim-participatory_processes/spec/permissions/decidim/participatory_processes/permissions_spec.rb b/decidim-participatory_processes/spec/permissions/decidim/participatory_processes/permissions_spec.rb index a78c24136fcc..fafb4d08f0c8 100644 --- a/decidim-participatory_processes/spec/permissions/decidim/participatory_processes/permissions_spec.rb +++ b/decidim-participatory_processes/spec/permissions/decidim/participatory_processes/permissions_spec.rb @@ -134,14 +134,6 @@ it { is_expected.to eq true } end - context "when reporting a resource" do - let(:action) do - { scope: :public, action: :create, subject: :moderation } - end - - it { is_expected.to eq true } - end - context "when any other action" do let(:action) do { scope: :public, action: :foo, subject: :bar } From 8de1ef86a61367c6b7d80bb9c25ed2669d924b58 Mon Sep 17 00:00:00 2001 From: phoebus-84 <83974413+phoebus-84@users.noreply.github.com> Date: Thu, 10 Mar 2022 11:05:57 +0100 Subject: [PATCH 8/8] Backport fixes for proposal picker (#125) * fix for proposals picker * DRAFT * increase max proposals to 2000 in proposals picker cell * remove useless js file * backport changes for proposal picker.js Co-authored-by: phoebus-84 --- .../proposals/admin/proposals_picker.js.es6 | 15 +++++++++++++++ .../decidim/proposals/proposals_picker_cell.rb | 14 ++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/decidim-proposals/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 b/decidim-proposals/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 index 4ceb9acc644a..1eb9d79ba511 100644 --- a/decidim-proposals/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 +++ b/decidim-proposals/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 @@ -8,6 +8,7 @@ $(() => { } let jqxhr = null + let filterBuffer = "" toggleNoProposals() @@ -16,14 +17,28 @@ $(() => { if (pickerMore) { if (jqxhr !== null) { + if (filter.length < 3) { + return + } + + if (filter === filterBuffer) { + return + } + jqxhr.abort() } $content.html("
") jqxhr = $.get(`${pickerPath}?q=${filter}`, (data) => { + filterBuffer = filter $content.html(data) jqxhr = null toggleNoProposals() + + if (typeof window.theDataPicker === "object" && window.theDataPicker.current !== null) { + window.theDataPicker._handleCheckboxes($content); + window.theDataPicker._handleLinks($content); + } }) } else { $("#proposals_list li").each((index, li) => { diff --git a/decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb b/decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb index 83b589ce3102..cba57cee5d72 100644 --- a/decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb +++ b/decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb @@ -6,7 +6,7 @@ module Decidim module Proposals # This cell renders a proposals picker. class ProposalsPickerCell < Decidim::ViewModel - MAX_PROPOSALS = 1000 + MAX_PROPOSALS = 2000 def show if filtered? @@ -50,9 +50,10 @@ def decorated_proposals def filtered_proposals @filtered_proposals ||= if filtered? - proposals.where("title::text ILIKE ?", "%#{search_text}%") - .or(proposals.where("reference ILIKE ?", "%#{search_text}%")) - .or(proposals.where("id::text ILIKE ?", "%#{search_text}%")) + table_name = Decidim::Proposals::Proposal.table_name + proposals.where(%("#{table_name}"."title"::text ILIKE ?), "%#{search_text}%") + .or(proposals.where(%("#{table_name}"."reference" ILIKE ?), "%#{search_text}%")) + .or(proposals.where(%("#{table_name}"."id"::text ILIKE ?), "%#{search_text}%")) else proposals end @@ -60,8 +61,9 @@ def filtered_proposals def proposals @proposals ||= Decidim.find_resource_manifest(:proposals).try(:resource_scope, component) - &.published - &.order(id: :asc) + &.includes(:component) + &.published + &.order(id: :asc) end def proposals_collection_name