Compare commits

...

9 Commits

Author SHA1 Message Date
bilal
a1744d82d7 sort 2020-06-23 17:23:28 +02:00
bilal
c1c86183aa rebase 2020-06-23 17:16:39 +02:00
bilal
85af8cd03d fix MR comments 2020-06-23 17:15:58 +02:00
bilal
9772e3cffc fix MR comments 2020-06-23 17:15:58 +02:00
bilal
9b3ad29b82 fix MR comments 2020-06-23 17:15:58 +02:00
bilal
0c25c5b3e9 fix MR comments 2020-06-23 17:15:58 +02:00
bilal
e3f69f55b1 add spec 2020-06-23 17:15:31 +02:00
bilal
9c91d86e47 make second guardian fields not required 2020-06-23 17:15:31 +02:00
bilal
a6104b4563 add second guardian fields 2020-06-23 17:15:31 +02:00
14 changed files with 268 additions and 26 deletions

View File

@@ -51,10 +51,8 @@ $(document).on("turbolinks:load", function() {
$("[data-behavior=guardian-photo-preview]").each(function(index, element) {
App.PhotoPreview.init(element);
});
$("[data-behavior=take-person-photo]").click(function(e) {
$("[data-ujs-target=person-photo-input]").trigger("click");
});
$("[data-behavior=take-guardian-photo]").click(function(e) {
$("[data-ujs-target=guardian-photo-input]").trigger("click");
$("[data-behavior=trigger-click]").click(function(e) {
const target = $(this).data("target");
$(target).trigger("click");
});
});

View File

@@ -71,8 +71,25 @@ class Public::AppearanceReleasesController < Public::BaseController
]
end
def second_guardian_params
%i[
guardian_2_first_name
guardian_2_last_name
guardian_2_phone
guardian_2_email
guardian_2_photo
guardian_2_address_street1
guardian_2_address_street2
guardian_2_address_city
guardian_2_address_state
guardian_2_address_zip
guardian_2_address_country
]
end
def appearance_release_params
params.require(:appearance_release).permit(person_params, guardian_params,
second_guardian_params,
:minor, :signature_base64,
:person_date_of_birth,
:locale, :contract_template)

View File

@@ -12,7 +12,9 @@ class AppearanceRelease < ApplicationRecord
include Taggable
include PersonName
include GuardianPhotoable
include SecondGuardianPhotoable
include GuardianName
include SecondGuardianName
has_one_attached :person_photo
@@ -38,6 +40,17 @@ class AppearanceRelease < ApplicationRecord
%w[guardian_address_country country]
]
composed_of :guardian_2_address,
class_name: 'Address',
mapping: [
%w[guardian_2_address_street1 street1],
%w[guardian_2_address_street2 street2],
%w[guardian_2_address_city city],
%w[guardian_2_address_state state],
%w[guardian_2_address_zip zip],
%w[guardian_2_address_country country]
]
# These validations apply to all releases
validates :person_email, email: true, allow_blank: true
@@ -132,6 +145,10 @@ class AppearanceRelease < ApplicationRecord
true
end
def second_guardian_present?
self.guardian_2_first_name.present?
end
def contract_file_name
"#{project.name.parameterize}_#{contract_template.release_type}_#{(signed_at || created_at).strftime('%Y.%m.%d')}_#{release_number}_#{filename_suffix.parameterize}"
end

View File

@@ -0,0 +1,20 @@
module SecondGuardianName
extend ActiveSupport::Concern
included do
def guardian_2_name
"#{guardian_2_first_name} #{guardian_2_last_name}".titleize
end
def guardian_2_name=(value)
if value.include?(' ')
split = value.split(" ", 2)
self.guardian_2_first_name = split.first
self.guardian_2_last_name = split.last
else
self.guardian_2_first_name = value
self.guardian_2_last_name = "(Not Given)"
end
end
end
end

View File

@@ -0,0 +1,9 @@
module SecondGuardianPhotoable
extend ActiveSupport::Concern
included do
has_one_attached :guardian_2_photo
validates :guardian_2_photo, content_type: ["image/png", "image/jpeg"]
end
end

View File

@@ -5,6 +5,9 @@
<% if release.respond_to? :guardian_photo %>
<% @total_photos_count += release.guardian_photo.attached? ? 1 : 0 %>
<% end %>
<% if release.respond_to? :guardian_2_photo %>
<% @total_photos_count += release.guardian_2_photo.attached? ? 1 : 0 %>
<% end %>
<p class="heading"><strong><u><%= t '.heading', count: @total_photos_count %></u></strong></p>
<ul>
@@ -29,6 +32,14 @@
<%= release.guardian_photo.filename.to_s %>
</li>
<% end %>
<% if release.respond_to?(:guardian_2_photo) && release.guardian_2_photo.attached? %>
<br>
<p class="heading"><strong><%= t '.guardian_2_photo_heading' %></strong></p>
<li>
<%= image_tag release.guardian_2_photo.variant(auto_orient: true, resize: "200x200") %><br />
<%= release.guardian_2_photo.filename.to_s %>
</li>
<% end %>
<% end %>
</ul>

View File

@@ -69,4 +69,19 @@
<%= description_list_pair_for releasable, :signed_on, append: ":" %>
</dl>
<% if releasable.respond_to?(:second_guardian_present?) && releasable.second_guardian_present? %>
<br/>
<p class="text-left"><strong>Second guardian Information</strong></p>
<% # Second guardian information %>
<dl>
<%= description_list_pair_for releasable, :guardian_2_name, append: ":" %>
<%= description_list_pair_for releasable, :guardian_2_address, append: ":" %>
<%= description_list_pair_for releasable, :guardian_2_phone, append: ":" %>
<%= description_list_pair_for releasable, :guardian_2_email, append: ":" %>
</dl>
<% end %>
<% end %>

View File

@@ -57,7 +57,7 @@
<%= form.hidden_field :person_photo, value: form.object.person_photo.signed_id if @appearance_release.person_photo.attached? %>
<%= form.file_field :person_photo, hide_label: true, data: { ujs_target: "person-photo-input" }, accept: @appearance_release.class.face_photo_acceptable_content_types.join(","), direct_upload: true %>
</div>
<%= button_tag t(".photo.take_photo"), type: "button", class: "btn btn-lg btn-primary take-photo-button", data: { behavior: "take-person-photo" } %>
<%= button_tag t(".photo.take_photo"), type: "button", class: "btn btn-lg btn-primary take-photo-button", data: { behavior: "trigger-click", target: "[data-ujs-target=person-photo-input]" } %>
</div>
<p class="p-2 font-weight-bold">
<%= fa_icon "arrow-up", text: t(".photo.camera_instructions_html") %><br>
@@ -75,8 +75,6 @@
<%= form.text_field :guardian_first_name, required: @appearance_release.minor?, wrapper_class: "col-sm-3" %>
<%= form.text_field :guardian_last_name, required: @appearance_release.minor?, wrapper_class: "col-sm-3" %>
<%= form.phone_field :guardian_phone, required: @appearance_release.minor?, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.text_field :guardian_email, required: @appearance_release.minor?, wrapper_class: "col-sm-6" %>
</div>
<%= render "shared/address_fields", form: form, subject: "guardian", required: @appearance_release.minor? %>
@@ -102,7 +100,48 @@
<%= form.hidden_field :guardian_photo, value: form.object.guardian_photo.signed_id if @appearance_release.guardian_photo.attached? %>
<%= form.file_field :guardian_photo, required: @appearance_release.minor?, hide_label: true, data: { ujs_target: "guardian-photo-input" }, accept: @appearance_release.class.face_photo_acceptable_content_types.join(","), direct_upload: true %>
</div>
<%= button_tag t(".photo.take_photo"), type: "button", class: "btn btn-lg btn-primary take-photo-button", data: { behavior: "take-guardian-photo" } %>
<%= button_tag t(".photo.take_photo"), type: "button", class: "btn btn-lg btn-primary take-photo-button", data: { behavior: "trigger-click", target: "[data-ujs-target=guardian-photo-input]" } %>
</div>
<p class="p-2 font-weight-bold">
<%= fa_icon "arrow-up", text: t(".photo.camera_instructions_html") %><br>
<small class="text-muted"><%= t ".photo.warning" %></small>
</p>
</div>
<% end %>
<hr>
<%= card_field_set_tag t(".guardian_2_info.heading") do %>
<div class="form-row">
<%= form.text_field :guardian_2_first_name, wrapper_class: "col-sm-3" %>
<%= form.text_field :guardian_2_last_name, wrapper_class: "col-sm-3" %>
<%= form.phone_field :guardian_2_phone, wrapper_class: "col-sm-6" %>
<%= form.text_field :guardian_2_email, wrapper_class: "col-sm-6" %>
</div>
<%= render "shared/address_fields", form: form, subject: "guardian_2" %>
<% end %>
<hr>
<%= card_field_set_tag t(".guardian_2_photo.heading") do %>
<div class="alert alert-warning font-weight-bold"><%= t ".guardian_2_photo.instructions" %></div>
<div class="text-center">
<div class="d-inline-block mb-2" data-behavior="guardian-photo-preview" data-file-input="[data-ujs-target=guardian-2-photo-input]">
<div class="align-items-center d-flex photo-preview img-thumbnail justify-content-center">
<span><%= t ".photo.no_photo" %></span>
</div>
</div>
<div class="d-inline-block text-left">
<% if @appearance_release.guardian_2_photo.attached? %>
<%= javascript_tag nonce: true do %>
App.PhotoPreview.set("[data-behavior=guardian-photo-preview]", "<%= url_for(@appearance_release.guardian_2_photo.variant(auto_orient: true, resize: '200x200')) %>");
<% end %>
<% end %>
<div class="hidden-file-input">
<%= form.hidden_field :guardian_2_photo, value: form.object.guardian_2_photo.signed_id if @appearance_release.guardian_2_photo.attached? %>
<%= form.file_field :guardian_2_photo, hide_label: true, data: { ujs_target: "guardian-2-photo-input" }, accept: @appearance_release.class.face_photo_acceptable_content_types.join(","), direct_upload: true %>
</div>
<%= button_tag t(".photo.take_photo"), type: "button", class: "btn btn-lg btn-primary take-photo-button", data: { behavior: "trigger-click", target: "[data-ujs-target=guardian-2-photo-input]" } %>
</div>
<p class="p-2 font-weight-bold">
<%= fa_icon "arrow-up", text: t(".photo.camera_instructions_html") %><br>

View File

@@ -78,7 +78,7 @@
<%= form.hidden_field :guardian_photo, value: form.object.guardian_photo.signed_id if @talent_release.guardian_photo.attached? %>
<%= form.file_field :guardian_photo, hide_label: true, data: { ujs_target: "guardian-photo-input" }, accept: @talent_release.class.face_photo_acceptable_content_types.join(","), direct_upload: true %>
</div>
<%= button_tag t(".guardian_photo.take_photo"), type: "button", class: "btn btn-lg btn-primary take-photo-button", data: { behavior: "take-guardian-photo" } %>
<%= button_tag t(".guardian_photo.take_photo"), type: "button", class: "btn btn-lg btn-primary take-photo-button", data: { behavior: "trigger-click", target: "[data-ujs-target=guardian-photo-input]" } %>
</div>
<p class="p-2 font-weight-bold">
<%= fa_icon "arrow-up", text: t(".guardian_photo.camera_instructions_html") %><br>

View File

@@ -60,6 +60,10 @@ en:
activerecord:
attributes:
appearance_release:
guardian_2_address: Guardian 2 address
guardian_2_email: Guardian 2 email
guardian_2_name: Guardian 2 name
guardian_2_phone: Guardian 2 phone
person_address: Address
person_email: Email
person_name: Name
@@ -237,6 +241,7 @@ en:
heading: New Release Template
contracts:
photos:
guardian_2_photo_heading: Second guardian photo
guardian_photo_heading: Guardian photo
heading:
one: Photo
@@ -328,6 +333,16 @@ en:
person_phone: Phone number
person_title: Title
appearance_release:
guardian_2_address_city: Guardian 2 city
guardian_2_address_country: Guardian 2 country
guardian_2_address_state: Guardian 2 state
guardian_2_address_street1: Guardian 2 address
guardian_2_address_street2: Guardian 2 address (Line 2)
guardian_2_address_zip: Guardian 2 zip code
guardian_2_email: Guardian 2 email
guardian_2_first_name: Guardian 2 first name
guardian_2_last_name: Guardian 2 last name
guardian_2_phone: Guardian 2 phone
guardian_address_city: Guardian city
guardian_address_country: Guardian country
guardian_address_state: Guardian state
@@ -802,6 +817,12 @@ en:
notice: Your release has been signed. Thank you!
new:
cancel: Cancel
guardian_2_info:
heading: Second Guardian Information (if company requires)
guardian_2_photo:
heading: Second Guardian Photo
instructions: >
Lastly, it's time for second guardian to take a selfie photo! Please remove your hat and sunglasses (regular eyewear is ok), make sure that you are the only person in the photo, look straight into the camera, and say Cheese!
guardian_clause:
heading: Guardian Clause
guardian_info:

View File

@@ -66,6 +66,7 @@ es:
heading: Release Info (ES)
contracts:
photos:
guardian_2_photo_heading: Second guardian photo (ES)
guardian_photo_heading: Guardian photo (ES)
heading:
one: Photo (ES)
@@ -115,6 +116,16 @@ es:
helpers:
label:
appearance_release:
guardian_2_address_city: Second guardian city (ES)
guardian_2_address_country: Second guardian country (ES)
guardian_2_address_state: Second guardian state (ES)
guardian_2_address_street1: Second guardian address (ES)
guardian_2_address_street2: Second guardian address (Line 2) (ES)
guardian_2_address_zip: Second guardian zip code (ES)
guardian_2_email: Second guardian email (ES)
guardian_2_first_name: Second guardian first name (ES)
guardian_2_last_name: Second guardian last name (ES)
guardian_2_phone: Second guardian phone (ES)
guardian_address_city: Guardian city (ES)
guardian_address_country: Guardian country (ES)
guardian_address_state: Guardian state (ES)
@@ -167,6 +178,12 @@ es:
notice: La autorización está firmada. ¡Gracias!
new:
cancel: Cancelar
guardian_2_info:
heading: Second Guardian Information (ES)
guardian_2_photo:
heading: Second Guardian Photo (ES)
instructions: >
(ES) Lastly, it's time for second guardian to take a selfie photo! Please remove your hat and sunglasses (regular eyewear is ok), make sure that you are the only person in the photo, look straight into the camera, and say Cheese! (ES)
guardian_clause:
heading: Guardian Clause (ES)
guardian_photo:

View File

@@ -0,0 +1,14 @@
class AddSecondGuardianFieldsToAppearanceReleases < ActiveRecord::Migration[6.0]
def change
add_column :appearance_releases, :guardian_2_first_name, :string
add_column :appearance_releases, :guardian_2_last_name, :string
add_column :appearance_releases, :guardian_2_email, :string
add_column :appearance_releases, :guardian_2_phone, :string
add_column :appearance_releases, :guardian_2_address_street1, :string
add_column :appearance_releases, :guardian_2_address_street2, :string
add_column :appearance_releases, :guardian_2_address_city, :string
add_column :appearance_releases, :guardian_2_address_state, :string
add_column :appearance_releases, :guardian_2_address_zip, :string
add_column :appearance_releases, :guardian_2_address_country, :string
end
end

View File

@@ -9,20 +9,6 @@ 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: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: -
--
@@ -342,7 +328,17 @@ CREATE TABLE public.appearance_releases (
guardian_address_city character varying,
guardian_address_state character varying,
guardian_address_zip character varying,
guardian_address_country character varying
guardian_address_country character varying,
guardian_2_first_name character varying,
guardian_2_last_name character varying,
guardian_2_email character varying,
guardian_2_phone character varying,
guardian_2_address_street1 character varying,
guardian_2_address_street2 character varying,
guardian_2_address_city character varying,
guardian_2_address_state character varying,
guardian_2_address_zip character varying,
guardian_2_address_country character varying
);
@@ -3793,6 +3789,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200615133602'),
('20200616124214'),
('20200619081446'),
('20200619085823');
('20200619085823'),
('20200619134853');

View File

@@ -72,6 +72,61 @@ feature 'User managing appearance releases' do
expect(page).to have_content(successful_submission_message)
end
scenario 'creating a release for a minor with two guardians', js: true do
allow(BrayniacAI::Validation).to receive(:create).and_return(double(:validation, valid: true))
project = create(:project, members: current_user, account: current_user.primary_account)
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_appearance_release_path(project.account, project, contract_template)
expect(page).to have_photo_button
expect(page).not_to have_content('SECOND GUARDIAN INFORMATION')
expect(page).not_to have_content('SECOND GUARDIAN PHOTO')
page.check person_is_minor_checkbox
expect(page).to have_content('GUARDIAN INFORMATION')
expect(page).to have_content('GUARDIAN PHOTO')
expect(page).to have_content 'Guardian Email'
expect(page).to have_content 'SECOND GUARDIAN INFORMATION'
expect(page).to have_content 'SECOND GUARDIAN PHOTO'
expect(page).to have_content 'Guardian 2 Email'
expect(page).to have_content 'Guardian 2 Phone'
expect(page).to have_content 'Guardian 2 Address'
fill_in guardian_first_name_field, with: 'Guardian'
fill_in guardian_last_name_field, with: 'Name'
fill_in guardian_phone_field, with: '001101'
fill_in person_first_name_field, with: 'Jane'
fill_in person_last_name_field, with: 'Doe'
fill_in_person_address_fields
fill_in person_phone_field, with: '555-555-5555'
fill_in person_email_field, with: 'jane.doe@test.com'
fill_in person_date_of_birth, with: '01/01/1999'
attach_file person_photo_field, file_fixture('person_photo.png'), visible: :all
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
draw_signature file_fixture('signature.png'), 'appearance_release_signature_base64'
fill_in guardian_email_field, with: 'invalid@email'
click_button submit_release_button
expect(page).to have_content('Guardian email is not an email')
fill_in guardian_email_field, with: 'valid@email.com'
fill_in_guardian_address_fields
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
draw_signature file_fixture('signature.png'), 'appearance_release_signature_base64'
fill_in guardian_2_first_name_field, with: 'Second'
fill_in guardian_2_last_name_field, with: 'Guardian'
fill_in guardian_2_phone_field, with: '999'
click_button submit_release_button
expect(page).to have_content(successful_submission_message)
expect(AppearanceRelease.last.guardian_2_first_name).to eq 'Second'
end
end
context 'when signed in' do
@@ -454,6 +509,18 @@ feature 'User managing appearance releases' do
'appearance_release_minor'
end
def guardian_2_first_name_field
'Guardian 2 first name'
end
def guardian_2_last_name_field
'Guardian 2 last name'
end
def guardian_2_phone_field
'Guardian 2 phone'
end
def guardian_first_name_field
'Guardian first name'
end