show archived shared templates

This commit is contained in:
Pete Matsyburka
2026-06-24 19:08:15 +03:00
parent 2840359396
commit b2790776ef
8 changed files with 38 additions and 13 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ module Api
archived = params.key?(:archived) ? params[:archived] : params.dig(:template, :archived)
if archived.in?([true, false])
if archived.in?([true, false]) && current_ability.can?(:destroy, @template)
@template.archived_at = archived == true ? Time.current : nil
end
@@ -4,7 +4,7 @@ class TemplatesRestoreController < ApplicationController
load_and_authorize_resource :template
def create
authorize!(:update, @template)
authorize!(:destroy, @template)
@template.update!(archived_at: nil)
@@ -4,10 +4,16 @@ class TemplatesSharedController < ApplicationController
def index
authorize!(:read, Template)
@is_archived = params[:archived] == 'true'
@templates = Templates.shared(current_user)
.active
.preload(:author, :template_accesses, :template_sharings)
.order(id: :desc)
@has_archived = !@is_archived && @templates.archived.exists?
@templates = @is_archived ? @templates.archived : @templates.active
@templates = @templates.preload(:author, :template_accesses, :template_sharings)
.order(id: :desc)
@templates = Templates.search(current_user, @templates, params[:q])