diff --git a/app/controllers/public/amendments_controller.rb b/app/controllers/public/amendments_controller.rb new file mode 100644 index 0000000..7a214d3 --- /dev/null +++ b/app/controllers/public/amendments_controller.rb @@ -0,0 +1,44 @@ +class Public::AmendmentsController < Public::BaseController + skip_after_action :verify_authorized, :verify_policy_scoped + before_action :set_account, :set_project, :set_contract_template, :set_release + + def new + if @release.amendment_signed? + render :create, locals: { already_signed: true } + end + end + + def create + @release.amendment_signer_name = release_params[:amendment_signer_name] + @release.amendment_signature_base64 = release_params[:amendment_signature_base64] + render :new unless @release.save + end + + private + + def release_params + release_type = @contract_template.release_type + param_name = "#{release_type}_release".to_s + params.require(param_name).permit(:amendment_signer_name, :amendment_signature_base64) + end + + def set_release + release_type = @contract_template.release_type + param_name = "#{release_type}_release_id".to_s + release_id = params[param_name] + + @release = @contract_template.releases.find(release_id) + end + + def set_contract_template + @contract_template = @project.contract_templates.find(params[:contract_template_id]) + end + + def set_project + @project = @account.projects.find(params[:project_id]) + end + + def set_account + @account = Account.find_by(slug: params[:account_id]) + end +end \ No newline at end of file diff --git a/app/models/concerns/amendmenable.rb b/app/models/concerns/amendmenable.rb new file mode 100644 index 0000000..9f03b3d --- /dev/null +++ b/app/models/concerns/amendmenable.rb @@ -0,0 +1,27 @@ +module Amendmenable + extend ActiveSupport::Concern + + included do + include ActiveStorageSupport::SupportForBase64 + + has_one_base64_attached :amendment_signature + end + + def amendment_signable? + contract_template.amendment_clause.present? + end + + def amendment_signed? + amendment_signature.attached? + end + + def amendment_signature_base64 + nil + end + + def amendment_signature_base64=(data_uri) + return if data_uri.blank? + + amendment_signature.attach(data: data_uri, filename: "amendment_signature.png", content_type: "image/png", identify: "false") + end +end diff --git a/app/models/location_release.rb b/app/models/location_release.rb index f6063e8..266ea07 100644 --- a/app/models/location_release.rb +++ b/app/models/location_release.rb @@ -12,6 +12,7 @@ class LocationRelease < ApplicationRecord include PersonName include CsvExportable include Approvable + include Amendmenable class << self def custom_csv_exportable_headers diff --git a/app/policies/location_release_policy.rb b/app/policies/location_release_policy.rb index ead9d02..16522dd 100644 --- a/app/policies/location_release_policy.rb +++ b/app/policies/location_release_policy.rb @@ -39,6 +39,10 @@ class LocationReleasePolicy < ReleasePolicy user.account_manager? end + def sign_amendment? + user.manager? || user.account_manager? + end + def approve? review? end diff --git a/app/views/location_releases/_location_release.html.erb b/app/views/location_releases/_location_release.html.erb index e5b9c76..82fa7a9 100644 --- a/app/views/location_releases/_location_release.html.erb +++ b/app/views/location_releases/_location_release.html.erb @@ -30,6 +30,15 @@ <%= location_release.signed_on %> + + <% if location_release.amendment_signed? %> + + <% else %> + + <% end %> +
@@ -44,6 +53,9 @@ <% if policy(location_release).edit_photos? %> <%= link_to fa_icon("picture-o fw", text: "Photos"), [:edit, location_release, :photos], class: "dropdown-item" %> <% end %> + <% if policy(location_release).sign_amendment? && location_release.amendment_signable? && !location_release.amendment_signed? %> + <%= link_to fa_icon("file-text fw", text: t('.actions.sign_amendment')), [:new, location_release.project.account, location_release.project, location_release.contract_template, location_release, :amendment], class: "dropdown-item", target: "_blank" %> + <% end %> <% if policy(Contract).show? && (location_release.contract.attached? || location_release.contract_template.present?) %> <%= link_to fa_icon("download fw", text: "Download"), [location_release, :contracts, format: "pdf"], class: "dropdown-item", target: "_blank" %> <% end %> diff --git a/app/views/location_releases/index.html.erb b/app/views/location_releases/index.html.erb index 96ec918..f2aced3 100644 --- a/app/views/location_releases/index.html.erb +++ b/app/views/location_releases/index.html.erb @@ -32,8 +32,8 @@ <%= t(".table_headers.address") %> <%= t(".table_headers.notes") %> <%= t(".table_headers.tags") %> - <%= t(".table_headers.signed_at") %> - + <%= t(".table_headers.signed_at") %> + diff --git a/app/views/public/amendments/create.html.erb b/app/views/public/amendments/create.html.erb new file mode 100644 index 0000000..cdc2055 --- /dev/null +++ b/app/views/public/amendments/create.html.erb @@ -0,0 +1,3 @@ +<% message = local_assigns[:already_signed] ? t('.amendment_already_signed_message') : t('.amendment_signed_message') %> +<% alert_type = local_assigns[:already_signed] ? "alert-warning" : "alert-success" %> +

<%= message %>

diff --git a/app/views/public/amendments/new.html.erb b/app/views/public/amendments/new.html.erb new file mode 100644 index 0000000..9a1ffa7 --- /dev/null +++ b/app/views/public/amendments/new.html.erb @@ -0,0 +1,24 @@ +
+
+ <%= errors_summary_for @release %> + <%= bootstrap_form_with model: @release, method: :post, url: public_send("account_project_contract_template_#{@contract_template.release_type}_release_amendments_path"), local: true do |form| %> + <%= card_field_set_tag t(".amendment.heading") do %> +

<%= @contract_template.amendment_clause %>

+ <% end %> + +
+ +
+ <%= form.text_field :amendment_signer_name, required: true, wrapper_class: "col-sm-6" %> +
+ + <%= card_field_set_tag t(".signature.heading") do %> + <%= render "shared/signature_fields", signature_field: :amendment_signature_base64, form: form %> + <% end %> + +
+ <%= form.button t("shared.submit_release_long"), class: "btn btn-block btn-lg btn-success", data: { disable_with: t("shared.disable_with") } %> +
+ <% end %> +
+
diff --git a/app/views/shared/_signature_fields.html.erb b/app/views/shared/_signature_fields.html.erb index eb1fc6e..ec2b3dc 100644 --- a/app/views/shared/_signature_fields.html.erb +++ b/app/views/shared/_signature_fields.html.erb @@ -1,3 +1,4 @@ +<% signature_field = local_assigns[:signature_field] ? local_assigns[:signature_field] : :signature_base64 %> <% if local_assigns[:instruction] %> @@ -6,7 +7,7 @@ <% end %> -<%= form.hidden_field :signature_base64, data: { ujs_target: "signature-input" } %> +<%= form.hidden_field signature_field, data: { ujs_target: "signature-input" } %>
<%= button_tag class: "btn btn-sm btn-danger", data: { behavior: "clear-digital-signature" } do %> <%= fa_icon "refresh" %> <%= t "shared.clear" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index ffd63da..407e858 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -781,7 +781,9 @@ en: actions: manage: Manage review: Review + sign_amendment: Sign Amendment messages: + amendment_signed_tooltip: Amendment Signed approved_tooltip: Approved by %{user} on %{timestamp} no_photos: Needs Photo new: @@ -1028,6 +1030,15 @@ en: heading: Licensor/Owner Contact Information signature: heading: Signature + amendments: + create: + amendment_already_signed_message: Release amendment is already signed! + amendment_signed_message: Release amendment signed successfully! Thank you + new: + amendment: + heading: Amendment + signature: + heading: Signature appearance_releases: create: notice: Your release has been signed. Thank you! diff --git a/config/locales/es.yml b/config/locales/es.yml index 4a3f00c..b59e363 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -339,6 +339,11 @@ es: notes: Notes (ES) signed_at: Date Signed (ES) tags: Tags (ES) + location_release: + actions: + sign_amendment: Sign Amendment (ES) + messages: + amendment_signed_tooltip: Amendment Signed (ES) material_releases: form: photos: @@ -385,6 +390,15 @@ es: signed_at: Date Signed (ES) tags: Tags (ES) public: + amendments: + create: + amendment_already_signed_message: Release amendment is already signed! (ES) + amendment_signed_message: Release amendment signed successfully! Thank you (ES) + new: + amendment: + heading: Amendment + signature: + heading: Signature (ES) appearance_releases: create: notice: La autorización está firmada. ¡Gracias! diff --git a/config/routes.rb b/config/routes.rb index 6f2e9a9..0bf991e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -128,7 +128,9 @@ Rails.application.routes.draw do resources :talent_releases, only: [:new, :create] resources :appearance_releases, only: [:new, :create] resources :acquired_media_releases, only: [:new, :create] - resources :location_releases, only: [:new, :create] + resources :location_releases, only: [:new, :create] do + resources :amendments, only: [:new, :create] + end resources :material_releases, only: [:new, :create] resources :medical_releases, only: [:new, :create] resources :misc_releases, only: [:new, :create] diff --git a/db/migrate/20200721140821_add_amendment_signer_details_to_location_releases.rb b/db/migrate/20200721140821_add_amendment_signer_details_to_location_releases.rb new file mode 100644 index 0000000..3c1e448 --- /dev/null +++ b/db/migrate/20200721140821_add_amendment_signer_details_to_location_releases.rb @@ -0,0 +1,5 @@ +class AddAmendmentSignerDetailsToLocationReleases < ActiveRecord::Migration[6.0] + def change + add_column :location_releases, :amendment_signer_name, :string + end +end