adjust email templates

pull/105/head
Alex Turchyn 2 years ago
parent 43b32d05cb
commit d53fa5613b

@ -17,7 +17,9 @@ class SendSubmissionEmailController < ApplicationController
Submitter.find_by!(slug: params[:submitter_slug])
end
SubmitterMailer.copy_to_submitter(@submitter).deliver_later!
Submissions::GenerateResultAttachments.call(@submitter) if @submitter.documents.blank?
SubmitterMailer.documents_copy_email(@submitter).deliver_later!
respond_to do |f|
f.html { redirect_to success_send_submission_email_index_path }

@ -42,7 +42,7 @@ class SubmissionsController < ApplicationController
submission.update!(deleted_at: Time.current)
redirect_to template_submissions_path(submission.template), notice: 'Submission has been archieved'
redirect_to template_submissions_path(submission.template), notice: 'Submission has been archived'
end
private

@ -1,7 +1,7 @@
# frozen_string_literal: true
class SubmissionsDebugController < ApplicationController
layout 'form'
layout 'plain'
skip_before_action :authenticate_user!

@ -8,12 +8,8 @@ class SubmissionsDownloadController < ApplicationController
Submissions::GenerateResultAttachments.call(submitter) if submitter.documents.blank?
original_documents = submitter.submission.template.documents.preload(:blob)
is_more_than_two_images = original_documents.count(&:image?) > 1
urls = submitter.documents.preload(:blob).filter_map do |attachment|
next if is_more_than_two_images && original_documents.find { |a| a.uuid == attachment.uuid }&.image?
urls =
Submitters.select_attachments_for_download(submitter).map do |attachment|
helpers.rails_blob_url(attachment)
end

@ -22,6 +22,12 @@ class SubmitFormController < ApplicationController
submitter.save!
if submitter.completed_at?
submitter.submission.template.account.users.active.each do |user|
SubmitterMailer.completed_email(submitter, user).deliver_later!
end
end
head :ok
end

@ -1,7 +1,7 @@
# frozen_string_literal: true
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
default from: 'DocuSeal <hi@docuseal.co>'
layout 'mailer'
register_interceptor ActionMailerConfigsInterceptor

@ -1,19 +1,32 @@
# frozen_string_literal: true
class SubmitterMailer < ApplicationMailer
DEFAULT_MESSAGE = "You've been invited to submit the following documents:"
DEFAULT_MESSAGE = %(You have been invited to submit the "%<name>s" form:)
def invitation_email(submitter, message: DEFAULT_MESSAGE)
def invitation_email(submitter, message: format(DEFAULT_MESSAGE, name: submitter.submission.template.name))
@submitter = submitter
@message = message
mail(to: @submitter.email,
subject: 'You have been invited to submit forms')
subject: 'You have been invited to submit a form')
end
def copy_to_submitter(submitter)
def completed_email(submitter, user)
@submitter = submitter
@user = user
mail(to: submitter.email, subject: 'Here is your copy')
mail(to: user.email,
subject: %(#{submitter.email} has completed the "#{submitter.submission.template.name}" form))
end
def documents_copy_email(submitter)
@submitter = submitter
@documents = Submitters.select_attachments_for_download(submitter)
@documents.each do |attachment|
attachments[attachment.filename.to_s] = attachment.download
end
mail(to: submitter.email, subject: 'Your copy of documents')
end
end

@ -46,7 +46,7 @@ class User < ApplicationRecord
belongs_to :account
devise :database_authenticatable, :recoverable, :rememberable, :validatable, :trackable
devise :registerable # if ENV['APP_MULTITENANT']
devise :registerable if Docuseal.multitenant?
attribute :role, :string, default: 'admin'

@ -1 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0"></path>
<path d="M12 9h.01"></path>
<path d="M11 12h1v4h1"></path>
</svg>

Before

Width:  |  Height:  |  Size: 255 B

After

Width:  |  Height:  |  Size: 412 B

@ -2,7 +2,7 @@
<html data-theme="docuseal">
<head>
<title>
Docuseal
DocuSeal
</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

@ -2,7 +2,7 @@
<html data-theme="docuseal">
<head>
<title>
Docuseal
DocuSeal
</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

@ -8,5 +8,11 @@
</head>
<body>
<%= yield %>
<p>
---
</p>
<p>
Sent using <a href="<%= Docuseal::PRODUCT_URL %>"><%= Docuseal::PRODUCT_NAME %></a> documents software.
</p>
</body>
</html>

@ -2,11 +2,12 @@
<html data-theme="docuseal">
<head>
<title>
Docuseal
DocuSeal
</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex">
<%= javascript_pack_tag 'application', defer: true %>
<%= stylesheet_pack_tag 'application', media: 'all' %>
</head>

@ -41,7 +41,7 @@
<% end %>
</div>
<div class="form-control">
<%= f.button button_title(title: 'Confirm', disabled_with: 'Processing'), class: 'base-button' %>
<%= f.button button_title, class: 'base-button' %>
</div>
<% end %>
</div>

@ -0,0 +1,4 @@
<div class="text-center px-2">
Powered by
<a href="<%= Docuseal::PRODUCT_URL %>" class="underline"><%= Docuseal::PRODUCT_NAME %></a> - open source documents software
</div>

@ -1,5 +1,4 @@
<p>
Form has been submitted alredy by ypu - thanks!
Form has been submitted already - thanks!
</p>
<%= button_to button_title(title: 'Send copy to Email', disabled_with: 'Sending'), send_submission_email_index_path, params: { template_slug: @template.slug, email: params[:email] }, form: { onsubmit: 'event.submitter.disabled = true' } %>
<%# do not allow donwload for securetiy reaosn<a href="">Download documets</a> %>

@ -1,7 +1,7 @@
<div class="max-w-xl mx-auto px-2 mt-12">
<div class="max-w-xl mx-auto px-2 mt-12 mb-4">
<div class="card bg-base-200">
<div class="card-body">
<div class="space-y-4 mx-auto">
<div class="space-y-4 w-full md:px-10 mx-auto">
<div class="space-y-4">
<div class="flex items-center justify-center">
<div class="flex items-center">
@ -11,7 +11,7 @@
<h1 class="text-5xl font-bold text-center">DocuSeal</h1>
</div>
</div>
<h2 class="text-xl font-semibold text-center">You have been invited to submit the document</h2>
<h2 class="text-xl font-semibold text-center">You have been invited to submit the form</h2>
<div class="flex items-center bg-neutral rounded-xl p-4">
<div class="flex items-center">
<div class="mr-3">
@ -35,10 +35,11 @@
<%= f.email_field :email, required: true, class: 'base-input', placeholder: 'Provide your email to start' %>
</div>
<div class="form-control">
<%= f.button button_title(title: 'Confirm', disabled_with: 'Processing'), class: 'base-button' %>
<%= f.button button_title(title: 'Start'), class: 'base-button' %>
</div>
<% end %>
</div>
</div>
</div>
</div>
<%= render 'shared/attribution' %>

@ -36,16 +36,30 @@
</dynamic-list>
<% end %>
<div class="form-control">
<% is_smtp_configured = Docuseal.multitenant? || current_account.encrypted_configs.exists?(key: EncryptedConfig::EMAIL_SMTP_KEY) %>
<%= f.label :send_email, class: 'flex items-center cursor-pointer' do %>
<%= f.check_box :send_email, class: 'base-checkbox', onchange: "message_field.classList.toggle('hidden', !event.currentTarget.checked)" %>
<%= f.check_box :send_email, class: 'base-checkbox', disabled: !is_smtp_configured, onchange: "message_field.classList.toggle('hidden', !event.currentTarget.checked)" %>
<span class="label">Send Email</span>
<% end %>
<% unless is_smtp_configured %>
<div class="alert my-4">
<%= svg_icon('info_circle', class: 'w-6 h-6') %>
<div>
<h3 class="font-bold">SMTP not Configured</h3>
<p class="text-gray-700">
Configure SMTP settings in order to send emails:
<br>
<a class="link font-medium" data-turbo-frame="_top" href="<%= settings_email_index_path %>">Go to SMTP settings</a>
</p>
</div>
</div>
<% end %>
</div>
<div id="message_field" class="card card-compact bg-base-200 hidden">
<div class="card-body">
<div class="form-control space-y-2">
<span class="label-text">Hi there,</span>
<%= f.text_area :message, value: SubmitterMailer::DEFAULT_MESSAGE, required: true, class: 'base-textarea !rounded-lg' %>
<%= f.text_area :message, value: format(SubmitterMailer::DEFAULT_MESSAGE, name: @template.name), required: true, class: 'base-textarea !rounded-lg' %>
<span class="label-text">
Thanks,
</br>

@ -63,22 +63,22 @@
<div class="flex items-center space-x-1 ">
<span class="mx-1 w-3 h-3 rounded-full <%= colors[index] %>"></span>
<span class="text-lg">
<%= @submission.template.submitters.find { |e| e['uuid'] == submitter.uuid }&.dig('name') || "#{(index + 1).ordinalize} Submitter" %>
<%= @submission.template.submitters.find { |e| e['uuid'] == submitter&.uuid }&.dig('name') || "#{(index + 1).ordinalize} Submitter" %>
</span>
</div>
<div class="flex items-center space-x-1 mt-1">
<%= svg_icon('mail', class: 'w-5 h-5') %>
<span>
<%= submitter.email %>
<%= submitter&.email || 'N/A' %>
</span>
</div>
<div class="flex items-center space-x-1 mt-1">
<%= svg_icon('writing', class: 'w-5 h-5') %>
<span>
<%= submitter.completed_at? ? l(submitter.completed_at, format: :long) : 'Not completed yet' %>
<%= submitter&.completed_at? ? l(submitter.completed_at, format: :long) : 'Not completed yet' %>
</span>
</div>
<% unless submitter.completed_at? %>
<% if submitter && !submitter.completed_at? %>
<div class="mt-2 mb-1">
<a class="btn btn-xs btn-primary w-full" target="_blank" href="<%= submit_form_url(slug: submitter.slug) %>">
Submit Form
@ -89,7 +89,7 @@
</div>
<div class="px-1.5 mb-4">
<% submitter_field_counters = Hash.new { 0 } %>
<% submitter_fields_index[submitter.uuid].each_with_index do |field, index| %>
<% submitter_fields_index[item['uuid']].to_a.each_with_index do |field, index| %>
<% submitter_field_counters[field['type']] += 1 %>
<% value = values[field['uuid']] %>
<% next if value.blank? %>

@ -1,4 +1,4 @@
<div class="max-w-md mx-auto px-2 mt-12">
<div class="max-w-md mx-auto px-2 mt-12 mb-4">
<div class="space-y-6 mx-auto">
<div class="space-y-6">
<div class="flex items-center justify-center">
@ -42,3 +42,4 @@
</div>
</div>
</div>
<%= render 'shared/attribution' %>

@ -23,10 +23,7 @@
</div>
<% end %>
<% end %>
<div class="text-center px-2">
Powered by
<a href="https://www.docuseal.co" class="underline">DocuSeal</a> - open source documents software
</div>
<%= render 'shared/attribution' %>
</div>
<div class="fixed bottom-0 w-full h-0 z-20">
<div class="mx-auto" style="max-width: 1000px">

@ -0,0 +1,3 @@
<p>Hi <%= @user.first_name %>,</p>
<p><%= @submitter.email %> has completed the "<%= @submitter.submission.template.name %>" form.</p>
<p><%= link_to 'View Submission', submission_url(@submitter.submission) %></p>

@ -1,3 +0,0 @@
<p>Hi</a>
<%= @submitter.values %>
<%= link_to 'Download', submitter_download_index_url(@submitter.slug) %>

@ -0,0 +1,13 @@
<p>Hi there,</p>
<p>Please check the copy of your "<%= @submitter.submission.template.name %>" submission in the email attachments.</p>
<p>Alternatively, you can download the copy using:</p>
<% @documents.each do |document| %>
<ul>
<li>
<%= link_to document.filename.to_s, rails_blob_url(document) %>
</li>
</ul>
<% end %>
<p>
Thanks,<br><%= @submitter.submission.template.account.name %>
</p>

@ -1,4 +1,7 @@
<p>Hi there,</p>
<p>You have been invited to submit a form:</p>
<p><%= link_to 'Submit', submit_form_url(slug: @submitter.slug) %></p>
<p>If you didn't request this, please ignore this email.</p>
<%= simple_format(@message) %>
<p><%= link_to 'Submit Form', submit_form_url(slug: @submitter.slug) %></p>
<p>Please contact us by replying to this email if you didn't request this.</p>
<p>
Thanks,<br><%= @submitter.submission.template.account.name %>
</p>

@ -1,4 +1,7 @@
<p>Hello <%= @user.first_name %>,</p>
<p>You have been invited to Docuseal. You can sign up this through the link below.</p>
<p><%= link_to 'Set my password', invitation_url(reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>You have been invited to <%= @user.account.name %> DocuSeal. Please sign up using the link below:</p>
<p><%= link_to 'Sign up', invitation_url(reset_password_token: @token) %></p>
<p>Please contact us by replying to this email if you didn't request this.</p>
<p>
Thanks,<br><%= @user.account.name %>
</p>

@ -18,6 +18,6 @@
</div>
</div>
<div class="form-control">
<%= f.button button_title(title: 'Confirm', disabled_with: 'Processing'), class: 'base-button' %>
<%= f.button button_title, class: 'base-button' %>
</div>
<% end %>

@ -48,7 +48,7 @@ Rails.application.routes.draw do
resources :submitters, only: %i[], param: 'slug' do
resources :download, only: %i[index], controller: 'submissions_download'
resources :debug, only: %i[index], controller: 'submissions_debug'
resources :debug, only: %i[index], controller: 'submissions_debug' if Rails.env.development?
end
scope '/settings', as: :settings do

@ -1,10 +1,16 @@
# frozen_string_literal: true
module Docuseal
PRODUCT_URL = 'https://www.docuseal.co'
PRODUCT_NAME = 'DocuSeal'
DEFAULT_APP_URL = 'http://localhost:3000'
module_function
def multitenant?
ENV['MULTITENANT'] == true
end
def default_url_options
@default_url_options ||= begin
value = EncryptedConfig.find_by(key: EncryptedConfig::APP_URL_KEY)&.value

@ -1,7 +1,7 @@
# frozen_string_literal: true
module GenerateCertificate
NAME = 'DocuSeal'
NAME = Docuseal::PRODUCT_NAME
SIZE = 2**11
module_function

@ -5,7 +5,8 @@ module Submissions
FONT_SIZE = 11
FONT_NAME = 'Helvetica'
INFO_CREATOR = 'DocuSeal (https://www.docuseal.co)'
INFO_CREATOR = "#{Docuseal::PRODUCT_NAME} (#{Docuseal::PRODUCT_URL})".freeze
SIGN_REASON = 'Signed by %<email>s with docuseal.co'
TEXT_LEFT_MARGIN = 1
TEXT_TOP_MARGIN = 1
@ -184,7 +185,7 @@ module Submissions
pdf.trailer.info[:Creator] = INFO_CREATOR
pdf.sign(io, reason: "Signed by #{submitter.email} with docuseal.co",
pdf.sign(io, reason: format(SIGN_REASON, email: submitter.email),
certificate: OpenSSL::X509::Certificate.new(cert['cert']),
key: OpenSSL::PKey::RSA.new(cert['key']),
certificate_chain: [OpenSSL::X509::Certificate.new(cert['sub_ca']),

@ -0,0 +1,14 @@
# frozen_string_literal: true
module Submitters
module_function
def select_attachments_for_download(submitter)
original_documents = submitter.submission.template.documents.preload(:blob)
is_more_than_two_images = original_documents.count(&:image?) > 1
submitter.documents.preload(:blob).reject do |attachment|
is_more_than_two_images && original_documents.find { |a| a.uuid == attachment.uuid }&.image?
end
end
end

@ -1,2 +1,2 @@
User-agent: *
Disallow: /
Allow: /

@ -0,0 +1,19 @@
# frozen_string_literal: true
class SubmitterMailerPreview < ActionMailer::Preview
def invitation_email
SubmitterMailer.invitation_email(Submitter.last)
end
def completed_email
submitter = Submitter.where.not(completed_at: nil).joins(:documents_attachments).last
SubmitterMailer.completed_email(submitter, User.last)
end
def documents_copy_email
submitter = Submitter.where.not(completed_at: nil).joins(:documents_attachments).last
SubmitterMailer.documents_copy_email(submitter)
end
end
Loading…
Cancel
Save