mirror of https://github.com/docusealco/docuseal
parent
c91b4a765b
commit
e77b5fa2c9
@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TemplatesShareLinkController < ApplicationController
|
||||
load_and_authorize_resource :template
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
authorize!(:update, @template)
|
||||
|
||||
@template.update!(template_params)
|
||||
|
||||
head :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def template_params
|
||||
params.require(:template).permit(:shared_link)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,14 @@
|
||||
export default class extends HTMLElement {
|
||||
connectedCallback () {
|
||||
this.addEventListener('click', () => {
|
||||
if (!this.element.checked) {
|
||||
this.element.checked = true
|
||||
this.element.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
get element () {
|
||||
return document.getElementById(this.dataset.elementId)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<% content_for(:html_title, "#{@template.name} | DocuSeal") %>
|
||||
<% content_for(:html_description, t('share_link_is_currently_disabled')) %>
|
||||
<div class="max-w-md mx-auto px-2 mt-12 mb-4">
|
||||
<div class="space-y-6 mx-auto">
|
||||
<div class="space-y-6">
|
||||
<div class="text-center w-full space-y-6">
|
||||
<%= render 'banner' %>
|
||||
<p class="text-xl font-semibold text-center">
|
||||
<%= t('share_link_is_currently_disabled') %>
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center bg-base-200 rounded-xl p-4 mb-4">
|
||||
<div class="flex items-center">
|
||||
<div class="mr-3">
|
||||
<%= svg_icon('writing_sign', class: 'w-10 h-10') %>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-lg font-bold mb-1"><%= @template.name %></p>
|
||||
<% if @template.archived_at? %>
|
||||
<p dir="auto" class="text-sm"><%= t('form_has_been_deleted_by_html', name: @template.account.name) %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%= render 'shared/attribution', link_path: '/start', account: @template.account %>
|
||||
@ -0,0 +1,16 @@
|
||||
<%= render 'shared/turbo_modal_large', title: t('share_link') do %>
|
||||
<div class="mt-2 mb-4 px-5">
|
||||
<%= form_for @template, url: template_share_link_path(@template), method: :post, html: { id: 'shared_link_form', autocomplete: 'off', class: 'mt-3' }, data: { close_on_submit: false } do |f| %>
|
||||
<div class="flex items-center justify-between gap-1 px-1">
|
||||
<span><%= t('enable_shared_link') %></span>
|
||||
<%= f.check_box :shared_link, { disabled: !can?(:update, @template), class: 'toggle', onchange: 'this.form.requestSubmit()' }, 'true', 'false' %>
|
||||
</div>
|
||||
<div class="flex gap-2 mt-3">
|
||||
<input id="embedding_url" type="text" value="<%= start_form_url(slug: @template.slug) %>" class="base-input w-full" autocomplete="off" readonly>
|
||||
<check-on-click data-element-id="template_shared_link">
|
||||
<%= render 'shared/clipboard_copy', icon: 'copy', text: start_form_url(slug: @template.slug), class: 'base-button', icon_class: 'w-6 h-6 text-white', copy_title: t('copy'), copied_title: t('copied') %>
|
||||
</check-on-click>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddSharedLinkToTemplates < ActiveRecord::Migration[8.0]
|
||||
disable_ddl_transaction
|
||||
|
||||
class MigrationTemplate < ActiveRecord::Base
|
||||
self.table_name = 'templates'
|
||||
end
|
||||
|
||||
def up
|
||||
add_column :templates, :shared_link, :boolean, if_not_exists: true
|
||||
|
||||
MigrationTemplate.where(shared_link: nil).in_batches.update_all(shared_link: true)
|
||||
|
||||
change_column_default :templates, :shared_link, from: nil, to: false
|
||||
change_column_null :templates, :shared_link, false
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :templates, :shared_link
|
||||
end
|
||||
end
|
||||
Binary file not shown.
@ -0,0 +1,66 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe 'Template Share Link' do
|
||||
let!(:account) { create(:account) }
|
||||
let!(:author) { create(:user, account:) }
|
||||
let!(:template) { create(:template, account:, author:) }
|
||||
|
||||
before do
|
||||
sign_in(author)
|
||||
end
|
||||
|
||||
context 'when the template is not shareable' do
|
||||
before do
|
||||
visit template_path(template)
|
||||
end
|
||||
|
||||
it 'makes the template shareable' do
|
||||
click_on 'Link'
|
||||
|
||||
expect do
|
||||
within '#modal' do
|
||||
check 'template_shared_link'
|
||||
end
|
||||
end.to change { template.reload.shared_link }.from(false).to(true)
|
||||
end
|
||||
|
||||
it 'makes the template shareable when copying the shareable link' do
|
||||
click_on 'Link'
|
||||
|
||||
expect do
|
||||
within '#modal' do
|
||||
find('clipboard-copy').click
|
||||
end
|
||||
end.to change { template.reload.shared_link }.from(false).to(true)
|
||||
end
|
||||
|
||||
it 'copies the shareable link without changing its status' do
|
||||
template.update(shared_link: true)
|
||||
|
||||
click_on 'Link'
|
||||
|
||||
expect do
|
||||
within '#modal' do
|
||||
find('clipboard-copy').click
|
||||
end
|
||||
end.not_to(change { template.reload.shared_link })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the template is already shareable' do
|
||||
before do
|
||||
template.update(shared_link: true)
|
||||
visit template_path(template)
|
||||
end
|
||||
|
||||
it 'makes the template unshareable' do
|
||||
click_on 'Link'
|
||||
|
||||
expect do
|
||||
within '#modal' do
|
||||
uncheck 'template_shared_link'
|
||||
end
|
||||
end.to change { template.reload.shared_link }.from(true).to(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in new issue