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.

fix: align upstream authorization contracts

Josh Corbetta399a7464b7e
diff --git a/invokeai/app/api/routers/_access.py b/invokeai/app/api/routers/_access.py
index 25fad23bb0..85d376d7d7 100644
--- a/invokeai/app/api/routers/_access.py
+++ b/invokeai/app/api/routers/_access.py
@@ -211,11 +211,11 @@ def assert_board_read_access(board_id: str, current_user: CurrentUserOrDefault)
- The board visibility is Shared or Public.
- The board is explicitly shared with the user.
"""
+ board = _get_board_record(board_id)
+
if current_user.is_admin:
return
- board = _get_board_record(board_id)
-
if board.user_id == current_user.user_id:
return
diff --git a/invokeai/app/api/routers/images.py b/invokeai/app/api/routers/images.py
index c7abfb98fe..fc0ed8040d 100644
--- a/invokeai/app/api/routers/images.py
+++ b/invokeai/app/api/routers/images.py
@@ -659,7 +659,7 @@ class CopyImagesResult(BaseModel):
@images_router.post("/copy", operation_id="copy_images_to_board", response_model=CopyImagesResult)
def copy_images_to_board(
current_user: CurrentUserOrDefault,
- image_names: list[str] = Body(description="The names of the images to copy", max_length=MAX_COPY_BATCH_SIZE),
+ image_names: list[ImageName] = Body(description="The names of the images to copy", max_length=MAX_COPY_BATCH_SIZE),
board_id: Optional[str] = Body(default=None, description="The board to put the copies on, if any"),
) -> CopyImagesResult:
"""Copies images, optionally onto a board, and returns the new names.
diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.json
index 9c269d6e5f..2e75b0f056 100644
--- a/invokeai/frontend/web/openapi.json
+++ b/invokeai/frontend/web/openapi.json
@@ -17667,7 +17667,8 @@
"properties": {
"image_names": {
"items": {
- "type": "string"
+ "type": "string",
+ "maxLength": 255
},
"type": "array",
"maxItems": 1000,
diff --git a/tests/app/routers/test_images.py b/tests/app/routers/test_images.py
index de838253b6..7b694c280b 100644
--- a/tests/app/routers/test_images.py
+++ b/tests/app/routers/test_images.py
@@ -48,19 +48,17 @@ def test_download_images_from_board_id_empty_image_name_list(
) -> None:
expected_board_name = "test"
- def mock_get(*args, **kwargs):
- return BoardRecord(board_id="12345", board_name=expected_board_name, created_at="None", updated_at="None")
-
+ mock_get = MagicMock(
+ return_value=BoardRecord(board_id="12345", board_name=expected_board_name, created_at="None", updated_at="None")
+ )
monkeypatch.setattr(mock_invoker.services.board_records, "get", mock_get)
- mock_get_dto = MagicMock(return_value=object())
- monkeypatch.setattr(mock_invoker.services.boards, "get_dto", mock_get_dto)
prepare_download_images_test(monkeypatch, mock_invoker)
response = client.post("/api/v1/images/download", json={"board_id": "test"})
json_response = response.json()
assert response.status_code == 202
assert json_response["bulk_download_item_name"] == "test.zip"
- mock_get_dto.assert_called_once_with(board_id="test")
+ mock_get.assert_called_once_with("test")
def prepare_download_images_test(monkeypatch: Any, mock_invoker: Invoker) -> None:
@@ -352,6 +350,7 @@ def prepare_image_batch_test(monkeypatch: Any, mock_invoker: Invoker) -> MagicMo
monkeypatch.setattr(mock_invoker.services, "images", images_service)
mock_invoker.services.image_moves = MagicMock()
mock_invoker.services.image_moves.is_maintenance_active.return_value = False
+ monkeypatch.setattr(mock_invoker.services.image_records, "exists", MagicMock(return_value=True))
monkeypatch.setattr(mock_invoker.services.board_image_records, "get_board_for_image", MagicMock(return_value=None))
mock_deps = MockApiDependencies(mock_invoker)
@@ -604,6 +603,7 @@ def test_star_unstar_dedupes_repeated_names(
"/api/v1/images/unstar",
"/api/v1/images/images_by_names",
"/api/v1/images/download",
+ "/api/v1/images/copy",
"/api/v1/board_images/batch",
"/api/v1/board_images/batch/delete",
],
@@ -679,6 +679,7 @@ def test_every_image_names_body_is_bounded(client: TestClient) -> None:
assert sorted(checked) == [
"/api/v1/board_images/batch",
"/api/v1/board_images/batch/delete",
+ "/api/v1/images/copy",
"/api/v1/images/delete",
"/api/v1/images/download",
"/api/v1/images/images_by_names",
diff --git a/tests/app/routers/test_videos_multiuser.py b/tests/app/routers/test_videos_multiuser.py
index ced769900d..6fcddf11a1 100644
--- a/tests/app/routers/test_videos_multiuser.py
+++ b/tests/app/routers/test_videos_multiuser.py
@@ -867,11 +867,11 @@ def test_remove_video_from_board_succeeds_for_board_owner_of_non_owned_video(
mock_invoker.services.video_records.get_user_id.return_value = user2.user_id
mock_invoker.services.board_video_records.get_board_for_video.return_value = "user1-board"
- # _assert_board_write_access reads the board DTO to check ownership/visibility.
+ # _assert_board_write_access reads the lightweight board record to check ownership/visibility.
fake_board = MagicMock()
fake_board.user_id = user1.user_id
fake_board.board_visibility = BoardVisibility.Private
- with patch.object(mock_invoker.services.boards, "get_dto", return_value=fake_board):
+ with patch.object(mock_invoker.services.board_records, "get", return_value=fake_board):
response = client.request(
"DELETE",
"/api/v1/videos/board",
@@ -902,7 +902,7 @@ def test_remove_video_from_board_rejects_third_party(
fake_board.board_visibility = BoardVisibility.Private
# user2 has no claim to either resource.
- with patch.object(mock_invoker.services.boards, "get_dto", return_value=fake_board):
+ with patch.object(mock_invoker.services.board_records, "get", return_value=fake_board):
response = client.request(
"DELETE",
"/api/v1/videos/board",