Compare commits

...
8 Commits
Author SHA1 Message Date
Alex Turchyn 88968897e9 update gems 2023-08-21 20:09:56 +03:00
Alex Turchyn 966b786a30 store template submitters on submission creation 2023-08-21 16:32:39 +03:00
Alex Turchyn bc3b1b477e add export button 2023-08-20 15:18:15 +03:00
Alex Turchyn cbc6f4497a add base feature specs 2023-08-20 15:15:48 +03:00
Alex Turchyn 6b4e7c2264 allow to edit email templates 2023-08-20 00:11:11 +03:00
Alex Turchyn 8e6639d891 add a link to the console in navbar 2023-08-20 00:05:00 +03:00
Alex Turchyn 8e39f0078d add source to templates 2023-08-19 22:08:17 +03:00
Alex Turchyn 46f350217a refactor and fixes 2023-08-19 21:30:36 +03:00
73 changed files with 2044 additions and 267 deletions

No files matched your search

+5 -2
View File
@@ -53,10 +53,13 @@ RSpec/NestedGroups:
Max: 6
RSpec/MultipleExpectations:
Max: 7
Max: 20
RSpec/ExampleLength:
Max: 15
Max: 40
RSpec/MultipleMemoizedHelpers:
Max: 6
Rails/I18nLocaleTexts:
Enabled: false
+1
View File
@@ -28,6 +28,7 @@ gem 'rails_autolink'
gem 'rails-i18n'
gem 'rollbar', require: ENV.key?('ROLLBAR_ACCESS_TOKEN')
gem 'ruby-vips'
gem 'rubyXL'
gem 'shakapacker'
gem 'sidekiq', require: ENV.key?('REDIS_URL')
gem 'sqlite3', require: false
+115 -102
View File
@@ -1,92 +1,92 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.5)
actionpack (= 7.0.5)
activesupport (= 7.0.5)
actioncable (7.0.7)
actionpack (= 7.0.7)
activesupport (= 7.0.7)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.5)
actionpack (= 7.0.5)
activejob (= 7.0.5)
activerecord (= 7.0.5)
activestorage (= 7.0.5)
activesupport (= 7.0.5)
actionmailbox (7.0.7)
actionpack (= 7.0.7)
activejob (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.5)
actionpack (= 7.0.5)
actionview (= 7.0.5)
activejob (= 7.0.5)
activesupport (= 7.0.5)
actionmailer (7.0.7)
actionpack (= 7.0.7)
actionview (= 7.0.7)
activejob (= 7.0.7)
activesupport (= 7.0.7)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.5)
actionview (= 7.0.5)
activesupport (= 7.0.5)
actionpack (7.0.7)
actionview (= 7.0.7)
activesupport (= 7.0.7)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.5)
actionpack (= 7.0.5)
activerecord (= 7.0.5)
activestorage (= 7.0.5)
activesupport (= 7.0.5)
actiontext (7.0.7)
actionpack (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.5)
activesupport (= 7.0.5)
actionview (7.0.7)
activesupport (= 7.0.7)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.5)
activesupport (= 7.0.5)
activejob (7.0.7)
activesupport (= 7.0.7)
globalid (>= 0.3.6)
activemodel (7.0.5)
activesupport (= 7.0.5)
activerecord (7.0.5)
activemodel (= 7.0.5)
activesupport (= 7.0.5)
activestorage (7.0.5)
actionpack (= 7.0.5)
activejob (= 7.0.5)
activerecord (= 7.0.5)
activesupport (= 7.0.5)
activemodel (7.0.7)
activesupport (= 7.0.7)
activerecord (7.0.7)
activemodel (= 7.0.7)
activesupport (= 7.0.7)
activestorage (7.0.7)
actionpack (= 7.0.7)
activejob (= 7.0.7)
activerecord (= 7.0.7)
activesupport (= 7.0.7)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.5)
activesupport (7.0.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.4)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.781.0)
aws-sdk-core (3.175.0)
aws-partitions (1.807.0)
aws-sdk-core (3.180.3)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.67.0)
aws-sdk-core (~> 3, >= 3.174.0)
aws-sdk-kms (1.71.0)
aws-sdk-core (~> 3, >= 3.177.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.126.0)
aws-sdk-core (~> 3, >= 3.174.0)
aws-sdk-s3 (1.132.1)
aws-sdk-core (~> 3, >= 3.179.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
aws-sigv4 (1.5.2)
aws-sigv4 (~> 1.6)
aws-sigv4 (1.6.0)
aws-eventstream (~> 1, >= 1.0.2)
azure-storage-blob (2.0.3)
azure-storage-common (~> 2.0)
@@ -96,8 +96,9 @@ GEM
faraday_middleware (~> 1.0, >= 1.0.0.rc1)
net-http-persistent (~> 4.0)
nokogiri (~> 1, >= 1.10.8)
base64 (0.1.1)
bcrypt (3.1.19)
better_html (2.0.1)
better_html (2.0.2)
actionview (>= 6.0)
activesupport (>= 6.0)
ast (~> 2.0)
@@ -105,7 +106,7 @@ GEM
parser (>= 2.4)
smart_properties
bindex (0.8.1)
bootsnap (1.15.0)
bootsnap (1.16.0)
msgpack (~> 1.2)
builder (3.2.4)
bullet (7.0.7)
@@ -144,7 +145,7 @@ GEM
responders
warden (~> 1.2.3)
diff-lcs (1.5.0)
digest-crc (0.6.4)
digest-crc (0.6.5)
rake (>= 12.0.0, < 14.0.0)
docile (1.4.0)
dotenv (2.8.1)
@@ -161,7 +162,7 @@ GEM
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
faker (3.2.0)
faker (3.2.1)
i18n (>= 1.8.11, < 2)
faraday (1.10.3)
faraday-em_http (~> 1.0)
@@ -194,10 +195,10 @@ GEM
webrick (~> 1.7)
websocket-driver (>= 0.6, < 0.8)
ffi (1.15.5)
geom2d (0.3.1)
geom2d (0.4.1)
globalid (1.1.0)
activesupport (>= 5.0)
google-apis-core (0.11.0)
google-apis-core (0.11.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
httpclient (>= 2.8.1, < 3.a)
@@ -224,7 +225,7 @@ GEM
google-cloud-core (~> 1.6)
googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0)
googleauth (1.6.0)
googleauth (1.7.0)
faraday (>= 0.17.3, < 3.a)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
@@ -233,9 +234,9 @@ GEM
signet (>= 0.16, < 2.a)
hashdiff (1.0.1)
hashie (5.0.0)
hexapdf (0.32.2)
hexapdf (0.33.0)
cmdparse (~> 3.0, >= 3.0.3)
geom2d (~> 0.3)
geom2d (~> 0.4, >= 0.4.1)
openssl (>= 2.2.1)
htmlentities (4.3.4)
httpclient (2.8.3)
@@ -245,8 +246,8 @@ GEM
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
io-console (0.6.0)
irb (1.7.0)
reline (>= 0.3.0)
irb (1.7.4)
reline (>= 0.3.6)
jmespath (1.6.2)
json (2.6.3)
jwt (2.7.1)
@@ -260,7 +261,7 @@ GEM
letter_opener (~> 1.7)
railties (>= 5.2)
rexml
lograge (0.12.0)
lograge (0.13.0)
actionpack (>= 4)
activesupport (>= 4)
railties (>= 4)
@@ -278,17 +279,17 @@ GEM
memoist (0.16.2)
method_source (1.0.0)
mini_magick (4.12.0)
mini_mime (1.1.2)
mini_portile2 (2.8.2)
minitest (5.18.1)
msgpack (1.7.1)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
minitest (5.19.0)
msgpack (1.7.2)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.3.0)
mysql2 (0.5.5)
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
net-imap (0.3.6)
net-imap (0.3.7)
date
net-protocol
net-pop (0.1.2)
@@ -298,7 +299,10 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.2-arm64-darwin)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
@@ -307,7 +311,7 @@ GEM
rack (>= 1.2, < 4)
snaky_hash (~> 2.0)
version_gem (~> 1.1)
oj (3.15.0)
oj (3.16.0)
omniauth (2.1.1)
hashie (>= 3.4.6)
rack (>= 2.2.3)
@@ -345,57 +349,58 @@ GEM
method_source (~> 1.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (5.0.1)
puma (6.3.0)
public_suffix (5.0.3)
puma (6.3.1)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.7)
rack-protection (3.0.6)
rack
rack (2.2.8)
rack-protection (3.1.0)
rack (~> 2.2, >= 2.2.4)
rack-proxy (0.7.6)
rack
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.5)
actioncable (= 7.0.5)
actionmailbox (= 7.0.5)
actionmailer (= 7.0.5)
actionpack (= 7.0.5)
actiontext (= 7.0.5)
actionview (= 7.0.5)
activejob (= 7.0.5)
activemodel (= 7.0.5)
activerecord (= 7.0.5)
activestorage (= 7.0.5)
activesupport (= 7.0.5)
rails (7.0.7)
actioncable (= 7.0.7)
actionmailbox (= 7.0.7)
actionmailer (= 7.0.7)
actionpack (= 7.0.7)
actiontext (= 7.0.7)
actionview (= 7.0.7)
activejob (= 7.0.7)
activemodel (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
bundler (>= 1.15.0)
railties (= 7.0.5)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
railties (= 7.0.7)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
rails-i18n (7.0.7)
rails-i18n (7.0.8)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
rails_autolink (1.1.8)
actionview (> 3.1)
activesupport (> 3.1)
railties (> 3.1)
railties (7.0.5)
actionpack (= 7.0.5)
activesupport (= 7.0.5)
railties (7.0.7)
actionpack (= 7.0.7)
activesupport (= 7.0.7)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
redis-client (0.14.1)
redis-client (0.16.0)
connection_pool
regexp_parser (2.8.1)
reline (0.3.5)
reline (0.3.8)
io-console (~> 0.5)
representable (3.2.0)
declarative (< 0.1.0)
@@ -407,14 +412,14 @@ GEM
actionpack (>= 5.2)
railties (>= 5.2)
retriable (3.1.2)
rexml (3.2.5)
rexml (3.2.6)
rollbar (3.4.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.5)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-rails (6.0.3)
@@ -425,8 +430,9 @@ GEM
rspec-expectations (~> 3.12)
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.0)
rubocop (1.53.0)
rspec-support (3.12.1)
rubocop (1.56.1)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
@@ -434,7 +440,7 @@ GEM
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
@@ -443,14 +449,14 @@ GEM
rubocop (~> 1.41)
rubocop-factory_bot (2.23.1)
rubocop (~> 1.33)
rubocop-performance (1.18.0)
rubocop-performance (1.19.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.20.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rspec (2.22.0)
rubocop-rspec (2.23.2)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
@@ -458,8 +464,12 @@ GEM
ruby-vips (2.1.4)
ffi (~> 1.12)
ruby2_keywords (0.0.5)
rubyXL (3.4.25)
nokogiri (>= 1.10.8)
rubyzip (>= 1.3.0)
rubyzip (2.3.2)
semantic_range (3.0.0)
shakapacker (7.0.0)
shakapacker (7.0.3)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
@@ -484,8 +494,9 @@ GEM
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
sqlite3 (1.5.4)
sqlite3 (1.6.3)
mini_portile2 (~> 2.8.0)
sqlite3 (1.6.3-arm64-darwin)
strip_attributes (1.13.0)
activemodel (>= 3.0, < 8.0)
thor (1.2.2)
@@ -515,15 +526,16 @@ GEM
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
websocket-driver (0.7.5)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.8)
zeitwerk (2.6.11)
PLATFORMS
arm64-darwin-22
ruby
DEPENDENCIES
annotate
@@ -566,6 +578,7 @@ DEPENDENCIES
rubocop-rails
rubocop-rspec
ruby-vips
rubyXL
shakapacker
sidekiq
simplecov
+3 -2
View File
@@ -16,16 +16,17 @@ class SetupController < ApplicationController
def create
@account = Account.new(account_params)
@account.timezone = Accounts.normalize_timezone(@account.timezone)
@user = @account.users.new(user_params)
@encrypted_config = EncryptedConfig.new(encrypted_config_params)
unless URI.parse(encrypted_config_params[:value].to_s).class.in?([URI::HTTP, URI::HTTPS])
@encrypted_config = EncryptedConfig.new(encrypted_config_params)
@encrypted_config.errors.add(:value, 'should be a valid URL')
return render :index, status: :unprocessable_entity
end
return render :index, status: :unprocessable_entity unless @account.valid?
if @user.save
encrypted_configs = [
{ key: EncryptedConfig::APP_URL_KEY, value: encrypted_config_params[:value] },
@@ -0,0 +1,28 @@
# frozen_string_literal: true
class SubmissionsExportController < ApplicationController
before_action :load_template
def index
submissions = @template.submissions.active
.preload(submitters: { documents_attachments: :blob,
attachments_attachments: :blob })
.order(id: :asc)
if params[:format] == 'csv'
send_data Submissions::GenerateExportFiles.call(submissions, format: params[:format]),
filename: "#{@template.name}.csv"
elsif params[:format] == 'xlsx'
send_data Submissions::GenerateExportFiles.call(submissions, format: params[:format]),
filename: "#{@template.name}.xlsx"
end
end
def new; end
private
def load_template
@template = current_account.templates.find(params[:template_id])
end
end
+1 -1
View File
@@ -17,7 +17,7 @@ class TemplatesController < ApplicationController
end
def edit
@template = current_account.templates.preload(documents_attachments: { preview_images_attachments: :blob })
@template = current_account.templates.preload(schema_documents: { preview_images_attachments: :blob })
.find(params[:id])
render :edit, layout: 'plain'
+22
View File
@@ -45,10 +45,32 @@ window.customElements.define('set-timezone', SetTimezone)
window.customElements.define('autoresize-textarea', AutoresizeTextarea)
document.addEventListener('turbo:before-fetch-request', encodeMethodIntoRequestBody)
document.addEventListener('turbo:submit-end', async (event) => {
const resp = event.detail?.formSubmission?.result?.fetchResponse?.response
if (!resp?.headers?.get('content-disposition')?.includes('attachment')) {
return
}
const url = URL.createObjectURL(await resp.blob())
const link = document.createElement('a')
link.href = url
link.setAttribute('download', decodeURIComponent(resp.headers.get('content-disposition').split('"')[1]))
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
})
window.customElements.define('template-builder', class extends HTMLElement {
connectedCallback () {
this.appElem = document.createElement('div')
this.appElem.classList.add('max-h-screen')
this.app = createApp(TemplateBuilder, {
template: reactive(JSON.parse(this.dataset.template)),
+5 -1
View File
@@ -5,8 +5,12 @@ export default actionable(class extends HTMLElement {
document.body.classList.add('overflow-hidden')
document.addEventListener('keyup', this.onEscKey)
document.addEventListener('turbo:submit-end', this.onSubmit)
document.addEventListener('turbo:before-cache', this.close)
if (this.dataset.closeAfterSubmit !== 'false') {
document.addEventListener('turbo:submit-end', this.onSubmit)
}
}
disconnectedCallback () {
@@ -10,6 +10,7 @@
data-tip="Type text"
>
<button
id="type_text_button"
class="btn btn-sm btn-circle"
:class="{ 'btn-neutral': isTextSignature, 'btn-outline': !isTextSignature }"
@click.prevent="toggleTextInput"
@@ -78,6 +79,7 @@
/>
<input
v-if="isTextSignature"
id="signature_text_input"
ref="textInput"
class="base-input !text-2xl w-full mt-6"
:required="field.required"
+16 -14
View File
@@ -226,14 +226,14 @@ export default {
}
},
startResizeCell (e) {
document.addEventListener('mousemove', this.onResizeCell)
document.addEventListener('mouseup', this.stopResizeCell)
this.$el.getRootNode().addEventListener('mousemove', this.onResizeCell)
this.$el.getRootNode().addEventListener('mouseup', this.stopResizeCell)
this.$emit('start-resize', 'ew')
},
stopResizeCell (e) {
document.removeEventListener('mousemove', this.onResizeCell)
document.removeEventListener('mouseup', this.stopResizeCell)
this.$el.getRootNode().removeEventListener('mousemove', this.onResizeCell)
this.$el.getRootNode().removeEventListener('mouseup', this.stopResizeCell)
this.$emit('stop-resize')
@@ -266,11 +266,13 @@ export default {
})
},
onNameBlur (e) {
const text = this.$refs.name.innerText.trim()
this.isNameFocus = false
this.$refs.name.style.minWidth = ''
if (e.target.innerText.trim()) {
this.field.name = e.target.innerText.trim()
if (text) {
this.field.name = text
} else {
this.field.name = ''
this.$refs.name.innerText = this.defaultName
@@ -302,14 +304,14 @@ export default {
this.dragFrom = { x: e.clientX - rect.left, y: e.clientY - rect.top }
document.addEventListener('mousemove', this.drag)
document.addEventListener('mouseup', this.stopDrag)
this.$el.getRootNode().addEventListener('mousemove', this.drag)
this.$el.getRootNode().addEventListener('mouseup', this.stopDrag)
this.$emit('start-drag')
},
stopDrag () {
document.removeEventListener('mousemove', this.drag)
document.removeEventListener('mouseup', this.stopDrag)
this.$el.getRootNode().removeEventListener('mousemove', this.drag)
this.$el.getRootNode().removeEventListener('mouseup', this.stopDrag)
if (this.isDragged) {
this.save()
@@ -322,14 +324,14 @@ export default {
startResize () {
this.selectedAreaRef.value = this.area
document.addEventListener('mousemove', this.resize)
document.addEventListener('mouseup', this.stopResize)
this.$el.getRootNode().addEventListener('mousemove', this.resize)
this.$el.getRootNode().addEventListener('mouseup', this.stopResize)
this.$emit('start-resize', 'nwse')
},
stopResize () {
document.removeEventListener('mousemove', this.resize)
document.removeEventListener('mouseup', this.stopResize)
this.$el.getRootNode().removeEventListener('mousemove', this.resize)
this.$el.getRootNode().removeEventListener('mouseup', this.stopResize)
this.$emit('stop-resize')
+134 -50
View File
@@ -1,13 +1,17 @@
<template>
<div
style="max-width: 1600px"
class="mx-auto pl-4"
class="mx-auto pl-4 h-full"
>
<div class="flex justify-between py-1.5 items-center pr-4">
<div class="flex space-x-3">
<a href="/">
<a
v-if="withLogoLink"
href="/"
>
<Logo />
</a>
<Logo v-else />
<Contenteditable
:model-value="template.name"
class="text-3xl font-semibold focus:text-clip"
@@ -16,46 +20,53 @@
/>
</div>
<div class="space-x-3 flex items-center">
<a
:href="`/templates/${template.id}/submissions/new`"
data-turbo-frame="modal"
class="btn btn-primary"
>
<IconUsersPlus
width="20"
class="inline"
/>
<span class="hidden md:inline">
Recipients
</span>
</a>
<button
class="base-button"
:class="{ disabled: isSaving }"
v-bind="isSaving ? { disabled: true } : {}"
@click.prevent="onSaveClick"
>
<IconInnerShadowTop
v-if="isSaving"
width="20"
class="animate-spin"
/>
<IconDeviceFloppy
v-else
width="20"
/>
<span class="hidden md:inline">
Save
</span>
</button>
<slot
v-if="$slots.buttons"
name="buttons"
/>
<template v-else>
<a
:href="`/templates/${template.id}/submissions/new`"
data-turbo-frame="modal"
class="btn btn-primary"
>
<IconUsersPlus
width="20"
class="inline"
/>
<span class="hidden md:inline">
Recipients
</span>
</a>
<button
class="base-button"
:class="{ disabled: isSaving }"
v-bind="isSaving ? { disabled: true } : {}"
@click.prevent="onSaveClick"
>
<IconInnerShadowTop
v-if="isSaving"
width="20"
class="animate-spin"
/>
<IconDeviceFloppy
v-else
width="20"
/>
<span class="hidden md:inline">
Save
</span>
</button>
</template>
</div>
</div>
<div
class="flex"
style="max-height: calc(100vh - 60px)"
style="max-height: calc(100% - 60px)"
>
<div
ref="previews"
:style="{ 'display': isBreakpointLg ? 'none' : 'initial' }"
class="overflow-y-auto overflow-x-hidden w-52 flex-none pr-3 mt-0.5 pt-0.5 hidden lg:block"
>
<DocumentPreview
@@ -94,19 +105,46 @@
@success="updateFromUpload"
/>
<template v-else>
<Document
<template
v-for="document in sortedDocuments"
:key="document.uuid"
:ref="setDocumentRefs"
:areas-index="fieldAreasIndex[document.uuid]"
:selected-submitter="selectedSubmitter"
:document="document"
:is-drag="!!dragFieldType"
:draw-field="drawField"
@draw="onDraw"
@drop-field="onDropfield"
@remove-area="removeArea"
/>
>
<Document
:ref="setDocumentRefs"
:areas-index="fieldAreasIndex[document.uuid]"
:selected-submitter="selectedSubmitter"
:document="document"
:is-drag="!!dragFieldType"
:draw-field="drawField"
@draw="onDraw"
@drop-field="onDropfield"
@remove-area="removeArea"
/>
<DocumentControls
v-if="isBreakpointLg"
:with-arrows="template.schema.length > 1"
:item="template.schema.find((item) => item.attachment_uuid === document.uuid)"
:document="document"
:template="template"
:is-direct-upload="isDirectUpload"
class="pb-2 mb-2 border-b border-base-300 border-dashed"
@remove="onDocumentRemove"
@replace="onDocumentReplace"
@up="moveDocument(template.schema.find((item) => item.attachment_uuid === document.uuid), -1)"
@down="moveDocument(template.schema.find((item) => item.attachment_uuid === document.uuid), 1)"
@change="save"
/>
</template>
<div
v-if="sortedDocuments.length && isBreakpointLg"
class="pb-4"
>
<Upload
:template-id="template.id"
:is-direct-upload="isDirectUpload"
@success="updateFromUpload"
/>
</div>
</template>
</div>
<div
@@ -122,7 +160,7 @@
</div>
</div>
<div
class="relative w-80 flex-none pt-0.5 pr-4 pl-0.5 hidden md:block"
class="relative w-80 flex-none mt-1 pr-4 pl-0.5 hidden md:block"
:class="drawField ? 'overflow-hidden' : 'overflow-auto'"
>
<div
@@ -149,6 +187,7 @@
:fields="template.fields"
:submitters="template.submitters"
:selected-submitter="selectedSubmitter"
:with-sticky-submitters="withStickySubmitters"
@set-draw="drawField = $event"
@set-drag="dragFieldType = $event"
@change-submitter="selectedSubmitter = $event"
@@ -169,6 +208,7 @@ import Document from './document'
import Logo from './logo'
import Contenteditable from './contenteditable'
import DocumentPreview from './preview'
import DocumentControls from './controls'
import { IconUsersPlus, IconDeviceFloppy, IconInnerShadowTop } from '@tabler/icons-vue'
import { v4 } from 'uuid'
import { ref, computed } from 'vue'
@@ -182,6 +222,7 @@ export default {
Logo,
Dropzone,
DocumentPreview,
DocumentControls,
IconInnerShadowTop,
Contenteditable,
IconUsersPlus,
@@ -191,6 +232,7 @@ export default {
return {
template: this.template,
save: this.save,
baseFetch: this.baseFetch,
selectedAreaRef: computed(() => this.selectedAreaRef)
}
},
@@ -201,13 +243,34 @@ export default {
},
isDirectUpload: {
type: Boolean,
required: true,
required: false,
default: false
},
baseUrl: {
type: String,
required: false,
default: ''
},
withLogoLink: {
type: Boolean,
required: false,
default: true
},
withStickySubmitters: {
type: Boolean,
required: false,
default: true
},
fetchOptions: {
type: Object,
required: false,
default: () => ({ headers: {} })
}
},
data () {
return {
documentRefs: [],
isBreakpointLg: false,
isSaving: false,
selectedSubmitter: null,
drawField: null,
@@ -244,15 +307,28 @@ export default {
this.selectedSubmitter = this.template.submitters[0]
},
mounted () {
this.$nextTick(() => {
this.onWindowResize()
})
document.addEventListener('keyup', this.onKeyUp)
window.addEventListener('resize', this.onWindowResize)
},
unmounted () {
document.removeEventListener('keyup', this.onKeyUp)
window.removeEventListener('resize', this.onWindowResize)
},
beforeUpdate () {
this.documentRefs = []
},
methods: {
onWindowResize (e) {
const breakpointLg = 1024
this.isBreakpointLg = this.$el.getRootNode().children[0].offsetWidth < breakpointLg
},
setDocumentRefs (el) {
if (el) {
this.documentRefs.push(el)
@@ -474,10 +550,18 @@ export default {
this.selectedAreaRef.value = area
},
baseFetch (path, options = {}) {
return fetch(this.baseUrl + path, {
...options,
headers: { ...this.fetchOptions.headers, ...options.headers }
})
},
save () {
this.$el.closest('template-builder').dataset.template = JSON.stringify(this.template)
if (this.$el.closest('template-builder')) {
this.$el.closest('template-builder').dataset.template = JSON.stringify(this.template)
}
return fetch(`/api/templates/${this.template.id}`, {
return this.baseFetch(`/api/templates/${this.template.id}`, {
method: 'PUT',
body: JSON.stringify({
template: {
@@ -0,0 +1,91 @@
<template>
<div class="flex space-x-2">
<Contenteditable
class="w-full block mr-6"
:model-value="item.name"
:icon-width="16"
@update:model-value="onUpdateName"
/>
<ReplaceButton
:is-direct-upload="isDirectUpload"
:template-id="template.id"
@click.stop
@success="$emit('replace', { replaceSchemaItem: item, ...$event })"
/>
<button
v-if="withArrows"
class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors"
style="width: 24px; height: 24px"
@click.stop="$emit('up', item)"
>
&uarr;
</button>
<button
v-if="withArrows"
class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors"
style="width: 24px; height: 24px"
@click.stop="$emit('down', item)"
>
&darr;
</button>
<button
class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors"
style="width: 24px; height: 24px"
@click.stop="$emit('remove', item)"
>
&times;
</button>
</div>
</template>
<script>
import Contenteditable from './contenteditable'
import Upload from './upload'
import ReplaceButton from './replace'
export default {
name: 'DocumentControls',
components: {
Contenteditable,
ReplaceButton
},
props: {
item: {
type: Object,
required: true
},
template: {
type: Object,
required: true
},
document: {
type: Object,
required: true
},
isDirectUpload: {
type: Boolean,
required: true,
default: false
},
withArrows: {
type: Boolean,
required: false,
default: true
}
},
emits: ['change', 'remove', 'up', 'down', 'replace'],
mounted () {
if (this.isDirectUpload) {
import('@rails/activestorage')
}
},
methods: {
upload: Upload.methods.upload,
onUpdateName (value) {
this.item.name = value
this.$emit('change')
}
}
}
</script>
@@ -61,6 +61,7 @@ export default {
IconCloudUpload,
IconInnerShadowTop
},
inject: ['baseFetch'],
props: {
templateId: {
type: [Number, String],
+9 -7
View File
@@ -58,7 +58,7 @@
<label
tabindex="0"
title="Areas"
class="cursor-pointer text-base-100 group-hover:text-base-content"
class="cursor-pointer text-transparent group-hover:text-base-content"
>
<IconShape
:width="18"
@@ -104,7 +104,7 @@
<button
v-else
title="Areas"
class="relative cursor-pointer text-base-100 group-hover:text-base-content"
class="relative cursor-pointer text-transparent group-hover:text-base-content"
@click="$emit('set-draw', field)"
>
<IconShape
@@ -113,7 +113,7 @@
/>
</button>
<button
class="relative text-base-100 group-hover:text-base-content"
class="relative text-transparent group-hover:text-base-content"
title="Remove"
@click="$emit('remove', field)"
>
@@ -122,7 +122,7 @@
:stroke-width="1.6"
/>
</button>
<div class="flex flex-col pr-1 text-base-100 group-hover:text-base-content">
<div class="flex flex-col pr-1 text-transparent group-hover:text-base-content">
<button
title="Up"
class="relative"
@@ -156,7 +156,7 @@
</span>
<input
v-model="field.options[index]"
class="w-full input input-primary input-xs text-sm"
class="w-full input input-primary input-xs text-sm bg-transparent"
type="text"
required
@blur="save"
@@ -254,8 +254,10 @@ export default {
})
},
onNameBlur (e) {
if (e.target.innerText.trim()) {
this.field.name = e.target.innerText.trim()
const text = this.$refs.name.$refs.contenteditable.innerText.trim()
if (text) {
this.field.name = text
} else {
this.field.name = ''
this.$refs.name.$refs.contenteditable.innerText = this.defaultName
+9 -3
View File
@@ -1,8 +1,9 @@
<template>
<div class="sticky -top-1 bg-base-100 pt-1 -mt-1 z-10">
<div :class="withStickySubmitters ? 'sticky top-0 z-10' : ''">
<FieldSubmitter
:model-value="selectedSubmitter.uuid"
class="w-full bg-base-100"
class="w-full rounded-lg"
:class="{ 'bg-base-100': withStickySubmitters }"
:submitters="submitters"
@new-submitter="save"
@remove="removeSubmitter"
@@ -28,7 +29,7 @@
v-for="(icon, type) in fieldIcons"
:key="type"
draggable="true"
class="flex items-center justify-center border border-dashed border-base-300 bg-base-100 w-full rounded relative"
class="flex items-center justify-center border border-dashed border-base-300 w-full rounded relative"
@dragstart="onDragstart(type)"
@dragend="$emit('drag-end')"
@click="addField(type)"
@@ -106,6 +107,11 @@ export default {
type: Array,
required: true
},
withStickySubmitters: {
type: Boolean,
required: false,
default: true
},
submitters: {
type: Array,
required: true
+1 -1
View File
@@ -4,7 +4,7 @@
ref="image"
:src="image.url"
:width="width"
class="shadow-md mb-4"
class="border rounded mb-4"
:height="height"
loading="lazy"
>
@@ -26,6 +26,7 @@ import Upload from './upload'
export default {
name: 'ReplaceDocument',
inject: ['baseFetch'],
props: {
templateId: {
type: [Number, String],
+3 -2
View File
@@ -50,6 +50,7 @@ export default {
IconUpload,
IconInnerShadowTop
},
inject: ['baseFetch'],
props: {
templateId: {
type: [Number, String],
@@ -113,7 +114,7 @@ export default {
this.isProcessing = true
fetch(`/api/templates/${this.templateId}/documents`, {
this.baseFetch(`/api/templates/${this.templateId}/documents`, {
method: 'POST',
body: JSON.stringify({ blobs }),
headers: { 'Content-Type': 'application/json' }
@@ -124,7 +125,7 @@ export default {
this.isProcessing = false
})
} else {
fetch(`/api/templates/${this.templateId}/documents`, {
this.baseFetch(`/api/templates/${this.templateId}/documents`, {
method: 'POST',
body: new FormData(this.$refs.form)
}).then(resp => resp.json()).then((data) => {
+31 -3
View File
@@ -18,6 +18,7 @@ class SubmitterMailer < ApplicationMailer
end
mail(to: @submitter.email,
from: from_address_for_submitter(submitter),
subject:,
reply_to: submitter.submission.created_by_user&.friendly_name)
end
@@ -27,8 +28,18 @@ class SubmitterMailer < ApplicationMailer
@submitter = submitter
@user = user
mail(to: user.email,
subject: %(#{submitter.email} has completed the "#{submitter.submission.template.name}" form))
@email_config = @current_account.account_configs.find_by(key: AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY)
subject =
if @email_config
ReplaceEmailVariables.call(@email_config.value['subject'], submitter:)
else
%(#{submitter.email} has completed the "#{submitter.submission.template.name}" form)
end
mail(from: from_address_for_submitter(submitter),
to: user.email,
subject:)
end
def documents_copy_email(submitter)
@@ -43,6 +54,23 @@ class SubmitterMailer < ApplicationMailer
attachments[attachment.filename.to_s] = attachment.download
end
mail(to: submitter.email, subject: 'Your copy of documents')
@email_config = @current_account.account_configs.find_by(key: AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY)
subject =
if @email_config
ReplaceEmailVariables.call(@email_config.value['subject'], submitter:)
else
'Your copy of documents'
end
mail(from: from_address_for_submitter(submitter),
to: submitter.email,
subject:)
end
private
def from_address_for_submitter(submitter)
submitter.submission.created_by_user&.friendly_name || submitter.submission.template.author.friendly_name
end
end
+19
View File
@@ -22,6 +22,8 @@
#
class AccountConfig < ApplicationRecord
SUBMITTER_INVITATION_EMAIL_KEY = 'submitter_invitation_email'
SUBMITTER_COMPLETED_EMAIL_KEY = 'submitter_completed_email'
SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY = 'submitter_documents_copy_email'
DEFAULT_VALUES = {
SUBMITTER_INVITATION_EMAIL_KEY => {
@@ -32,6 +34,23 @@ class AccountConfig < ApplicationRecord
"Please contact us by replying to this email if you didn't request this.\n\n" \
"Thanks,\n" \
'{{account.name}}'
},
SUBMITTER_COMPLETED_EMAIL_KEY => {
'subject' => '{{submitter.email}} has completed the "{{template.name}}" form',
'body' => "Hi,\n\n" \
"{{submitter.email}} has completed the \"{{template.name}}\" form:\n\n" \
"{{submission.link}}\n\n" \
"Thanks,\n" \
'{{account.name}}'
},
SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY => {
'subject' => 'Your copy of documents',
'body' => "Hi there,\n\n" \
"Please check the copy of your \"{{template.name}}\" submission in the email attachments.\n" \
"Alternatively, you can download the copy using:\n\n" \
"{{documents.links}}\n\n" \
"Thanks,\n" \
'{{account.name}}'
}
}.freeze
+9 -5
View File
@@ -21,14 +21,18 @@
# fk_rails_... (account_id => accounts.id)
#
class EncryptedConfig < ApplicationRecord
FILES_STORAGE_KEY = 'active_storage'
EMAIL_SMTP_KEY = 'action_mailer_smtp'
ESIGN_CERTS_KEY = 'esign_certs'
APP_URL_KEY = 'app_url'
WEBHOOK_URL_KEY = 'webhook_url'
CONFIG_KEYS = [
FILES_STORAGE_KEY = 'active_storage',
EMAIL_SMTP_KEY = 'action_mailer_smtp',
ESIGN_CERTS_KEY = 'esign_certs',
APP_URL_KEY = 'app_url',
WEBHOOK_URL_KEY = 'webhook_url'
].freeze
belongs_to :account
validates :key, inclusion: { in: CONFIG_KEYS }
encrypts :value
serialize :value, JSON
+2
View File
@@ -10,6 +10,7 @@
# name :string not null
# schema :text not null
# slug :string not null
# source :text not null
# submitters :text not null
# created_at :datetime not null
# updated_at :datetime not null
@@ -37,6 +38,7 @@ class Template < ApplicationRecord
attribute :schema, :string, default: -> { [] }
attribute :submitters, :string, default: -> { [{ name: DEFAULT_SUBMITTER_NAME, uuid: SecureRandom.uuid }] }
attribute :slug, :string, default: -> { SecureRandom.base58(14) }
attribute :source, :string, default: 'native'
serialize :fields, JSON
serialize :schema, JSON
+15 -7
View File
@@ -11,8 +11,8 @@
# email :string not null
# encrypted_password :string not null
# failed_attempts :integer default(0), not null
# first_name :string not null
# last_name :string not null
# first_name :string
# last_name :string
# last_sign_in_at :datetime
# last_sign_in_ip :string
# locked_at :datetime
@@ -40,20 +40,24 @@
# fk_rails_... (account_id => accounts.id)
#
class User < ApplicationRecord
ROLES = %w[admin].freeze
ROLES = [
ADMIN_ROLE = 'admin'
].freeze
EMAIL_REGEXP = /[^@,\s]+@[^@,\s]+/
belongs_to :account
has_one :access_token, dependent: :destroy
has_many :templates, dependent: :destroy, foreign_key: :author_id, inverse_of: :author
devise :database_authenticatable, :recoverable, :rememberable, :validatable, :trackable
devise :registerable, :omniauthable, omniauth_providers: [:google_oauth2] if Docuseal.multitenant?
attribute :role, :string, default: 'admin'
attribute :role, :string, default: ADMIN_ROLE
attribute :uuid, :string, default: -> { SecureRandom.uuid }
scope :active, -> { where(deleted_at: nil) }
scope :admins, -> { where(role: ADMIN_ROLE) }
def access_token
super || build_access_token.tap(&:save!)
@@ -68,14 +72,18 @@ class User < ApplicationRecord
end
def initials
[first_name.first, last_name.first].join.upcase
[first_name&.first, last_name&.first].compact_blank.join.upcase
end
def full_name
[first_name, last_name].join(' ')
[first_name, last_name].compact_blank.join(' ')
end
def friendly_name
"#{full_name} <#{email}>"
if full_name.present?
"#{full_name} <#{email}>"
else
email
end
end
end
+1 -1
View File
@@ -17,7 +17,7 @@
<div class="pb-6 pt-1 space-y-1">
<p class="flex items-center space-x-1 text-xs text-base-content/60">
<%= svg_icon('user', class: 'w-4 h-4') %>
<span><%= template.author.full_name %></span>
<span><%= template.author.full_name.presence || template.author.email %></span>
</p>
<p class="flex items-center space-x-1 text-xs text-base-content/60">
<%= svg_icon('calendar', class: 'w-4 h-4') %>
+6
View File
@@ -0,0 +1,6 @@
<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="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M8 9l3 3l-3 3" />
<path d="M13 15l3 0" />
<path d="M3 4m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z" />
</svg>

After

Width:  |  Height:  |  Size: 428 B

+6
View File
@@ -0,0 +1,6 @@
<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="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" />
<path d="M21 21l-6 -6" />
<path d="M7 10l2 2l4 -4" />
</svg>

After

Width:  |  Height:  |  Size: 394 B

@@ -1,25 +1,91 @@
<div class="flex flex-wrap space-y-4 md:flex-nowrap md:space-y-0">
<%= render 'shared/settings_nav' %>
<div class="flex-grow max-w-xl mx-auto">
<p class="text-4xl font-bold mb-4">Signature Request Email</p>
<%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY), url: settings_personalization_path, method: :post, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
<%= f.hidden_field :key %>
<%= f.fields_for :value, Struct.new(:subject, :body).new(*f.object.value.values_at('subject', 'body')) do |ff| %>
<div class="form-control">
<%= ff.label :subject, class: 'label' %>
<%= ff.text_field :subject, required: true, class: 'base-input' %>
<p class="text-4xl font-bold mb-4">Email Templates</p>
<div class="collapse collapse-plus bg-base-200 px-1">
<input type="checkbox">
<div class="collapse-title text-xl font-medium">
<div>
Signature Request Email
</div>
<div class="form-control">
<%= ff.label :body, class: 'label' %>
<autoresize-textarea>
<%= ff.text_area :body, required: true, class: 'base-input w-full py-2' %>
</autoresize-textarea>
</div>
<% end %>
<div class="form-control pt-2">
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %>
</div>
<% end %>
<div class="collapse-content">
<%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY), url: settings_personalization_path, method: :post, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
<%= f.hidden_field :key %>
<%= f.fields_for :value, Struct.new(:subject, :body).new(*f.object.value.values_at('subject', 'body')) do |ff| %>
<div class="form-control">
<%= ff.label :subject, class: 'label' %>
<%= ff.text_field :subject, required: true, class: 'base-input' %>
</div>
<div class="form-control">
<%= ff.label :body, class: 'label' %>
<autoresize-textarea>
<%= ff.text_area :body, required: true, class: 'base-input w-full py-2' %>
</autoresize-textarea>
</div>
<% end %>
<div class="form-control pt-2">
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %>
</div>
<% end %>
</div>
</div>
<div class="collapse collapse-plus bg-base-200 px-1 mt-4">
<input type="checkbox">
<div class="collapse-title text-xl font-medium">
<div>
Form Completed Email
</div>
</div>
<div class="collapse-content">
<%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY), url: settings_personalization_path, method: :post, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
<%= f.hidden_field :key %>
<%= f.fields_for :value, Struct.new(:subject, :body).new(*f.object.value.values_at('subject', 'body')) do |ff| %>
<div class="form-control">
<%= ff.label :subject, class: 'label' %>
<%= ff.text_field :subject, required: true, class: 'base-input' %>
</div>
<div class="form-control">
<%= ff.label :body, class: 'label' %>
<autoresize-textarea>
<%= ff.text_area :body, required: true, class: 'base-input w-full py-2' %>
</autoresize-textarea>
</div>
<% end %>
<div class="form-control pt-2">
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %>
</div>
<% end %>
</div>
</div>
<div class="collapse collapse-plus bg-base-200 px-1 mt-4">
<input type="checkbox">
<div class="collapse-title text-xl font-medium">
<div>
Documents Copy Email
</div>
</div>
<div class="collapse-content">
<%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY), url: settings_personalization_path, method: :post, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
<%= f.hidden_field :key %>
<%= f.fields_for :value, Struct.new(:subject, :body).new(*f.object.value.values_at('subject', 'body')) do |ff| %>
<div class="form-control">
<%= ff.label :subject, class: 'label' %>
<%= ff.text_field :subject, required: true, class: 'base-input' %>
</div>
<div class="form-control">
<%= ff.label :body, class: 'label' %>
<autoresize-textarea>
<%= ff.text_area :body, required: true, class: 'base-input w-full py-2' %>
</autoresize-textarea>
</div>
<% end %>
<div class="form-control pt-2">
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %>
</div>
<% end %>
</div>
</div>
<p class="text-4xl font-bold mb-4 mt-8">Company Logo</p>
<%= render 'logo_form' %>
</div>
+10
View File
@@ -6,12 +6,22 @@
<span class="hidden md:inline">
<%= local_assigns[:copy_title] || 'Copy' %>
</span>
<% if local_assigns[:copy_title_md] %>
<span class="inline md:hidden">
<%= local_assigns[:copy_title_md] %>
</span>
<% end %>
</span>
<span class="hidden peer-checked:flex items-center space-x-2">
<%= svg_icon(local_assigns[:copied_icon] || 'clipboard_copy', class: local_assigns[:icon_class] || 'w-6 h-6 text-white') %>
<span class="hidden md:inline">
<%= local_assigns[:copied_title] || 'Copied' %>
</span>
<% if local_assigns[:copied_title_md] %>
<span class="inline md:hidden">
<%= local_assigns[:copied_title_md] %>
</span>
<% end %>
</span>
</label>
</clipboard-copy>
+25 -4
View File
@@ -15,7 +15,14 @@
<% if Docuseal.demo? %>
<%= render 'shared/github_button' %>
<% else %>
<%= link_to 'Settings', settings_profile_index_path, class: 'hidden md:inline font-medium text-lg mr-2' %>
<div class="flex items-center justify-center space-x-4 mr-1">
<%= link_to Docuseal.multitenant? ? console_redirect_index_path : Docuseal::CONSOLE_URL, class: 'hidden md:inline-flex items-center font-medium text-lg', data: { prefetch: false } do %>
Console
<span class="badge badge-warning ml-1">New</span>
<% end %>
<span class="hidden md:inline-flex h-3 border-r border-base-content"></span>
<%= link_to 'Settings', settings_profile_index_path, class: 'hidden md:inline-flex font-medium text-lg' %>
</div>
<% end %>
<div class="dropdown dropdown-end">
<label tabindex="0" class="cursor-pointer bg-base-content text-purple-300 rounded-full p-2 w-9 justify-center flex">
@@ -23,14 +30,28 @@
</label>
<ul tabindex="0" class="z-10 dropdown-content p-2 mt-2 shadow menu text-base bg-base-100 rounded-box whitespace-nowrap text-right">
<li>
<%= link_to settings_profile_index_path do %>
<%= link_to settings_profile_index_path, class: 'flex items-center' do %>
<%= svg_icon('adjustments', class: 'w-5 h-5 stroke-2') %>
<span class="mr-1">Profile</span>
<% end %>
</li>
<% unless Docuseal.demo? %>
<li>
<%= link_to Docuseal.multitenant? ? console_redirect_index_path : Docuseal::CONSOLE_URL, data: { prefetch: false }, class: 'flex items-center' do %>
<%= svg_icon('terminal', class: 'w-5 h-5 stroke-2') %>
Console
<% end %>
</li>
<% end %>
<li>
<%= button_to destroy_user_session_path, method: :delete, data: { turbo: false } do %>
<%= svg_icon('logout', class: 'w-5 h-5 stroke-2 inline') %>
<%= link_to settings_esign_index_path, class: 'flex items-center' do %>
<%= svg_icon('zoom_check', class: 'w-5 h-5 stroke-2') %>
<span class="mr-1">Verify PDF</span>
<% end %>
</li>
<li>
<%= button_to destroy_user_session_path, method: :delete, data: { turbo: false }, class: 'flex items-center' do %>
<%= svg_icon('logout', class: 'w-5 h-5 stroke-2 mr-2 inline') %>
<span class="mr-1">Sign out</span>
<% end %>
</li>
+1 -1
View File
@@ -1,5 +1,5 @@
<turbo-frame id="modal">
<turbo-modal class="modal modal-open items-start !animate-none overflow-y-auto">
<turbo-modal class="modal modal-open items-start !animate-none overflow-y-auto" data-close-after-submit="<%= local_assigns.key?(:close_after_submit) ? local_assigns[:close_after_submit] : true %>">
<div class="absolute top-0 bottom-0 right-0 left-0" data-action="click:turbo-modal#close"></div>
<div class="modal-box pt-4 pb-6 px-6 mt-20 max-h-none">
<% if local_assigns[:title] %>
+32
View File
@@ -0,0 +1,32 @@
<%= render 'shared/turbo_modal', title: 'Export', close_after_submit: false do %>
<div class="space-y-2">
<%= button_to template_submissions_export_index_path(@template), params: { format: :xlsx }, method: :get, data: { turbo_frame: :_top } do %>
<div class="flex items-center p-4 text-left rounded-2xl border border-neutral-300 hover:cursor-pointer hover:bg-neutral hover:text-gray-300">
<div class="enabled">
<%= svg_icon('download', class: 'w-12 h-12 stroke-2 mr-2') %>
</div>
<div class="disabled">
<%= svg_icon('loader', class: 'w-12 h-12 stroke-2 mr-2 animate-spin') %>
</div>
<div class="flex flex-col">
<span class="mb-1 text-lg font-semibold">XLSX</span>
<p class="text-sm"> Primarily opened with Microsoft Excel. Other options include Google Sheets, LibreOffice Calc, and OpenOffice Calc.</p>
</div>
</div>
<% end %>
<%= button_to template_submissions_export_index_path(@template), params: { format: :csv }, method: :get, data: { turbo_frame: :_top } do %>
<div class="flex items-center text-left p-4 rounded-2xl border border-neutral-300 hover:cursor-pointer hover:bg-neutral hover:text-gray-300">
<div class="enabled">
<%= svg_icon('download', class: 'w-12 h-12 stroke-2 mr-2') %>
</div>
<div class="disabled">
<%= svg_icon('loader', class: 'w-12 h-12 stroke-2 mr-2 animate-spin') %>
</div>
<div class="flex flex-col">
<span class="mb-1 text-lg font-semibold">CSV</span>
<p class="text-sm">Can be opened with Microsoft Excel, Google Sheets, or any text editor like Notepad.</p>
</div>
</div>
<% end %>
</div>
<% end %>
@@ -1,3 +1,7 @@
<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>
<% if @email_config %>
<%= auto_link(simple_format(h(ReplaceEmailVariables.call(@email_config.value['body'], submitter: @submitter)))) %>
<% else %>
<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>
<% end %>
@@ -1,13 +1,17 @@
<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>
<% if @email_config %>
<%= auto_link(simple_format(h(ReplaceEmailVariables.call(@email_config.value['body'], submitter: @submitter)))) %>
<% else %>
<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><%= @current_account.name %>
</p>
<% end %>
<p>
Thanks,<br><%= @current_account.name %>
</p>
+1 -1
View File
@@ -1 +1 @@
<template-builder data-is-direct-upload="<%= Docuseal.active_storage_public? %>" data-template="<%= @template.as_json.merge(documents: @template.schema_documents.as_json(include: { preview_images: { methods: %i[url metadata filename] } })).to_json %>"></template-builder>
<template-builder class="grid" data-is-direct-upload="<%= Docuseal.active_storage_public? %>" data-template="<%= @template.as_json.merge(documents: @template.schema_documents.as_json(include: { preview_images: { methods: %i[url metadata filename] } })).to_json %>"></template-builder>
+18 -12
View File
@@ -1,4 +1,4 @@
<div class="flex flex-col md:flex-row space-y-2 md:space-y-0 md:justify-between items-start mb-8">
<div class="flex flex-col items-start md:flex-row space-y-2 md:space-y-0 md:justify-between md:items-center mb-8">
<h1 class="text-4xl font-semibold mr-4" style="overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;">
<%= @template.name %>
</h1>
@@ -17,16 +17,22 @@
</div>
</div>
<% if !@pagy.count.zero? || @template.submitters.to_a.size == 1 %>
<div class="flex justify-between mb-6 items-end">
<div class="flex justify-between mb-6 md:items-end flex-col md:flex-row">
<p class="text-3xl font-bold">Submissions</p>
<div class="flex space-x-2">
<div class="flex space-x-2 mt-3 md:mt-0">
<%= link_to new_template_submissions_export_path(@template), class: 'order-3 md:order-1 btn btn-ghost text-base', data: { turbo_frame: 'modal' } do %>
<%= svg_icon('download', class: 'w-6 h-6 stroke-2') %>
<span>Export</span>
<% end %>
<% if @template.submitters.to_a.size == 1 %>
<%= render 'shared/clipboard_copy', text: start_form_url(slug: @template.slug), class: 'base-button', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy Share Link', copied_title: 'Copied to Clipboard' %>
<span class="order-1">
<%= render 'shared/clipboard_copy', text: start_form_url(slug: @template.slug), class: 'base-button', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy Share Link', copied_title: 'Copied to Clipboard', copy_title_md: 'Copy', copied_title_md: 'Copied' %>
</span>
<% end %>
<% unless @pagy.count.zero? %>
<%= link_to new_template_submission_path(@template), class: 'btn btn-primary text-base', data: { turbo_frame: 'modal' } do %>
<%= link_to new_template_submission_path(@template), class: 'order-1 btn btn-primary text-base', data: { turbo_frame: 'modal' } do %>
<%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %>
<span class="hidden md:block">Add Recipients</span>
<span>Add <span class="hidden md:inline">Recipients</span></span>
<% end %>
<% end %>
</div>
@@ -38,7 +44,7 @@
<% @submissions.each do |submission| %>
<a href="<%= submission_path(submission) %>" class="bg-base-200 w-full flex flex-col md:flex-row space-y-4 md:space-y-0 md:justify-between rounded-2xl px-6 py-5 md:items-center">
<% submitters = (submission.template_submitters || submission.template.submitters).filter_map { |item| submission.submitters.find { |e| e.uuid == item['uuid'] } } %>
<% is_submission_complated = submitters.all?(&:completed_at?) %>
<% is_submission_completed = submitters.all?(&:completed_at?) %>
<% if submitters.size == 1 %>
<div>
<% submitter = submitters.first %>
@@ -80,7 +86,7 @@
<% else %>
<div class="space-y-1 w-full md:mr-2">
<div class="flex items-center space-x-3">
<% if is_submission_complated %>
<% if is_submission_completed %>
<% latest_submitter = submitters.select(&:completed_at?).max_by(&:completed_at) %>
<div class="tooltip flex" data-tip="<%= l(latest_submitter.status_event_at.in_time_zone(current_account.timezone), format: :short, locale: current_account.locale) %>">
<span class="badge <%= status_badges[latest_submitter.status] %> md:w-32 bg-opacity-50 badge-lg uppercase text-sm font-semibold">
@@ -92,7 +98,7 @@
<% submitters.each_with_index do |submitter, index| %>
<div class="flex justify-between items-center space-x-3">
<span class="flex items-center space-x-3">
<% unless is_submission_complated %>
<% unless is_submission_completed %>
<div class="tooltip flex" data-tip="<%= l(submitter.status_event_at.in_time_zone(current_account.timezone), format: :short, locale: current_account.locale) %>">
<span class="badge md:w-24 <%= status_badges[submitter.status] %> bg-opacity-50 uppercase text-xs font-semibold">
<%= submitter.status %>
@@ -103,7 +109,7 @@
<%= submitter.email %>
</span>
</span>
<% if submitter.completed_at? && !is_submission_complated %>
<% if submitter.completed_at? && !is_submission_completed %>
<form onsubmit="event.preventDefault()">
<button onclick="event.stopPropagation()">
<download-button data-src="<%= submitter_download_index_path(submitter.slug) %>" class="btn btn-xs btn-neutral text-white md:w-36">
@@ -118,7 +124,7 @@
</download-button>
</button>
</form>
<% elsif !is_submission_complated %>
<% elsif !is_submission_completed %>
<div class="flex items-center space-x-3">
<%= render 'shared/clipboard_copy', text: submit_form_url(slug: submitter.slug), class: 'btn btn-xs text-xs btn-neutral text-white md:w-36 flex', icon_class: 'w-4 h-4 text-white', copy_title: 'Copy Link' %>
</div>
@@ -129,7 +135,7 @@
</div>
</div>
<div class="flex space-x-2 items-center">
<% if is_submission_complated %>
<% if is_submission_completed %>
<% latest_submitter = submitters.select(&:completed_at?).max_by(&:completed_at) %>
<form onsubmit="event.preventDefault()">
<button onclick="event.stopPropagation()">
+6
View File
@@ -59,4 +59,10 @@ Rails.application.configure do
# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true
config.active_record.encryption = {
primary_key: 'test master key',
deterministic_key: 'test deterministic key',
key_derivation_salt: 'test key derivation salt'
}
end
+3
View File
@@ -0,0 +1,3 @@
# frozen_string_literal: true
require 'csv'
+2 -1
View File
@@ -32,7 +32,7 @@ Rails.application.routes.draw do
resources :submissions, only: %i[create]
resources :templates, only: %i[update show index] do
resources :submissions, only: %i[create]
resources :documents, only: %i[create destroy], controller: 'templates_documents'
resources :documents, only: %i[create], controller: 'templates_documents'
end
end
@@ -44,6 +44,7 @@ Rails.application.routes.draw do
resources :console_redirect, only: %i[index]
resources :templates, only: %i[new create edit show destroy] do
resources :submissions, only: %i[new create]
resources :submissions_export, only: %i[index new]
end
resources :start_form, only: %i[show update], path: 'd', param: 'slug' do
-1
View File
@@ -12,7 +12,6 @@ default: &default
compiler_strategy: digest
cache_manifest: false
ensure_consistent_versioning: false
useContentHash: false
development:
<<: *default
+5
View File
@@ -27,3 +27,8 @@ azure:
storage_access_key: <%= ENV['AZURE_STORAGE_ACCESS_KEY'] %>
container: <%= ENV['AZURE_CONTAINER'] %>
public: <%= ENV['ACTIVE_STORAGE_PUBLIC'] == 'true' %>
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
public: true
@@ -0,0 +1,8 @@
# frozen_string_literal: true
class RemoveUserFirstLastNameNotNull < ActiveRecord::Migration[7.0]
def change
change_column_null :users, :first_name, true
change_column_null :users, :last_name, true
end
end
@@ -0,0 +1,19 @@
# frozen_string_literal: true
class AddSourceToTemplates < ActiveRecord::Migration[7.0]
class MigrationTemplate < ApplicationRecord
self.table_name = 'templates'
end
def up
add_column :templates, :source, :text
MigrationTemplate.where(source: nil).update_all(source: :native)
change_column_null :templates, :source, false
end
def down
drop_column :templates, :source
end
end
+4 -3
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_08_15_190540) do
ActiveRecord::Schema[7.0].define(version: 2023_08_19_190316) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -134,14 +134,15 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_15_190540) do
t.datetime "deleted_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "source", null: false
t.index ["account_id"], name: "index_templates_on_account_id"
t.index ["author_id"], name: "index_templates_on_author_id"
t.index ["slug"], name: "index_templates_on_slug", unique: true
end
create_table "users", force: :cascade do |t|
t.string "first_name", null: false
t.string "last_name", null: false
t.string "first_name"
t.string "last_name"
t.string "email", null: false
t.string "role", null: false
t.string "encrypted_password", null: false
+2
View File
@@ -4,6 +4,8 @@ module ActionMailerConfigsInterceptor
module_function
def delivering_email(message)
return message unless Rails.env.production?
if Docuseal.demo?
message.delivery_method(:test)
+1
View File
@@ -18,6 +18,7 @@ module LoadActiveStorageConfigs
def reload
return if Docuseal.multitenant?
return if IS_ENV_CONFIGURED
return if Rails.env.test?
encrypted_config = EncryptedConfig.find_by(key: EncryptedConfig::FILES_STORAGE_KEY)
+24 -2
View File
@@ -4,18 +4,40 @@ module ReplaceEmailVariables
TEMAPLTE_NAME = '{{template.name}}'
SUBMITTER_LINK = '{{submitter.link}}'
ACCOUNT_NAME = '{{account.name}}'
SUBMITTER_EMAIL = '{{submitter.email}}'
SUBMISSION_LINK = '{{submission.link}}'
DOCUMENTS_LINKS = '{{documents.links}}'
module_function
def call(text, submitter:)
link =
submitter_link =
Rails.application.routes.url_helpers.submit_form_url(
slug: submitter.slug, **Docuseal.default_url_options
)
submission_link =
Rails.application.routes.url_helpers.submission_url(
submitter.submission, **Docuseal.default_url_options
)
text = text.gsub(TEMAPLTE_NAME, submitter.template.name)
text = text.gsub(SUBMITTER_LINK, link)
text = text.gsub(SUBMITTER_EMAIL, submitter.email)
text = text.gsub(SUBMITTER_LINK, submitter_link)
text = text.gsub(SUBMISSION_LINK, submission_link)
text = text.gsub(DOCUMENTS_LINKS, build_documents_links_text(submitter))
text.gsub(ACCOUNT_NAME, submitter.template.account.name)
end
def build_documents_links_text(submitter)
submitter.documents.map do |document|
link =
Rails.application.routes.url_helpers.rails_blob_url(
document, **Docuseal.default_url_options
)
"#{link}\n"
end.join
end
end
+3 -3
View File
@@ -6,7 +6,7 @@ module Submissions
def update_template_fields!(submission)
submission.template_fields = submission.template.fields
submission.template_schema = submission.template.schema
submission.template_submitters = submission.template.submitters
submission.template_submitters = submission.template.submitters if submission.template_submitters.blank?
submission.save!
end
@@ -15,7 +15,7 @@ module Submissions
emails = emails.to_s.scan(User::EMAIL_REGEXP) unless emails.is_a?(Array)
emails.map do |email|
submission = template.submissions.new(created_by_user: user, source:)
submission = template.submissions.new(created_by_user: user, source:, template_submitters: template.submitters)
submission.submitters.new(email:,
uuid: template.submitters.first['uuid'],
sent_at: send_email ? Time.current : nil)
@@ -26,7 +26,7 @@ module Submissions
def create_from_submitters(template:, user:, submissions_attrs:, source:, send_email: false)
submissions_attrs.map do |attrs|
submission = template.submissions.new(created_by_user: user, source:)
submission = template.submissions.new(created_by_user: user, source:, template_submitters: template.submitters)
attrs[:submitters].each_with_index do |submitter_attrs, index|
uuid =
+137
View File
@@ -0,0 +1,137 @@
# frozen_string_literal: true
module Submissions
module GenerateExportFiles
UnknownFormat = Class.new(StandardError)
module_function
def call(submissions, format: :csv)
rows = build_table_rows(submissions)
if format.to_sym == :csv
rows_to_csv(rows)
elsif format.to_sym == :xlsx
rows_to_xlsx(rows)
else
raise UnknownFormat
end
end
def rows_to_xlsx(rows)
workbook = RubyXL::Workbook.new
worksheet = workbook[0]
worksheet.sheet_name = I18n.l(Time.current.to_date)
headers = build_headers(rows)
headers.each_with_index do |column_name, column_index|
worksheet.add_cell(0, column_index, column_name)
end
rows.each.with_index(1) do |row, row_index|
extract_columns(row, headers).each_with_index do |value, column_index|
worksheet.add_cell(row_index, column_index, value)
end
end
workbook.stream.string
end
def rows_to_csv(rows)
headers = build_headers(rows)
CSV.generate do |csv|
csv << headers
rows.each do |row|
csv << extract_columns(row, headers)
end
end
end
def build_headers(rows)
rows.reduce(Set.new) { |acc, row| acc + row.pluck(:name) }
end
def extract_columns(row, headers)
headers.map { |key| row.find { |e| e[:name] == key }&.dig(:value) }
end
def build_table_rows(submissions)
submissions.map do |submission|
submission_data = []
submitters_count = submission.submitters.size
submission.submitters.each do |submitter|
template_submitters = submission.template_submitters || submission.template.submitters
submitter_name = template_submitters.find { |s| s['uuid'] == submitter.uuid }['name']
submission_data += build_submission_data(submitter, submitter_name, submitters_count)
submission_data += submitter_formatted_fields(submitter).map do |field|
{
name: column_name(field[:name], submitter_name, submitters_count),
value: field[:value]
}
end
next if submitter != submission.submitters.select(&:completed_at?).max_by(&:completed_at)
submission_data += submitter.documents.map.with_index(1) do |attachment, index|
{
name: "Document #{index}",
value: attachment.url
}
end
end
submission_data
end
end
def build_submission_data(submitter, submitter_name, submitters_count)
[
{
name: column_name('Email', submitter_name, submitters_count),
value: submitter.email
},
{
name: column_name('Completed At', submitter_name, submitters_count),
value: submitter.completed_at
}
]
end
def column_name(name, submitter_name, submitters_count = 1)
submitters_count > 1 ? "#{submitter_name} - #{name}" : name
end
def submitter_formatted_fields(submitter)
fields = submitter.submission.template_fields || submitter.submission.template.fields
template_fields = fields.select { |f| f['submitter_uuid'] == submitter.uuid }
attachments_index = submitter.attachments.index_by(&:uuid)
template_field_counters = Hash.new { 0 }
template_fields.map do |template_field|
submitter_value = submitter.values.fetch(template_field['uuid'], nil)
template_field_type = template_field['type']
template_field_counters[template_field_type] += 1
template_field_name = template_field['name'].presence
template_field_name ||= "#{template_field_type.titleize} Field #{template_field_counters[template_field_type]}"
value =
if template_field_type.in?(%w[image signature])
attachments_index[submitter_value]&.url
elsif template_field_type == 'file'
Array.wrap(submitter_value).compact_blank.filter_map { |e| attachments_index[e]&.url }
else
submitter_value
end
{ name: template_field_name, uuid: template_field['uuid'], value: }
end
end
end
end
+1 -1
View File
@@ -19,7 +19,7 @@ module Submitters
SendWebhookRequestJob.perform_later(submitter)
end
submitter.submission.template.account.users.active.each do |user|
submitter.submission.template.account.users.active.admins.each do |user|
SubmitterMailer.completed_email(submitter, user).deliver_later!
end
+1 -1
View File
@@ -26,7 +26,7 @@
"postcss-loader": "^7.3.0",
"sass": "^1.62.1",
"sass-loader": "^13.2.2",
"shakapacker": "7.0.0",
"shakapacker": "7.0.3",
"signature_pad": "^4.1.5",
"tailwindcss": "^3.3.2",
"terser-webpack-plugin": "5.3.8",
+9
View File
@@ -0,0 +1,9 @@
# frozen_string_literal: true
FactoryBot.define do
factory :account do
name { Faker::Company.name }
locale { 'en-US' }
timezone { 'UTC' }
end
end
+7
View File
@@ -0,0 +1,7 @@
# frozen_string_literal: true
FactoryBot.define do
factory :encrypted_config do
account
end
end
+14
View File
@@ -0,0 +1,14 @@
# frozen_string_literal: true
FactoryBot.define do
factory :submission do
template
created_by_user factory: %i[user]
before(:create) do |submission, _|
submission.template_fields = submission.template.fields
submission.template_schema = submission.template.schema
submission.template_submitters = submission.template.submitters
end
end
end
+8
View File
@@ -0,0 +1,8 @@
# frozen_string_literal: true
FactoryBot.define do
factory :submitter do
submission
email { Faker::Internet.email }
end
end
+62
View File
@@ -0,0 +1,62 @@
# frozen_string_literal: true
FactoryBot.define do
factory :template do
account
author factory: %i[user]
name { Faker::Book.title }
after(:create) do |template|
blob = ActiveStorage::Blob.create_and_upload!(
io: Rails.root.join('spec/fixtures/sample-document.pdf').open,
filename: 'sample-document.pdf',
content_type: 'application/pdf'
)
attachment = ActiveStorage::Attachment.create!(
blob:,
name: :documents,
record: template
)
Templates::ProcessDocument.call(attachment)
template.schema = [{ attachment_uuid: attachment.uuid, name: 'sample-document' }]
template.submitters = [
{
'name' => 'First Submitter',
'uuid' => '513848eb-1096-4abc-a743-68596b5aaa4c'
}
]
template.fields = [
{
'uuid' => '21637fc9-0655-45df-8952-04ec64949e85',
'submitter_uuid' => '513848eb-1096-4abc-a743-68596b5aaa4c',
'name' => 'First Name',
'type' => 'text',
'required' => true,
'areas' => [
{
'x' => 0.09027777777777778,
'y' => 0.1197252208047105,
'w' => 0.3069444444444444,
'h' => 0.03336604514229637,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => '1f97f8e3-dc82-4586-aeea-6ebed6204e46',
'submitter_uuid' => '513848eb-1096-4abc-a743-68596b5aaa4c',
'name' => '',
'type' => 'signature',
'required' => true,
'areas' => []
}
]
template.save!
end
end
end
+12
View File
@@ -0,0 +1,12 @@
# frozen_string_literal: true
FactoryBot.define do
factory :user do
account
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
password { 'password' }
role { User::ADMIN_ROLE }
email { Faker::Internet.email }
end
end
Binary file not shown.
+2
View File
@@ -7,6 +7,7 @@ require_relative '../config/environment'
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'rspec/rails'
require 'capybara/cuprite'
require 'capybara/rspec'
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)
@@ -45,6 +46,7 @@ RSpec.configure do |config|
config.filter_rails_from_backtrace!
config.include FactoryBot::Syntax::Methods
config.include Devise::Test::IntegrationHelpers
config.before(:each, type: :system) do
if ENV['HEADLESS'] == 'false'
+39
View File
@@ -0,0 +1,39 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Account Settings' do
let!(:account) { create(:account) }
let!(:user) { create(:user, account:) }
let!(:encrypted_config) { create(:encrypted_config, account:, key: EncryptedConfig::APP_URL_KEY, value: 'https://www.test.com') }
before do
sign_in(user)
visit settings_account_path
end
it 'shows pre-filled account settings page' do
expect(page).to have_content('Account')
expect(page).to have_field('Company Name', with: account.name)
expect(page).to have_field('Timezone', with: account.timezone)
expect(page).to have_field('Time format', with: account.locale)
expect(page).to have_field('App URL', with: encrypted_config.value)
end
it 'updates the account settings' do
fill_in 'Company Name', with: 'New Company Name'
fill_in 'App URL', with: 'https://example.com'
select '(GMT+01:00) Berlin', from: 'Timezone'
select 'Spanish (Spain)', from: 'Time format'
click_button 'Update'
account.reload
encrypted_config.reload
expect(account.name).to eq('New Company Name')
expect(account.timezone).to eq('Berlin')
expect(account.locale).to eq('es-ES')
expect(encrypted_config.value).to eq('https://example.com')
end
end
+18
View File
@@ -0,0 +1,18 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'API Settings' do
let!(:account) { create(:account) }
let!(:user) { create(:user, account:) }
before do
sign_in(user)
visit settings_api_index_path
end
it 'shows verify signed PDF page' do
expect(page).to have_content('API')
expect(page).to have_field('X-Auth-Token', with: user.access_token.token)
end
end
+55
View File
@@ -0,0 +1,55 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Dashboard Page' do
let!(:account) { create(:account) }
let!(:user) { create(:user, account:) }
before do
sign_in(user)
end
context 'when are no templates' do
it 'shows empty state' do
visit root_path
expect(page).to have_content('Welcome to DocuSeal')
expect(page).to have_content('Streamline document workflows, from creating customizable')
expect(page).to have_link('Create Template', href: new_template_path)
end
end
context 'when there are templates' do
let!(:authors) { create_list(:user, 5, account:) }
let!(:templates) { authors.map { |author| create(:template, account:, author:) } }
before do
visit root_path
end
it 'shows the list of templates' do
templates.each do |template|
expect(page).to have_content(template.name)
expect(page).to have_content(template.author.full_name)
end
expect(page).to have_content('Templates')
expect(page).to have_link('Create', href: new_template_path)
end
it 'initializes the template creation process' do
click_link 'Create'
within('#modal') do
fill_in 'template[name]', with: 'New Template'
expect do
click_button 'Create'
end.to change(Template, :count).by(1)
expect(page).to have_current_path(edit_template_path(Template.last), ignore_query: true)
end
end
end
end
+98
View File
@@ -0,0 +1,98 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Email Settings' do
let!(:account) { create(:account) }
let!(:user) { create(:user, account:) }
before do
sign_in(user)
end
context 'when SMTP settings are not set' do
it 'setup SMTP settings' do
visit settings_email_index_path
fill_in 'Host', with: 'smtp.example.com'
fill_in 'Port', with: '587'
fill_in 'Username', with: 'user@example.com'
fill_in 'Password', with: 'password'
fill_in 'Domain', with: 'example.com'
fill_in 'Send from Email', with: 'user@example.com'
select 'Plain', from: 'Authentication'
choose 'TLS'
expect do
click_button 'Save'
end.to change(EncryptedConfig, :count).by(1)
encrypted_config = EncryptedConfig.find_by(account:, key: EncryptedConfig::EMAIL_SMTP_KEY)
expect(encrypted_config.value['host']).to eq('smtp.example.com')
expect(encrypted_config.value['port']).to eq('587')
expect(encrypted_config.value['username']).to eq('user@example.com')
expect(encrypted_config.value['password']).to eq('password')
expect(encrypted_config.value['domain']).to eq('example.com')
expect(encrypted_config.value['authentication']).to eq('plain')
expect(encrypted_config.value['security']).to eq('tls')
expect(encrypted_config.value['from_email']).to eq('user@example.com')
end
end
context 'when SMTP settings are set' do
let!(:encrypted_config) do
create(:encrypted_config, account:, key: EncryptedConfig::EMAIL_SMTP_KEY, value: {
host: 'smtp.example.com',
port: '587',
username: 'user@example.co',
password: 'password',
domain: 'example.com',
authentication: 'plain',
security: 'tls',
from_email: 'user@example.co'
})
end
before do
visit settings_email_index_path
end
it 'shows pre-filled SMTP settings' do
expect(page).to have_content('Email SMTP')
expect(page).to have_field('Host', with: encrypted_config.value['host'])
expect(page).to have_field('Port', with: encrypted_config.value['port'])
expect(page).to have_field('Username', with: encrypted_config.value['username'])
expect(page).to have_field('Password', with: encrypted_config.value['password'])
expect(page).to have_field('Domain', with: encrypted_config.value['domain'])
expect(page).to have_select('Authentication', selected: 'Plain')
expect(page).to have_field('Send from Email', with: encrypted_config.value['from_email'])
end
it 'updates SMTP settings' do
fill_in 'Host', with: 'smtp.gmail.com'
fill_in 'Port', with: '465'
fill_in 'Username', with: 'user@gmail.com'
fill_in 'Password', with: 'new_password'
fill_in 'Domain', with: 'gmail.com'
fill_in 'Send from Email', with: 'user@gmail.com'
select 'Plain', from: 'Authentication'
choose 'SSL'
expect do
click_button 'Save'
end.not_to change(EncryptedConfig, :count)
encrypted_config.reload
expect(encrypted_config.value['host']).to eq('smtp.gmail.com')
expect(encrypted_config.value['port']).to eq('465')
expect(encrypted_config.value['username']).to eq('user@gmail.com')
expect(encrypted_config.value['password']).to eq('new_password')
expect(encrypted_config.value['domain']).to eq('gmail.com')
expect(encrypted_config.value['authentication']).to eq('plain')
expect(encrypted_config.value['security']).to eq('ssl')
expect(encrypted_config.value['from_email']).to eq('user@gmail.com')
end
end
end
+20
View File
@@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'PDF Signature Settings' do
let!(:account) { create(:account) }
let!(:user) { create(:user, account:) }
before do
sign_in(user)
visit settings_esign_index_path
end
it 'shows verify signed PDF page' do
expect(page).to have_content('PDF Signature')
expect(page).to have_content('Upload signed PDF file to validate its signature')
expect(page).to have_content('Verify Signed PDF')
expect(page).to have_content('Click to upload or drag and drop files')
end
end
+32
View File
@@ -0,0 +1,32 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Newsletter' do
let(:user) { create(:user, account: create(:account)) }
before do
sign_in(user)
stub_request(:post, Docuseal::NEWSLETTER_URL).to_return(status: 200)
visit newsletter_path
end
it 'shows the newsletter page' do
expect(page).to have_content('Developer Newsletters')
expect(page).to have_button('Submit')
expect(page).to have_content('Skip')
expect(page).to have_field('user[email]', with: user.email)
end
it 'submits the newsletter form' do
click_button 'Submit'
expect(a_request(:post, Docuseal::NEWSLETTER_URL)).to have_been_made.once
end
it 'skips the newsletter form' do
click_on 'Skip'
expect(page).to have_current_path(root_path, ignore_query: true)
end
end
+23
View File
@@ -0,0 +1,23 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Personalization' do
let!(:account) { create(:account) }
let!(:user) { create(:user, account:) }
before do
sign_in(user)
visit settings_personalization_path
end
it 'shows the personalization page' do
expect(page).to have_content('Email Templates')
expect(page).to have_content('Signature Request Email')
expect(page).to have_content('Form Completed Email')
expect(page).to have_content('Documents Copy Email')
expect(page).to have_content('Company Logo')
expect(page).to have_content('Unlock with DocuSeal Enterprise')
expect(page).to have_content('Display your company name and logo when signing documents')
end
end
+59
View File
@@ -0,0 +1,59 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Profile Settings' do
let(:user) { create(:user, account: create(:account)) }
before do
sign_in(user)
visit settings_profile_index_path
end
it 'shows the profile settings page' do
expect(page).to have_content('Profile')
expect(page).to have_field('user[email]', with: user.email)
expect(page).to have_field('user[first_name]', with: user.first_name)
expect(page).to have_field('user[last_name]', with: user.last_name)
expect(page).to have_content('Change Password')
expect(page).to have_field('user[password]')
expect(page).to have_field('user[password_confirmation]')
end
context 'when changes contact information' do
it 'updates first name, last name and email' do
fill_in 'First name', with: 'Devid'
fill_in 'Last name', with: 'Beckham'
fill_in 'Email', with: 'david.beckham@example.com'
all(:button, 'Update')[0].click
user.reload
expect(user.first_name).to eq('Devid')
expect(user.last_name).to eq('Beckham')
expect(user.email).to eq('david.beckham@example.com')
end
end
context 'when changes password' do
it 'updates password' do
fill_in 'New password', with: 'newpassword'
fill_in 'Confirm new password', with: 'newpassword'
all(:button, 'Update')[1].click
expect(page).to have_content('Password has been changed')
end
it 'does not update if password confirmation does not match' do
fill_in 'New password', with: 'newpassword'
fill_in 'Confirm new password', with: 'newpassword1'
all(:button, 'Update')[1].click
expect(page).to have_content("Password confirmation doesn't match Password")
end
end
end
+88
View File
@@ -0,0 +1,88 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'App Setup', js: true do
let(:form_data) do
{
first_name: 'John',
last_name: 'Doe',
email: 'john.doe@example.com',
company_name: 'Example Company',
password: 'password',
app_url: 'https://example.com'
}
end
before do
visit setup_index_path
end
it 'shows the setup page' do
expect(page).to have_content('Initial Setup')
['First name', 'Last name', 'Email', 'Company name', 'Password', 'App URL'].each do |field|
expect(page).to have_field(field)
end
end
context 'when valid information' do
it 'setups the app' do
fill_setup_form(form_data)
expect do
click_button 'Submit'
sleep 1
end.to change(Account, :count).by(1).and change(User, :count).by(1).and change(EncryptedConfig, :count).by(2)
user = User.last
encrypted_config_app_url = EncryptedConfig.find_by(account: user.account,
key: EncryptedConfig::APP_URL_KEY)
encrypted_config_esign_certs = EncryptedConfig.find_by(account: user.account,
key: EncryptedConfig::ESIGN_CERTS_KEY)
expect(user.first_name).to eq(form_data[:first_name])
expect(user.last_name).to eq(form_data[:last_name])
expect(user.email).to eq(form_data[:email])
expect(user.account.timezone).to eq('UTC')
expect(user.account.locale).to eq('en-US')
expect(user.account.name).to eq(form_data[:company_name])
expect(encrypted_config_app_url.value).to eq(form_data[:app_url])
expect(encrypted_config_esign_certs.value).to be_present
end
end
context 'when invalid information' do
it 'does not setup the app if the password is too short' do
fill_setup_form(form_data.merge(password: 'pass'))
expect do
click_button 'Submit'
end.not_to(change(User, :count))
expect(page).to have_content('Password is too short (minimum is 6 characters)')
end
end
context 'when the app is already setup' do
let!(:user) { create(:user, account: create(:account)) }
it 'redirects to the dashboard page' do
sign_in(user)
visit setup_index_path
expect(page).to have_content('Welcome to DocuSeal')
end
end
private
def fill_setup_form(form_data)
fill_in 'First name', with: form_data[:first_name]
fill_in 'Last name', with: form_data[:last_name]
fill_in 'Email', with: form_data[:email]
fill_in 'Company name', with: form_data[:company_name]
fill_in 'Password', with: form_data[:password]
fill_in 'App URL', with: form_data[:app_url]
end
end
+247
View File
@@ -0,0 +1,247 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Storage Settings' do
let!(:account) { create(:account) }
let!(:user) { create(:user, account:) }
before do
sign_in(user)
end
context 'when storage settings are not set' do
before do
visit settings_storage_index_path
end
context 'when Disk is selected' do
it 'shows default storage settings page' do
expect(page).to have_content('Storage')
expect(page).to have_content('Store all files on disk')
expect(page).to have_content('No configs are needed but make sure your disk is persistent')
expect(page).to have_checked_field('Disk')
end
end
context 'when AWS S3 is selected' do
it 'setups AWS S3 storage settings' do
choose 'AWS'
fill_in 'Access key ID', with: 'access_key_id'
fill_in 'Secret access key', with: 'secret_access_key'
fill_in 'Region', with: 'us-west-1'
fill_in 'Bucket', with: 'bucket'
fill_in 'Endpoint', with: 'https://s3.us-west-1.amazonaws.com'
expect do
click_button 'Save'
end.to change(EncryptedConfig, :count).by(1)
encrypted_config = EncryptedConfig.find_by(account:, key: EncryptedConfig::FILES_STORAGE_KEY)
configs = encrypted_config.value['configs']
expect(encrypted_config.value['service']).to eq('aws_s3')
expect(configs['access_key_id']).to eq('access_key_id')
expect(configs['secret_access_key']).to eq('secret_access_key')
expect(configs['region']).to eq('us-west-1')
expect(configs['bucket']).to eq('bucket')
expect(configs['endpoint']).to eq('https://s3.us-west-1.amazonaws.com')
end
end
context 'when Google Cloud Storage is selected' do
it 'setups Google Cloud Storage settings' do
choose 'GCP'
fill_in 'Project', with: 'project_id'
fill_in 'Bucket', with: 'bucket'
fill_in 'Credentials (JSON key content)', with: '{ "type": "service_account", "project_id": "project_id" }'
expect do
click_button 'Save'
end.to change(EncryptedConfig, :count).by(1)
encrypted_config = EncryptedConfig.find_by(account:, key: EncryptedConfig::FILES_STORAGE_KEY)
configs = encrypted_config.value['configs']
expect(encrypted_config.value['service']).to eq('google')
expect(configs['project']).to eq('project_id')
expect(configs['bucket']).to eq('bucket')
expect(configs['credentials']).to eq('{ "type": "service_account", "project_id": "project_id" }')
end
end
context 'when Azure is selected' do
it 'setup Azure storage settings' do
choose 'Azure'
fill_in 'Storage Account Name', with: 'storage_account_name'
fill_in 'Container', with: 'container'
fill_in 'Storage Access Key', with: 'storage_access_key'
expect do
click_button 'Save'
end.to change(EncryptedConfig, :count).by(1)
encrypted_config = EncryptedConfig.find_by(account:, key: EncryptedConfig::FILES_STORAGE_KEY)
configs = encrypted_config.value['configs']
expect(encrypted_config.value['service']).to eq('azure')
expect(configs['storage_account_name']).to eq('storage_account_name')
expect(configs['container']).to eq('container')
expect(configs['storage_access_key']).to eq('storage_access_key')
end
end
end
context 'when storage settings are set' do
context 'when updates the same storage settings' do
context 'when AWS S3' do
let!(:encrypted_config) do
create(:encrypted_config, account:, key: EncryptedConfig::FILES_STORAGE_KEY, value: {
service: 'aws_s3',
configs: {
access_key_id: 'access_key_id',
secret_access_key: 'secret_access_key',
region: 'us-west-1',
bucket: 'bucket',
endpoint: 'https://s3.us-west-1.amazonaws.com'
}
})
end
it 'updates AWS S3 storage settings' do
visit settings_storage_index_path
fill_in 'Access key ID', with: 'new_access_key_id'
fill_in 'Secret access key', with: 'new_secret_access_key'
fill_in 'Region', with: 'us-west-2'
fill_in 'Bucket', with: 'new_bucket'
fill_in 'Endpoint', with: 'https://s3.us-west-2.amazonaws.com'
expect do
click_button 'Save'
end.not_to(change(EncryptedConfig, :count))
encrypted_config.reload
configs = encrypted_config.value['configs']
expect(encrypted_config.value['service']).to eq('aws_s3')
expect(configs['access_key_id']).to eq('new_access_key_id')
expect(configs['secret_access_key']).to eq('new_secret_access_key')
expect(configs['region']).to eq('us-west-2')
expect(configs['bucket']).to eq('new_bucket')
expect(configs['endpoint']).to eq('https://s3.us-west-2.amazonaws.com')
end
end
context 'when Google Cloud Storage' do
let!(:encrypted_config) do
create(:encrypted_config, account:, key: EncryptedConfig::FILES_STORAGE_KEY, value: {
service: 'google',
configs: {
project: 'project_id',
bucket: 'bucket',
credentials: '{ "type": "service_account", "project_id": "project_id" }'
}
})
end
it 'updates Google Cloud Storage settings' do
visit settings_storage_index_path
fill_in 'Project', with: 'new_project_id'
fill_in 'Bucket', with: 'new_bucket'
fill_in 'Credentials (JSON key content)',
with: '{ "type": "new_service_account", "project_id": "new_project_id" }'
expect do
click_button 'Save'
end.not_to(change(EncryptedConfig, :count))
encrypted_config.reload
configs = encrypted_config.value['configs']
expect(encrypted_config.value['service']).to eq('google')
expect(configs['project']).to eq('new_project_id')
expect(configs['bucket']).to eq('new_bucket')
expect(configs['credentials']).to eq('{ "type": "new_service_account", "project_id": "new_project_id" }')
end
end
context 'when Azure' do
let!(:encrypted_config) do
create(:encrypted_config, account:, key: EncryptedConfig::FILES_STORAGE_KEY, value: {
service: 'azure',
configs: {
storage_account_name: 'storage_account_name',
container: 'container',
storage_access_key: 'storage_access_key'
}
})
end
it 'updates Azure storage settings' do
visit settings_storage_index_path
fill_in 'Storage Account Name', with: 'new_storage_account_name'
fill_in 'Container', with: 'new_container'
fill_in 'Storage Access Key', with: 'new_storage_access_key'
expect do
click_button 'Save'
end.not_to(change(EncryptedConfig, :count))
encrypted_config.reload
configs = encrypted_config.value['configs']
expect(encrypted_config.value['service']).to eq('azure')
expect(configs['storage_account_name']).to eq('new_storage_account_name')
expect(configs['container']).to eq('new_container')
expect(configs['storage_access_key']).to eq('new_storage_access_key')
end
end
end
context 'when switches to another storage settings' do
context 'when Google Cloud Storage' do
let!(:encrypted_config) do
create(:encrypted_config, account:, key: EncryptedConfig::FILES_STORAGE_KEY, value: {
service: 'google',
configs: {
project: 'project_id',
bucket: 'bucket',
credentials: '{ "type": "service_account", "project_id": "project_id" }'
}
})
end
it 'switches to AWS S3' do
visit settings_storage_index_path
choose 'AWS'
fill_in 'Access key ID', with: 'access_key_id'
fill_in 'Secret access key', with: 'secret_access_key'
fill_in 'Region', with: 'us-west-1'
fill_in 'Bucket', with: 'bucket'
fill_in 'Endpoint', with: 'https://s3.us-west-1.amazonaws.com'
expect do
click_button 'Save'
end.not_to(change(EncryptedConfig, :count))
encrypted_config.reload
configs = encrypted_config.value['configs']
expect(encrypted_config.value['service']).to eq('aws_s3')
expect(configs['access_key_id']).to eq('access_key_id')
expect(configs['secret_access_key']).to eq('secret_access_key')
expect(configs['region']).to eq('us-west-1')
expect(configs['bucket']).to eq('bucket')
expect(configs['endpoint']).to eq('https://s3.us-west-1.amazonaws.com')
end
end
end
end
end
+95
View File
@@ -0,0 +1,95 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Submit Form' do
let!(:account) { create(:account) }
let!(:user) { create(:user, account:) }
let!(:template) { create(:template, account:, author: user) }
before do
sign_in(user)
end
context 'when initialized by shared link' do
before do
visit start_form_path(slug: template.slug)
end
it 'shows start form page' do
expect(page).to have_content('You have been invited to submit a form')
expect(page).to have_content(template.name)
expect(page).to have_content("Invited by #{template.account.name}")
end
it 'complete the form' do
fill_in 'Email', with: 'john.dou@example.com'
click_button 'Start'
fill_in 'First Name', with: 'Adam'
click_on 'Next'
click_on 'type_text_button'
fill_in 'signature_text_input', with: 'Adam'
expect do
click_on 'Submit'
end.not_to(change(Submitter, :count))
submitter = Submitter.find_by(email: 'john.dou@example.com')
expect(page).to have_button('Download')
expect(submitter.email).to eq('john.dou@example.com')
expect(submitter.ip).to eq('127.0.0.1')
expect(submitter.ua).to be_present
expect(submitter.opened_at).to be_present
expect(submitter.completed_at).to be_present
expect(submitter.values.values).to include('Adam')
end
end
context 'when initialized by shared email address' do
let!(:submission) { create(:submission, template:, created_by_user: user) }
let!(:submitters) { template.submitters.map { |s| create(:submitter, submission:, uuid: s['uuid']) } }
let(:submitter) { submitters.first }
before do
visit submit_form_path(slug: submitter.slug)
end
it 'completes the form' do
fill_in 'First Name', with: 'Sally'
click_on 'Next'
click_on 'type_text_button'
fill_in 'signature_text_input', with: 'Sally'
click_on 'Submit'
submitter.reload
expect(page).to have_button('Download')
expect(submitter.ip).to eq('127.0.0.1')
expect(submitter.ua).to be_present
expect(submitter.opened_at).to be_present
expect(submitter.completed_at).to be_present
expect(submitter.values.values).to include('Sally')
end
it 'sends completed email' do
fill_in 'First Name', with: 'Adam'
click_on 'Next'
click_on 'type_text_button'
fill_in 'signature_text_input', with: 'Adam'
expect do
click_on 'Submit'
end.to change { ActionMailer::Base.deliveries.size }.by(1)
email = ActionMailer::Base.deliveries.last
expect(email.subject).to eq("#{submitter.email} has completed the \"#{template.name}\" form")
expect(email.body.encoded).to include "Hi #{user.first_name},"
expect(email.body.encoded).to include "#{submitter.email} has completed the \"#{template.name}\" form."
expect(email.body.encoded).to have_link('View Submission')
end
end
end
+96
View File
@@ -0,0 +1,96 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Team Settings' do
let(:account) { create(:account) }
let(:current_user) { create(:user, account:) }
before do
sign_in(current_user)
end
context 'when multiple users' do
let!(:users) { create_list(:user, 2, account:) }
before do
visit settings_users_path
end
it 'shows all users' do
within '.table' do
users.each do |user|
expect(page).to have_content(user.full_name)
expect(page).to have_content(user.email)
end
end
end
it 'creates a new user' do
click_link 'New User'
within '#modal' do
fill_in 'First name', with: 'Joseph'
fill_in 'Last name', with: 'Smith'
fill_in 'Email', with: 'joseph.smith@example.com'
fill_in 'Password', with: 'password'
expect do
click_button 'Submit'
end.to change(User, :count).by(1)
user = User.last
expect(user.first_name).to eq('Joseph')
expect(user.last_name).to eq('Smith')
expect(user.email).to eq('joseph.smith@example.com')
expect(user.account).to eq(account)
end
end
it 'updates a user' do
first(:link, 'Edit').click
fill_in 'First name', with: 'Adam'
fill_in 'Last name', with: 'Meier'
fill_in 'Email', with: 'adam.meier@example.com'
fill_in 'Password', with: 'new_password'
expect do
click_button 'Submit'
end.not_to change(User, :count)
user = User.find_by(email: 'adam.meier@example.com')
expect(user.first_name).to eq('Adam')
expect(user.last_name).to eq('Meier')
expect(user.email).to eq('adam.meier@example.com')
end
it 'removes a user' do
expect do
accept_confirm('Are you sure?') do
first(:link, 'Delete').click
end
end.to change { User.active.count }.by(-1)
expect(page).to have_content('User has been removed')
end
end
context 'when single user' do
before do
visit settings_users_path
end
it 'does not allow to remove the current user' do
expect do
accept_confirm('Are you sure?') do
first(:link, 'Delete').click
end
end.not_to(change { User.admins.count })
expect(page).to have_content('Unable to remove user')
end
end
end
+80
View File
@@ -0,0 +1,80 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Template' do
let!(:account) { create(:account) }
let!(:user) { create(:user, account:) }
let!(:template) { create(:template, account:, author: user) }
before do
sign_in(user)
end
context 'when no submissions' do
it 'shows the template page' do
visit template_path(template)
expect(page).to have_content(template.name)
expect(page).to have_content('There are no Submissions')
expect(page).to have_content('Send an invitation to fill and complete the form')
expect(page).to have_link('Add Recipients', href: new_template_submission_path(template))
expect(page).to have_link('Submit it Yourself')
end
end
context 'when there are submissions' do
let!(:submission) { create(:submission, template:, created_by_user: user) }
let!(:submitters) { template.submitters.map { |s| create(:submitter, submission:, uuid: s['uuid']) } }
it 'shows the template page with submissions' do
visit template_path(template)
submitters.each do |submitter|
expect(page).to have_content(submitter.email)
end
expect(page).to have_content(template.name)
end
end
context 'when managing a template' do
before do
visit template_path(template)
end
it 'removes a template' do
expect do
accept_confirm('Are you sure?') do
click_button 'Remove'
end
end.to change { Template.active.count }.by(-1)
expect(page).to have_content('Template has been archived')
expect(page).to have_current_path(root_path, ignore_query: true)
end
it 'edits a template' do
click_link 'Edit'
expect(page).to have_current_path(edit_template_path(template), ignore_query: true)
end
it 'clones a template' do
click_link 'Clone'
within '#modal' do
fill_in 'template[name]', with: 'New Template Name'
expect do
click_button 'Submit'
end.to change { Template.active.count }.by(1)
template = Template.last
expect(template.name).to eq('New Template Name')
expect(page).to have_current_path(edit_template_path(template), ignore_query: true)
end
end
end
end
+31
View File
@@ -0,0 +1,31 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Webhook Settings' do
let!(:account) { create(:account) }
let!(:user) { create(:user, account:) }
before do
sign_in(user)
visit settings_webhooks_path
end
it 'shows webhook settings page' do
expect(page).to have_content('Webhooks')
expect(page).to have_field('Webhook URL')
expect(page).to have_button('Save')
end
it 'updates the webhook URL' do
fill_in 'Webhook URL', with: 'https://example.com'
expect do
click_button 'Save'
end.to change(EncryptedConfig, :count).by(1)
encrypted_config = EncryptedConfig.find_by(account:, key: EncryptedConfig::WEBHOOK_URL_KEY)
expect(encrypted_config.value).to eq('https://example.com')
end
end
+4 -4
View File
@@ -4827,10 +4827,10 @@ setprototypeof@1.2.0:
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424"
integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==
shakapacker@7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/shakapacker/-/shakapacker-7.0.0.tgz#788c96e86eb78e44ee84c3cc03b7c091e4621fc3"
integrity sha512-yL5lbCdgtI8nUxZHarL7X5aB40r069wAunHwb59Hgw1gPg6/nMuYo7ofNTGXg11v1eunwAdjx8EfYnk4XwX27Q==
shakapacker@7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/shakapacker/-/shakapacker-7.0.3.tgz#e67fca4e74c3ef380e1acf53a1d51ab4784ca01c"
integrity sha512-2kwNP8kadkmGOqb7Bp/iNzF3bV31zni8b35Uzst2DZHjnFcnDbW96MERXHc7lS3p3AmKJVbUBmHAFCPsLT9tcw==
dependencies:
glob "^7.2.0"
js-yaml "^4.1.0"