Skip to content

Commit

Permalink
Merge from docusealco/wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBTurchyn authored Dec 9, 2024
2 parents c5178b9 + c2014a1 commit dd18c51
Show file tree
Hide file tree
Showing 51 changed files with 664 additions and 121 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ GEM
activesupport (>= 4)
railties (>= 4)
request_store (~> 1.0)
loofah (2.22.0)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
Expand All @@ -311,7 +311,7 @@ GEM
method_source (1.1.0)
mini_magick (4.13.2)
mini_mime (1.1.5)
mini_portile2 (2.8.7)
mini_portile2 (2.8.8)
minitest (5.25.1)
msgpack (1.7.3)
multi_json (1.15.0)
Expand All @@ -330,12 +330,12 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.7)
nokogiri (1.16.8)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.7-aarch64-linux)
nokogiri (1.16.8-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
nokogiri (1.16.8-x86_64-linux)
racc (~> 1.4)
oj (3.16.6)
bigdecimal (>= 3.0)
Expand Down Expand Up @@ -400,9 +400,9 @@ GEM
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
rails-html-sanitizer (1.6.1)
loofah (~> 2.21)
nokogiri (~> 1.14)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
rails-i18n (7.0.9)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/api/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def create

submissions.each do |submission|
submission.submitters.each do |submitter|
ProcessSubmitterCompletionJob.perform_async('submitter_id' => submitter.id) if submitter.completed_at?
next unless submitter.completed_at?

ProcessSubmitterCompletionJob.perform_async('submitter_id' => submitter.id, 'send_invitation_email' => false)
end
end

Expand Down
3 changes: 3 additions & 0 deletions app/controllers/submissions_archived_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def index
@submissions = @submissions.where.not(archived_at: nil)
.or(@submissions.where.not(templates: { archived_at: nil }))
.preload(:created_by_user, template: :author)

@submissions = @submissions.preload(:template_accesses) unless current_user.role.in?(%w[admin superadmin])

@submissions = Submissions.search(@submissions, params[:q], search_template: true)
@submissions = Submissions::Filter.call(@submissions, current_user, params)

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/submissions_dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def index
.where(templates: { archived_at: nil })
.preload(:created_by_user, template: :author)

@submissions = @submissions.preload(:template_accesses) unless current_user.role.in?(%w[admin superadmin])

@submissions = Submissions.search(@submissions, params[:q], search_template: true)
@submissions = Submissions::Filter.call(@submissions, current_user, params)

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/submitters_autocomplete_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class SubmittersAutocompleteController < ApplicationController
def index
submitters = search_submitters(@submitters)

values = submitters.limit(LIMIT).group(SELECT_COLUMNS.join(', ')).pluck(SELECT_COLUMNS.join(', '))
arel_columns = SELECT_COLUMNS.map { |col| Submitter.arel_table[col] }
values = submitters.limit(LIMIT).group(arel_columns).pluck(arel_columns)

attrs = values.map { |row| SELECT_COLUMNS.zip(row).to_h }
attrs = attrs.uniq { |e| e[params[:field]] } if params[:field].present?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/template_folders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class TemplateFoldersController < ApplicationController
load_and_authorize_resource :template_folder

def show
@templates = @template_folder.templates.active.preload(:author).order(id: :desc)
@templates = @template_folder.templates.active.preload(:author, :template_accesses).order(id: :desc)
@templates = Templates.search(@templates, params[:q])

@pagy, @templates = pagy(@templates, limit: 12)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/templates_archived_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class TemplatesArchivedController < ApplicationController
load_and_authorize_resource :template, parent: false

def index
@templates = @templates.where.not(archived_at: nil).preload(:author, :folder).order(id: :desc)
@templates = @templates.where.not(archived_at: nil).preload(:author, :folder, :template_accesses).order(id: :desc)
@templates = Templates.search(@templates, params[:q])

@pagy, @templates = pagy(@templates, limit: 12)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def show
submissions.order(id: :desc)
end

submissions = submissions.preload(:template_accesses) unless current_user.role.in?(%w[admin superadmin])

@pagy, @submissions = pagy(submissions.preload(submitters: :start_form_submission_events))
rescue ActiveRecord::RecordNotFound
redirect_to root_path
Expand Down Expand Up @@ -109,7 +111,7 @@ def destroy
def template_params
params.require(:template).permit(
:name,
{ schema: [%i[attachment_uuid name]],
{ schema: [[:attachment_uuid, :name, { conditions: [%i[field_uuid value action operation]] }]],
submitters: [%i[name uuid is_requester linked_to_uuid invite_by_uuid email]],
fields: [[:uuid, :submitter_uuid, :name, :type,
:required, :readonly, :default_value,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/templates_dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def filter_template_folders(template_folders)
end

def filter_templates(templates)
rel = templates.active.preload(:author).order(id: :desc)
rel = templates.active.preload(:author, :template_accesses).order(id: :desc)

if params[:q].blank?
if Docuseal.multitenant? && !current_account.testing?
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def create
@user = existing_user
end

@user.role = User::ADMIN_ROLE unless role_valid?(@user.role)

if @user.save
UserMailer.invitation_email(@user).deliver_later!

Expand Down
1 change: 1 addition & 0 deletions app/javascript/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ safeRegisterElement('submission-form', class extends HTMLElement {
this.app = createApp(Form, {
submitter: JSON.parse(this.dataset.submitter),
inviteSubmitters: JSON.parse(this.dataset.inviteSubmitters),
schema: JSON.parse(this.dataset.schema),
canSendEmail: this.dataset.canSendEmail === 'true',
previousSignatureValue: this.dataset.previousSignatureValue,
goToLast: this.dataset.goToLast === 'true',
Expand Down
53 changes: 50 additions & 3 deletions app/javascript/submission_form/form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
/>
<FieldAreas
:steps="readonlyConditionalFields.map((e) => [e])"
:values="readonlyConditionalFields.reduce((acc, f) => { acc[f.uuid] = f.default_value; return acc }, {})"
:values="readonlyConditionalFields.reduce((acc, f) => { acc[f.uuid] = (values[f.uuid] || f.default_value); return acc }, {})"
:submitter="submitter"
:attachments-index="attachmentsIndex"
:submittable="false"
/>
<FormulaFieldAreas
Expand Down Expand Up @@ -651,6 +652,11 @@ export default {
required: false,
default: null
},
schema: {
type: Array,
required: false,
default: () => []
},
attachments: {
type: Array,
required: false,
Expand Down Expand Up @@ -840,6 +846,21 @@ export default {
isMobile () {
return /android|iphone|ipad/i.test(navigator.userAgent)
},
attachmentConditionsIndex () {
return this.schema.reduce((acc, item) => {
if (item.conditions?.length) {
if (item.conditions.every((c) => this.fieldsUuidIndex[c.field_uuid])) {
acc[item.attachment_uuid] = this.checkFieldConditions(item)
} else {
acc[item.attachment_uuid] = true
}
} else {
acc[item.attachment_uuid] = true
}
return acc
}, {})
},
emptyValueRequiredStep () {
return this.stepFields.find((fields, index) => {
return fields.some((f) => {
Expand Down Expand Up @@ -920,7 +941,7 @@ export default {
return this.currentStepFields[0]
},
readonlyConditionalFields () {
return this.fields.filter((f) => f.readonly && f.conditions?.length && this.checkFieldConditions(f))
return this.fields.filter((f) => f.readonly && f.conditions?.length && this.checkFieldConditions(f) && this.checkFieldDocumentsConditions(f))
},
stepFields () {
const verificationFields = []
Expand All @@ -942,7 +963,7 @@ export default {
return sortedFields.reduce((acc, f) => {
const prevStep = acc[acc.length - 1]
if (this.checkFieldConditions(f)) {
if (this.checkFieldConditions(f) && this.checkFieldDocumentsConditions(f)) {
if (f.type === 'checkbox' && Array.isArray(prevStep) && prevStep[0].type === 'checkbox' && !f.description) {
prevStep.push(f)
} else {
Expand Down Expand Up @@ -975,6 +996,23 @@ export default {
if (isEmpty(value) && this.currentStep > 0) {
this.currentStep -= 1
}
},
attachmentConditionsIndex: {
deep: true,
immediate: true,
handler (value) {
this.$nextTick(() => {
const root = this.$root.$el.parentNode.getRootNode()
for (const key in value) {
const doc = root.querySelector(`[id="document-${key}"`)
if (doc) {
doc.classList.toggle('hidden', !value[key])
}
}
})
}
}
},
beforeUnmount () {
Expand Down Expand Up @@ -1056,6 +1094,15 @@ export default {
onOrientationChange (event) {
this.orientation = event.target.type
},
checkFieldDocumentsConditions (field) {
if (field.areas?.length) {
return field.areas.some((area) => {
return this.attachmentConditionsIndex[area.attachment_uuid]
})
} else {
return true
}
},
checkFieldConditions (field) {
if (field.conditions?.length) {
const result = field.conditions.reduce((acc, cond) => {
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/submission_form/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ const pt = {
verify_id: 'Verificar ID',
identity_verification: 'Verificação de identidade',
complete: 'Completar',
preencher_todos_os_campos_obrigatórios_para_concluir: 'Preencher todos os campos obrigatórios para concluir',
fill_all_required_fields_to_complete: 'Preencher todos os campos obrigatórios para concluir',
sign_and_complete: 'Assinar e Completar',
invite: 'Convidar',
email: 'E-mail',
Expand Down Expand Up @@ -975,7 +975,7 @@ const nl = {
verify_id: 'Verifiëren ID',
identity_verification: 'Identiteitsverificatie',
complete: 'Voltooien',
vul_alle_verplichte_velden_in_om_te_voltooien: 'Vul alle verplichte velden in om te voltooien',
fill_all_required_fields_to_complete: 'Vul alle verplichte velden in om te voltooien',
sign_and_complete: 'Ondertekenen en voltooien',
invite: 'Uitnodigen',
email: 'E-mail',
Expand Down
Loading

0 comments on commit dd18c51

Please sign in to comment.