From 7b1b4bcf2ca69baf8228d9e860f8c707d5c92f01 Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Mon, 23 Jun 2025 19:35:39 +0300 Subject: [PATCH] show shared link enable button on disabled link page --- .../templates_share_link_controller.rb | 6 ++- app/javascript/elements/check_on_click.js | 2 +- app/views/start_form/private.html.erb | 41 ++++++++++--------- spec/system/signing_form_spec.rb | 27 ++++++++++++ 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/app/controllers/templates_share_link_controller.rb b/app/controllers/templates_share_link_controller.rb index 5b84f6ca..5dfed111 100644 --- a/app/controllers/templates_share_link_controller.rb +++ b/app/controllers/templates_share_link_controller.rb @@ -10,7 +10,11 @@ class TemplatesShareLinkController < ApplicationController @template.update!(template_params) - head :ok + if params[:redir].present? + redirect_to params[:redir] + else + head :ok + end end private diff --git a/app/javascript/elements/check_on_click.js b/app/javascript/elements/check_on_click.js index 8b3b9ab8..e940dff3 100644 --- a/app/javascript/elements/check_on_click.js +++ b/app/javascript/elements/check_on_click.js @@ -1,7 +1,7 @@ export default class extends HTMLElement { connectedCallback () { this.addEventListener('click', () => { - if (!this.element.checked) { + if (this.element && !this.element.disabled && !this.element.checked) { this.element.checked = true this.element.dispatchEvent(new Event('change', { bubbles: true })) } diff --git a/app/views/start_form/private.html.erb b/app/views/start_form/private.html.erb index f976c7f1..6b8104d6 100644 --- a/app/views/start_form/private.html.erb +++ b/app/views/start_form/private.html.erb @@ -2,29 +2,30 @@ <% I18n.with_locale(@template.account.locale) do %> <% content_for(:html_description, t('share_link_is_currently_disabled')) %> <% end %> -
-
-
-
- <%= render 'banner' %> -

- <%= t('share_link_is_currently_disabled') %> -

+
+
+ <%= render 'banner' %> +

+ <%= t('share_link_is_currently_disabled') %> +

+
+
+
+
+ <%= svg_icon('writing_sign', class: 'w-10 h-10') %>
-
-
-
- <%= svg_icon('writing_sign', class: 'w-10 h-10') %> -
-
-

<%= @template.name %>

- <% if @template.archived_at? %> -

<%= t('form_has_been_deleted_by_html', name: @template.account.name) %>

- <% end %> -
-
+
+

<%= @template.name %>

+ <% if @template.archived_at? %> +

<%= t('form_has_been_deleted_by_html', name: @template.account.name) %>

+ <% end %>
+ <% if can?(:update, @template) %> + + <%= button_to button_title(title: t('enable_shared_link'), icon: svg_icon('lock_open', class: 'w-6 h-6')), template_share_link_path(@template), params: { template: { shared_link: true }, redir: start_form_path(slug: @template.slug) }, method: :post, class: 'white-button w-full' %> + + <% end %>
<%= render 'shared/attribution', link_path: '/start', account: @template.account %> diff --git a/spec/system/signing_form_spec.rb b/spec/system/signing_form_spec.rb index 83c1b30b..3dc2ff98 100644 --- a/spec/system/signing_form_spec.rb +++ b/spec/system/signing_form_spec.rb @@ -848,6 +848,33 @@ RSpec.describe 'Signing Form' do end end + context 'when the template shared link is disabled' do + let(:template) do + create(:template, shared_link: false, account:, author:, only_field_types: %w[text]) + end + + context 'when user is logged in' do + before do + login_as author + visit start_form_path(slug: template.slug) + end + + it 'shows a warning that the shared link is disabled and provides an option to enable it' do + expect(page).to have_content('Share link is currently disabled') + expect(page).to have_content(template.name) + expect(page).to have_button('Enable shared link') + end + + it 'enables the shared link' do + expect do + click_button 'Enable shared link' + end.to change { template.reload.shared_link }.from(false).to(true) + + expect(page).to have_content('You have been invited to submit a form') + end + end + end + it 'sends completed email' do template = create(:template, account:, author:, only_field_types: %w[text signature]) submission = create(:submission, template:)