22
33class BaseDocumentsController < ApplicationController
44 helper_method :can_manage_documents?
5- before_action :set_document , only : %i[ show edit update ]
5+ before_action :set_document , only : %i[ show edit update destroy restore ]
66
77 include Hashable
88 include GptConcern
99 include NeighborConcern
1010 # GET /documents or /documents.json
1111 def index
12- @documents = Document . includes ( :library , :user )
12+ # Handle show_deleted parameter to include deleted documents
13+ @documents = if params [ :show_deleted ] == 'true'
14+ Document . unscoped . includes ( :library , :user )
15+ elsif params [ :show_deleted ] == 'only'
16+ Document . unscoped . includes ( :library , :user ) . where . not ( deleted_date : nil )
17+ else
18+ Document . includes ( :library , :user ) . not_deleted
19+ end
1320
1421 # Apply cheap filters first for better performance
1522 library_id = params [ :library_id ]
@@ -136,6 +143,30 @@ def create
136143 end
137144 end
138145
146+ # DELETE /documents/1 or /documents/1.json
147+ def destroy
148+ authorize @document
149+
150+ @document . soft_delete!
151+
152+ respond_to do |format |
153+ format . html { redirect_to @document , notice : 'Document was successfully deleted.' }
154+ format . json { head :no_content }
155+ end
156+ end
157+
158+ # PATCH /documents/1/restore or /documents/1/restore.json
159+ def restore
160+ authorize @document , :destroy? # Use same authorization as destroy
161+
162+ @document . restore!
163+
164+ respond_to do |format |
165+ format . html { redirect_to @document , notice : 'Document was successfully restored.' }
166+ format . json { render :show , status : :ok , location : @document }
167+ end
168+ end
169+
139170 private
140171
141172 def can_manage_documents?
@@ -151,7 +182,7 @@ def can_manage_documents?
151182
152183 # Use callbacks to share common setup or constraints between actions.
153184 def set_document
154- @document = Document . find ( params [ :id ] )
185+ @document = Document . unscoped . find ( params [ :id ] )
155186 end
156187
157188 # Only allow a list of trusted parameters through.
0 commit comments