Skip to content

Commit

Permalink
Use i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr committed Aug 21, 2024
1 parent b4ec9d7 commit 253d896
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
27 changes: 15 additions & 12 deletions app/domain/people/data_quality_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def initialize(person)
check_stammsektion if @person.roles.exists?(type: SacCas::STAMMSEKTION_ROLES)

if @person.company?
check("warning", "company_name", "ist leer", invalid: @person.company_name.blank?)
check("warning", "company_name", "empty", invalid: @person.company_name.blank?)
else
check("error", "first_name", "ist leer", invalid: @person.first_name.blank?)
check("error", "last_name", "ist leer", invalid: @person.last_name.blank?)
check("error", "first_name", "empty", invalid: @person.first_name.blank?)
check("error", "last_name", "empty", invalid: @person.last_name.blank?)
end

highest_severity = @person.data_quality_issues.order(severity: :desc).first&.severity
Expand All @@ -29,25 +29,28 @@ def initialize(person)
private

def check_invoice_recipient
check("error", "street", "ist leer", invalid: @person.street.blank?)
check("error", "zip_code", "ist leer", invalid: @person.zip_code.blank?)
check("error", "town", "ist leer", invalid: @person.town.blank?)
check("warning", "email", "ist leer", invalid: @person.email.blank?)
check("warning", "phone_numbers", "sind leer", invalid: @person.phone_numbers.blank?)
check("error", "street", "empty", invalid: @person.street.blank?)
check("error", "zip_code", "empty", invalid: @person.zip_code.blank?)
check("error", "town", "empty", invalid: @person.town.blank?)
check("warning", "email", "empty", invalid: @person.email.blank?)
check("warning", "phone_numbers", "empty", invalid: @person.phone_numbers.blank?)
end

def check_stammsektion
join_date = @person.roles.find_by(type: SacCas::STAMMSEKTION_ROLES).created_at

check("error", "birthday", "ist leer", invalid: @person.birthday.blank?)
check("warning", "birthday", "liegt weniger als 6 Jahre vor dem SAC-Eintritt",
check("error", "birthday", "empty", invalid: @person.birthday.blank?)
check("warning", "birthday", "less_than_6_years_before_entry",
invalid: @person.birthday.present? && (@person.birthday > join_date - 6.years))
end

def check(severity, attr, key, invalid: false)
if invalid
issue = @person.data_quality_issues.new(severity: severity, attr: attr, key: key)
issue.save! if issue.valid?
begin
@person.data_quality_issues.create!(severity: severity, attr: attr, key: key)
rescue
nil
end
else
@person.data_quality_issues.find_by(severity: severity, attr: attr, key: key)&.destroy!
end
Expand Down
4 changes: 3 additions & 1 deletion app/models/person/data_quality_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def severity=(value)

def message
I18n.t("activemodel.errors.models.person.data_quality_issue.message",
attr: Person.human_attribute_name(attr), key: key)
attr: Person.human_attribute_name(attr),
key: I18n.t(key, scope: "activemodel.errors.models.data_quality_issue.messages"),
default: key)
end

private
Expand Down
4 changes: 4 additions & 0 deletions config/locales/wagon.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ de:
person:
data_quality_issue:
message: "%{attr} %{key}"
data_quality_issue:
messages:
empty: ist leer
less_than_6_years_before_entry: liegt weniger als 6 Jahre vor dem SAC-Eintritt

wizards/steps/choose_sektion:
requires_admin: Wir bitten dich den gewünschten Sektionswechsel
Expand Down
2 changes: 1 addition & 1 deletion spec/models/person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def create_role(**attrs)
person.update!(email: nil)
end.to change(person.data_quality_issues, :count).by(2)
expect(person.data_quality_issues.map(&:message))
.to include("Telefonnummern sind leer", "Haupt-E-Mail ist leer")
.to include("Telefonnummern ist leer", "Haupt-E-Mail ist leer")
expect(person.data_quality).to eq("warning")
end
end
Expand Down

0 comments on commit 253d896

Please sign in to comment.