From b44d5593a25f9b8dc8e20b34fc02094d9ac1deaa Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 23 Nov 2023 14:51:38 +0100 Subject: [PATCH 1/7] fix locale was not set until terms acceptance, so the locale selected by the user was lost (#712) --- app/controllers/application_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1a7f0d1a..a8823c0c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,10 +6,10 @@ class ApplicationController < ActionController::Base MissingTOSAcceptance = Class.new(Exception) OutadedTOSAcceptance = Class.new(Exception) - append_before_action :check_for_terms_acceptance!, unless: :devise_controller? + before_action :set_locale + before_action :check_for_terms_acceptance!, unless: :devise_controller? before_action :configure_permitted_parameters, if: :devise_controller? - before_action :set_locale, - :set_current_organization, + before_action :set_current_organization, :store_user_location rescue_from MissingTOSAcceptance, OutadedTOSAcceptance do From 0ddc6bb1f4c1a016cd496ea25841318bf7cdf672 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 23 Nov 2023 16:10:58 +0100 Subject: [PATCH 2/7] adds not null db constraint on members.member_uid, adds unique index on members.member_uid (#713) --- ...ull_constraint_to_member_uid_in_members.rb | 5 + ...d_unique_index_on_member_uid_in_members.rb | 5 + db/structure.sql | 107 ++++++++++-------- 3 files changed, 67 insertions(+), 50 deletions(-) create mode 100644 db/migrate/20231120164231_add_not_null_constraint_to_member_uid_in_members.rb create mode 100644 db/migrate/20231120164346_add_unique_index_on_member_uid_in_members.rb diff --git a/db/migrate/20231120164231_add_not_null_constraint_to_member_uid_in_members.rb b/db/migrate/20231120164231_add_not_null_constraint_to_member_uid_in_members.rb new file mode 100644 index 00000000..bf7cc876 --- /dev/null +++ b/db/migrate/20231120164231_add_not_null_constraint_to_member_uid_in_members.rb @@ -0,0 +1,5 @@ +class AddNotNullConstraintToMemberUidInMembers < ActiveRecord::Migration[6.1] + def change + change_column_null :members, :member_uid, false + end +end diff --git a/db/migrate/20231120164346_add_unique_index_on_member_uid_in_members.rb b/db/migrate/20231120164346_add_unique_index_on_member_uid_in_members.rb new file mode 100644 index 00000000..56315453 --- /dev/null +++ b/db/migrate/20231120164346_add_unique_index_on_member_uid_in_members.rb @@ -0,0 +1,5 @@ +class AddUniqueIndexOnMemberUidInMembers < ActiveRecord::Migration[6.1] + def change + add_index :members, [:organization_id, :member_uid], unique: true + end +end diff --git a/db/structure.sql b/db/structure.sql index 7239a85a..1a912a79 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -413,7 +413,7 @@ CREATE TABLE public.members ( created_at timestamp without time zone, updated_at timestamp without time zone, entry_date date, - member_uid integer, + member_uid integer NOT NULL, active boolean DEFAULT true, tags text[] DEFAULT '{}'::text[] ); @@ -728,126 +728,126 @@ ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id; -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: accounts id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.accounts ALTER COLUMN id SET DEFAULT nextval('public.accounts_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: active_admin_comments id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_admin_comments ALTER COLUMN id SET DEFAULT nextval('public.active_admin_comments_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: active_storage_attachments id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_attachments ALTER COLUMN id SET DEFAULT nextval('public.active_storage_attachments_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: active_storage_blobs id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_blobs ALTER COLUMN id SET DEFAULT nextval('public.active_storage_blobs_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: active_storage_variant_records id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_variant_records ALTER COLUMN id SET DEFAULT nextval('public.active_storage_variant_records_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: categories id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.categories ALTER COLUMN id SET DEFAULT nextval('public.categories_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: device_tokens id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.device_tokens ALTER COLUMN id SET DEFAULT nextval('public.device_tokens_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: documents id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.documents ALTER COLUMN id SET DEFAULT nextval('public.documents_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: events id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.events ALTER COLUMN id SET DEFAULT nextval('public.events_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: members id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.members ALTER COLUMN id SET DEFAULT nextval('public.members_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: movements id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.movements ALTER COLUMN id SET DEFAULT nextval('public.movements_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: organizations id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.organizations ALTER COLUMN id SET DEFAULT nextval('public.organizations_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: petitions id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.petitions ALTER COLUMN id SET DEFAULT nextval('public.petitions_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: posts id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.posts ALTER COLUMN id SET DEFAULT nextval('public.posts_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: push_notifications id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.push_notifications ALTER COLUMN id SET DEFAULT nextval('public.push_notifications_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: transfers id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.transfers ALTER COLUMN id SET DEFAULT nextval('public.transfers_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: users id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass); -- --- Name: accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: accounts accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.accounts @@ -855,7 +855,7 @@ ALTER TABLE ONLY public.accounts -- --- Name: active_admin_comments_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: active_admin_comments active_admin_comments_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_admin_comments @@ -863,7 +863,7 @@ ALTER TABLE ONLY public.active_admin_comments -- --- Name: active_storage_attachments_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: active_storage_attachments active_storage_attachments_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_attachments @@ -871,7 +871,7 @@ ALTER TABLE ONLY public.active_storage_attachments -- --- Name: active_storage_blobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: active_storage_blobs active_storage_blobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_blobs @@ -879,7 +879,7 @@ ALTER TABLE ONLY public.active_storage_blobs -- --- Name: active_storage_variant_records_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: active_storage_variant_records active_storage_variant_records_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_variant_records @@ -887,7 +887,7 @@ ALTER TABLE ONLY public.active_storage_variant_records -- --- Name: ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.ar_internal_metadata @@ -895,7 +895,7 @@ ALTER TABLE ONLY public.ar_internal_metadata -- --- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: categories categories_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.categories @@ -903,7 +903,7 @@ ALTER TABLE ONLY public.categories -- --- Name: device_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: device_tokens device_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.device_tokens @@ -911,7 +911,7 @@ ALTER TABLE ONLY public.device_tokens -- --- Name: documents_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: documents documents_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.documents @@ -919,7 +919,7 @@ ALTER TABLE ONLY public.documents -- --- Name: events_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: events events_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.events @@ -927,7 +927,7 @@ ALTER TABLE ONLY public.events -- --- Name: members_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: members members_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.members @@ -935,7 +935,7 @@ ALTER TABLE ONLY public.members -- --- Name: movements_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: movements movements_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.movements @@ -943,7 +943,7 @@ ALTER TABLE ONLY public.movements -- --- Name: organizations_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: organizations organizations_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.organizations @@ -951,7 +951,7 @@ ALTER TABLE ONLY public.organizations -- --- Name: petitions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: petitions petitions_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.petitions @@ -959,7 +959,7 @@ ALTER TABLE ONLY public.petitions -- --- Name: posts_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: posts posts_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.posts @@ -967,7 +967,7 @@ ALTER TABLE ONLY public.posts -- --- Name: push_notifications_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: push_notifications push_notifications_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.push_notifications @@ -975,7 +975,7 @@ ALTER TABLE ONLY public.push_notifications -- --- Name: transfers_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: transfers transfers_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.transfers @@ -983,7 +983,7 @@ ALTER TABLE ONLY public.transfers -- --- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.users @@ -1102,6 +1102,13 @@ CREATE INDEX index_events_on_transfer_id ON public.events USING btree (transfer_ CREATE INDEX index_members_on_organization_id ON public.members USING btree (organization_id); +-- +-- Name: index_members_on_organization_id_and_member_uid; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_members_on_organization_id_and_member_uid ON public.members USING btree (organization_id, member_uid); + + -- -- Name: index_members_on_user_id; Type: INDEX; Schema: public; Owner: - -- @@ -1208,14 +1215,14 @@ CREATE UNIQUE INDEX unique_schema_migrations ON public.schema_migrations USING b -- --- Name: tsvectorupdate; Type: TRIGGER; Schema: public; Owner: - +-- Name: posts tsvectorupdate; Type: TRIGGER; Schema: public; Owner: - -- CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON public.posts FOR EACH ROW EXECUTE PROCEDURE public.posts_trigger(); -- --- Name: events_member_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: events events_member_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.events @@ -1223,7 +1230,7 @@ ALTER TABLE ONLY public.events -- --- Name: events_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: events events_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.events @@ -1231,7 +1238,7 @@ ALTER TABLE ONLY public.events -- --- Name: events_transfer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: events events_transfer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.events @@ -1239,7 +1246,7 @@ ALTER TABLE ONLY public.events -- --- Name: fk_rails_0f0c5fe120; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: petitions fk_rails_0f0c5fe120; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.petitions @@ -1247,7 +1254,7 @@ ALTER TABLE ONLY public.petitions -- --- Name: fk_rails_148f563e25; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: petitions fk_rails_148f563e25; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.petitions @@ -1255,7 +1262,7 @@ ALTER TABLE ONLY public.petitions -- --- Name: fk_rails_1ceb778440; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: accounts fk_rails_1ceb778440; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.accounts @@ -1263,7 +1270,7 @@ ALTER TABLE ONLY public.accounts -- --- Name: fk_rails_36fb6ef1a8; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: push_notifications fk_rails_36fb6ef1a8; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.push_notifications @@ -1271,7 +1278,7 @@ ALTER TABLE ONLY public.push_notifications -- --- Name: fk_rails_79a395b2d7; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: push_notifications fk_rails_79a395b2d7; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.push_notifications @@ -1279,7 +1286,7 @@ ALTER TABLE ONLY public.push_notifications -- --- Name: fk_rails_993965df05; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: active_storage_variant_records fk_rails_993965df05; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_variant_records @@ -1287,7 +1294,7 @@ ALTER TABLE ONLY public.active_storage_variant_records -- --- Name: fk_rails_c3b3935057; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: active_storage_attachments fk_rails_c3b3935057; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_attachments @@ -1368,6 +1375,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20221016192111'), ('20230312231058'), ('20230314233504'), -('20230401114456'); - - +('20230401114456'), +('20231120164231'), +('20231120164346'); From 12affd6af93041c0e72a9010a0b0964b65c1f3b7 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Fri, 24 Nov 2023 10:44:45 +0100 Subject: [PATCH 3/7] adds file validation for organization logo to avoids crash (#714) --- Gemfile | 1 + Gemfile.lock | 6 ++++++ app/helpers/application_helper.rb | 2 +- app/models/organization.rb | 1 + app/views/organizations/_form.html.erb | 2 +- spec/models/organization_spec.rb | 14 ++++++++++++++ 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index d58616d3..386447c9 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,7 @@ gem 'sidekiq', '~> 6.5' gem 'sidekiq-cron', '~> 1.9.1' gem 'aws-sdk-s3', '~> 1.94', require: false gem 'image_processing', '~> 1.12' +gem 'active_storage_validations', '~> 1.1.3' # Assets gem 'jquery-rails', '~> 4.4.0' diff --git a/Gemfile.lock b/Gemfile.lock index 7792343b..2fb28811 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,6 +39,11 @@ GEM erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) + active_storage_validations (1.1.3) + activejob (>= 5.2.0) + activemodel (>= 5.2.0) + activestorage (>= 5.2.0) + activesupport (>= 5.2.0) activeadmin (2.9.0) arbre (~> 1.2, >= 1.2.1) formtastic (>= 3.1, < 5.0) @@ -447,6 +452,7 @@ PLATFORMS ruby DEPENDENCIES + active_storage_validations (~> 1.1.3) activeadmin (~> 2.9.0) aws-sdk-s3 (~> 1.94) bootsnap (~> 1.12.0) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 30d02375..5fe37cdd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -27,7 +27,7 @@ def gravatar_url(user, size = 32) def organization_logo org = @organization || @current_organization - return unless org && org.logo.attached? + return unless org && org.logo.attached? && org.errors.details[:logo].blank? return if "#{controller_name}##{action_name}".in? %w(organizations#index pages#show) content_tag(:div, class: "row organization-logo") do diff --git a/app/models/organization.rb b/app/models/organization.rb index 559f34a8..bc62cc11 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -26,6 +26,7 @@ class Organization < ApplicationRecord has_many :petitions, dependent: :delete_all validates :name, presence: true, uniqueness: true + validates :logo, content_type: /\Aimage\/.*\z/ before_validation :ensure_url after_create :create_account diff --git a/app/views/organizations/_form.html.erb b/app/views/organizations/_form.html.erb index d87e4188..c0a3de0f 100644 --- a/app/views/organizations/_form.html.erb +++ b/app/views/organizations/_form.html.erb @@ -9,6 +9,6 @@ <%= f.input :address %> <%= f.input :neighborhood %> <%= f.input :city %> - <%= f.input :logo %> + <%= f.input :logo, input_html: { accept: "image/*" } %> <%= f.button :submit %> <% end %> diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index 978d4e94..121d5dc1 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -1,6 +1,20 @@ RSpec.describe Organization do let(:organization) { Fabricate(:organization) } + describe "logo validation" do + it "validates content_type" do + temp_file = Tempfile.new('test.txt') + organization.logo.attach(io: File.open(temp_file.path), filename: 'test.txt') + + expect(organization).to be_invalid + + temp_file = Tempfile.new('test.png') + organization.logo.attach(io: File.open(temp_file.path), filename: 'test.png') + + expect(organization).to be_valid + end + end + describe '#display_id' do subject { organization.display_id } From b508d99ead6c0d59767aed3a6837c7f88aa605b4 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 7 Dec 2023 09:33:07 +0100 Subject: [PATCH 4/7] makes tag searches accent insensitive --- app/models/concerns/taggable.rb | 3 ++- spec/models/taggable_spec.rb | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/taggable.rb b/app/models/concerns/taggable.rb index 70f1c0ab..4dba82ec 100644 --- a/app/models/concerns/taggable.rb +++ b/app/models/concerns/taggable.rb @@ -42,7 +42,8 @@ def tag_cloud end def find_like_tag(pattern) - all_tags.uniq.select { |t| t =~ /#{pattern}/i } + transliterated_pattern = pattern.present? ? ActiveSupport::Inflector.transliterate(pattern) : "" + all_tags.uniq.select { |t| ActiveSupport::Inflector.transliterate(t) =~ /#{transliterated_pattern}/i } end # Builds a hash where the keys are the capital letters of the tags and the diff --git a/spec/models/taggable_spec.rb b/spec/models/taggable_spec.rb index 542c1a3d..167e40c0 100644 --- a/spec/models/taggable_spec.rb +++ b/spec/models/taggable_spec.rb @@ -1,7 +1,7 @@ RSpec.describe Taggable do let(:organization) { Fabricate(:organization) } - let(:tags) { %w(foo bar baz) } - let(:more_tags) { %w(foo baz qux) } + let(:tags) { %w(foo bar baz test) } + let(:more_tags) { %w(foo baz qux têst) } let!(:offer) do Fabricate( :offer, @@ -30,6 +30,8 @@ expect(Offer.find_like_tag("foo")).to eq ["foo"] expect(Offer.find_like_tag("Foo")).to eq ["foo"] expect(Offer.find_like_tag("none")).to eq [] + expect(Offer.find_like_tag("test")).to match_array ["test", "têst"] + expect(Offer.find_like_tag("têst")).to match_array ["test", "têst"] end describe '.alphabetical_grouped_tags' do From 78d0fb001532507826fedb3def4fe17d2e7c17f1 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 7 Dec 2023 09:33:56 +0100 Subject: [PATCH 5/7] makes member searches accent insensitive --- app/views/users/index.html.erb | 2 +- app/views/users/manage.html.erb | 2 +- config/initializers/ransack.rb | 8 ++++++++ spec/controllers/users_controller_spec.rb | 12 +++++++----- 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 config/initializers/ransack.rb diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 47b7322e..bf73c674 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -11,7 +11,7 @@
<%= search_form_for(@search, class: "navbar-form navbar-left", url: users_path) do |f| %>
- <%= f.search_field :member_search_cont, value: params.dig(:q, :member_search_cont), class: "form-control" %> + <%= f.search_field :member_search_unaccent_cont, value: params.dig(:q, :member_search_unaccent_cont), class: "form-control" %>
+ <%= render "organizations/petition_button", organization: @organization %>
diff --git a/spec/controllers/petitions_controller_spec.rb b/spec/controllers/petitions_controller_spec.rb index be689706..0d7bb916 100644 --- a/spec/controllers/petitions_controller_spec.rb +++ b/spec/controllers/petitions_controller_spec.rb @@ -7,9 +7,12 @@ before { login(user) } it 'creates the petition' do + request.env['HTTP_REFERER'] = organizations_path + expect do post :create, params: { user_id: user.id, organization_id: organization.id } end.to change(Petition, :count).by(1) + expect(response).to redirect_to(organizations_path) end end @@ -35,7 +38,7 @@ describe 'GET #manage' do before do - allow(controller).to receive(:current_organization) { organization } + allow(controller).to receive(:current_organization) { organization } login(admin.user) end let!(:petition) { Petition.create(user: user, organization: organization, status: 'pending') } diff --git a/spec/views/organizations/show.html.erb_spec.rb b/spec/views/organizations/show.html.erb_spec.rb index be14b5c7..1b59d4a1 100644 --- a/spec/views/organizations/show.html.erb_spec.rb +++ b/spec/views/organizations/show.html.erb_spec.rb @@ -59,5 +59,63 @@ it 'displays the organization page' do expect(rendered).to match(organization.name) end + + it 'displays link to delete the member' do + expect(rendered).to have_link( + t('users.user_rows.delete_membership'), + href: member_path(member) + ) + end + end + + context 'with a logged user (but not organization member)' do + let(:user) { Fabricate(:user) } + + before do + allow(view).to receive(:current_user).and_return(user) + + assign :movements, Movement.page + render template: 'organizations/show' + end + + it 'displays link to create petition' do + expect(rendered).to have_link( + t('petitions.apply'), + href: petitions_path(user_id: user.id, organization_id: organization.id) + ) + end + end + + context 'with a logged admin' do + let(:admin) { Fabricate(:member, organization: organization, manager: true) } + let(:user) { admin.user } + + before do + allow(view).to receive(:current_user).and_return(user) + + assign :movements, Movement.page + render template: 'organizations/show' + end + + it 'has link to edit organization' do + expect(rendered).to have_link(t('global.edit'), href: edit_organization_path(organization)) + end + end + + context 'with a logged admin from other organization' do + let(:other_organization) { Fabricate(:organization) } + let(:admin) { Fabricate(:member, organization: other_organization, manager: true) } + let(:user) { admin.user } + + before do + allow(view).to receive(:current_user).and_return(user) + + assign :movements, Movement.page + render template: 'organizations/show' + end + + it 'does not have link to edit organization' do + expect(rendered).to_not have_link(t('global.edit'), href: edit_organization_path(organization)) + end end end From 5d56ea65756dbc0306dd22f54e9f1f55b466dd1f Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Fri, 8 Dec 2023 16:55:21 +0100 Subject: [PATCH 7/7] fix organization logo validation (#720) --- app/models/organization.rb | 4 +++- app/views/organizations/_form.html.erb | 2 +- spec/models/organization_spec.rb | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/organization.rb b/app/models/organization.rb index bc62cc11..cec86710 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -26,7 +26,9 @@ class Organization < ApplicationRecord has_many :petitions, dependent: :delete_all validates :name, presence: true, uniqueness: true - validates :logo, content_type: /\Aimage\/.*\z/ + + LOGO_CONTENT_TYPES = %w(image/jpeg image/png image/gif) + validates :logo, content_type: LOGO_CONTENT_TYPES before_validation :ensure_url after_create :create_account diff --git a/app/views/organizations/_form.html.erb b/app/views/organizations/_form.html.erb index c0a3de0f..4405fa83 100644 --- a/app/views/organizations/_form.html.erb +++ b/app/views/organizations/_form.html.erb @@ -9,6 +9,6 @@ <%= f.input :address %> <%= f.input :neighborhood %> <%= f.input :city %> - <%= f.input :logo, input_html: { accept: "image/*" } %> + <%= f.input :logo, input_html: { accept: Organization::LOGO_CONTENT_TYPES.join(',') } %> <%= f.button :submit %> <% end %> diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index 121d5dc1..557c48ea 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -8,6 +8,11 @@ expect(organization).to be_invalid + temp_file = Tempfile.new('test.svg') + organization.logo.attach(io: File.open(temp_file.path), filename: 'test.svg') + + expect(organization).to be_invalid + temp_file = Tempfile.new('test.png') organization.logo.attach(io: File.open(temp_file.path), filename: 'test.png')