implement amendment signing

This commit is contained in:
Bilal
2020-07-21 22:09:08 +02:00
parent 8d16c310df
commit 141ab42d4b
13 changed files with 152 additions and 4 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -12,6 +12,7 @@ class LocationRelease < ApplicationRecord
include PersonName
include CsvExportable
include Approvable
include Amendmenable
class << self
def custom_csv_exportable_headers

View File

@@ -39,6 +39,10 @@ class LocationReleasePolicy < ReleasePolicy
user.account_manager?
end
def sign_amendment?
user.manager? || user.account_manager?
end
def approve?
review?
end

View File

@@ -30,6 +30,15 @@
<td>
<%= location_release.signed_on %>
</td>
<td class="text-center">
<% if location_release.amendment_signed? %>
<i class="fa fa-check-square-o text-dark"
data-toggle="tooltip"
title="<%= t '.messages.amendment_signed_tooltip' %>"></i>
<% else %>
<i class="fa fa-square-o"></i>
<% end %>
</td>
<td class="text-right">
<div class="btn-group">
@@ -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 %>

View File

@@ -32,8 +32,8 @@
<th><%= t(".table_headers.address") %>
<th><%= t(".table_headers.notes") %></th>
<th><%= t(".table_headers.tags") %></th>
<th><%= t(".table_headers.signed_at") %></th>
<th><%= t(".table_headers.signed_at") %></th>
<th></th>
<th></th>
</tr>
</thead>

View File

@@ -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" %>
<p class="alert <%= alert_type %> p-3 lead text-center"><%= message %></p>

View File

@@ -0,0 +1,24 @@
<div class="card shadow-sm">
<div class="card-body">
<%= 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 %>
<p><%= @contract_template.amendment_clause %></p>
<% end %>
<hr>
<div class="form-row">
<%= form.text_field :amendment_signer_name, required: true, wrapper_class: "col-sm-6" %>
</div>
<%= card_field_set_tag t(".signature.heading") do %>
<%= render "shared/signature_fields", signature_field: :amendment_signature_base64, form: form %>
<% end %>
<div class="mt-5">
<%= form.button t("shared.submit_release_long"), class: "btn btn-block btn-lg btn-success", data: { disable_with: t("shared.disable_with") } %>
</div>
<% end %>
</div>
</div>

View File

@@ -1,3 +1,4 @@
<% signature_field = local_assigns[:signature_field] ? local_assigns[:signature_field] : :signature_base64 %>
<canvas class="border bg-light w-100" data-behavior="digital-signature" data-signature-input="[data-ujs-target=signature-input]" style="height: 150px"></canvas>
<% if local_assigns[:instruction] %>
@@ -6,7 +7,7 @@
</small>
<% end %>
<%= form.hidden_field :signature_base64, data: { ujs_target: "signature-input" } %>
<%= form.hidden_field signature_field, data: { ujs_target: "signature-input" } %>
<div class="text-right">
<%= button_tag class: "btn btn-sm btn-danger", data: { behavior: "clear-digital-signature" } do %>
<%= fa_icon "refresh" %> <%= t "shared.clear" %>

View File

@@ -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!

View File

@@ -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!

View File

@@ -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]

View File

@@ -0,0 +1,5 @@
class AddAmendmentSignerDetailsToLocationReleases < ActiveRecord::Migration[6.0]
def change
add_column :location_releases, :amendment_signer_name, :string
end
end