adjust shared templates

This commit is contained in:
Pete Matsyburka
2026-06-24 14:17:17 +03:00
parent 90c1a6f4ad
commit 432435aa23
11 changed files with 155 additions and 47 deletions
+2 -10
View File
@@ -4,16 +4,8 @@ module Abilities
module TemplateConditions
module_function
def collection(user, ability: nil)
templates = Template.where(account_id: user.account_id)
return templates unless user.account.testing?
shared_ids =
TemplateSharing.where({ ability:, account_id: [user.account_id, TemplateSharing::ALL_ID] }.compact)
.select(:template_id)
Template.where(Template.arel_table[:id].in(templates.select(:id).arel.union(:all, shared_ids.arel)))
def collection(user)
Template.where(account_id: user.account_id)
end
def entity(template, user:, ability: nil)
+15
View File
@@ -47,6 +47,21 @@ module Templates
nil
end
def shared(current_user)
account = current_user.account
return Template.none if Docuseal.multitenant? ? !account.testing? : !account.linked_account_account
shared_account_ids = [current_user.account_id]
shared_account_ids << TemplateSharing::ALL_ID if !Docuseal.multitenant? && !account.testing?
exists_access = TemplateAccess.where(TemplateAccess.arel_table[:template_id].eq(Template.arel_table[:id]))
.select(1).arel.exists
Template.where(id: TemplateSharing.where(account_id: shared_account_ids).select(:template_id))
.where.not(exists_access)
end
def search(current_user, templates, keyword)
if Docuseal.fulltext_search?
fulltext_search(current_user, templates, keyword)