adjust shared templates
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user