Skip to content
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

feat: Disable Email from Extended Authorization Handler form #77

Closed
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
49 changes: 49 additions & 0 deletions app/services/extended_socio_demographic_authorization_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

# Allows to create a form for simple Socio Demographic authorization
class ExtendedSocioDemographicAuthorizationHandler < Decidim::AuthorizationHandler
attribute :last_name, String
attribute :usual_last_name, String
attribute :first_name, String
attribute :usual_first_name, String
attribute :birth_date, Date
attribute :address, String
attribute :postal_code, String
attribute :city, String
attribute :certification, Boolean
attribute :news_cese, Boolean

validates :last_name, presence: true
validates :first_name, presence: true
validates :birth_date, presence: true
validates :address, presence: true
validates :postal_code, numericality: { only_integer: true }, presence: true, length: { is: 5 }
validates :city, presence: true
validates :certification, acceptance: true, presence: true

validate :over_16?

def metadata
super.merge(
last_name: last_name,
usual_last_name: usual_last_name,
first_name: first_name,
usual_first_name: usual_first_name,
address: address,
postal_code: postal_code,
city: city,
birth_date: birth_date,
certification: certification,
news_cese: news_cese
)
end

private

def over_16?
return if birth_date.blank?
return true if birth_date < 16.years.ago.to_date

errors.add :birth_date, I18n.t("extended_socio_demographic_authorization.errors.messages.over_16")
end
end
74 changes: 74 additions & 0 deletions app/views/extended_socio_demographic_authorization/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<%= hidden_field :authorization_handler, :handler_name, value: "extended_socio_demographic_authorization_handler" %>

<div class="card-section">
<div class="row">
<div class="columns medium-6">
<div class="field">
<%= form.text_field :first_name, minlength: 1, pattern: "[A-Za-z]+", autocomplete: "given-name", label: t(".name") %>
</div>
</div>
<div class="columns medium-6">
<div class="field">
<%= form.text_field :last_name, minlength: 1, pattern: "[A-Za-z]+", autocomplete: "given-name", label: t(".lastname") %>
</div>
</div>
</div>
<div class="row">
<div class="columns medium-6">
<div class="field">
<%= form.text_field :usual_first_name, pattern: "[A-Za-z]+", autocomplete: "family-name", label: t(".usual_firstname") %>
</div>
</div>
<div class="columns medium-6">
<div class="field">
<%= form.text_field :usual_last_name, pattern: "[A-Za-z]+", autocomplete: "family-name", label: t(".usual_lastname") %>
</div>
</div>
</div>

<div class="row">
<div class="columns medium-12">
<%= form.date_select :birth_date, {label: t(".birth_date"), start_year: Date.today.year - 120, end_year: Date.today.year }, { class: "columns medium-3" } %>
</div>
<div class="columns margin-bottom-1 postal_code_help">
<small><em><%= t(".birth_date_help") %></em></small>
</div>
</div>

<div class="field">
<%= form.text_field :address, autocomplete: "street-address", label: t(".address") %>
</div>

<div class="row">
<div class="columns medium-4">
<div class="field">
<%= form.text_field :postal_code, pattern: "^[0-9]+$", minlength: 5, maxlength: 5, autocomplete: "postal-code", label: t(".code") %>
</div>
</div>
<div class="columns medium-8">
<div class="field">
<%= form.text_field :city, label: t(".city") %>
</div>
</div>

<div class="columns margin-bottom-1 postal_code_help">
<small><em><%= t(".postal_code.help_message") %></em></small>
</div>
</div>

<div class="row">
<div class="columns">
<div class="field">
<%= form.check_box :certification, label: t(".certification") %>
</div>
</div>
<div class="columns">
<div class="field">
<%== form.check_box :news_cese, label: t(".news_cese") %>
</div>
</div>
</div>
</div>

<%= javascript_pack_tag "extended_socio_demographic_authorization_handler" %>
<%= stylesheet_pack_tag "extended_socio_demographic_css" %>
22 changes: 20 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ en:
verifications:
authorizations:
create:
error: Error
success: Success
error: There was a problem creating the authorization.
success: You've been successfully authorized
first_login:
actions:
osp_authorization_handler: Verify with the identity verification form
Expand Down Expand Up @@ -225,6 +225,24 @@ en:
shared:
links:
forgot_your_password: Forgot your password
extended_socio_demographic_authorization:
errors:
messages:
over_16: You must be over 16 years old to access this service.
form:
address: Address
birth_date: Date of birth
birth_date_help: You must be over 16 years old to access this service.
certification: Certification CESE
city: City
code: Postal code
lastname: Last name
name: First name
news_cese: Do you want to receive news from CESE ?
postal_code:
help_message: Please fill the postal code field to be able to select your city
usual_firstname: Usual first name
usual_lastname: Usual last name
faker:
address:
country_code:
Expand Down
18 changes: 18 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,24 @@ fr:
shared:
links:
forgot_your_password: Mot de passe oublié ?
extended_socio_demographic_authorization:
errors:
messages:
over_16: Vous devez avoir plus de 16 ans pour accéder à ce service.
form:
address: Addresse
birth_date: Date de naissance
birth_date_help: Vous devez avoir plus de 16 ans pour avoir accès à ce service.
certification: Certification CESE
city: Ville
code: Code postal
lastname: Nom
name: Prénom
news_cese: Souhaitez-vous recevoir les actualités du CESE ?
postal_code:
help_message: Veuillez renseigner votre code postal pour choisir la ville
usual_firstname: Prénom d'usage
usual_lastname: Nom d'usage
faker:
address:
country_code:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# frozen_string_literal: true

require "spec_helper"

describe ExtendedSocioDemographicAuthorizationHandler do
subject do
described_class.new(
last_name: last_name,
usual_last_name: usual_last_name,
first_name: first_name,
usual_first_name: usual_first_name,
address: address,
postal_code: postal_code,
city: city,
birth_date: birth_date,
certification: certification,
news_cese: news_cese
)
end

let(:user) { create(:user) }

let(:organization) { user.organization }

let(:last_name) { "Doe" }
let(:usual_last_name) { "Smith" }
let(:first_name) { "John" }
let(:usual_first_name) { "Jack" }
let(:address) { "21 Jump Street" }
let(:postal_code) { "75018" }
let(:city) { "Nowhere" }
let(:birth_date) { 20.years.ago.to_date }
let(:certification) { true }
let(:news_cese) { true }

context "when the information is valid" do
it "is valid" do
expect(subject).to be_valid
end
end

context "when name is nil" do
let(:last_name) { nil }

it "is invalid" do
expect(subject).to be_invalid
end
end

context "when first name is nil" do
let(:first_name) { nil }

it "is invalid" do
expect(subject).to be_invalid
end
end

context "with postal code" do
context "and nil" do
let(:postal_code) { nil }

it "is invalid" do
expect(subject).to be_invalid
end
end

context "and not a number" do
let(:postal_code) { "Some string" }

it "is invalid" do
expect(subject).to be_invalid
end
end

context "and length inferior than 5 chars" do
let(:postal_code) { "1234" }

it "is invalid" do
expect(subject).to be_invalid
end
end

context "and length greater than 5 chars" do
let(:postal_code) { "123456" }

it "is invalid" do
expect(subject).to be_invalid
end
end
end

context "when city is nil" do
let(:city) { nil }

it "is invalid" do
expect(subject).to be_invalid
end
end

context "when certification is unchecked" do
let(:certification) { "0" }

it "is invalid" do
expect(subject).to be_invalid
end
end

context "when birthdate is nil" do
let(:birth_date) { nil }

it "is invalid" do
expect(subject).to be_invalid
end
end

context "when the person is too young" do
let(:birth_date) { 14.years.ago.to_date }

it "is invalid" do
expect(subject).to be_invalid
end
end
end
Loading
Loading