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.rbindex 530d255035..a64888a6ef 100644--- a/app/models/assistant/external.rb+++ b/app/models/assistant/external.rb@@ -25,8 +25,8 @@ class Assistant::External < Assistant::Basedef configConfig.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.rbindex a53e70273a..b62d4073d0 100644--- a/app/models/setting.rb+++ b/app/models/setting.rb@@ -10,9 +10,9 @@ class Setting < RailsSettings::Basefield :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: :stringfield :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.erbindex 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.yamlindex 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: stringImportConfiguration:type: objectproperties:@@ -2718,3 +2725,66 @@ paths:type: stringdescription: Additional notesrequired: 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.rbindex 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) dofamily.users.create!(email: '[email protected]',password: 'password123',- password_confirmation: 'password123'+ password_confirmation: 'password123',+ role: role)end@@ -38,7 +41,8 @@ RSpec.describe 'API V1 Users', type: :request dotags '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 dorun_test!end- response '403', 'insufficient scope' do+ response '403', 'forbidden - requires read_write scope and admin role' dolet(:api_key) dokey = ApiKey.generate_secure_keyApiKey.create!(