From 0b6df0784114e2082b6e6d713e5219573d370fc4 Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Sun, 29 Dec 2024 16:49:46 +0100 Subject: [PATCH 01/11] redirect users with no membership to organizations list + add org name in new_petition email subject --- app/controllers/application_controller.rb | 2 +- app/mailers/organization_notifier.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a8823c0c..e62d199d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -53,7 +53,7 @@ def after_sign_in_path_for(user) elsif user.members.present? users_path else - page_path("about") + organizations_path end end diff --git a/app/mailers/organization_notifier.rb b/app/mailers/organization_notifier.rb index 5827711f..4fbb68b3 100644 --- a/app/mailers/organization_notifier.rb +++ b/app/mailers/organization_notifier.rb @@ -18,7 +18,7 @@ def new_petition(petition) I18n.with_locale(locale) do mail( - subject: 'New Application', + subject: "New Application - #{organization.name}", bcc: organization.users.joins(:members).where(members: { manager: true }).pluck(:email).uniq ) end From 3d103a1f2501a6829d01511e1967c73308738584 Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Sun, 29 Dec 2024 17:55:26 +0100 Subject: [PATCH 02/11] Notify orgs admins (CCO) when membership remove their membership --- app/controllers/members_controller.rb | 2 ++ app/mailers/organization_notifier.rb | 14 +++++++++++++- app/models/organization.rb | 8 ++++++-- .../organization_notifier/member_deleted.html.erb | 1 + app/views/organizations/index.html.erb | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 app/views/organization_notifier/member_deleted.html.erb diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index ad585bb4..62021164 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -6,6 +6,8 @@ def destroy toggle_active_posts @member.destroy + OrganizationNotifier.member_deleted(@member).deliver_now + redirect_to request.referer.include?(organizations_path) ? organizations_path : manage_users_path end diff --git a/app/mailers/organization_notifier.rb b/app/mailers/organization_notifier.rb index 4fbb68b3..9efe0a62 100644 --- a/app/mailers/organization_notifier.rb +++ b/app/mailers/organization_notifier.rb @@ -19,7 +19,7 @@ def new_petition(petition) I18n.with_locale(locale) do mail( subject: "New Application - #{organization.name}", - bcc: organization.users.joins(:members).where(members: { manager: true }).pluck(:email).uniq + bcc: organization.all_managers.pluck(:email).uniq ) end end @@ -34,4 +34,16 @@ def petition_sent(petition) ) end end + + def member_deleted(member) + @user = member.user + organization = member.organization + + I18n.with_locale(locale) do + mail( + subject: "Membership deleted - #{organization.name}", + bcc: organization.all_managers.pluck(:email).uniq + ) + end + end end diff --git a/app/models/organization.rb b/app/models/organization.rb index cec86710..90847ee3 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -33,6 +33,10 @@ class Organization < ApplicationRecord before_validation :ensure_url after_create :create_account + def to_s + "#{name}" + end + def all_transfers_with_accounts all_transfers. includes(movements: { account: :accountable }). @@ -40,8 +44,8 @@ def all_transfers_with_accounts distinct end - def to_s - "#{name}" + def all_managers + users.where(members: { manager: true }) end def display_name_with_uid diff --git a/app/views/organization_notifier/member_deleted.html.erb b/app/views/organization_notifier/member_deleted.html.erb new file mode 100644 index 00000000..6142c261 --- /dev/null +++ b/app/views/organization_notifier/member_deleted.html.erb @@ -0,0 +1 @@ +User <%= @user.username %> has unsubscribed from the organization. diff --git a/app/views/organizations/index.html.erb b/app/views/organizations/index.html.erb index 64082bf5..26db4573 100644 --- a/app/views/organizations/index.html.erb +++ b/app/views/organizations/index.html.erb @@ -31,7 +31,7 @@ - <%= render partial: 'organizations_row', collection: @user_organizations, as: :org if !params[:page] || params[:page] == '1' %> + <%= render partial: 'organizations_row', collection: @user_organizations, as: :org if @user_organizations.present? %> <%= render partial: 'organizations_row', collection: @organizations, as: :org %> From 1e7454f22feda0f97036ab66a5040b00bd462b93 Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Mon, 30 Dec 2024 18:30:14 +0100 Subject: [PATCH 03/11] introduce "highlighted" flag for organizations (they will be featured in the organization list) --- app/admin/organization.rb | 5 ++++- app/controllers/organizations_controller.rb | 2 +- app/views/organizations/index.html.erb | 2 +- ...170753_add_highlighted_to_organizations.rb | 5 +++++ db/structure.sql | 21 ++++++++++++++++--- 5 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20241230170753_add_highlighted_to_organizations.rb diff --git a/app/admin/organization.rb b/app/admin/organization.rb index 2d8fe6dc..37364efb 100644 --- a/app/admin/organization.rb +++ b/app/admin/organization.rb @@ -23,6 +23,7 @@ column :posts do |organization| organization.posts.count end + column :highlighted actions end @@ -37,6 +38,7 @@ form do |f| f.inputs do + f.input :highlighted, hint: "Highlighted Time Banks will appear first" f.input :name f.input :email f.input :web @@ -71,7 +73,8 @@ def destroy filter :neighborhood filter :created_at filter :updated_at + filter :highlighted permit_params :name, :email, :web, :phone, :city, :neighborhood, - :address, :description, :public_opening_times, :logo + :address, :description, :public_opening_times, :logo, :highlighted end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 37daeafc..7fc2ec66 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -10,7 +10,7 @@ def index organizations = Organization.where.not(id: @user_organizations&.pluck(:id)) organizations = organizations.search_by_query(params[:q]) if params[:q].present? - @organizations = organizations.page(params[:page]).per(25) + @organizations = organizations.order(highlighted: :desc).page(params[:page]).per(25) end def show diff --git a/app/views/organizations/index.html.erb b/app/views/organizations/index.html.erb index 26db4573..64082bf5 100644 --- a/app/views/organizations/index.html.erb +++ b/app/views/organizations/index.html.erb @@ -31,7 +31,7 @@ - <%= render partial: 'organizations_row', collection: @user_organizations, as: :org if @user_organizations.present? %> + <%= render partial: 'organizations_row', collection: @user_organizations, as: :org if !params[:page] || params[:page] == '1' %> <%= render partial: 'organizations_row', collection: @organizations, as: :org %> diff --git a/db/migrate/20241230170753_add_highlighted_to_organizations.rb b/db/migrate/20241230170753_add_highlighted_to_organizations.rb new file mode 100644 index 00000000..a7f07ffc --- /dev/null +++ b/db/migrate/20241230170753_add_highlighted_to_organizations.rb @@ -0,0 +1,5 @@ +class AddHighlightedToOrganizations < ActiveRecord::Migration[7.0] + def change + add_column :organizations, :highlighted, :boolean, default: false + end +end diff --git a/db/structure.sql b/db/structure.sql index 1a912a79..5200e1ad 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -107,6 +107,7 @@ CREATE TABLE public.accounts ( -- CREATE SEQUENCE public.accounts_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -143,6 +144,7 @@ CREATE TABLE public.active_admin_comments ( -- CREATE SEQUENCE public.active_admin_comments_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -286,6 +288,7 @@ CREATE TABLE public.categories ( -- CREATE SEQUENCE public.categories_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -318,6 +321,7 @@ CREATE TABLE public.device_tokens ( -- CREATE SEQUENCE public.device_tokens_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -353,6 +357,7 @@ CREATE TABLE public.documents ( -- CREATE SEQUENCE public.documents_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -387,6 +392,7 @@ CREATE TABLE public.events ( -- CREATE SEQUENCE public.events_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -424,6 +430,7 @@ CREATE TABLE public.members ( -- CREATE SEQUENCE public.members_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -457,6 +464,7 @@ CREATE TABLE public.movements ( -- CREATE SEQUENCE public.movements_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -490,7 +498,8 @@ CREATE TABLE public.organizations ( address text, neighborhood character varying, city character varying, - domain character varying + domain character varying, + highlighted boolean DEFAULT false ); @@ -499,6 +508,7 @@ CREATE TABLE public.organizations ( -- CREATE SEQUENCE public.organizations_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -574,6 +584,7 @@ CREATE TABLE public.posts ( -- CREATE SEQUENCE public.posts_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -610,6 +621,7 @@ CREATE TABLE public.push_notifications ( -- CREATE SEQUENCE public.push_notifications_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -652,6 +664,7 @@ CREATE TABLE public.transfers ( -- CREATE SEQUENCE public.transfers_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -713,6 +726,7 @@ CREATE TABLE public.users ( -- CREATE SEQUENCE public.users_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1305,7 +1319,7 @@ ALTER TABLE ONLY public.active_storage_attachments -- PostgreSQL database dump complete -- -SET search_path TO "$user",public; +SET search_path TO "$user", public; INSERT INTO "schema_migrations" (version) VALUES ('1'), @@ -1377,4 +1391,5 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230314233504'), ('20230401114456'), ('20231120164231'), -('20231120164346'); +('20231120164346'), +('20241230170753'); From d88be54e4cef2bb566f2bc4329aad9a8cf0463b1 Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Wed, 1 Jan 2025 17:12:44 +0100 Subject: [PATCH 04/11] [admin] allow to filter out users with no memberships --- app/admin/user.rb | 3 +++ app/models/user.rb | 1 + 2 files changed, 4 insertions(+) diff --git a/app/admin/user.rb b/app/admin/user.rb index dc0de5e0..29e0e9e1 100644 --- a/app/admin/user.rb +++ b/app/admin/user.rb @@ -16,6 +16,9 @@ redirect_to action: :index end + scope :all + scope :without_memberships + index do selectable_column column do |user| diff --git a/app/models/user.rb b/app/models/user.rb index 2877fb8e..66fe0f4e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -38,6 +38,7 @@ class User < ApplicationRecord accepts_nested_attributes_for :members, allow_destroy: true default_scope { order("users.id ASC") } + scope :without_memberships, -> { where.missing(:members) } scope :actives, -> { joins(:members).where(members: { active: true }) } scope :online_active, -> { where("sign_in_count > 0") } scope :notifications, -> { where(notifications: true) } From 827a6f6bbe6dcb706792714a4c3bfb6e5892d93e Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Wed, 1 Jan 2025 18:07:35 +0100 Subject: [PATCH 05/11] add warning for user with no memberships --- app/admin/user.rb | 1 + app/assets/stylesheets/application.scss | 4 + app/models/user.rb | 4 + .../_no_membership_warning.html.erb | 3 + app/views/layouts/application.html.erb | 1 + config/locales/ca.yml | 7 +- config/locales/en.yml | 5 +- config/locales/es.yml | 7 +- config/locales/eu.yml | 63 ++++++++-------- config/locales/fr.yml | 25 ++++--- config/locales/gl.yml | 73 ++++++++++--------- config/locales/pt-BR.yml | 73 ++++++++++--------- 12 files changed, 143 insertions(+), 123 deletions(-) create mode 100644 app/views/application/_no_membership_warning.html.erb diff --git a/app/admin/user.rb b/app/admin/user.rb index 29e0e9e1..f34aed6c 100644 --- a/app/admin/user.rb +++ b/app/admin/user.rb @@ -32,6 +32,7 @@ column :posts do |u| u.posts.count end + column :created_at actions end diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 3c4ad3f5..f20205cb 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -302,6 +302,10 @@ ul.statistics li{ padding-left: 1.5rem; } +.alert a { + text-decoration: underline; +} + // fields that contain an error .field_with_errors{ color: red; diff --git a/app/models/user.rb b/app/models/user.rb index 66fe0f4e..cd5ba7e8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -94,6 +94,10 @@ def active?(organization) organization && !!(as_member_of(organization).try :active) end + def memberships? + members.any? + end + def member(organization) members.where(organization_id: organization).first end diff --git a/app/views/application/_no_membership_warning.html.erb b/app/views/application/_no_membership_warning.html.erb new file mode 100644 index 00000000..8a2c552e --- /dev/null +++ b/app/views/application/_no_membership_warning.html.erb @@ -0,0 +1,3 @@ +
+ <%= t('layouts.application.no_memberhsip_warning', link: organizations_path).html_safe %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1fc53ee7..44a62624 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -17,6 +17,7 @@
<%= render 'layouts/messages' unless devise_controller? %>
+ <%= render 'application/no_membership_warning' if current_user && !current_user.memberships? && !devise_controller? %> <%= yield %>
<%= organization_logo %> diff --git a/config/locales/ca.yml b/config/locales/ca.yml index f30d500d..e9458b83 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -319,6 +319,7 @@ ca: help: Ajuda login: Entra manage_memberships: Gestiona membres + no_memberhsip_warning: report: report_title: INFORME locales: @@ -393,8 +394,8 @@ ca: banner-title: Ets un Banc de Temps? empower-adbdt: ADBdT empower-adbdt-title: Associació pel Desenvolupament dels Bancs de Temps - empower-coopdevs: CoopDevs - empower-coopdevs-title: CoopDevs + empower-coopdevs: Coopdevs + empower-coopdevs-title: Coopdevs empower-github: Github empower-github-title: Github empower-showmap: veure mapa @@ -417,7 +418,7 @@ ca: title2: als Bancs de Temps petitions: application_sent: Sol·licitud enviada correctament - application_sent_body: Hola! La teva sol·licitud a %{organization_name} s'ha enviat correctament. + application_sent_body: Hola! La teva sol·licitud a %{organization_name} s'ha enviat correctament. Algú de l'equip del banc de temps es posarà en contacte amb tu per finalitzar el procés dalta. application_status: Sol·licitud %{status} applications: Sol·licituds apply: Sol·licita unir-te diff --git a/config/locales/en.yml b/config/locales/en.yml index 155a2194..3a75e34f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -319,6 +319,7 @@ en: help: Help login: Login manage_memberships: Manage memberships + no_memberhsip_warning: Remember users without membership (15 days after register) they should ask for membership in some Organization or the user will be deleted when user have 1 month on the platform without any membership. report: report_title: REPORT locales: @@ -393,8 +394,8 @@ en: banner-title: Are you a Time Bank? empower-adbdt: ADBdT empower-adbdt-title: Association for the Development of Time Banks - empower-coopdevs: CoopDevs - empower-coopdevs-title: CoopDevs + empower-coopdevs: Coopdevs + empower-coopdevs-title: Coopdevs empower-github: Github empower-github-title: Github empower-showmap: see map diff --git a/config/locales/es.yml b/config/locales/es.yml index da201547..3f739bea 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -319,6 +319,7 @@ es: help: Ayuda login: Entra manage_memberships: Gestionar membresia + no_memberhsip_warning: report: report_title: INFORME locales: @@ -393,8 +394,8 @@ es: banner-title: "¿Eres un Banco de Tiempo?" empower-adbdt: ADBdT empower-adbdt-title: Asociación para el Desarrollo de los Bancos de Tiempo - empower-coopdevs: CoopDevs - empower-coopdevs-title: CoopDevs + empower-coopdevs: Coopdevs + empower-coopdevs-title: Coopdevs empower-github: Github empower-github-title: Github empower-showmap: ver mapa @@ -417,7 +418,7 @@ es: title2: los Bancos de Tiempo petitions: application_sent: Solicitud enviada correctamente - application_sent_body: 'Hola! Tu solicitud a %{organization_name} se ha enviado correctamente. ' + application_sent_body: Hola! Tu solicitud a %{organization_name} se ha enviado correctamente. Alguien del equipo del banco de tiempo se pondrá en contacto contigo para finalizar el proceso de alta. application_status: Solicitud %{status} applications: Solicitudes apply: Solicita unirte diff --git a/config/locales/eu.yml b/config/locales/eu.yml index b0723f2b..c87ff60b 100644 --- a/config/locales/eu.yml +++ b/config/locales/eu.yml @@ -65,7 +65,7 @@ eu: notifications: Jaso eposta jakinarazpenak organization: Erakundea phone: Telefonoa - postcode: + postcode: push_notifications: Jaso jakinarazpenak sakelakoan registration_date: Erregistratze-da registration_number: Erabiltzaile kodea @@ -274,7 +274,7 @@ eu: contact_details: Kontaktuaren datuak create: Sortu date: Datuak - decline: + decline: delete: Ezabatu demote: Ohiko erabiltzaile bihurtu edit: Aldaketak egin @@ -282,7 +282,7 @@ eu: filter: Iragazkia from: tik give_time: Denbora eman - here: + here: home: Hasiera information: Informazioa locales_header: Hizkuntza aldatu @@ -290,13 +290,13 @@ eu: more: 'Gehiago ikusi ' movements: Mugimenduak next: Hurrengoa - or: + or: promote: Administratzaile bihurtu reason: Arrazoia required_field: Derrigorrez bete beharrekoa save: Gorde search: Bilatu - search_location: + search_location: show: Erakutsi source_destination: Jatorria/ helmuga statistics: Estatistika @@ -313,12 +313,13 @@ eu: layouts: application: about: TimeOverflowri buruz - bdtnear: + bdtnear: edit_org: " %{organization} aldaketak egin" edit_profile: Nire profila aldatu help: Laguntza login: Sartu - manage_memberships: + manage_memberships: + no_memberhsip_warning: report: report_title: TXOSTENA locales: @@ -383,7 +384,7 @@ eu: new: Banku berria show: contact_information: kontaktuaren informazioa - join_timebank: + join_timebank: pages: about: app-mobile: Mugikorrerako Appa @@ -393,8 +394,8 @@ eu: banner-title: Denbora banku bat al zara? empower-adbdt: ADBdT empower-adbdt-title: Denbora Bankuen garapenerako elkartea - empower-coopdevs: CoopDevs - empower-coopdevs-title: CoopDevs + empower-coopdevs: Coopdevs + empower-coopdevs-title: Coopdevs empower-github: Github empower-github-title: Github empower-showmap: Mapa ikusi @@ -416,25 +417,25 @@ eu: title: Denbora bankuek diseinaturiko softwarea, title2: Denbora bankuentzat petitions: - application_sent: - application_sent_body: - application_status: - applications: - apply: - new: - new_body: + application_sent: + application_sent_body: + application_status: + applications: + apply: + new: + new_body: status: - accepted: - declined: - pending: - sent: - status_applications: + accepted: + declined: + pending: + sent: + status_applications: posts: show: info: "%{type} hau %{organization}(e)ri dagokio." reports: download: Jaitsi - download_all: + download_all: shared: movements: delete_reason: Zihur zaude azalpen hau ezabatu nahi duzula? @@ -521,12 +522,12 @@ eu: error_amount: Denbora 0 baino handiagoa izan behar da users: avatar: - change_your_image: - crop_the_image: - max_size_warning: + change_your_image: + crop_the_image: + max_size_warning: confirm_email: - email_sent: - please: + email_sent: + please: edit: edit_user: Erabiltzailea aldatu form: @@ -563,7 +564,7 @@ eu: from_to: Jatorria/ Helmuga inactive: "( Ez erabilgarri)" inactive_user: Erabiltzailea ez dago erabilgarri - invalid_format: + invalid_format: phone: one: Telefono zenbakia other: Telefono zenbakiak @@ -576,9 +577,9 @@ eu: active_warning: " %{user} erabiltzailearen kontuaren egoera aldatuko duzu" cancel_warning: " %{user} erabiltzailea D bankutik ezabatuko duzu" deactivate: Desaktibatu - delete_membership: + delete_membership: manage_warning: "%{user} erabiltzailearen onurak aldatuko dituzu" - sure_delete: + sure_delete: views: pagination: first: Lehenengoa diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 75a97ce3..a23897b4 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -319,6 +319,7 @@ fr: help: Aide login: Connexion manage_memberships: Gérer les inscriptions + no_memberhsip_warning: report: report_title: RAPPORT locales: @@ -393,8 +394,8 @@ fr: banner-title: Êtes-vous une Banque de temps ? empower-adbdt: ADBdT empower-adbdt-title: Association pour le développement des Banques de temps - empower-coopdevs: CoopDevs - empower-coopdevs-title: CoopDevs + empower-coopdevs: Coopdevs + empower-coopdevs-title: Coopdevs empower-github: Github empower-github-title: Github empower-showmap: Voir la map @@ -416,19 +417,19 @@ fr: title: L'application conçue par et pour title2: Banques de temps petitions: - application_sent: Demande envoyée avec succès - application_sent_body: Bonjour! votre demande à %{organization_name} a bien été envoyée. - application_status: Demande %{status} - applications: Applications - apply: Demande à nous rejoindre - new: Nouvelle demande - new_body: Bonjour! Nouvelle demande de %{username}. Gérer vos demandes %{here_link}. + application_sent: Demande d'inscription envoyée avec succès + application_sent_body: Bonjour! votre demande d'inscription à %{organization_name} a bien été envoyée. + application_status: Demande d'inscription %{status} + applications: Demandes d'inscription + apply: Demander à nous rejoindre + new: Nouvelle demande d'inscription + new_body: Bonjour! Nouvelle demande d'inscription de %{username}. Gérer vos demandes %{here_link}. status: accepted: acceptée declined: déclinée pending: en attente sent: envoyée - status_applications: "%{status} demandes" + status_applications: Demandes d'inscription %{status} posts: show: info: Cette %{type} appartient à %{organization}. @@ -505,9 +506,9 @@ fr: alpha_grouped_index: maintitle: Tags disponibles terms: - accept: Accept + accept: Accepter show: - accept: Accept + accept: Accepter transfers: computation: hour: diff --git a/config/locales/gl.yml b/config/locales/gl.yml index 16661d4e..a4afdeeb 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -57,7 +57,7 @@ gl: alt_phone: Teléfono alternativo created_at: Creado date_of_birth: Data de nacemento - deactivated: + deactivated: description: Descrición email: Correo electrónico gender: Xénero @@ -65,7 +65,7 @@ gl: notifications: Recibir notificacións por correo electrónico organization: Organización phone: Teléfono - postcode: + postcode: push_notifications: Recibir notificacións móbiles registration_date: Data de rexistro registration_number: Código de persoa usuaria @@ -144,7 +144,7 @@ gl: reports: Informes sign_out: Saír statistics: Estatísticas - statistics_all_transfers: + statistics_all_transfers: stats: Estatísticas tags: Etiquetas type_of_swaps: Tipo de transaccións @@ -274,15 +274,15 @@ gl: contact_details: Datos de contacto create: Crea date: Datos - decline: + decline: delete: Eliminar demote: Degradar a usuario/a normal edit: Actualización - enter_to_timebank: + enter_to_timebank: filter: Filtro from: Desde give_time: Transferencia de tempo - here: + here: home: Inicio information: Información locales_header: cambiar o idioma @@ -290,13 +290,13 @@ gl: more: Máis movements: Transaccións next: Próximo - or: + or: promote: Promover á persoa administradora reason: Razón required_field: "* Campo obrigatorio" save: Gardar search: Busca - search_location: + search_location: show: Amosar source_destination: Dende/ata statistics: Estatísticas @@ -313,12 +313,13 @@ gl: layouts: application: about: Sobre TimeOverflow - bdtnear: + bdtnear: edit_org: Actualización %{organization} edit_profile: Actualiza o meu perfil help: Axuda login: Acceder - manage_memberships: + manage_memberships: + no_memberhsip_warning: report: report_title: INFORME locales: @@ -383,7 +384,7 @@ gl: new: Novo banco show: contact_information: Información de contacto - join_timebank: + join_timebank: pages: about: app-mobile: Aplicación móbil @@ -393,8 +394,8 @@ gl: banner-title: Es ti un Banco de Tempo? empower-adbdt: ADBdT empower-adbdt-title: Asociación para o Desenvolvemento de Bancos de Tempo - empower-coopdevs: CoopDevs - empower-coopdevs-title: CoopDevs + empower-coopdevs: Coopdevs + empower-coopdevs-title: Coopdevs empower-github: Github empower-github-title: Github empower-showmap: ver o mapa @@ -416,25 +417,25 @@ gl: title: O software deseñado por e para title2: Bancos de tempo petitions: - application_sent: - application_sent_body: - application_status: - applications: - apply: - new: - new_body: + application_sent: + application_sent_body: + application_status: + applications: + apply: + new: + new_body: status: - accepted: - declined: - pending: - sent: - status_applications: + accepted: + declined: + pending: + sent: + status_applications: posts: show: info: Este %{type} pertence a %{organization}. reports: download: Descarga - download_all: + download_all: shared: movements: delete_reason: Estás seguro/a de borrar este comentario? @@ -521,12 +522,12 @@ gl: error_amount: O tempo debe ser superior a 0 users: avatar: - change_your_image: - crop_the_image: - max_size_warning: + change_your_image: + crop_the_image: + max_size_warning: confirm_email: - email_sent: - please: + email_sent: + please: edit: edit_user: Actualizar persoa usuaria form: @@ -534,12 +535,12 @@ gl: give_time: give_time: Dálle tempo index: - account_deactivated: + account_deactivated: actions: Accións active_warning: Vas cambiar o estado da conta de usuario/a %{username} cancel_warning: Vas borrar a conta do Banco de tempo para o usuario/a %{username} create: Crea unha nova persoa usuaria - deactivated_warning: + deactivated_warning: manage_warning: Vas cambiar privilexios para o usuario/a %{username} members: Persoas usuarias user_created: O usuario/a %{uid} %{name} gardouse @@ -563,7 +564,7 @@ gl: from_to: De / Para inactive: "(Inactivo/a)" inactive_user: A persoa usuaria non está activa - invalid_format: + invalid_format: phone: one: Teléfono other: Teléfonos @@ -576,9 +577,9 @@ gl: active_warning: Vas cambiar o estado da conta de usuario/a para %{user} cancel_warning: Vas borrar a conta do Banco de tempo para o usuario/a %{user} deactivate: Desactivar - delete_membership: + delete_membership: manage_warning: Vas cambiar privilexios para o usuario/a %{user} - sure_delete: + sure_delete: views: pagination: first: Primeira diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 684f7f3a..14451d97 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -57,7 +57,7 @@ pt-BR: alt_phone: Telefone alternativo created_at: Criado date_of_birth: Data de nascimento - deactivated: + deactivated: description: Descrição email: E-mail gender: Gênero @@ -65,7 +65,7 @@ pt-BR: notifications: Receber notificações organization: Organização phone: Telefone - postcode: + postcode: push_notifications: Receber notificações pelo celular registration_date: Data de ingresso registration_number: Código do usuário @@ -144,7 +144,7 @@ pt-BR: reports: Informes sign_out: Desconectar statistics: Estatísticas - statistics_all_transfers: + statistics_all_transfers: stats: Estatísticas tags: Etiquetas type_of_swaps: Tipos de trocas @@ -274,15 +274,15 @@ pt-BR: contact_details: Dados de contato create: Criar date: Data - decline: + decline: delete: Apagar demote: Converter em usuário normal edit: Modificar - enter_to_timebank: + enter_to_timebank: filter: Filtro from: De give_time: Transferir tempo - here: + here: home: Início information: Informação locales_header: Trocar idioma @@ -290,13 +290,13 @@ pt-BR: more: Ver mais movements: Movimentos next: Próximo - or: + or: promote: Converter em administrador reason: Razão required_field: "* Campo obrigatório" save: Guardar search: Pesquisar - search_location: + search_location: show: Mostrar source_destination: Origem/Destino statistics: Estatísticas @@ -313,12 +313,13 @@ pt-BR: layouts: application: about: Sobre TimeOverflow - bdtnear: + bdtnear: edit_org: Modificar %{organization} edit_profile: Modificar meu perfil help: Ajuda login: Entre - manage_memberships: + manage_memberships: + no_memberhsip_warning: report: report_title: INFORME locales: @@ -383,7 +384,7 @@ pt-BR: new: Novo banco show: contact_information: Informação de contato - join_timebank: + join_timebank: pages: about: app-mobile: Aplicativo móvel @@ -393,8 +394,8 @@ pt-BR: banner-title: Você é um Banco de Tempo? empower-adbdt: ADBdt empower-adbdt-title: Associação para o Desenvolvimento dos Bancos de Tempo - empower-coopdevs: CoopDevs - empower-coopdevs-title: CoopDevs + empower-coopdevs: Coopdevs + empower-coopdevs-title: Coopdevs empower-github: Github empower-github-title: Github empower-showmap: ver mapa @@ -416,25 +417,25 @@ pt-BR: title: O software desenhado por e para title2: os Bancos de Tempo petitions: - application_sent: - application_sent_body: - application_status: - applications: - apply: - new: - new_body: + application_sent: + application_sent_body: + application_status: + applications: + apply: + new: + new_body: status: - accepted: - declined: - pending: - sent: - status_applications: + accepted: + declined: + pending: + sent: + status_applications: posts: show: info: Este %{type} pertence a %{organization}. reports: download: Baixar - download_all: + download_all: shared: movements: delete_reason: Tem certeza de que quer apagar este comentário? @@ -521,12 +522,12 @@ pt-BR: error_amount: O tempo deve ser maior que 0 users: avatar: - change_your_image: - crop_the_image: - max_size_warning: + change_your_image: + crop_the_image: + max_size_warning: confirm_email: - email_sent: - please: + email_sent: + please: edit: edit_user: Trocar usuário form: @@ -534,12 +535,12 @@ pt-BR: give_time: give_time: Dar Tempo a index: - account_deactivated: + account_deactivated: actions: Ações active_warning: Você mudará o status da conta para %{username} cancel_warning: Você deletará a conta do Banco de Tempo %{username} create: Criar novo usuário - deactivated_warning: + deactivated_warning: manage_warning: Você mudará privilégios para o usuário %{username} members: Membros user_created: Usuário %{uid} %{name} guardado @@ -563,7 +564,7 @@ pt-BR: from_to: Origem/Destino inactive: "(Inativo)" inactive_user: O usuário não está ativo - invalid_format: + invalid_format: phone: one: Telefone other: Telefones @@ -576,9 +577,9 @@ pt-BR: active_warning: Mudará o estado da conta do usuário %{user} cancel_warning: Eliminará o usuário do banco %{user} deactivate: Desativar - delete_membership: + delete_membership: manage_warning: Mudará os privilégios do usuário %{user} - sure_delete: + sure_delete: views: pagination: first: "« Primeira" From 8eaddd332ae2731ba8a7ef79e890873e98a7b037 Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Wed, 1 Jan 2025 18:12:09 +0100 Subject: [PATCH 06/11] rename partial: layouts/messages -> application/flash_messages --- .../_messages.html.erb => application/_flash_messages.html.erb} | 0 app/views/devise/confirmations/new.html.erb | 2 +- app/views/devise/passwords/edit.html.erb | 2 +- app/views/devise/passwords/new.html.erb | 2 +- app/views/devise/sessions/new.html.erb | 2 +- app/views/devise/unlocks/new.html.erb | 2 +- app/views/layouts/application.html.erb | 2 +- 7 files changed, 6 insertions(+), 6 deletions(-) rename app/views/{layouts/_messages.html.erb => application/_flash_messages.html.erb} (100%) diff --git a/app/views/layouts/_messages.html.erb b/app/views/application/_flash_messages.html.erb similarity index 100% rename from app/views/layouts/_messages.html.erb rename to app/views/application/_flash_messages.html.erb diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb index 4231f238..d219ae20 100644 --- a/app/views/devise/confirmations/new.html.erb +++ b/app/views/devise/confirmations/new.html.erb @@ -4,7 +4,7 @@

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

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

- <%= render 'layouts/messages' %> + <%= render 'application/flash_messages' %> <%= show_error_messages!(resource) %> <%= form_for resource, url: confirmation_path(resource_name), html: { method: :post } do |f| %>
diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index 45ac98b7..cc362d33 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -3,7 +3,7 @@

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

- <%= render 'layouts/messages' %> + <%= render 'application/flash_messages' %> <%= show_error_messages!(resource) %> <%= form_for resource, url: password_path(resource_name), html: { method: :put } do |f| %> <%= f.hidden_field :reset_password_token %> diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index 582464ca..b86ac881 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -4,7 +4,7 @@

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

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

- <%= render 'layouts/messages' %> + <%= render 'application/flash_messages' %> <%= show_error_messages!(resource) %> <%= form_for resource, url: password_path(resource_name), html: { method: :post } do |f| %>
diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 35673c42..7ee90a47 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -2,7 +2,7 @@
- <%= render 'layouts/messages' %> + <%= render 'application/flash_messages' %> <%= show_error_messages!(resource) %> <%= form_for resource, url: session_path(resource_name) do |f| %>
diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb index 7dd14d1d..5cb65830 100644 --- a/app/views/devise/unlocks/new.html.erb +++ b/app/views/devise/unlocks/new.html.erb @@ -4,7 +4,7 @@

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

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

- <%= render 'layouts/messages' %> + <%= render 'application/flash_messages' %> <%= show_error_messages!(resource) %> <%= form_for resource, url: unlock_path(resource_name), html: { method: :post } do |f| %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 44a62624..14c7d617 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,7 +15,7 @@ <%= render 'navbar' %>
- <%= render 'layouts/messages' unless devise_controller? %> + <%= render 'application/flash_messages' unless devise_controller? %>
<%= render 'application/no_membership_warning' if current_user && !current_user.memberships? && !devise_controller? %> <%= yield %> From 0ecec0fc9a574c42f49893f2e3022dfc5f202135 Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Thu, 2 Jan 2025 17:44:46 +0100 Subject: [PATCH 07/11] [mailer] refine locale for sending emails to org managers --- app/mailers/organization_notifier.rb | 12 +++++++----- .../organization_notifier/member_deleted.html.erb | 2 +- config/locales/ca.yml | 4 +++- config/locales/en.yml | 2 ++ config/locales/es.yml | 4 +++- config/locales/eu.yml | 4 +++- config/locales/fr.yml | 4 +++- config/locales/gl.yml | 4 +++- config/locales/pt-BR.yml | 4 +++- spec/controllers/statistics_controller_spec.rb | 2 +- 10 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/mailers/organization_notifier.rb b/app/mailers/organization_notifier.rb index 9efe0a62..7483a9a9 100644 --- a/app/mailers/organization_notifier.rb +++ b/app/mailers/organization_notifier.rb @@ -15,11 +15,12 @@ def recent_posts(posts, locale, users) def new_petition(petition) @user = petition.user organization = petition.organization + org_managers = organization.all_managers - I18n.with_locale(locale) do + I18n.with_locale(org_managers.first&.locale) do mail( subject: "New Application - #{organization.name}", - bcc: organization.all_managers.pluck(:email).uniq + bcc: org_managers.pluck(:email).uniq ) end end @@ -27,7 +28,7 @@ def new_petition(petition) def petition_sent(petition) @organization_name = petition.organization.name - I18n.with_locale(locale) do + I18n.with_locale(petition.user.locale) do mail( subject: 'Application sent correctly', to: petition.user.email @@ -38,11 +39,12 @@ def petition_sent(petition) def member_deleted(member) @user = member.user organization = member.organization + org_managers = organization.all_managers - I18n.with_locale(locale) do + I18n.with_locale(org_managers.first&.locale) do mail( subject: "Membership deleted - #{organization.name}", - bcc: organization.all_managers.pluck(:email).uniq + bcc: org_managers.pluck(:email).uniq ) end end diff --git a/app/views/organization_notifier/member_deleted.html.erb b/app/views/organization_notifier/member_deleted.html.erb index 6142c261..e2b838f4 100644 --- a/app/views/organization_notifier/member_deleted.html.erb +++ b/app/views/organization_notifier/member_deleted.html.erb @@ -1 +1 @@ -User <%= @user.username %> has unsubscribed from the organization. +<%= t("organization_notifier.member_deleted.body", user: @user.username) %> diff --git a/config/locales/ca.yml b/config/locales/ca.yml index e9458b83..52de2114 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -319,7 +319,7 @@ ca: help: Ajuda login: Entra manage_memberships: Gestiona membres - no_memberhsip_warning: + no_memberhsip_warning: Recordeu als usuaris sense membresia (15 dies després de registrar-se) que han de sol·licitar membresia a alguna organització, o l'usuari serà eliminat quan porti 1 mes a la plataforma sense cap membresia. report: report_title: INFORME locales: @@ -371,6 +371,8 @@ ca: give_time_for: Transferir temps per aquesta oferta offered_by: Oferents organization_notifier: + member_deleted: + body: L'usuari %{username} s'ha donat de baixa de l'organització. recent_posts: subject: Butlletí setmanal text1: 'Últimas ofertas publicadas:' diff --git a/config/locales/en.yml b/config/locales/en.yml index 3a75e34f..d6cca189 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -371,6 +371,8 @@ en: give_time_for: Time transfer for this offer offered_by: Offered by organization_notifier: + member_deleted: + body: User %{username} has unsubscribed from the organization. recent_posts: subject: Newsletter text1: 'Latest offers published:' diff --git a/config/locales/es.yml b/config/locales/es.yml index 3f739bea..8fe596ba 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -319,7 +319,7 @@ es: help: Ayuda login: Entra manage_memberships: Gestionar membresia - no_memberhsip_warning: + no_memberhsip_warning: Recuerda a los usuarios sin membresía (15 días después de registrarse) que deben solicitar membresía en alguna organización, o el usuario será eliminado cuando tenga 1 mes en la plataforma sin ninguna membresía. report: report_title: INFORME locales: @@ -371,6 +371,8 @@ es: give_time_for: Transferir tiempo por esta oferta offered_by: Ofertantes organization_notifier: + member_deleted: + body: El usuario %{username} se ha dado de baja de la organización. recent_posts: subject: Boletín semanal text1: 'Últimas ofertas publicadas:' diff --git a/config/locales/eu.yml b/config/locales/eu.yml index c87ff60b..60bbbb5e 100644 --- a/config/locales/eu.yml +++ b/config/locales/eu.yml @@ -319,7 +319,7 @@ eu: help: Laguntza login: Sartu manage_memberships: - no_memberhsip_warning: + no_memberhsip_warning: Erabiltzaileei, 15 egun erregistratu eta gero, jakinarazi behar dute antolamendu batean bazkidetzak eskatu behar dituztela, bestela, erabiltzailea ezabatuko da plataforman hilabete bat bazkidetzarik gabe betetzean. report: report_title: TXOSTENA locales: @@ -371,6 +371,8 @@ eu: give_time_for: Eskaintza honengatik denbora eman offered_by: Eskaintzaren emaileak organization_notifier: + member_deleted: + body: Erabiltzaileak %{username} erakundetik baja eman du. recent_posts: subject: Asteroko buletina text1: Argitaraturiko azken eskaintzak diff --git a/config/locales/fr.yml b/config/locales/fr.yml index a23897b4..10793560 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -319,7 +319,7 @@ fr: help: Aide login: Connexion manage_memberships: Gérer les inscriptions - no_memberhsip_warning: + no_memberhsip_warning: Rappelez aux utilisateurs sans adhésion (15 jours après l'inscription) qu'ils doivent demander une adhésion à une organisation, ou l'utilisateur sera supprimé après 1 mois sur la plateforme sans aucune adhésion. report: report_title: RAPPORT locales: @@ -371,6 +371,8 @@ fr: give_time_for: Donner du temps pour cette offre offered_by: Offert par organization_notifier: + member_deleted: + body: L'utilisateur %{username} s'est désabonné de l'organisation. recent_posts: subject: Newsletter text1: 'Dernières offres publiées :' diff --git a/config/locales/gl.yml b/config/locales/gl.yml index a4afdeeb..7be0f404 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -319,7 +319,7 @@ gl: help: Axuda login: Acceder manage_memberships: - no_memberhsip_warning: + no_memberhsip_warning: Lembra aos usuarios sen membresía (15 días despois de rexistrarse) que deben solicitar unha membresía en unha organización, ou o usuario será eliminado cando teña 1 mes na plataforma sen ningunha membresía. report: report_title: INFORME locales: @@ -371,6 +371,8 @@ gl: give_time_for: Transferencia de tempo para esta oferta offered_by: Ofrecido por organization_notifier: + member_deleted: + body: O usuario %{username} deu de baixa na organización. recent_posts: subject: Boletín informativo text1: 'Últimas ofertas publicadas:' diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 14451d97..4b6b9a2c 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -319,7 +319,7 @@ pt-BR: help: Ajuda login: Entre manage_memberships: - no_memberhsip_warning: + no_memberhsip_warning: Lembre os usuários sem associação (15 dias após o registro) que eles devem solicitar associação em alguma organização, ou o usuário será excluído após 1 mês na plataforma sem nenhuma associação. report: report_title: INFORME locales: @@ -371,6 +371,8 @@ pt-BR: give_time_for: Transferir tempo para esta oferta offered_by: Ofertantes organization_notifier: + member_deleted: + body: O usuário %{username} cancelou a inscrição na organização. recent_posts: subject: Boletim semanal text1: 'Últimas ofertas publicadas:' diff --git a/spec/controllers/statistics_controller_spec.rb b/spec/controllers/statistics_controller_spec.rb index 9907d7bc..d7c61992 100644 --- a/spec/controllers/statistics_controller_spec.rb +++ b/spec/controllers/statistics_controller_spec.rb @@ -45,7 +45,7 @@ it 'populates age_counts and gender_counts variables' do get :demographics - expect(assigns(:age_counts)).to eq({ "35-44" => 1 }) + expect(assigns(:age_counts)).to eq({ "45-54" => 1 }) expect(assigns(:gender_counts)).to eq({ "Otro" => 1 }) end end From e9690bc4836a17dd8edb9dcc730bf4c88c7a7699 Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Fri, 3 Jan 2025 16:57:01 +0100 Subject: [PATCH 08/11] add validation to avoid petitions between the same user and organization --- app/controllers/petitions_controller.rb | 4 ++-- app/models/petition.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/petitions_controller.rb b/app/controllers/petitions_controller.rb index 8dc4d432..8cdd1b50 100644 --- a/app/controllers/petitions_controller.rb +++ b/app/controllers/petitions_controller.rb @@ -11,7 +11,7 @@ def create flash[:notice] = t('petitions.application_status', status: t("petitions.status.sent")) else - flash[:error] = t('errors.internal_server_error.description') + flash[:error] = petition.errors.full_messages.to_sentence end redirect_back fallback_location: organization_path(petition.organization) @@ -25,7 +25,7 @@ def update petition.user.add_to_organization(petition.organization) if status == 'accepted' flash[:notice] = t('petitions.application_status', status: t("petitions.status.#{status}")) else - flash[:error] = t('errors.internal_server_error.description') + flash[:error] = petition.errors.full_messages.to_sentence end redirect_to manage_petitions_path diff --git a/app/models/petition.rb b/app/models/petition.rb index 24ad2837..8dbdc1d9 100644 --- a/app/models/petition.rb +++ b/app/models/petition.rb @@ -3,4 +3,6 @@ class Petition < ApplicationRecord belongs_to :user belongs_to :organization + + validates :user_id, uniqueness: { scope: :organization_id } end From db6c315f76c0d666ded9d2da86d898a4a6f3e8df Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Fri, 3 Jan 2025 17:37:36 +0100 Subject: [PATCH 09/11] [refactor] Petition: make "pending" the default status --- app/controllers/petitions_controller.rb | 3 +-- app/helpers/application_helper.rb | 4 ++++ app/models/petition.rb | 4 +++- app/views/layouts/application.html.erb | 2 +- spec/controllers/petitions_controller_spec.rb | 4 ++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/controllers/petitions_controller.rb b/app/controllers/petitions_controller.rb index 8cdd1b50..684a607f 100644 --- a/app/controllers/petitions_controller.rb +++ b/app/controllers/petitions_controller.rb @@ -3,7 +3,6 @@ class PetitionsController < ApplicationController def create petition = Petition.new petition_params - petition.status = "pending" if petition.save OrganizationNotifier.new_petition(petition).deliver_now @@ -32,7 +31,7 @@ def update end def manage - @status = params[:status] || 'pending' + @status = params[:status] || Petition::DEFAULT_STATUS @users = User.joins(:petitions).where(petitions: { organization_id: current_organization.id, status: @status }).page(params[:page]).per(20) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index eff524c3..f9bb541d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -113,4 +113,8 @@ def alert_class(alert) 'alert-info' end end + + def show_no_membership_warning? + current_user && !current_user.memberships? && !devise_controller? + end end diff --git a/app/models/petition.rb b/app/models/petition.rb index 8dbdc1d9..5297e4f8 100644 --- a/app/models/petition.rb +++ b/app/models/petition.rb @@ -1,5 +1,7 @@ class Petition < ApplicationRecord - enum status: %i[pending accepted declined] + DEFAULT_STATUS = "pending" + + enum status: %i[pending accepted declined], _default: DEFAULT_STATUS belongs_to :user belongs_to :organization diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 14c7d617..34bd06db 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -17,7 +17,7 @@
<%= render 'application/flash_messages' unless devise_controller? %>
- <%= render 'application/no_membership_warning' if current_user && !current_user.memberships? && !devise_controller? %> + <%= render 'application/no_membership_warning' if show_no_membership_warning? %> <%= yield %>
<%= organization_logo %> diff --git a/spec/controllers/petitions_controller_spec.rb b/spec/controllers/petitions_controller_spec.rb index 0d7bb916..c6de5572 100644 --- a/spec/controllers/petitions_controller_spec.rb +++ b/spec/controllers/petitions_controller_spec.rb @@ -18,7 +18,7 @@ describe 'PUT #update' do before { login(admin.user) } - let(:petition) { Petition.create(user: user, organization: organization, status: 'pending') } + let(:petition) { Petition.create(user: user, organization: organization) } it 'decline the petition' do put :update, params: { status: 'declined', id: petition.id } @@ -41,7 +41,7 @@ allow(controller).to receive(:current_organization) { organization } login(admin.user) end - let!(:petition) { Petition.create(user: user, organization: organization, status: 'pending') } + let!(:petition) { Petition.create(user: user, organization: organization) } it 'populates a list of users with pending petitions' do get :manage From d9eaed3d45a702bb82e7a360684b08e6274bd58c Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Fri, 3 Jan 2025 17:54:30 +0100 Subject: [PATCH 10/11] [admin] allow to destroy pending and declined petitions --- app/admin/petition.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/admin/petition.rb b/app/admin/petition.rb index 9a1bcab4..77e41bdd 100644 --- a/app/admin/petition.rb +++ b/app/admin/petition.rb @@ -1,5 +1,15 @@ ActiveAdmin.register Petition do - actions :index + actions :index, :destroy + + controller do + def destroy + if resource.accepted? + redirect_to admin_petitions_path, alert: "ACCEPTED petitions can't be deleted" + else + super + end + end + end index do id_column @@ -9,6 +19,7 @@ column :status do |petition| petition.status.upcase end + actions end filter :organization From 9756c714506f8907da0646b42b397dd3f11264cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Jos=C3=A9=20Perej=C3=B3n=20Barrios?= <70280187+franpb14@users.noreply.github.com> Date: Mon, 6 Jan 2025 20:28:34 +0000 Subject: [PATCH 11/11] [FIX] Push notifications are not being sent (#772) --- app/services/push_notifications/broadcast.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/push_notifications/broadcast.rb b/app/services/push_notifications/broadcast.rb index 9681ea9d..2b3ef2eb 100644 --- a/app/services/push_notifications/broadcast.rb +++ b/app/services/push_notifications/broadcast.rb @@ -1,3 +1,5 @@ +require "net/http" + module PushNotifications class Broadcast class PostError < ::StandardError; end