Skip to content

[NZ changes] reset password fixes, translatable terms, Inquiry -> Request, max hours in transfers removed #678

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ gem 'has_scope', '~> 0.7.2'
gem 'pundit', '~> 2.1.0'
gem 'pg', '~> 1.4'
gem 'json_translate', '~> 4.0.0'
gem 'devise', '~> 4.7.1'
gem 'devise', '~> 4.9.1'
gem 'devise-i18n', '~> 1.11.0'
gem 'http_accept_language', '~> 2.1.1'
gem 'unicorn', '~> 5.5.1'
gem 'kaminari', '~> 1.2.1'
Expand Down
9 changes: 6 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ GEM
aws-sigv4 (~> 1.1)
aws-sigv4 (1.2.3)
aws-eventstream (~> 1, >= 1.0.2)
bcrypt (3.1.16)
bcrypt (3.1.18)
bindex (0.8.1)
bootsnap (1.12.0)
msgpack (~> 1.2)
Expand Down Expand Up @@ -131,12 +131,14 @@ GEM
crass (1.0.6)
database_cleaner (1.8.5)
date (3.3.3)
devise (4.7.3)
devise (4.9.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
devise-i18n (1.11.0)
devise (>= 4.9.0)
diff-lcs (1.4.4)
docile (1.3.5)
domain_name (0.5.20190701)
Expand Down Expand Up @@ -451,7 +453,8 @@ DEPENDENCIES
capistrano-rbenv (~> 2.1)
capybara (~> 3.29)
database_cleaner (~> 1.8.5)
devise (~> 4.7.1)
devise (~> 4.9.1)
devise-i18n (~> 1.11.0)
dotenv-rails (~> 2.7.1)
fabrication (~> 2.20)
faker (~> 2.15)
Expand Down
5 changes: 1 addition & 4 deletions app/admin/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
row :updated_at
row :icon_name
row :name_translations do
cat.name_translations.map do |locale, translation|
tag.strong("#{I18n.t("locales.#{locale}", locale: locale)}: ") +
tag.span(translation)
end.join(" | ").html_safe
render_translations(cat.name_translations)
end
end
end
Expand Down
14 changes: 9 additions & 5 deletions app/admin/document.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ActiveAdmin.register Document do
permit_params *Document.attribute_names
permit_params :label, :title, :content

index do
id_column
Expand All @@ -16,16 +16,20 @@
t.documentable
end
row :label
row :title
row :content
row :title_translations do
render_translations(t.title_translations)
end
row :content_translations do
render_translations(t.content_translations, "<br>")
end
end
end

form do |f|
f.inputs do
f.input :label
f.input :title, as: :string
f.input :content
f.input :title, as: :text
f.input :content, as: :text
end
f.actions
end
Expand Down
3 changes: 2 additions & 1 deletion app/admin/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ def destroy
filter :city, as: :select, collection: -> { Organization.pluck(:city).uniq }
filter :neighborhood

permit_params *Organization.attribute_names
permit_params :name, :email, :web, :phone, :city, :neighborhood,
:address, :description, :public_opening_times
end
3 changes: 2 additions & 1 deletion app/admin/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
f.actions
end

permit_params :type, :tag_list, *Post.attribute_names
permit_params :type, :tag_list, :title, :category_id, :user_id,
:description, :organization_id, :active, :is_group

filter :type, as: :select, collection: -> { Post.subclasses }
filter :id
Expand Down
4 changes: 2 additions & 2 deletions app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@
end
end

permit_params *User.attribute_names,
members_attributes: Member.attribute_names
permit_params :username, :email, :phone, :postcode, :gender,
members_attributes: [:organization_id, :active, :manager]
end
8 changes: 8 additions & 0 deletions app/helpers/active_admin_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module ActiveAdminHelper
def render_translations(attribute, joiner = " | ")
attribute.map do |locale, translation|
tag.strong("#{I18n.t("locales.#{locale}", locale: locale)}: ") +
tag.span(translation)
end.join(joiner).html_safe
end
end
2 changes: 2 additions & 0 deletions app/models/document.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Document < ApplicationRecord
belongs_to :documentable, polymorphic: true, optional: true

translates :title, :content

def self.terms_and_conditions
where(label: "t&c", documentable_id: nil).first
end
Expand Down
5 changes: 0 additions & 5 deletions app/views/devise/mailer/confirmation_instructions.ca.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/devise/mailer/confirmation_instructions.es.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/devise/mailer/confirmation_instructions.html.erb

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions app/views/devise/mailer/reset_password_instructions.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/devise/mailer/unlock_instructions.ca.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/devise/mailer/unlock_instructions.es.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/devise/mailer/unlock_instructions.html.erb

This file was deleted.

4 changes: 1 addition & 3 deletions app/views/multi_transfers/steps/_set_params.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
input_html: {
value: @transfer_hours,
min: 0,
max: 20,
"data-rule-either-hours-minutes-informed" => "true",
"data-rule-range" => "[0,20]"
"data-rule-either-hours-minutes-informed" => "true"
} %>
<%= f.input :minutes,
required: false,
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_post.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<div class="col-md-9 lead">
<div class="panel panel-info break-word">
<div class="panel-body post-description">
<%= m post.rendered_description.to_html.html_safe %>
<%= m post.rendered_description.to_html %>
</div>
</div>
</div>
Expand Down
4 changes: 1 addition & 3 deletions app/views/transfers/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
as: :integer,
input_html: {
min: 0,
max: 20,
"data-rule-either-hours-minutes-informed" => "true",
"data-rule-range" => "[0,20]"
"data-rule-either-hours-minutes-informed" => "true"
} %>
<%= f.input :minutes,
as: :integer,
Expand Down
16 changes: 8 additions & 8 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ en:
created_at: Created
updated_at: Updated
inquiry:
is_group: Group inquiry
is_group: Group request
offer:
is_group: Group offer
organization:
Expand Down Expand Up @@ -95,8 +95,8 @@ en:
one: Comment
other: Comments
inquiry:
one: Inquiry
other: Inquiries
one: Request
other: Requests
offer:
one: Offer
other: Offers
Expand Down Expand Up @@ -137,7 +137,7 @@ en:
demographics: Demographics data
global_activity: Global activity
inactive_users: Inactive users
inquiry_public_link: Inquiries public link
inquiry_public_link: Requests public link
last_login: Last login
offer_public_link: Offers public link
organizations: Organizations
Expand Down Expand Up @@ -305,11 +305,11 @@ en:
to: To
inquiries:
edit:
submit: Change inquiry
submit: Change request
index:
new_inquiry: New inquiry
new_inquiry: New request
new:
submit: Create inquiry
submit: Create request
layouts:
application:
about: About TimeOverflow
Expand Down Expand Up @@ -440,7 +440,7 @@ en:
delete_reason: Are you sure to delete this comment?
movements: Movements
post_form:
group_inquiry: Is it a group inquiry?
group_inquiry: Is it a group request?
group_offer: Is it a group offer?
you_can_use: You can use
simple_form:
Expand Down
21 changes: 21 additions & 0 deletions db/migrate/20230401114456_make_terms_translatable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class MakeTermsTranslatable < ActiveRecord::Migration[6.1]
def up
add_column :documents, :title_translations, :jsonb, default: {}, null: false
add_column :documents, :content_translations, :jsonb, default: {}, null: false
Document.find_each do |doc|
doc.update_columns(title_translations: { es: doc[:title] }, content_translations: { es: doc[:content] })
end
remove_column :documents, :title
remove_column :documents, :content
end

def down
add_column :documents, :title, :text
add_column :documents, :content, :text
Document.find_each do |doc|
doc.update_columns(title: doc.title_translations["es"], content: doc.content_translations["es"])
end
remove_column :documents, :title_translations
remove_column :documents, :content_translations
end
end
9 changes: 5 additions & 4 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ CREATE TABLE public.documents (
id integer NOT NULL,
documentable_id integer,
documentable_type character varying,
title text,
content text,
label character varying,
created_at timestamp without time zone,
updated_at timestamp without time zone
updated_at timestamp without time zone,
title_translations jsonb DEFAULT '{}'::jsonb NOT NULL,
content_translations jsonb DEFAULT '{}'::jsonb NOT NULL
);


Expand Down Expand Up @@ -1367,6 +1367,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210503201944'),
('20221016192111'),
('20230312231058'),
('20230314233504');
('20230314233504'),
('20230401114456');


8 changes: 8 additions & 0 deletions spec/helpers/active_admin_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RSpec.describe ActiveAdminHelper do
describe '#render_translations' do
it 'renders hash to HTML' do
attr_with_translations = { en: 'hi', es: 'hola' }
expect(helper.render_translations(attr_with_translations)).to eq("<strong>English: </strong><span>hi</span> | <strong>Español: </strong><span>hola</span>")
end
end
end