Skip to content

Commit fbec76e

Browse files
pjurewiczclaude
andcommitted
Add EXTRACTIONS_LOCKED flag to disable manual extractions
When ENV["EXTRACTIONS_LOCKED"] is set, the manual extraction endpoint returns 403 and the Extract button in the UI is rendered as disabled (with a tooltip and a muted hint on the ingestion page). Intended for public demos where we don't want visitors to trigger LLM calls. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent df065ba commit fbec76e

5 files changed

Lines changed: 39 additions & 4 deletions

File tree

app/assets/stylesheets/application.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,20 @@ a:hover { color: var(--accent-hover); }
903903
background: var(--accent-hover);
904904
}
905905

906+
.btn-sm:disabled,
907+
.btn-sm[disabled] {
908+
background: var(--surface-hover);
909+
color: var(--text-muted);
910+
cursor: not-allowed;
911+
opacity: 0.7;
912+
}
913+
914+
.model-select:disabled,
915+
.model-select[disabled] {
916+
opacity: 0.6;
917+
cursor: not-allowed;
918+
}
919+
906920
.content-search-bar {
907921
display: flex;
908922
align-items: center;

app/controllers/ingestions_controller.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class IngestionsController < ApplicationController
2+
before_action :reject_if_extractions_locked, only: :extract
3+
24
def index
35
@ingestions = Ingestion.order(created_at: :desc)
46
end
@@ -37,4 +39,16 @@ def extract
3739
format.html { redirect_to ingestion_path(ingestion), alert: alert_message }
3840
end
3941
end
42+
43+
private
44+
45+
def reject_if_extractions_locked
46+
return unless ENV["EXTRACTIONS_LOCKED"].present?
47+
48+
alert_message = "Manual extractions are temporarily disabled."
49+
respond_to do |format|
50+
format.turbo_stream { render turbo_stream: turbo_stream.update("flash", partial: "shared/flash", locals: { alert: alert_message }), status: :forbidden }
51+
format.html { redirect_to ingestion_path(params[:id]), alert: alert_message }
52+
end
53+
end
4054
end

app/helpers/application_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
module ApplicationHelper
2+
def extractions_locked?
3+
ENV["EXTRACTIONS_LOCKED"].present?
4+
end
5+
26
def extraction_cost(extraction)
37
return nil unless extraction.model_id
48

app/views/ingestions/index.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
<span id="ingestion-actions-<%= ing.id %>">
2626
<% unless status.in?(%w[queued requeued extracting]) %>
2727
<%= form_with url: extract_ingestion_path(ing), method: :post, class: "reextract-form" do |f| %>
28-
<%= f.select :model_id, ExtractionPrompt::AVAILABLE_MODELS, {}, class: "model-select" %>
29-
<%= f.submit "Extract", class: "btn btn-sm" %>
28+
<%= f.select :model_id, ExtractionPrompt::AVAILABLE_MODELS, {}, class: "model-select", disabled: extractions_locked? %>
29+
<%= f.submit "Extract", class: "btn btn-sm", disabled: extractions_locked?, title: extractions_locked? ? "Manual extractions are temporarily disabled" : nil %>
3030
<% end %>
3131
<% end %>
3232
</span>

app/views/ingestions/show.html.erb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@
3333
<% unless @ingestion.status.in?(%w[queued requeued extracting]) %>
3434
<div style="margin-top: 1.5rem;">
3535
<%= form_with url: extract_ingestion_path(@ingestion), method: :post, class: "reextract-form" do |f| %>
36-
<%= f.select :model_id, ExtractionPrompt::AVAILABLE_MODELS, {}, class: "model-select" %>
37-
<%= f.submit "Extract", class: "btn btn-sm" %>
36+
<%= f.select :model_id, ExtractionPrompt::AVAILABLE_MODELS, {}, class: "model-select", disabled: extractions_locked? %>
37+
<%= f.submit "Extract", class: "btn btn-sm", disabled: extractions_locked?, title: extractions_locked? ? "Manual extractions are temporarily disabled" : nil %>
38+
<% end %>
39+
<% if extractions_locked? %>
40+
<div class="text-muted" style="font-size: 0.75rem; margin-top: 0.4rem;">Manual extractions are temporarily disabled.</div>
3841
<% end %>
3942
</div>
4043
<% end %>

0 commit comments

Comments
 (0)