Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Document admin-only reset auth in OpenAPI docs (#1198)

Juan José Matacade5b22f715
diff --git a/app/models/assistant/external.rb b/app/models/assistant/external.rb
index 530d255035..a64888a6ef 100644
--- a/app/models/assistant/external.rb
+++ b/app/models/assistant/external.rb
@@ -25,8 +25,8 @@ class Assistant::External < Assistant::Base
def config
Config.new(
- url: ENV["EXTERNAL_ASSISTANT_URL"].presence || Setting.external_assistant_url,
- token: ENV["EXTERNAL_ASSISTANT_TOKEN"].presence || Setting.external_assistant_token,
+ url: ENV["EXTERNAL_ASSISTANT_URL"].presence || Setting.external_assistant_url.presence,
+ token: ENV["EXTERNAL_ASSISTANT_TOKEN"].presence || Setting.external_assistant_token.presence,
agent_id: ENV["EXTERNAL_ASSISTANT_AGENT_ID"].presence || Setting.external_assistant_agent_id.presence || "main",
session_key: ENV.fetch("EXTERNAL_ASSISTANT_SESSION_KEY", "agent:main:main")
)
diff --git a/app/models/setting.rb b/app/models/setting.rb
index a53e70273a..b62d4073d0 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -10,9 +10,9 @@ class Setting < RailsSettings::Base
field :openai_uri_base, type: :string, default: ENV["OPENAI_URI_BASE"]
field :openai_model, type: :string, default: ENV["OPENAI_MODEL"]
field :openai_json_mode, type: :string, default: ENV["LLM_JSON_MODE"]
- field :external_assistant_url, type: :string, default: ENV["EXTERNAL_ASSISTANT_URL"]
- field :external_assistant_token, type: :string, default: ENV["EXTERNAL_ASSISTANT_TOKEN"]
- field :external_assistant_agent_id, type: :string, default: ENV.fetch("EXTERNAL_ASSISTANT_AGENT_ID", "main")
+ field :external_assistant_url, type: :string
+ field :external_assistant_token, type: :string
+ field :external_assistant_agent_id, type: :string
field :brand_fetch_client_id, type: :string, default: ENV["BRAND_FETCH_CLIENT_ID"]
field :brand_fetch_high_res_logos, type: :boolean, default: ENV.fetch("BRAND_FETCH_HIGH_RES_LOGOS", "false") == "true"
diff --git a/app/views/settings/hostings/_assistant_settings.html.erb b/app/views/settings/hostings/_assistant_settings.html.erb
index 5522706ada..082fddde7a 100644
--- a/app/views/settings/hostings/_assistant_settings.html.erb
+++ b/app/views/settings/hostings/_assistant_settings.html.erb
@@ -75,7 +75,7 @@
<%= form.text_field :external_assistant_url,
label: t(".url_label"),
placeholder: t(".url_placeholder"),
- value: Setting.external_assistant_url,
+ value: Assistant::External.config.url,
autocomplete: "off",
autocapitalize: "none",
spellcheck: "false",
@@ -87,7 +87,7 @@
<%= form.password_field :external_assistant_token,
label: t(".token_label"),
placeholder: t(".token_placeholder"),
- value: (Setting.external_assistant_token.present? ? "********" : nil),
+ value: (Assistant::External.config.token.present? ? "********" : nil),
autocomplete: "off",
autocapitalize: "none",
spellcheck: "false",
@@ -99,7 +99,7 @@
<%= form.text_field :external_assistant_agent_id,
label: t(".agent_id_label"),
placeholder: t(".agent_id_placeholder"),
- value: Setting.external_assistant_agent_id,
+ value: Assistant::External.config.agent_id,
autocomplete: "off",
autocapitalize: "none",
spellcheck: "false",
diff --git a/docs/api/openapi.yaml b/docs/api/openapi.yaml
index 4a1515f900..e71c1568c7 100644
--- a/docs/api/openapi.yaml
+++ b/docs/api/openapi.yaml
@@ -545,6 +545,13 @@ components:
properties:
message:
type: string
+ SuccessMessage:
+ type: object
+ required:
+ - message
+ properties:
+ message:
+ type: string
ImportConfiguration:
type: object
properties:
@@ -2718,3 +2725,66 @@ paths:
type: string
description: Additional notes
required: true
+ "/api/v1/users/reset":
+ delete:
+ summary: Reset account
+ tags:
+ - Users
+ description: Resets all financial data (accounts, categories, merchants, tags,
+ etc.) for the current user's family while keeping the user account intact.
+ The reset runs asynchronously in the background. Requires admin role.
+ security:
+ - apiKeyAuth: []
+ responses:
+ '200':
+ description: account reset initiated
+ content:
+ application/json:
+ schema:
+ "$ref": "#/components/schemas/SuccessMessage"
+ '401':
+ description: unauthorized
+ content:
+ application/json:
+ schema:
+ "$ref": "#/components/schemas/ErrorResponse"
+ '403':
+ description: "forbidden \u2014 requires read_write scope and admin role"
+ content:
+ application/json:
+ schema:
+ "$ref": "#/components/schemas/ErrorResponse"
+ "/api/v1/users/me":
+ delete:
+ summary: Delete account
+ tags:
+ - Users
+ description: Permanently deactivates the current user account and all associated
+ data. This action cannot be undone.
+ security:
+ - apiKeyAuth: []
+ responses:
+ '200':
+ description: account deleted
+ content:
+ application/json:
+ schema:
+ "$ref": "#/components/schemas/SuccessMessage"
+ '401':
+ description: unauthorized
+ content:
+ application/json:
+ schema:
+ "$ref": "#/components/schemas/ErrorResponse"
+ '403':
+ description: insufficient scope
+ content:
+ application/json:
+ schema:
+ "$ref": "#/components/schemas/ErrorResponse"
+ '422':
+ description: deactivation failed
+ content:
+ application/json:
+ schema:
+ "$ref": "#/components/schemas/ErrorResponse"
diff --git a/spec/requests/api/v1/users_spec.rb b/spec/requests/api/v1/users_spec.rb
index 65c745ede6..bb714d8ef7 100644
--- a/spec/requests/api/v1/users_spec.rb
+++ b/spec/requests/api/v1/users_spec.rb
@@ -12,11 +12,14 @@ RSpec.describe 'API V1 Users', type: :request do
)
end
+ let(:role) { :admin }
+
let(:user) do
family.users.create!(
password: 'password123',
- password_confirmation: 'password123'
+ password_confirmation: 'password123',
+ role: role
)
end
@@ -38,7 +41,8 @@ RSpec.describe 'API V1 Users', type: :request do
tags 'Users'
description 'Resets all financial data (accounts, categories, merchants, tags, etc.) ' \
'for the current user\'s family while keeping the user account intact. ' \
- 'The reset runs asynchronously in the background.'
+ 'The reset runs asynchronously in the background. ' \
+ 'Requires admin role.'
security [ { apiKeyAuth: [] } ]
produces 'application/json'
@@ -54,7 +58,7 @@ RSpec.describe 'API V1 Users', type: :request do
run_test!
end
- response '403', 'insufficient scope' do
+ response '403', 'forbidden - requires read_write scope and admin role' do
let(:api_key) do
key = ApiKey.generate_secure_key
ApiKey.create!(