Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

Merge remote-tracking branch 'upstream/main' into integration/upstream-main-2026-07-29

joshistoastc78ed30cea5f
diff --cc invokeai/app/api/dependencies.py
index d708ad0d77,61b02e7620..abc3dbfb43
--- a/invokeai/app/api/dependencies.py
+++ b/invokeai/app/api/dependencies.py
@@@ -204,11 -203,10 +205,12 @@@ class ApiDependencies
urls = LocalUrlService()
workflow_records = SqliteWorkflowRecordsStorage(db=db)
style_preset_records = SqliteStylePresetRecordsStorage(db=db)
+ wildcard_records = SqliteWildcardRecordsStorage(db=db)
style_preset_image_files = StylePresetImageFileStorageDisk(style_presets_folder / "images")
+ system_prompt_records = SqliteSystemPromptRecordsStorage(db=db)
workflow_thumbnails = WorkflowThumbnailFileStorageDisk(workflow_thumbnails_folder)
client_state_persistence = ClientStatePersistenceSqlite(db=db)
+ project_records = ProjectRecordsSqlite(db=db)
users = UserService(db=db)
services = InvocationServices(
@@@ -240,11 -238,10 +242,12 @@@
tensors=tensors,
conditioning=conditioning,
style_preset_records=style_preset_records,
+ wildcard_records=wildcard_records,
style_preset_image_files=style_preset_image_files,
+ system_prompt_records=system_prompt_records,
workflow_thumbnails=workflow_thumbnails,
client_state_persistence=client_state_persistence,
+ project_records=project_records,
users=users,
videos=videos,
video_files=video_files,
diff --cc invokeai/app/api_app.py
index 17cdcb45b7,c0722c4bd1..96373df31e
--- a/invokeai/app/api_app.py
+++ b/invokeai/app/api_app.py
@@@ -422,9 -421,8 +423,10 @@@ app.include_router(app_info.app_router
app.include_router(session_queue.session_queue_router, prefix="/api")
app.include_router(workflows.workflows_router, prefix="/api")
app.include_router(style_presets.style_presets_router, prefix="/api")
+app.include_router(wildcards.wildcards_router, prefix="/api")
+ app.include_router(system_prompts.system_prompts_router, prefix="/api")
app.include_router(client_state.client_state_router, prefix="/api")
+app.include_router(projects.projects_router, prefix="/api")
app.include_router(recall_parameters.recall_parameters_router, prefix="/api")
app.include_router(custom_nodes.custom_nodes_router, prefix="/api")
diff --cc invokeai/app/services/invocation_services.py
index f1365c7e14,50e56a81ba..cc5182f761
--- a/invokeai/app/services/invocation_services.py
+++ b/invokeai/app/services/invocation_services.py
@@@ -6,7 -6,7 +6,8 @@@ from typing import TYPE_CHECKIN
from invokeai.app.services.object_serializer.object_serializer_base import ObjectSerializerBase
from invokeai.app.services.style_preset_images.style_preset_images_base import StylePresetImageFileStorageBase
from invokeai.app.services.style_preset_records.style_preset_records_base import StylePresetRecordsStorageBase
+ from invokeai.app.services.system_prompt_records.system_prompt_records_base import SystemPromptRecordsStorageBase
+from invokeai.app.services.wildcard_records.wildcard_records_base import WildcardRecordsStorageBase
if TYPE_CHECKING:
from logging import Logger
@@@ -83,11 -82,10 +84,12 @@@ class InvocationServices
tensors: "ObjectSerializerBase[torch.Tensor]",
conditioning: "ObjectSerializerBase[ConditioningFieldData]",
style_preset_records: "StylePresetRecordsStorageBase",
+ wildcard_records: "WildcardRecordsStorageBase",
style_preset_image_files: "StylePresetImageFileStorageBase",
+ system_prompt_records: "SystemPromptRecordsStorageBase",
workflow_thumbnails: "WorkflowThumbnailServiceBase",
client_state_persistence: "ClientStatePersistenceABC",
+ project_records: "ProjectRecordsStorageBase",
users: "UserServiceBase",
videos: "VideoServiceABC",
video_files: "VideoFileStorageBase",
@@@ -124,11 -122,10 +126,12 @@@
self.tensors = tensors
self.conditioning = conditioning
self.style_preset_records = style_preset_records
+ self.wildcard_records = wildcard_records
self.style_preset_image_files = style_preset_image_files
+ self.system_prompt_records = system_prompt_records
self.workflow_thumbnails = workflow_thumbnails
self.client_state_persistence = client_state_persistence
+ self.project_records = project_records
self.users = users
self.videos = videos
self.video_files = video_files
diff --cc invokeai/frontend/web/openapi.json
index af1eb7d66e,1f454f022c..71c0e4c71c
--- a/invokeai/frontend/web/openapi.json
+++ b/invokeai/frontend/web/openapi.json
@@@ -7499,6 -7377,6 +7499,44 @@@
"title": "Search Term"
},
"description": "The term to search for"
++ },
++ {
++ "name": "created_from",
++ "in": "query",
++ "required": false,
++ "schema": {
++ "anyOf": [
++ {
++ "type": "string",
++ "format": "date"
++ },
++ {
++ "type": "null"
++ }
++ ],
++ "description": "Inclusive start date (YYYY-MM-DD) to filter by created_at.",
++ "title": "Created From"
++ },
++ "description": "Inclusive start date (YYYY-MM-DD) to filter by created_at."
++ },
++ {
++ "name": "created_to",
++ "in": "query",
++ "required": false,
++ "schema": {
++ "anyOf": [
++ {
++ "type": "string",
++ "format": "date"
++ },
++ {
++ "type": "null"
++ }
++ ],
++ "description": "Inclusive end date (YYYY-MM-DD) to filter by created_at.",
++ "title": "Created To"
++ },
++ "description": "Inclusive end date (YYYY-MM-DD) to filter by created_at."
}
],
"responses": {
@@@ -7652,6 -7530,6 +7690,44 @@@
"title": "Search Term"
},
"description": "The term to search for"
++ },
++ {
++ "name": "created_from",
++ "in": "query",
++ "required": false,
++ "schema": {
++ "anyOf": [
++ {
++ "type": "string",
++ "format": "date"
++ },
++ {
++ "type": "null"
++ }
++ ],
++ "description": "Inclusive start date (YYYY-MM-DD) to filter by created_at.",
++ "title": "Created From"
++ },
++ "description": "Inclusive start date (YYYY-MM-DD) to filter by created_at."
++ },
++ {
++ "name": "created_to",
++ "in": "query",
++ "required": false,
++ "schema": {
++ "anyOf": [
++ {
++ "type": "string",
++ "format": "date"
++ },
++ {
++ "type": "null"
++ }
++ ],
++ "description": "Inclusive end date (YYYY-MM-DD) to filter by created_at.",
++ "title": "Created To"
++ },
++ "description": "Inclusive end date (YYYY-MM-DD) to filter by created_at."
}
],
"responses": {
@@@ -11950,29 -11745,91 +12026,251 @@@
"required": true,
"schema": {
"type": "string",
- "description": "The id of the system prompt to update",
- "title": "System Prompt Id"
+ "description": "The id of the wildcard to delete",
+ "title": "Wildcard Id"
},
- "description": "The id of the system prompt to update"
+ "description": "The id of the wildcard to delete"
}
],
+ "responses": {
+ "204": {
+ "description": "Successful Response"
+ },
+ "422": {
+ "description": "Validation Error",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/HTTPValidationError"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
++ "/api/v1/system_prompts/": {
++ "get": {
++ "tags": ["system_prompts"],
++ "summary": "List System Prompts",
++ "description": "Lists system prompts visible to the current user (own + public).",
++ "operationId": "list_system_prompts",
++ "responses": {
++ "200": {
++ "description": "Successful Response",
++ "content": {
++ "application/json": {
++ "schema": {
++ "items": {
++ "$ref": "#/components/schemas/SystemPromptRecordDTO"
++ },
++ "type": "array",
++ "title": "Response 200 List System Prompts"
++ }
++ }
++ }
++ }
++ },
++ "security": [
++ {
++ "HTTPBearer": []
++ }
++ ]
++ },
++ "post": {
++ "tags": ["system_prompts"],
++ "summary": "Create System Prompt",
++ "description": "Creates a new system prompt owned by the current user.",
++ "operationId": "create_system_prompt",
+ "requestBody": {
- "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
- "$ref": "#/components/schemas/SystemPromptChanges",
- "description": "The changes to apply"
++ "$ref": "#/components/schemas/SystemPromptWithoutId",
++ "description": "The system prompt to create"
+ }
+ }
- }
++ },
++ "required": true
++ },
++ "responses": {
++ "200": {
++ "description": "Successful Response",
++ "content": {
++ "application/json": {
++ "schema": {
++ "$ref": "#/components/schemas/SystemPromptRecordDTO"
++ }
++ }
++ }
++ },
++ "422": {
++ "description": "Validation Error",
++ "content": {
++ "application/json": {
++ "schema": {
++ "$ref": "#/components/schemas/HTTPValidationError"
++ }
++ }
++ }
++ }
++ },
++ "security": [
++ {
++ "HTTPBearer": []
++ }
++ ]
++ }
++ },
++ "/api/v1/system_prompts/i/{system_prompt_id}": {
++ "get": {
++ "tags": ["system_prompts"],
++ "summary": "Get System Prompt",
++ "description": "Gets a system prompt by id.",
++ "operationId": "get_system_prompt",
++ "security": [
++ {
++ "HTTPBearer": []
++ }
++ ],
++ "parameters": [
++ {
++ "name": "system_prompt_id",
++ "in": "path",
++ "required": true,
++ "schema": {
++ "type": "string",
++ "description": "The id of the system prompt to get",
++ "title": "System Prompt Id"
++ },
++ "description": "The id of the system prompt to get"
++ }
++ ],
++ "responses": {
++ "200": {
++ "description": "Successful Response",
++ "content": {
++ "application/json": {
++ "schema": {
++ "$ref": "#/components/schemas/SystemPromptRecordDTO"
++ }
++ }
++ }
++ },
++ "422": {
++ "description": "Validation Error",
++ "content": {
++ "application/json": {
++ "schema": {
++ "$ref": "#/components/schemas/HTTPValidationError"
++ }
++ }
++ }
++ }
++ }
++ },
++ "patch": {
++ "tags": ["system_prompts"],
++ "summary": "Update System Prompt",
++ "description": "Updates a system prompt. Only the owner or an admin may update.",
++ "operationId": "update_system_prompt",
++ "security": [
++ {
++ "HTTPBearer": []
++ }
++ ],
++ "parameters": [
++ {
++ "name": "system_prompt_id",
++ "in": "path",
++ "required": true,
++ "schema": {
++ "type": "string",
++ "description": "The id of the system prompt to update",
++ "title": "System Prompt Id"
++ },
++ "description": "The id of the system prompt to update"
++ }
++ ],
++ "requestBody": {
++ "required": true,
++ "content": {
++ "application/json": {
++ "schema": {
++ "$ref": "#/components/schemas/SystemPromptChanges",
++ "description": "The changes to apply"
++ }
++ }
++ }
+ },
+ "responses": {
+ "200": {
+ "description": "Successful Response",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/SystemPromptRecordDTO"
+ }
+ }
+ }
+ },
+ "422": {
+ "description": "Validation Error",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/HTTPValidationError"
+ }
+ }
+ }
+ }
+ }
+ },
+ "delete": {
+ "tags": ["system_prompts"],
+ "summary": "Delete System Prompt",
+ "description": "Deletes a system prompt. Only the owner or an admin may delete.",
+ "operationId": "delete_system_prompt",
+ "security": [
+ {
+ "HTTPBearer": []
+ }
+ ],
+ "parameters": [
+ {
+ "name": "system_prompt_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string",
+ "description": "The id of the system prompt to delete",
+ "title": "System Prompt Id"
+ },
+ "description": "The id of the system prompt to delete"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Successful Response",
+ "content": {
+ "application/json": {
+ "schema": {}
+ }
+ }
+ },
+ "422": {
+ "description": "Validation Error",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/HTTPValidationError"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/api/v1/client_state/{queue_id}/get_by_key": {
"get": {
"tags": ["client_state"],
diff --cc invokeai/frontend/web/src/services/api/schema.ts
index 6d97850f6a,58e62f9fed..97704786dd
--- a/invokeai/frontend/web/src/services/api/schema.ts
+++ b/invokeai/frontend/web/src/services/api/schema.ts
@@@ -3021,54 -2998,58 +3021,106 @@@ export type paths =
patch?: never;
trace?: never;
};
+ "/api/v1/wildcards/": {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ /**
+ * List Wildcards
+ * @description Lists the current user's wildcards.
+ */
+ get: operations["list_wildcards"];
+ put?: never;
+ /**
+ * Create Wildcard
+ * @description Creates a wildcard owned by the current user.
+ */
+ post: operations["create_wildcard"];
+ delete?: never;
+ options?: never;
+ head?: never;
+ patch?: never;
+ trace?: never;
+ };
+ "/api/v1/wildcards/{wildcard_id}": {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ get?: never;
+ put?: never;
+ post?: never;
+ /**
+ * Delete Wildcard
+ * @description Deletes a wildcard owned by the current user.
+ */
+ delete: operations["delete_wildcard"];
+ options?: never;
+ head?: never;
+ /**
+ * Update Wildcard
+ * @description Updates a wildcard owned by the current user.
+ */
+ patch: operations["update_wildcard"];
+ trace?: never;
+ };
+ "/api/v1/system_prompts/": {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ /**
+ * List System Prompts
+ * @description Lists system prompts visible to the current user (own + public).
+ */
+ get: operations["list_system_prompts"];
+ put?: never;
+ /**
+ * Create System Prompt
+ * @description Creates a new system prompt owned by the current user.
+ */
+ post: operations["create_system_prompt"];
+ delete?: never;
+ options?: never;
+ head?: never;
+ patch?: never;
+ trace?: never;
+ };
+ "/api/v1/system_prompts/i/{system_prompt_id}": {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ /**
+ * Get System Prompt
+ * @description Gets a system prompt by id.
+ */
+ get: operations["get_system_prompt"];
+ put?: never;
+ post?: never;
+ /**
+ * Delete System Prompt
+ * @description Deletes a system prompt. Only the owner or an admin may delete.
+ */
+ delete: operations["delete_system_prompt"];
+ options?: never;
+ head?: never;
+ /**
+ * Update System Prompt
+ * @description Updates a system prompt. Only the owner or an admin may update.
+ */
+ patch: operations["update_system_prompt"];
+ trace?: never;
+ };
"/api/v1/client_state/{queue_id}/get_by_key": {
parameters: {
query?: never;
@@@ -43741,6 -43603,6 +43939,10 @@@ export interface operations
starred_first?: boolean;
/** @description The term to search for */
search_term?: string | null;
++ /** @description Inclusive start date (YYYY-MM-DD) to filter by created_at. */
++ created_from?: string | null;
++ /** @description Inclusive end date (YYYY-MM-DD) to filter by created_at. */
++ created_to?: string | null;
};
header?: never;
path?: never;
@@@ -43785,6 -43647,6 +43987,10 @@@
starred_first?: boolean;
/** @description The term to search for */
search_term?: string | null;
++ /** @description Inclusive start date (YYYY-MM-DD) to filter by created_at. */
++ created_from?: string | null;
++ /** @description Inclusive end date (YYYY-MM-DD) to filter by created_at. */
++ created_to?: string | null;
};
header?: never;
path?: never;
@@@ -46318,125 -46169,159 +46524,278 @@@
};
};
};
+ list_wildcards: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description Successful Response */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["WildcardRecordDTO"][];
+ };
+ };
+ };
+ };
+ create_wildcard: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["WildcardWithoutId"];
+ };
+ };
+ responses: {
+ /** @description Successful Response */
+ 201: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["WildcardRecordDTO"];
+ };
+ };
+ /** @description Validation Error */
+ 422: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["HTTPValidationError"];
+ };
+ };
+ };
+ };
+ delete_wildcard: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path: {
+ /** @description The id of the wildcard to delete */
+ wildcard_id: string;
+ };
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description Successful Response */
+ 204: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content?: never;
+ };
+ /** @description Validation Error */
+ 422: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["HTTPValidationError"];
+ };
+ };
+ };
+ };
+ update_wildcard: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path: {
+ /** @description The id of the wildcard to update */
+ wildcard_id: string;
+ };
+ cookie?: never;
+ };
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["WildcardChanges"];
+ };
+ };
+ responses: {
+ /** @description Successful Response */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["WildcardRecordDTO"];
+ };
+ };
+ /** @description Validation Error */
+ 422: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["HTTPValidationError"];
+ };
+ };
+ };
+ };
+ list_system_prompts: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description Successful Response */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["SystemPromptRecordDTO"][];
+ };
+ };
+ };
+ };
+ create_system_prompt: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["SystemPromptWithoutId"];
+ };
+ };
+ responses: {
+ /** @description Successful Response */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["SystemPromptRecordDTO"];
+ };
+ };
+ /** @description Validation Error */
+ 422: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["HTTPValidationError"];
+ };
+ };
+ };
+ };
+ get_system_prompt: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path: {
+ /** @description The id of the system prompt to get */
+ system_prompt_id: string;
+ };
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description Successful Response */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["SystemPromptRecordDTO"];
+ };
+ };
+ /** @description Validation Error */
+ 422: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["HTTPValidationError"];
+ };
+ };
+ };
+ };
+ delete_system_prompt: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path: {
+ /** @description The id of the system prompt to delete */
+ system_prompt_id: string;
+ };
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description Successful Response */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": unknown;
+ };
+ };
+ /** @description Validation Error */
+ 422: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["HTTPValidationError"];
+ };
+ };
+ };
+ };
+ update_system_prompt: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path: {
+ /** @description The id of the system prompt to update */
+ system_prompt_id: string;
+ };
+ cookie?: never;
+ };
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["SystemPromptChanges"];
+ };
+ };
+ responses: {
+ /** @description Successful Response */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["SystemPromptRecordDTO"];
+ };
+ };
+ /** @description Validation Error */
+ 422: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["HTTPValidationError"];
+ };
+ };
+ };
+ };
get_client_state_by_key: {
parameters: {
query: {
diff --cc tests/app/routers/test_multiuser_authorization.py
index d125198476,be5d2a61be..9a22db11f8
--- a/tests/app/routers/test_multiuser_authorization.py
+++ b/tests/app/routers/test_multiuser_authorization.py
@@@ -80,9 -79,11 +80,12 @@@ def mock_services() -> InvocationServic
from invokeai.app.services.images.images_default import ImageService
from invokeai.app.services.invocation_cache.invocation_cache_memory import MemoryInvocationCache
from invokeai.app.services.invocation_stats.invocation_stats_default import InvocationStatsService
+ from invokeai.app.services.system_prompt_records.system_prompt_records_sqlite import (
+ SqliteSystemPromptRecordsStorage,
+ )
from invokeai.app.services.users.users_default import UserService
from invokeai.app.services.video_records.video_records_sqlite import SqliteVideoRecordStorage
+ from invokeai.app.services.wildcard_records.wildcard_records_sqlite import SqliteWildcardRecordsStorage
from tests.test_nodes import TestEventService
configuration = InvokeAIAppConfig(use_memory_db=True, node_cache_size=0)
diff --cc tests/app/routers/test_session_queue_workflow_call.py
index f8b1adf563,f1c45b2263..64c7f7a984
--- a/tests/app/routers/test_session_queue_workflow_call.py
+++ b/tests/app/routers/test_session_queue_workflow_call.py
@@@ -95,10 -93,9 +95,11 @@@ def mock_services() -> InvocationServic
model_relationship_records=None, # type: ignore
model_relationships=None, # type: ignore
client_state_persistence=ClientStatePersistenceSqlite(db=db),
+ project_records=ProjectRecordsSqlite(db=db),
users=UserService(db),
+ wildcard_records=SqliteWildcardRecordsStorage(db=db),
external_generation=None, # type: ignore
+ system_prompt_records=None, # type: ignore
videos=None, # type: ignore
video_files=None, # type: ignore
video_records=SqliteVideoRecordStorage(db=db),
diff --cc tests/app/routers/test_system_prompts_multiuser.py
index 0000000000,1dc7beeaf7..f4c16699ba
mode 000000,100644..100644
--- a/tests/app/routers/test_system_prompts_multiuser.py
+++ b/tests/app/routers/test_system_prompts_multiuser.py
@@@ -1,0 -1,284 +1,286 @@@
+ """Multi-user permission tests for the /api/v1/system_prompts router.
+
+ Verifies:
+ - list scopes to own + public for non-admins
+ - non-owner PATCH/DELETE returns 403
+ - owner can flip is_public
+ - admin sees and mutates everything
+ """
+
+ import logging
+ from typing import Any
+
+ import pytest
+ from fastapi import status
+ from fastapi.testclient import TestClient
+
+ from invokeai.app.api.dependencies import ApiDependencies
+ from invokeai.app.api_app import app
+ from invokeai.app.services.config.config_default import InvokeAIAppConfig
+ from invokeai.app.services.invocation_services import InvocationServices
+ from invokeai.app.services.invoker import Invoker
+ from invokeai.app.services.users.users_common import UserCreateRequest
+ from invokeai.backend.util.logging import InvokeAILogger
+ from tests.fixtures.sqlite_database import create_mock_sqlite_database
+
+
+ class MockApiDependencies(ApiDependencies):
+ invoker: Invoker
+
+ def __init__(self, invoker: Invoker) -> None:
+ self.invoker = invoker
+
+
+ @pytest.fixture
+ def setup_jwt_secret():
+ from invokeai.app.services.auth.token_service import set_jwt_secret
+
+ set_jwt_secret("test-secret-key-for-unit-tests-only-do-not-use-in-production")
+
+
+ @pytest.fixture
+ def client():
+ return TestClient(app)
+
+
+ @pytest.fixture
+ def mock_services() -> InvocationServices:
+ from invokeai.app.services.board_image_records.board_image_records_sqlite import SqliteBoardImageRecordStorage
+ from invokeai.app.services.board_records.board_records_sqlite import SqliteBoardRecordStorage
+ from invokeai.app.services.boards.boards_default import BoardService
+ from invokeai.app.services.bulk_download.bulk_download_default import BulkDownloadService
+ from invokeai.app.services.client_state_persistence.client_state_persistence_sqlite import (
+ ClientStatePersistenceSqlite,
+ )
+ from invokeai.app.services.image_records.image_records_sqlite import SqliteImageRecordStorage
+ from invokeai.app.services.images.images_default import ImageService
+ from invokeai.app.services.invocation_cache.invocation_cache_memory import MemoryInvocationCache
+ from invokeai.app.services.invocation_stats.invocation_stats_default import InvocationStatsService
+ from invokeai.app.services.system_prompt_records.system_prompt_records_sqlite import (
+ SqliteSystemPromptRecordsStorage,
+ )
+ from invokeai.app.services.users.users_default import UserService
+ from tests.test_nodes import TestEventService
+
+ configuration = InvokeAIAppConfig(use_memory_db=True, node_cache_size=0)
+ logger = InvokeAILogger.get_logger()
+ db = create_mock_sqlite_database(configuration, logger)
+
+ return InvocationServices(
+ board_image_records=SqliteBoardImageRecordStorage(db=db),
+ board_images=None, # type: ignore
+ board_records=SqliteBoardRecordStorage(db=db),
+ boards=BoardService(),
+ bulk_download=BulkDownloadService(),
+ configuration=configuration,
+ events=TestEventService(),
+ image_files=None, # type: ignore
+ image_records=SqliteImageRecordStorage(db=db),
+ images=ImageService(),
+ invocation_cache=MemoryInvocationCache(max_cache_size=0),
+ logger=logging, # type: ignore
+ model_images=None, # type: ignore
+ model_manager=None, # type: ignore
+ download_queue=None, # type: ignore
+ names=None, # type: ignore
+ performance_statistics=InvocationStatsService(),
+ session_processor=None, # type: ignore
+ session_queue=None, # type: ignore
+ urls=None, # type: ignore
+ workflow_records=None, # type: ignore
+ tensors=None, # type: ignore
+ conditioning=None, # type: ignore
+ style_preset_records=None, # type: ignore
+ style_preset_image_files=None, # type: ignore
+ system_prompt_records=SqliteSystemPromptRecordsStorage(db=db),
+ workflow_thumbnails=None, # type: ignore
+ model_relationship_records=None, # type: ignore
+ model_relationships=None, # type: ignore
+ client_state_persistence=ClientStatePersistenceSqlite(db=db),
++ project_records=None, # type: ignore
+ users=UserService(db),
++ wildcard_records=None, # type: ignore
+ external_generation=None, # type: ignore
+ videos=None, # type: ignore
+ video_files=None, # type: ignore
+ video_records=None, # type: ignore
+ board_video_records=None, # type: ignore
+ gallery=None, # type: ignore
+ )
+
+
+ @pytest.fixture
+ def mock_invoker(mock_services: InvocationServices) -> Invoker:
+ return Invoker(services=mock_services)
+
+
+ def create_test_user(mock_invoker: Invoker, email: str, display_name: str, is_admin: bool = False) -> str:
+ user_service = mock_invoker.services.users
+ user_data = UserCreateRequest(email=email, display_name=display_name, password="TestPass123", is_admin=is_admin)
+ user = user_service.create(user_data)
+ return user.user_id
+
+
+ def get_user_token(client: TestClient, email: str) -> str:
+ response = client.post(
+ "/api/v1/auth/login",
+ json={"email": email, "password": "TestPass123", "remember_me": False},
+ )
+ assert response.status_code == 200, response.text
+ return response.json()["token"]
+
+
+ @pytest.fixture
+ def enable_multiuser(monkeypatch: Any, mock_invoker: Invoker):
+ mock_invoker.services.configuration.multiuser = True
+ mock_deps = MockApiDependencies(mock_invoker)
+ # Patch every module that imports ApiDependencies for symbol resolution.
+ monkeypatch.setattr("invokeai.app.api.routers.auth.ApiDependencies", mock_deps)
+ monkeypatch.setattr("invokeai.app.api.auth_dependencies.ApiDependencies", mock_deps)
+ monkeypatch.setattr("invokeai.app.api.routers.system_prompts.ApiDependencies", mock_deps)
+ yield
+
+
+ @pytest.fixture
+ def admin_token(setup_jwt_secret: None, enable_multiuser: Any, mock_invoker: Invoker, client: TestClient):
+ create_test_user(mock_invoker, "[email protected]", "Admin", is_admin=True)
+ return get_user_token(client, "[email protected]")
+
+
+ @pytest.fixture
+ def user1_token(enable_multiuser: Any, mock_invoker: Invoker, client: TestClient, admin_token: str):
+ create_test_user(mock_invoker, "[email protected]", "User One", is_admin=False)
+ return get_user_token(client, "[email protected]")
+
+
+ @pytest.fixture
+ def user2_token(enable_multiuser: Any, mock_invoker: Invoker, client: TestClient, admin_token: str):
+ create_test_user(mock_invoker, "[email protected]", "User Two", is_admin=False)
+ return get_user_token(client, "[email protected]")
+
+
+ def _create_prompt(client: TestClient, token: str, name: str = "p", content: str = "c") -> dict:
+ r = client.post(
+ "/api/v1/system_prompts/",
+ json={"name": name, "content": content},
+ headers={"Authorization": f"Bearer {token}"},
+ )
+ assert r.status_code == 200, r.text
+ return r.json()
+
+
+ def _list(client: TestClient, token: str) -> list:
+ r = client.get("/api/v1/system_prompts/", headers={"Authorization": f"Bearer {token}"})
+ assert r.status_code == 200
+ return r.json()
+
+
+ # ---------------------------------------------------------------------------
+ # Auth gate
+ # ---------------------------------------------------------------------------
+
+
+ def test_list_requires_auth_in_multiuser(enable_multiuser: Any, client: TestClient):
+ r = client.get("/api/v1/system_prompts/")
+ assert r.status_code == status.HTTP_401_UNAUTHORIZED
+
+
+ # ---------------------------------------------------------------------------
+ # Visibility scoping
+ # ---------------------------------------------------------------------------
+
+
+ def test_user2_does_not_see_user1_private_prompt(client: TestClient, user1_token: str, user2_token: str):
+ p = _create_prompt(client, user1_token, name="user1 private")
+ assert p["is_public"] is False # multiuser create defaults to private
+ user2_ids = {row["id"] for row in _list(client, user2_token)}
+ assert p["id"] not in user2_ids
+
+
+ def test_user2_sees_user1_public_prompt(client: TestClient, user1_token: str, user2_token: str):
+ created = _create_prompt(client, user1_token, name="user1 created")
+ # flip to public via PATCH
+ r = client.patch(
+ f"/api/v1/system_prompts/i/{created['id']}",
+ json={"is_public": True},
+ headers={"Authorization": f"Bearer {user1_token}"},
+ )
+ assert r.status_code == 200
+ assert r.json()["is_public"] is True
+
+ user2_ids = {row["id"] for row in _list(client, user2_token)}
+ assert created["id"] in user2_ids
+
+
+ def test_seeded_defaults_visible_to_non_admin(client: TestClient, user1_token: str):
+ rows = _list(client, user1_token)
+ # The Default seed has fixed UUID …0000.
+ default_id = "0f8f5b2e-1c9e-4f2a-9a4e-1f1f1f1f0000"
+ assert any(r["id"] == default_id for r in rows)
+
+
+ # ---------------------------------------------------------------------------
+ # Mutation permissions
+ # ---------------------------------------------------------------------------
+
+
+ def test_user2_cannot_patch_user1_prompt(client: TestClient, user1_token: str, user2_token: str):
+ p = _create_prompt(client, user1_token, name="locked")
+ r = client.patch(
+ f"/api/v1/system_prompts/i/{p['id']}",
+ json={"name": "hijacked"},
+ headers={"Authorization": f"Bearer {user2_token}"},
+ )
+ assert r.status_code == status.HTTP_403_FORBIDDEN
+
+
+ def test_user2_cannot_delete_user1_prompt(client: TestClient, user1_token: str, user2_token: str):
+ p = _create_prompt(client, user1_token, name="locked")
+ r = client.delete(
+ f"/api/v1/system_prompts/i/{p['id']}",
+ headers={"Authorization": f"Bearer {user2_token}"},
+ )
+ assert r.status_code == status.HTTP_403_FORBIDDEN
+
+ # Confirm the row still exists by fetching it as the owner.
+ r2 = client.get(
+ f"/api/v1/system_prompts/i/{p['id']}",
+ headers={"Authorization": f"Bearer {user1_token}"},
+ )
+ assert r2.status_code == 200
+
+
+ def test_user2_cannot_get_user1_private_prompt(client: TestClient, user1_token: str, user2_token: str):
+ p = _create_prompt(client, user1_token, name="locked")
+ r = client.get(
+ f"/api/v1/system_prompts/i/{p['id']}",
+ headers={"Authorization": f"Bearer {user2_token}"},
+ )
+ assert r.status_code == status.HTTP_403_FORBIDDEN
+
+
+ def test_admin_can_patch_any_users_prompt(client: TestClient, user1_token: str, admin_token: str):
+ p = _create_prompt(client, user1_token, name="user1 owned")
+ r = client.patch(
+ f"/api/v1/system_prompts/i/{p['id']}",
+ json={"name": "renamed by admin"},
+ headers={"Authorization": f"Bearer {admin_token}"},
+ )
+ assert r.status_code == 200
+ assert r.json()["name"] == "renamed by admin"
+
+
+ def test_admin_can_delete_any_users_prompt(client: TestClient, user1_token: str, admin_token: str):
+ p = _create_prompt(client, user1_token, name="user1 owned")
+ r = client.delete(
+ f"/api/v1/system_prompts/i/{p['id']}",
+ headers={"Authorization": f"Bearer {admin_token}"},
+ )
+ assert r.status_code == 200
+
+ # Confirm gone (owner should get 404 now).
+ r2 = client.get(
+ f"/api/v1/system_prompts/i/{p['id']}",
+ headers={"Authorization": f"Bearer {user1_token}"},
+ )
+ assert r2.status_code == status.HTTP_404_NOT_FOUND
diff --cc tests/app/routers/test_system_prompts_single_user.py
index 0000000000,2dc45d7a16..1d9df114ea
mode 000000,100644..100644
--- a/tests/app/routers/test_system_prompts_single_user.py
+++ b/tests/app/routers/test_system_prompts_single_user.py
@@@ -1,0 -1,135 +1,137 @@@
+ """Single-user tests for the /api/v1/system_prompts router.
+
+ The multi-user tests cover the ownership checks. Single-user installs skip those checks
+ entirely, which is exactly where the delete contract used to diverge: DELETE reported 200 for
+ ids that GET 404s on, and deleting the same row twice succeeded twice.
+ """
+
+ import logging
+ from typing import Any
+
+ import pytest
+ from fastapi.testclient import TestClient
+
+ from invokeai.app.api.dependencies import ApiDependencies
+ from invokeai.app.api_app import app
+ from invokeai.app.services.config.config_default import InvokeAIAppConfig
+ from invokeai.app.services.invocation_services import InvocationServices
+ from invokeai.app.services.invoker import Invoker
+ from invokeai.backend.util.logging import InvokeAILogger
+ from tests.fixtures.sqlite_database import create_mock_sqlite_database
+
+
+ class MockApiDependencies(ApiDependencies):
+ invoker: Invoker
+
+ def __init__(self, invoker: Invoker) -> None:
+ self.invoker = invoker
+
+
+ @pytest.fixture
+ def client():
+ return TestClient(app)
+
+
+ @pytest.fixture
+ def mock_services() -> InvocationServices:
+ from invokeai.app.services.board_image_records.board_image_records_sqlite import SqliteBoardImageRecordStorage
+ from invokeai.app.services.board_records.board_records_sqlite import SqliteBoardRecordStorage
+ from invokeai.app.services.boards.boards_default import BoardService
+ from invokeai.app.services.bulk_download.bulk_download_default import BulkDownloadService
+ from invokeai.app.services.client_state_persistence.client_state_persistence_sqlite import (
+ ClientStatePersistenceSqlite,
+ )
+ from invokeai.app.services.image_records.image_records_sqlite import SqliteImageRecordStorage
+ from invokeai.app.services.images.images_default import ImageService
+ from invokeai.app.services.invocation_cache.invocation_cache_memory import MemoryInvocationCache
+ from invokeai.app.services.invocation_stats.invocation_stats_default import InvocationStatsService
+ from invokeai.app.services.system_prompt_records.system_prompt_records_sqlite import (
+ SqliteSystemPromptRecordsStorage,
+ )
+ from invokeai.app.services.users.users_default import UserService
+ from tests.test_nodes import TestEventService
+
+ configuration = InvokeAIAppConfig(use_memory_db=True, node_cache_size=0)
+ logger = InvokeAILogger.get_logger()
+ db = create_mock_sqlite_database(configuration, logger)
+
+ return InvocationServices(
+ board_image_records=SqliteBoardImageRecordStorage(db=db),
+ board_images=None, # type: ignore
+ board_records=SqliteBoardRecordStorage(db=db),
+ boards=BoardService(),
+ bulk_download=BulkDownloadService(),
+ configuration=configuration,
+ events=TestEventService(),
+ image_files=None, # type: ignore
+ image_records=SqliteImageRecordStorage(db=db),
+ images=ImageService(),
+ invocation_cache=MemoryInvocationCache(max_cache_size=0),
+ logger=logging, # type: ignore
+ model_images=None, # type: ignore
+ model_manager=None, # type: ignore
+ download_queue=None, # type: ignore
+ names=None, # type: ignore
+ performance_statistics=InvocationStatsService(),
+ session_processor=None, # type: ignore
+ session_queue=None, # type: ignore
+ urls=None, # type: ignore
+ workflow_records=None, # type: ignore
+ tensors=None, # type: ignore
+ conditioning=None, # type: ignore
+ style_preset_records=None, # type: ignore
+ style_preset_image_files=None, # type: ignore
+ system_prompt_records=SqliteSystemPromptRecordsStorage(db=db),
+ workflow_thumbnails=None, # type: ignore
+ model_relationship_records=None, # type: ignore
+ model_relationships=None, # type: ignore
+ client_state_persistence=ClientStatePersistenceSqlite(db=db),
++ project_records=None, # type: ignore
+ users=UserService(db),
++ wildcard_records=None, # type: ignore
+ external_generation=None, # type: ignore
+ videos=None, # type: ignore
+ video_files=None, # type: ignore
+ video_records=None, # type: ignore
+ board_video_records=None, # type: ignore
+ gallery=None, # type: ignore
+ )
+
+
+ @pytest.fixture
+ def mock_invoker(mock_services: InvocationServices) -> Invoker:
+ return Invoker(services=mock_services)
+
+
+ @pytest.fixture
+ def single_user(monkeypatch: Any, mock_invoker: Invoker):
+ mock_invoker.services.configuration.multiuser = False
+ mock_deps = MockApiDependencies(mock_invoker)
+ monkeypatch.setattr("invokeai.app.api.auth_dependencies.ApiDependencies", mock_deps)
+ monkeypatch.setattr("invokeai.app.api.routers.system_prompts.ApiDependencies", mock_deps)
+ yield
+
+
+ def _create_prompt(client: TestClient, name: str = "p", content: str = "c") -> dict:
+ r = client.post("/api/v1/system_prompts/", json={"name": name, "content": content})
+ assert r.status_code == 200, r.text
+ return r.json()
+
+
+ def test_delete_of_unknown_id_returns_404(single_user: Any, client: TestClient) -> None:
+ # GET and DELETE must agree: an id that does not exist is a 404 for both.
+ assert client.get("/api/v1/system_prompts/i/does-not-exist").status_code == 404
+ assert client.delete("/api/v1/system_prompts/i/does-not-exist").status_code == 404
+
+
+ def test_delete_is_not_idempotent_success(single_user: Any, client: TestClient) -> None:
+ created = _create_prompt(client, name="temp")
+ assert client.delete(f"/api/v1/system_prompts/i/{created['id']}").status_code == 200
+ assert client.get(f"/api/v1/system_prompts/i/{created['id']}").status_code == 404
+ # The second delete must not report success for a row that is already gone.
+ assert client.delete(f"/api/v1/system_prompts/i/{created['id']}").status_code == 404
+
+
+ def test_create_is_public_in_single_user_mode(single_user: Any, client: TestClient) -> None:
+ created = _create_prompt(client, name="shared by default")
+ assert created["is_public"] is True
diff --cc tests/app/routers/test_workflows_multiuser.py
index e6dc7fd63e,4844139148..6c34b02c00
--- a/tests/app/routers/test_workflows_multiuser.py
+++ b/tests/app/routers/test_workflows_multiuser.py
@@@ -70,9 -69,11 +70,12 @@@ def mock_services() -> InvocationServic
from invokeai.app.services.images.images_default import ImageService
from invokeai.app.services.invocation_cache.invocation_cache_memory import MemoryInvocationCache
from invokeai.app.services.invocation_stats.invocation_stats_default import InvocationStatsService
+ from invokeai.app.services.system_prompt_records.system_prompt_records_sqlite import (
+ SqliteSystemPromptRecordsStorage,
+ )
from invokeai.app.services.users.users_default import UserService
from invokeai.app.services.video_records.video_records_sqlite import SqliteVideoRecordStorage
+ from invokeai.app.services.wildcard_records.wildcard_records_sqlite import SqliteWildcardRecordsStorage
from tests.test_nodes import TestEventService
configuration = InvokeAIAppConfig(use_memory_db=True, node_cache_size=0)
diff --cc tests/conftest.py
index 83b023b44a,bb8afd1d8d..a22de7483b
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@@ -25,10 -25,11 +25,13 @@@ from invokeai.app.services.invocation_c
from invokeai.app.services.invocation_services import InvocationServices
from invokeai.app.services.invocation_stats.invocation_stats_default import InvocationStatsService
from invokeai.app.services.invoker import Invoker
+from invokeai.app.services.project_records.project_records_sqlite import ProjectRecordsSqlite
+ from invokeai.app.services.system_prompt_records.system_prompt_records_sqlite import (
+ SqliteSystemPromptRecordsStorage,
+ )
from invokeai.app.services.users.users_default import UserService
from invokeai.app.services.video_records.video_records_sqlite import SqliteVideoRecordStorage
+from invokeai.app.services.wildcard_records.wildcard_records_sqlite import SqliteWildcardRecordsStorage
from invokeai.app.services.workflow_records.workflow_records_sqlite import SqliteWorkflowRecordsStorage
from invokeai.backend.util.logging import InvokeAILogger
from tests.backend.model_manager.model_manager_fixtures import * # noqa: F403