From 59ae149956d57accd6a556affa427438e3d2240c Mon Sep 17 00:00:00 2001 From: franpb14 Date: Sun, 25 Apr 2021 17:57:04 +0200 Subject: [PATCH 01/14] feat: tags and postcode attributes have been added postcode was added to users and tags to members. For the postcode was added to users and tags to members. For the postcode I used the rails form but for the tags I used Html. Issue #623. --- app/controllers/users_controller.rb | 13 +- app/models/user.rb | 8 +- app/views/users/_form.html.erb | 2 + app/views/users/_form_tags.erb | 14 + .../20210423193937_add_post_code_to_users.rb | 5 + .../20210424174640_add_tags_to_members.rb | 5 + db/structure.sql | 309 ++++++++---------- 7 files changed, 173 insertions(+), 183 deletions(-) create mode 100644 app/views/users/_form_tags.erb create mode 100644 db/migrate/20210423193937_add_post_code_to_users.rb create mode 100644 db/migrate/20210424174640_add_tags_to_members.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 02a14402c..9cf242b06 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -18,11 +18,13 @@ def show def new authorize User + @member = Member.new @user = scoped_users.build end def edit @user = find_user + @member = @user.as_member_of(current_organization) end def create @@ -36,7 +38,7 @@ def create @user.setup_and_save_user if @user.persisted? - @user.tune_after_persisted(current_organization) + @user.tune_after_persisted(current_organization, get_tags) redirect_to_after_create else @user.email = "" if empty_email @@ -46,9 +48,10 @@ def create def update @user = scoped_users.find(params[:id]) + @member = @user.as_member_of(current_organization) authorize @user - if @user.update(user_params) + if @user.update(user_params) && @member.update(tags: get_tags) redirect_to @user else render action: :edit, status: :unprocessable_entity @@ -76,7 +79,7 @@ def scoped_users def user_params fields_to_permit = %w"gender username email date_of_birth phone - alt_phone active description notifications push_notifications" + alt_phone active description notifications push_notifications postcode" fields_to_permit += %w"admin registration_number registration_date" if admin? fields_to_permit += %w"organization_id superadmin" if superadmin? @@ -106,4 +109,8 @@ def redirect_to_after_create name: @user.username) end end + + def get_tags + params.key?(:member) ? params.require(:member).permit([tag_list: []])[:tag_list][1..] : [] + end end diff --git a/app/models/user.rb b/app/models/user.rb index fae6223c2..3210c6577 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -64,7 +64,7 @@ def user self end - def add_to_organization(organization) + def add_to_organization(organization, tag_list = []) return unless organization member = members.where(organization: organization).first_or_initialize @@ -72,7 +72,7 @@ def add_to_organization(organization) return member if member.persisted? member.entry_date = DateTime.now.utc - + member.tags = tag_list persister = ::Persister::MemberPersister.new(member) persister.save @@ -102,8 +102,8 @@ def setup_and_save_user save end - def tune_after_persisted(organization) - add_to_organization organization + def tune_after_persisted(organization, tag_list = []) + add_to_organization organization, tag_list # If email was empty, udpate again with user.id just generated set_dummy_email if empty_email diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index f2b32484b..23a712279 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -20,6 +20,8 @@ end_year: Date.today.year - 12, include_blank: :true %> <%= f.input :description, as: "text" %> + <%= f.input :postcode %> + <%= render 'form_tags' %>
diff --git a/app/views/users/_form_tags.erb b/app/views/users/_form_tags.erb new file mode 100644 index 000000000..9a595ec1a --- /dev/null +++ b/app/views/users/_form_tags.erb @@ -0,0 +1,14 @@ +
+ + + +
\ No newline at end of file diff --git a/db/migrate/20210423193937_add_post_code_to_users.rb b/db/migrate/20210423193937_add_post_code_to_users.rb new file mode 100644 index 000000000..c081fa264 --- /dev/null +++ b/db/migrate/20210423193937_add_post_code_to_users.rb @@ -0,0 +1,5 @@ +class AddPostCodeToUsers < ActiveRecord::Migration[6.1] + def change + add_column :users, :postcode, :string + end +end diff --git a/db/migrate/20210424174640_add_tags_to_members.rb b/db/migrate/20210424174640_add_tags_to_members.rb new file mode 100644 index 000000000..4f3098936 --- /dev/null +++ b/db/migrate/20210424174640_add_tags_to_members.rb @@ -0,0 +1,5 @@ +class AddTagsToMembers < ActiveRecord::Migration[6.1] + def change + add_column :members, :tags, :text, array: true, default: [] + end +end diff --git a/db/structure.sql b/db/structure.sql index fcb2d6336..7765c86c0 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1,31 +1,13 @@ --- --- PostgreSQL database dump --- - --- Dumped from database version 9.5.14 --- Dumped by pg_dump version 9.5.14 - SET statement_timeout = 0; SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SELECT pg_catalog.set_config('search_path', '', false); SET check_function_bodies = false; +SET xmloption = content; SET client_min_messages = warning; - --- --- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; - - --- --- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; - +SET row_security = off; -- -- Name: hstore; Type: EXTENSION; Schema: -; Owner: - @@ -88,7 +70,7 @@ CREATE FUNCTION public.posts_trigger() RETURNS trigger SET default_tablespace = ''; -SET default_with_oids = false; +SET default_table_access_method = heap; -- -- Name: accounts; Type: TABLE; Schema: public; Owner: - @@ -163,6 +145,18 @@ CREATE SEQUENCE public.active_admin_comments_id_seq ALTER SEQUENCE public.active_admin_comments_id_seq OWNED BY public.active_admin_comments.id; +-- +-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.ar_internal_metadata ( + key character varying NOT NULL, + value character varying, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + -- -- Name: categories; Type: TABLE; Schema: public; Owner: - -- @@ -308,7 +302,8 @@ CREATE TABLE public.members ( updated_at timestamp without time zone, entry_date date, member_uid integer, - active boolean DEFAULT true + active boolean DEFAULT true, + tags text[] DEFAULT '{}'::text[] ); @@ -564,7 +559,8 @@ CREATE TABLE public.users ( locked_at timestamp without time zone, locale character varying DEFAULT 'es'::character varying, notifications boolean DEFAULT true, - push_notifications boolean DEFAULT true NOT NULL + push_notifications boolean DEFAULT true NOT NULL, + postcode character varying ); @@ -588,98 +584,98 @@ 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: 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: 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 @@ -687,7 +683,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 @@ -695,7 +691,15 @@ ALTER TABLE ONLY public.active_admin_comments -- --- Name: categories_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 + ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key); + + +-- +-- Name: categories categories_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.categories @@ -703,7 +707,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 @@ -711,7 +715,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 @@ -719,7 +723,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 @@ -727,7 +731,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 @@ -735,7 +739,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 @@ -743,7 +747,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 @@ -751,7 +755,7 @@ ALTER TABLE ONLY public.organizations -- --- Name: posts_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: posts posts_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.posts @@ -759,7 +763,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 @@ -767,7 +771,15 @@ ALTER TABLE ONLY public.push_notifications -- --- Name: transfers_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.schema_migrations + ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); + + +-- +-- Name: transfers transfers_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.transfers @@ -775,7 +787,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 @@ -958,14 +970,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(); +CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON public.posts FOR EACH ROW EXECUTE FUNCTION 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 @@ -973,7 +985,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 @@ -981,7 +993,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 @@ -989,7 +1001,7 @@ ALTER TABLE ONLY public.events -- --- 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 @@ -997,7 +1009,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 @@ -1005,7 +1017,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 @@ -1018,123 +1030,68 @@ ALTER TABLE ONLY public.push_notifications SET search_path TO "$user", public; -INSERT INTO schema_migrations (version) VALUES ('1'); - -INSERT INTO schema_migrations (version) VALUES ('2'); - -INSERT INTO schema_migrations (version) VALUES ('20121019101022'); - -INSERT INTO schema_migrations (version) VALUES ('20121104004639'); - -INSERT INTO schema_migrations (version) VALUES ('20121104085711'); - -INSERT INTO schema_migrations (version) VALUES ('20121121233818'); - -INSERT INTO schema_migrations (version) VALUES ('20130214175758'); - -INSERT INTO schema_migrations (version) VALUES ('20130214181128'); - -INSERT INTO schema_migrations (version) VALUES ('20130222185624'); - -INSERT INTO schema_migrations (version) VALUES ('20130425165150'); - -INSERT INTO schema_migrations (version) VALUES ('20130508085004'); - -INSERT INTO schema_migrations (version) VALUES ('20130513092219'); - -INSERT INTO schema_migrations (version) VALUES ('20130514094755'); - -INSERT INTO schema_migrations (version) VALUES ('20130618210236'); - -INSERT INTO schema_migrations (version) VALUES ('20130621102219'); - -INSERT INTO schema_migrations (version) VALUES ('20130621103053'); - -INSERT INTO schema_migrations (version) VALUES ('20130621103501'); - -INSERT INTO schema_migrations (version) VALUES ('20130621105452'); - -INSERT INTO schema_migrations (version) VALUES ('20130703233851'); - -INSERT INTO schema_migrations (version) VALUES ('20130703234011'); - -INSERT INTO schema_migrations (version) VALUES ('20130703234042'); - -INSERT INTO schema_migrations (version) VALUES ('20130723160206'); - -INSERT INTO schema_migrations (version) VALUES ('20131017144321'); - -INSERT INTO schema_migrations (version) VALUES ('20131025202608'); - -INSERT INTO schema_migrations (version) VALUES ('20131027215517'); - -INSERT INTO schema_migrations (version) VALUES ('20131029202724'); - -INSERT INTO schema_migrations (version) VALUES ('20131103221044'); - -INSERT INTO schema_migrations (version) VALUES ('20131104004235'); - -INSERT INTO schema_migrations (version) VALUES ('20131104013634'); - -INSERT INTO schema_migrations (version) VALUES ('20131104013829'); - -INSERT INTO schema_migrations (version) VALUES ('20131104032622'); - -INSERT INTO schema_migrations (version) VALUES ('20131220160257'); - -INSERT INTO schema_migrations (version) VALUES ('20131227110122'); - -INSERT INTO schema_migrations (version) VALUES ('20131227142805'); - -INSERT INTO schema_migrations (version) VALUES ('20131227155440'); - -INSERT INTO schema_migrations (version) VALUES ('20131231110424'); - -INSERT INTO schema_migrations (version) VALUES ('20140119161433'); - -INSERT INTO schema_migrations (version) VALUES ('20140513141718'); - -INSERT INTO schema_migrations (version) VALUES ('20140514225527'); - -INSERT INTO schema_migrations (version) VALUES ('20150329193421'); - -INSERT INTO schema_migrations (version) VALUES ('20150330200315'); - -INSERT INTO schema_migrations (version) VALUES ('20150422162806'); - -INSERT INTO schema_migrations (version) VALUES ('20180221161343'); - -INSERT INTO schema_migrations (version) VALUES ('20180501093846'); - -INSERT INTO schema_migrations (version) VALUES ('20180514193153'); - -INSERT INTO schema_migrations (version) VALUES ('20180524143938'); - -INSERT INTO schema_migrations (version) VALUES ('20180525141138'); - -INSERT INTO schema_migrations (version) VALUES ('20180529144243'); - -INSERT INTO schema_migrations (version) VALUES ('20180530180546'); - -INSERT INTO schema_migrations (version) VALUES ('20180604145622'); - -INSERT INTO schema_migrations (version) VALUES ('20180828160700'); - -INSERT INTO schema_migrations (version) VALUES ('20180831161349'); - -INSERT INTO schema_migrations (version) VALUES ('20180924164456'); - -INSERT INTO schema_migrations (version) VALUES ('20181004200104'); - -INSERT INTO schema_migrations (version) VALUES ('20190319121401'); - -INSERT INTO schema_migrations (version) VALUES ('20190322180602'); - -INSERT INTO schema_migrations (version) VALUES ('20190411192828'); - -INSERT INTO schema_migrations (version) VALUES ('20190412163011'); - -INSERT INTO schema_migrations (version) VALUES ('20190523213421'); +INSERT INTO "schema_migrations" (version) VALUES +('1'), +('2'), +('20121019101022'), +('20121104004639'), +('20121104085711'), +('20121121233818'), +('20130214175758'), +('20130214181128'), +('20130222185624'), +('20130425165150'), +('20130508085004'), +('20130513092219'), +('20130514094755'), +('20130618210236'), +('20130621102219'), +('20130621103053'), +('20130621103501'), +('20130621105452'), +('20130703233851'), +('20130703234011'), +('20130703234042'), +('20130723160206'), +('20131017144321'), +('20131025202608'), +('20131027215517'), +('20131029202724'), +('20131103221044'), +('20131104004235'), +('20131104013634'), +('20131104013829'), +('20131104032622'), +('20131220160257'), +('20131227110122'), +('20131227142805'), +('20131227155440'), +('20131231110424'), +('20140119161433'), +('20140513141718'), +('20140514225527'), +('20150329193421'), +('20150330200315'), +('20150422162806'), +('20180221161343'), +('20180501093846'), +('20180514193153'), +('20180524143938'), +('20180525141138'), +('20180529144243'), +('20180530180546'), +('20180604145622'), +('20180828160700'), +('20180831161349'), +('20180924164456'), +('20181004200104'), +('20190319121401'), +('20190322180602'), +('20190411192828'), +('20190412163011'), +('20190523213421'), +('20190523225323'), +('20210423193937'), +('20210424174640'); -INSERT INTO schema_migrations (version) VALUES ('20190523225323'); From 3752d653c9b2bb34237af88c125674291ae34ab9 Mon Sep 17 00:00:00 2001 From: franpb14 Date: Sun, 25 Apr 2021 19:11:35 +0200 Subject: [PATCH 02/14] refactor: I've changed the form using rails tools. #623. --- app/controllers/users_controller.rb | 2 +- app/views/users/_form.html.erb | 10 +++++++++- app/views/users/_form_tags.erb | 14 -------------- config/locales/en.yml | 1 + 4 files changed, 11 insertions(+), 16 deletions(-) delete mode 100644 app/views/users/_form_tags.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9cf242b06..5941c1f06 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -111,6 +111,6 @@ def redirect_to_after_create end def get_tags - params.key?(:member) ? params.require(:member).permit([tag_list: []])[:tag_list][1..] : [] + params.key?(:tag_list) ? params.require(:tag_list) : [] end end diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 23a712279..d11b9c121 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -21,7 +21,15 @@ include_blank: :true %> <%= f.input :description, as: "text" %> <%= f.input :postcode %> - <%= render 'form_tags' %> + <%= label_tag :tag_list, t('activerecord.attributes.post.tag_list') %> +
+ <%= select_tag :tag_list, + options_for_select(@member.tags, @member.tags), + multiple: true, + data: { placeholder: t('application.tips.entertag')}, + id: "tags-js", + class: "form-control" %> +
diff --git a/app/views/users/_form_tags.erb b/app/views/users/_form_tags.erb deleted file mode 100644 index 9a595ec1a..000000000 --- a/app/views/users/_form_tags.erb +++ /dev/null @@ -1,14 +0,0 @@ -
- - - -
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index e7419738b..a0ee4ead5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -73,6 +73,7 @@ en: unconfirmed_email: Unconfirmed Email updated_at: Updated username: Name + postcode: Post code errors: models: organization: From c398a8f93daf498389f0f54e9baf906edf0d5d73 Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Sun, 25 Apr 2021 21:25:15 +0200 Subject: [PATCH 03/14] delete :scissors: unused method Account#allowance --- app/models/account.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index 73ba91a19..c441349ba 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -22,16 +22,6 @@ def update_balance save end - # Return the maximum allowed amount of time that the acccount is able to - # spend without overflowing - def allowance - if min_allowed_balance - [0, balance - min_allowed_balance].min - else - Float::INFINITY - end - end - # Print the account as its accountable reference def to_s accountable.to_s From b3aa6d0f1e8e3c2b5b01352f92142940ac51c289 Mon Sep 17 00:00:00 2001 From: franpb14 Date: Mon, 26 Apr 2021 16:35:11 +0200 Subject: [PATCH 04/14] fix: I have run the migrate by changing the postgres version to 9.4. #623. --- db/structure.sql | 178 ++++++++++++++++++++++++----------------------- 1 file changed, 91 insertions(+), 87 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index 7765c86c0..57d6c8791 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1,13 +1,25 @@ SET statement_timeout = 0; SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SELECT pg_catalog.set_config('search_path', '', false); SET check_function_bodies = false; SET xmloption = content; SET client_min_messages = warning; -SET row_security = off; + +-- +-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; + + +-- +-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; + -- -- Name: hstore; Type: EXTENSION; Schema: -; Owner: - @@ -70,10 +82,10 @@ CREATE FUNCTION public.posts_trigger() RETURNS trigger SET default_tablespace = ''; -SET default_table_access_method = heap; +SET default_with_oids = false; -- --- Name: accounts; Type: TABLE; Schema: public; Owner: - +-- Name: accounts; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.accounts ( @@ -110,7 +122,7 @@ ALTER SEQUENCE public.accounts_id_seq OWNED BY public.accounts.id; -- --- Name: active_admin_comments; Type: TABLE; Schema: public; Owner: - +-- Name: active_admin_comments; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.active_admin_comments ( @@ -146,7 +158,7 @@ ALTER SEQUENCE public.active_admin_comments_id_seq OWNED BY public.active_admin_ -- --- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: - +-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.ar_internal_metadata ( @@ -158,7 +170,7 @@ CREATE TABLE public.ar_internal_metadata ( -- --- Name: categories; Type: TABLE; Schema: public; Owner: - +-- Name: categories; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.categories ( @@ -189,7 +201,7 @@ ALTER SEQUENCE public.categories_id_seq OWNED BY public.categories.id; -- --- Name: device_tokens; Type: TABLE; Schema: public; Owner: - +-- Name: device_tokens; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.device_tokens ( @@ -221,7 +233,7 @@ ALTER SEQUENCE public.device_tokens_id_seq OWNED BY public.device_tokens.id; -- --- Name: documents; Type: TABLE; Schema: public; Owner: - +-- Name: documents; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.documents ( @@ -256,7 +268,7 @@ ALTER SEQUENCE public.documents_id_seq OWNED BY public.documents.id; -- --- Name: events; Type: TABLE; Schema: public; Owner: - +-- Name: events; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.events ( @@ -290,7 +302,7 @@ ALTER SEQUENCE public.events_id_seq OWNED BY public.events.id; -- --- Name: members; Type: TABLE; Schema: public; Owner: - +-- Name: members; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.members ( @@ -327,7 +339,7 @@ ALTER SEQUENCE public.members_id_seq OWNED BY public.members.id; -- --- Name: movements; Type: TABLE; Schema: public; Owner: - +-- Name: movements; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.movements ( @@ -360,7 +372,7 @@ ALTER SEQUENCE public.movements_id_seq OWNED BY public.movements.id; -- --- Name: organizations; Type: TABLE; Schema: public; Owner: - +-- Name: organizations; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.organizations ( @@ -402,7 +414,7 @@ ALTER SEQUENCE public.organizations_id_seq OWNED BY public.organizations.id; -- --- Name: posts; Type: TABLE; Schema: public; Owner: - +-- Name: posts; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.posts ( @@ -444,7 +456,7 @@ ALTER SEQUENCE public.posts_id_seq OWNED BY public.posts.id; -- --- Name: push_notifications; Type: TABLE; Schema: public; Owner: - +-- Name: push_notifications; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.push_notifications ( @@ -480,7 +492,7 @@ ALTER SEQUENCE public.push_notifications_id_seq OWNED BY public.push_notificatio -- --- Name: schema_migrations; Type: TABLE; Schema: public; Owner: - +-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.schema_migrations ( @@ -489,7 +501,7 @@ CREATE TABLE public.schema_migrations ( -- --- Name: transfers; Type: TABLE; Schema: public; Owner: - +-- Name: transfers; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.transfers ( @@ -522,7 +534,7 @@ ALTER SEQUENCE public.transfers_id_seq OWNED BY public.transfers.id; -- --- Name: users; Type: TABLE; Schema: public; Owner: - +-- Name: users; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.users ( @@ -584,98 +596,98 @@ ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id; -- --- Name: accounts id; Type: DEFAULT; Schema: public; Owner: - +-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.accounts ALTER COLUMN id SET DEFAULT nextval('public.accounts_id_seq'::regclass); -- --- Name: active_admin_comments id; Type: DEFAULT; Schema: public; Owner: - +-- Name: 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: categories id; Type: DEFAULT; Schema: public; Owner: - +-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.categories ALTER COLUMN id SET DEFAULT nextval('public.categories_id_seq'::regclass); -- --- Name: device_tokens id; Type: DEFAULT; Schema: public; Owner: - +-- Name: 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: documents id; Type: DEFAULT; Schema: public; Owner: - +-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.documents ALTER COLUMN id SET DEFAULT nextval('public.documents_id_seq'::regclass); -- --- Name: events id; Type: DEFAULT; Schema: public; Owner: - +-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.events ALTER COLUMN id SET DEFAULT nextval('public.events_id_seq'::regclass); -- --- Name: members id; Type: DEFAULT; Schema: public; Owner: - +-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.members ALTER COLUMN id SET DEFAULT nextval('public.members_id_seq'::regclass); -- --- Name: movements id; Type: DEFAULT; Schema: public; Owner: - +-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.movements ALTER COLUMN id SET DEFAULT nextval('public.movements_id_seq'::regclass); -- --- Name: organizations id; Type: DEFAULT; Schema: public; Owner: - +-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.organizations ALTER COLUMN id SET DEFAULT nextval('public.organizations_id_seq'::regclass); -- --- Name: posts id; Type: DEFAULT; Schema: public; Owner: - +-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.posts ALTER COLUMN id SET DEFAULT nextval('public.posts_id_seq'::regclass); -- --- Name: push_notifications id; Type: DEFAULT; Schema: public; Owner: - +-- Name: 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: transfers id; Type: DEFAULT; Schema: public; Owner: - +-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.transfers ALTER COLUMN id SET DEFAULT nextval('public.transfers_id_seq'::regclass); -- --- Name: users id; Type: DEFAULT; Schema: public; Owner: - +-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass); -- --- Name: accounts accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.accounts @@ -683,7 +695,7 @@ ALTER TABLE ONLY public.accounts -- --- Name: active_admin_comments active_admin_comments_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: active_admin_comments_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.active_admin_comments @@ -691,7 +703,7 @@ ALTER TABLE ONLY public.active_admin_comments -- --- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.ar_internal_metadata @@ -699,7 +711,7 @@ ALTER TABLE ONLY public.ar_internal_metadata -- --- Name: categories categories_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.categories @@ -707,7 +719,7 @@ ALTER TABLE ONLY public.categories -- --- Name: device_tokens device_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: device_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.device_tokens @@ -715,7 +727,7 @@ ALTER TABLE ONLY public.device_tokens -- --- Name: documents documents_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: documents_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.documents @@ -723,7 +735,7 @@ ALTER TABLE ONLY public.documents -- --- Name: events events_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: events_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.events @@ -731,7 +743,7 @@ ALTER TABLE ONLY public.events -- --- Name: members members_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: members_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.members @@ -739,7 +751,7 @@ ALTER TABLE ONLY public.members -- --- Name: movements movements_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: movements_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.movements @@ -747,7 +759,7 @@ ALTER TABLE ONLY public.movements -- --- Name: organizations organizations_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: organizations_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.organizations @@ -755,7 +767,7 @@ ALTER TABLE ONLY public.organizations -- --- Name: posts posts_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: posts_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.posts @@ -763,7 +775,7 @@ ALTER TABLE ONLY public.posts -- --- Name: push_notifications push_notifications_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: push_notifications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.push_notifications @@ -771,15 +783,7 @@ ALTER TABLE ONLY public.push_notifications -- --- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.schema_migrations - ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); - - --- --- Name: transfers transfers_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: transfers_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.transfers @@ -787,7 +791,7 @@ ALTER TABLE ONLY public.transfers -- --- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.users @@ -795,189 +799,189 @@ ALTER TABLE ONLY public.users -- --- Name: index_accounts_on_accountable_type_and_accountable_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_accounts_on_accountable_type_and_accountable_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_accounts_on_accountable_type_and_accountable_id ON public.accounts USING btree (accountable_type, accountable_id); -- --- Name: index_accounts_on_organization_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_accounts_on_organization_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_accounts_on_organization_id ON public.accounts USING btree (organization_id); -- --- Name: index_active_admin_comments_on_author_type_and_author_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_active_admin_comments_on_author_type_and_author_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_active_admin_comments_on_author_type_and_author_id ON public.active_admin_comments USING btree (author_type, author_id); -- --- Name: index_active_admin_comments_on_namespace; Type: INDEX; Schema: public; Owner: - +-- Name: index_active_admin_comments_on_namespace; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_active_admin_comments_on_namespace ON public.active_admin_comments USING btree (namespace); -- --- Name: index_active_admin_comments_on_resource_type_and_resource_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_active_admin_comments_on_resource_type_and_resource_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_active_admin_comments_on_resource_type_and_resource_id ON public.active_admin_comments USING btree (resource_type, resource_id); -- --- Name: index_device_tokens_on_user_id_and_token; Type: INDEX; Schema: public; Owner: - +-- Name: index_device_tokens_on_user_id_and_token; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE UNIQUE INDEX index_device_tokens_on_user_id_and_token ON public.device_tokens USING btree (user_id, token); -- --- Name: index_documents_on_documentable_id_and_documentable_type; Type: INDEX; Schema: public; Owner: - +-- Name: index_documents_on_documentable_id_and_documentable_type; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_documents_on_documentable_id_and_documentable_type ON public.documents USING btree (documentable_id, documentable_type); -- --- Name: index_documents_on_label; Type: INDEX; Schema: public; Owner: - +-- Name: index_documents_on_label; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_documents_on_label ON public.documents USING btree (label); -- --- Name: index_events_on_member_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_events_on_member_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_events_on_member_id ON public.events USING btree (member_id) WHERE (member_id IS NOT NULL); -- --- Name: index_events_on_post_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_events_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_events_on_post_id ON public.events USING btree (post_id) WHERE (post_id IS NOT NULL); -- --- Name: index_events_on_transfer_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_events_on_transfer_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_events_on_transfer_id ON public.events USING btree (transfer_id) WHERE (transfer_id IS NOT NULL); -- --- Name: index_members_on_organization_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_members_on_organization_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_members_on_organization_id ON public.members USING btree (organization_id); -- --- Name: index_members_on_user_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_members_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_members_on_user_id ON public.members USING btree (user_id); -- --- Name: index_movements_on_account_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_movements_on_account_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_movements_on_account_id ON public.movements USING btree (account_id); -- --- Name: index_movements_on_transfer_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_movements_on_transfer_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_movements_on_transfer_id ON public.movements USING btree (transfer_id); -- --- Name: index_organizations_on_name; Type: INDEX; Schema: public; Owner: - +-- Name: index_organizations_on_name; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE UNIQUE INDEX index_organizations_on_name ON public.organizations USING btree (name); -- --- Name: index_posts_on_category_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_posts_on_category_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_posts_on_category_id ON public.posts USING btree (category_id); -- --- Name: index_posts_on_organization_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_posts_on_organization_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_posts_on_organization_id ON public.posts USING btree (organization_id); -- --- Name: index_posts_on_tags; Type: INDEX; Schema: public; Owner: - +-- Name: index_posts_on_tags; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_posts_on_tags ON public.posts USING gin (tags); -- --- Name: index_posts_on_tsv; Type: INDEX; Schema: public; Owner: - +-- Name: index_posts_on_tsv; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_posts_on_tsv ON public.posts USING gin (tsv); -- --- Name: index_posts_on_user_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_posts_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_posts_on_user_id ON public.posts USING btree (user_id); -- --- Name: index_transfers_on_operator_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_transfers_on_operator_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_transfers_on_operator_id ON public.transfers USING btree (operator_id); -- --- Name: index_transfers_on_post_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_transfers_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_transfers_on_post_id ON public.transfers USING btree (post_id); -- --- Name: index_users_on_email; Type: INDEX; Schema: public; Owner: - +-- Name: index_users_on_email; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE INDEX index_users_on_email ON public.users USING btree (email); -- --- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: - +-- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: -; Tablespace: -- CREATE UNIQUE INDEX unique_schema_migrations ON public.schema_migrations USING btree (version); -- --- Name: posts tsvectorupdate; Type: TRIGGER; Schema: public; Owner: - +-- Name: tsvectorupdate; Type: TRIGGER; Schema: public; Owner: - -- -CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON public.posts FOR EACH ROW EXECUTE FUNCTION public.posts_trigger(); +CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON public.posts FOR EACH ROW EXECUTE PROCEDURE public.posts_trigger(); -- --- Name: events events_member_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: events_member_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.events @@ -985,7 +989,7 @@ ALTER TABLE ONLY public.events -- --- Name: events events_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: events_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.events @@ -993,7 +997,7 @@ ALTER TABLE ONLY public.events -- --- Name: events events_transfer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: events_transfer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.events @@ -1001,7 +1005,7 @@ ALTER TABLE ONLY public.events -- --- Name: accounts fk_rails_1ceb778440; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: fk_rails_1ceb778440; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.accounts @@ -1009,7 +1013,7 @@ ALTER TABLE ONLY public.accounts -- --- Name: push_notifications fk_rails_36fb6ef1a8; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: fk_rails_36fb6ef1a8; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.push_notifications @@ -1017,7 +1021,7 @@ ALTER TABLE ONLY public.push_notifications -- --- Name: push_notifications fk_rails_79a395b2d7; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: fk_rails_79a395b2d7; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.push_notifications @@ -1028,7 +1032,7 @@ ALTER TABLE ONLY public.push_notifications -- PostgreSQL database dump complete -- -SET search_path TO "$user", public; +SET search_path TO "$user",public; INSERT INTO "schema_migrations" (version) VALUES ('1'), From 49a754bc30cb83937ce98c6136292dfdfff4b4a5 Mon Sep 17 00:00:00 2001 From: franpb14 Date: Mon, 26 Apr 2021 18:27:30 +0200 Subject: [PATCH 05/14] tests: I've added the attributes to the tests already implemented. #623. --- spec/controllers/users_controller_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index da6f59000..9bde9f43e 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -311,11 +311,14 @@ username: user.username, email: user.email, phone: "1234", - alt_phone: "4321") } + alt_phone: "4321", + postcode: "40000"), tag_list: %w"tag1 tag2" } user.reload expect(user.phone).to eq("1234") expect(user.alt_phone).to eq("4321") + expect(user.postcode).to eq("40000") + expect(user.as_member_of(test_organization).tags).to eq(%w"tag1 tag2") end it "cannot change another user's attributes" do @@ -344,11 +347,14 @@ username: user.username, email: user.email, phone: "1234", - alt_phone: "4321") } + alt_phone: "4321", + postcode: "40000"), tag_list: %w"tag1 tag2" } user.reload expect(user.phone).to eq("1234") expect(user.alt_phone).to eq("4321") + expect(user.postcode).to eq("40000") + expect(user.as_member_of(test_organization).tags).to eq(%w"tag1 tag2") end end end From 32f4ebe583ec571ab50c4f1c50a9cffd48048738 Mon Sep 17 00:00:00 2001 From: franpb14 Date: Tue, 27 Apr 2021 22:57:18 +0200 Subject: [PATCH 06/14] fix: the problem of ambiguity solved. #626. --- app/models/concerns/taggable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/taggable.rb b/app/models/concerns/taggable.rb index 61e3d6f78..191b5e447 100644 --- a/app/models/concerns/taggable.rb +++ b/app/models/concerns/taggable.rb @@ -6,7 +6,7 @@ module Taggable extend ActiveSupport::Concern included do - scope :tagged_with, ->(tag) { where("? = ANY (tags)", tag) } + scope :tagged_with, ->(tag) { where("? = ANY (posts.tags)", tag) } end def tag_list From f274d13dc5e82611a50973b81d40cdd08023b138 Mon Sep 17 00:00:00 2001 From: franpb14 Date: Wed, 28 Apr 2021 14:26:27 +0200 Subject: [PATCH 07/14] feat: the searcher is working on tags You can also click on a tag and the search will be executed directly. And the attributes are shown in the show and in the list (only the tags and if there are more than 3, not all). #623. --- .../stylesheets/application/member-card.scss | 6 +++++ app/controllers/users_controller.rb | 7 +++++- app/decorators/member_decorator.rb | 2 +- app/models/concerns/taggable.rb | 2 +- app/models/member.rb | 5 ++++ app/views/users/_member_card.html.erb | 11 +++++++++ app/views/users/index.html.erb | 2 +- app/views/users/show.html.erb | 23 +++++++++++++++++++ 8 files changed, 54 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/application/member-card.scss b/app/assets/stylesheets/application/member-card.scss index 6592e33f6..119331589 100644 --- a/app/assets/stylesheets/application/member-card.scss +++ b/app/assets/stylesheets/application/member-card.scss @@ -37,6 +37,12 @@ } } + &__tags { + a { + color: white; + } + } + &__activity { font-size: 14px; color: #78adb9; diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5941c1f06..aaab0b47f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,8 +1,13 @@ class UsersController < ApplicationController before_action :authenticate_user!, :member_should_be_active + has_scope :tagged_with, as: :tag + def index - search_and_load_members current_organization.members.active, { s: 'user_last_sign_in_at DESC' } + context = current_organization.members.active + members = apply_scopes(context) + + search_and_load_members members, { s: 'user_last_sign_in_at DESC' } end def manage diff --git a/app/decorators/member_decorator.rb b/app/decorators/member_decorator.rb index f08f33e5c..4902308c9 100644 --- a/app/decorators/member_decorator.rb +++ b/app/decorators/member_decorator.rb @@ -1,5 +1,5 @@ class MemberDecorator < ViewModel - delegate :user, :member_uid, :active?, to: :object + delegate :user, :member_uid, :tags, :active?, to: :object delegate :phone, :alt_phone, :username, :description, :last_sign_in_at, to: :user def manager? diff --git a/app/models/concerns/taggable.rb b/app/models/concerns/taggable.rb index 191b5e447..70f1c0aba 100644 --- a/app/models/concerns/taggable.rb +++ b/app/models/concerns/taggable.rb @@ -6,7 +6,7 @@ module Taggable extend ActiveSupport::Concern included do - scope :tagged_with, ->(tag) { where("? = ANY (posts.tags)", tag) } + scope :tagged_with, ->(tag) { where("? = ANY (#{table_name}.tags)", tag) } end def tag_list diff --git a/app/models/member.rb b/app/models/member.rb index e9a05215b..fe266aae6 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -1,9 +1,14 @@ class Member < ApplicationRecord + include Taggable # Cast the member_uid integer to a string to allow pg ILIKE search (from Ransack *_contains) ransacker :member_uid_search do Arel.sql("member_uid::text") end + ransacker :member_tags do + Arel.sql("array_to_string(tags, ',')") + end + belongs_to :user belongs_to :organization has_one :account, as: :accountable diff --git a/app/views/users/_member_card.html.erb b/app/views/users/_member_card.html.erb index d4e556498..e4263c41f 100644 --- a/app/views/users/_member_card.html.erb +++ b/app/views/users/_member_card.html.erb @@ -11,6 +11,17 @@ <% else %> <%= t('.no_activity') %> <% end %> + <% member.tags[0..2].each do |tag| %> + + <%= link_to users_path tag: tag do %> + <%= glyph :tag %> + <%= tag&.truncate(29) %> + <% end %> + + <% end %> + <% if member.tags.size > 3 %> + ... + <% end %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index b2e84ee80..4d956c408 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -14,7 +14,7 @@
<%= search_form_for(@search, class: "navbar-form navbar-left", url: users_path) do |f| %>
- <%= f.search_field :user_username_or_user_email_or_member_uid_search_contains, class: "form-control" %> + <%= f.search_field :user_username_or_user_email_or_member_tags_or_member_uid_search_contains, class: "form-control" %>
From 1b29acd751050f01a9cbfdd91629f7a3769ea595 Mon Sep 17 00:00:00 2001 From: franpb14 Date: Wed, 28 Apr 2021 17:15:52 +0200 Subject: [PATCH 08/14] feat: tags now have member-related autocompletion Member tags have also been added in the "Tags" section. Issue #623. --- app/assets/javascripts/application/tags.js | 26 +++++++++++++++++++++ app/controllers/tags_controller.rb | 21 ++++++++++------- app/models/member.rb | 1 + app/views/tags/alpha_grouped_index.html.erb | 4 ++++ app/views/users/_form.html.erb | 2 +- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/application/tags.js b/app/assets/javascripts/application/tags.js index d7341a03d..dd69488f6 100644 --- a/app/assets/javascripts/application/tags.js +++ b/app/assets/javascripts/application/tags.js @@ -7,6 +7,10 @@ $(function() { loadTags('inquiry'); }); + $(".switch_member-js").on("click", function() { + loadTags('user'); + }); + function loadTags(type){ $.get({ url: `/tags/alpha_grouped_index.js?post_type=${type}`, @@ -41,4 +45,26 @@ $(function() { } } }); + + $('#tags-js-members').select2({ + tags: true, + tokenSeparators: [','], + dataType: 'json', + delay: 250, + ajax: { + url: '/tags.json', + data: function(params) { + console.log(params); + return { term: params.term, member: "true" }; + }, + processResults: function(data, params) { + return { + results: $.map(data, item => ({ + id: item, + text: item + })) + }; + } + } + }); }); diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 339ad9411..063bee973 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -2,8 +2,9 @@ class TagsController < ApplicationController before_action :authenticate_user!, :member_should_be_active def index - posts = Post.by_organization(current_organization) - @all_tags = posts.find_like_tag(params[:term]) + model = params.key?(:member) ? Member : Post + model_organization = model.by_organization(current_organization) + @all_tags = model_organization.find_like_tag(params[:term]) render json: @all_tags end @@ -13,12 +14,10 @@ def alpha_grouped_index post_type = params[:post_type] || "offer" @alpha_tags = case post_type - when "offer" then Offer - when "inquiry" then Inquiry - end.by_organization(current_organization). - active.of_active_members. - alphabetical_grouped_tags - + when "offer" then post_tags Offer + when "inquiry" then post_tags Inquiry + when "user" then Member.by_organization(current_organization).active + end.alphabetical_grouped_tags respond_to do |format| format.html format.js do @@ -26,4 +25,10 @@ def alpha_grouped_index end end end + + private + + def post_tags(type) + type.by_organization(current_organization).active.of_active_members + end end diff --git a/app/models/member.rb b/app/models/member.rb index fe266aae6..1d5cd39fe 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -20,6 +20,7 @@ class Member < ApplicationRecord scope :by_month, -> (month) { where(created_at: month.beginning_of_month..month.end_of_month) } scope :active, -> { where active: true } + scope :by_organization, ->(org) { where(organization_id: org) if org } validates :organization_id, presence: true validates :member_uid, diff --git a/app/views/tags/alpha_grouped_index.html.erb b/app/views/tags/alpha_grouped_index.html.erb index 8c7cf58e7..25188351e 100644 --- a/app/views/tags/alpha_grouped_index.html.erb +++ b/app/views/tags/alpha_grouped_index.html.erb @@ -10,6 +10,10 @@ <%= radio_button_tag 'switch_inquiry', 'inquiry' %> <%= Inquiry.model_name.human count: :many %> + <% end %> diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index d11b9c121..6cf3e338f 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -27,7 +27,7 @@ options_for_select(@member.tags, @member.tags), multiple: true, data: { placeholder: t('application.tips.entertag')}, - id: "tags-js", + id: "tags-js-members", class: "form-control" %> From fe7b878f35be60e4d4fc690bc53092ea5ef47f5b Mon Sep 17 00:00:00 2001 From: franpb14 Date: Wed, 28 Apr 2021 17:24:38 +0200 Subject: [PATCH 09/14] feat: added tags to searcher in "/members/manage". #623 --- app/views/users/manage.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/manage.html.erb b/app/views/users/manage.html.erb index ef715a5a9..0bf95428f 100644 --- a/app/views/users/manage.html.erb +++ b/app/views/users/manage.html.erb @@ -14,7 +14,7 @@
<%= search_form_for(@search, class: "navbar-form navbar-left", url: manage_users_path) do |f| %>
- <%= f.search_field :user_username_or_user_email_or_user_phone_or_user_alt_phone_or_member_uid_search_contains, class: "form-control" %> + <%= f.search_field :user_username_or_user_email_or_user_phone_or_user_alt_phone_or_member_tags_or_member_uid_search_contains, class: "form-control" %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 4d956c408..a2600bbd9 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -14,7 +14,7 @@
<%= search_form_for(@search, class: "navbar-form navbar-left", url: users_path) do |f| %>
- <%= f.search_field :user_username_or_user_email_or_member_tags_or_member_uid_search_contains, class: "form-control" %> + <%= f.search_field :member_search_cont, class: "form-control" %>
diff --git a/app/views/tags/alpha_grouped_index.html.erb b/app/views/tags/alpha_grouped_index.html.erb index 25188351e..9c71acfa4 100644 --- a/app/views/tags/alpha_grouped_index.html.erb +++ b/app/views/tags/alpha_grouped_index.html.erb @@ -1,24 +1,22 @@ -

- <%= t '.maintitle' %> - <%= form_tag alpha_grouped_index_tags_path, method: :get do %> -
- - - -
- <% end %> -

+

<%= t '.maintitle' %>

+ +<%= form_tag alpha_grouped_index_tags_path, method: :get do %> +
+ + + +
+<% end %> +
- <%= render 'grouped_index', - alpha_tags: @alpha_tags, - post_type: params[:post_type] || 'offer' %> + <%= render 'grouped_index', alpha_tags: @tags, post_type: params[:post_type] || 'offer' %>
diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 414189f6d..39a845213 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -23,12 +23,12 @@ <%= f.input :postcode %> <%= label_tag :tag_list, t('activerecord.attributes.post.tag_list') %>
- <%= select_tag :tag_list, - options_for_select(@member.tags, @member.tags), - multiple: true, - data: { placeholder: t('application.tips.entertag'), member: "true"}, - id: "tags-js", - class: "form-control" %> + <%= select_tag :tag_list, + options_for_select(member.tags, member.tags), + multiple: true, + data: { placeholder: t("application.tips.entertag"), model: "member" }, + id: "tags-js", + class: "form-control" %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 75e1c9a56..55fb08316 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -3,4 +3,4 @@ <%= t ".edit_user" %> -<%= render "form" %> +<%= render "form", member: @user.as_member_of(current_organization) %> diff --git a/app/views/users/manage.html.erb b/app/views/users/manage.html.erb index 14c290a77..dfc08098c 100644 --- a/app/views/users/manage.html.erb +++ b/app/views/users/manage.html.erb @@ -14,7 +14,7 @@
<%= search_form_for(@search, class: "navbar-form navbar-left", url: manage_users_path) do |f| %>
- <%= f.search_field :member_manage_search_cont, class: "form-control" %> + <%= f.search_field :member_search_cont, class: "form-control" %>