diff --git a/app/controllers/api/templates_controller.rb b/app/controllers/api/templates_controller.rb index b3d05cec..d20defb3 100644 --- a/app/controllers/api/templates_controller.rb +++ b/app/controllers/api/templates_controller.rb @@ -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 diff --git a/app/controllers/templates_restore_controller.rb b/app/controllers/templates_restore_controller.rb index 422b69cf..64afea11 100644 --- a/app/controllers/templates_restore_controller.rb +++ b/app/controllers/templates_restore_controller.rb @@ -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) diff --git a/app/controllers/templates_shared_controller.rb b/app/controllers/templates_shared_controller.rb index ea6193aa..90b5d159 100644 --- a/app/controllers/templates_shared_controller.rb +++ b/app/controllers/templates_shared_controller.rb @@ -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]) diff --git a/app/views/shared/_search_input.html.erb b/app/views/shared/_search_input.html.erb index 8457b2af..1868c658 100644 --- a/app/views/shared/_search_input.html.erb +++ b/app/views/shared/_search_input.html.erb @@ -4,6 +4,9 @@ <% end %> <% end %> + <% if params[:archived].present? %> + + <% end %> <% if params[:q].present? %>