pull/493/head
Pete Matsyburka 5 months ago
parent 95627c5963
commit f2888a08dc

@ -25,7 +25,7 @@ class TemplatesDashboardController < ApplicationController
@templates = @templates.none @templates = @templates.none
else else
@template_folders = @template_folders.reject { |e| e.name == TemplateFolder::DEFAULT_NAME } @template_folders = @template_folders.reject { |e| e.name == TemplateFolder::DEFAULT_NAME }
@templates = filter_templates(@templates) @templates = filter_templates(@templates).preload(:author, :template_accesses)
@templates = Templates::Order.call(@templates, current_user, cookies.permanent[:dashboard_templates_order]) @templates = Templates::Order.call(@templates, current_user, cookies.permanent[:dashboard_templates_order])
limit = limit =
@ -42,7 +42,7 @@ class TemplatesDashboardController < ApplicationController
private private
def filter_templates(templates) def filter_templates(templates)
rel = templates.active.preload(:author, :template_accesses) rel = templates.active
if params[:q].blank? if params[:q].blank?
if Docuseal.multitenant? ? current_account.testing? : current_account.linked_account_account if Docuseal.multitenant? ? current_account.testing? : current_account.linked_account_account
@ -51,7 +51,14 @@ class TemplatesDashboardController < ApplicationController
shared_template_ids = TemplateSharing.where(account_id: shared_account_ids).select(:template_id) shared_template_ids = TemplateSharing.where(account_id: shared_account_ids).select(:template_id)
rel = rel.where(folder_id: current_account.default_template_folder.id).or(rel.where(id: shared_template_ids)) rel = Template.where(
Template.arel_table[:id].in(
Arel::Nodes::Union.new(
rel.where(folder_id: current_account.default_template_folder.id).select(:id).arel,
shared_template_ids.arel
)
)
)
else else
rel = rel.where(folder_id: current_account.default_template_folder.id) rel = rel.where(folder_id: current_account.default_template_folder.id)
end end

@ -13,12 +13,7 @@ module Abilities
TemplateSharing.where({ ability:, account_id: [user.account_id, TemplateSharing::ALL_ID] }.compact) TemplateSharing.where({ ability:, account_id: [user.account_id, TemplateSharing::ALL_ID] }.compact)
.select(:template_id) .select(:template_id)
join_query = Template.where(Template.arel_table[:id].in(Arel::Nodes::Union.new(templates.select(:id).arel, shared_ids.arel)))
Template.arel_table
.join(Arel::Nodes::TableAlias.new(templates.select(:id).arel.union(shared_ids.arel), 'union_ids'))
.on(Template.arel_table[:id].eq(Arel::Table.new(:union_ids)[:id]))
Template.joins(join_query.join_sources.first)
end end
def entity(template, user:, ability: nil) def entity(template, user:, ability: nil)

Loading…
Cancel
Save