From 6f39a706b2e409c8e6a1fa7654e6fae52d919d44 Mon Sep 17 00:00:00 2001 From: Daimolean <92239625+wuzihao051119@users.noreply.github.com> Date: Thu, 29 May 2025 21:48:44 +0800 Subject: [PATCH] fix: missing permissions and optional update (#18735) * fix: missing permissions * fix: test --- .../openapi/lib/model/api_key_update_dto.dart | 20 +++++++++++++------ open-api/immich-openapi-specs.json | 4 ---- open-api/typescript-sdk/src/fetch-client.ts | 4 ++-- server/src/dtos/api-key.dto.ts | 6 ++++-- web/src/lib/modals/ApiKeyModal.svelte | 8 +++++++- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/mobile/openapi/lib/model/api_key_update_dto.dart b/mobile/openapi/lib/model/api_key_update_dto.dart index 60ac168fdbd..7f32c951187 100644 --- a/mobile/openapi/lib/model/api_key_update_dto.dart +++ b/mobile/openapi/lib/model/api_key_update_dto.dart @@ -13,11 +13,17 @@ part of openapi.api; class APIKeyUpdateDto { /// Returns a new [APIKeyUpdateDto] instance. APIKeyUpdateDto({ - required this.name, + this.name, this.permissions = const [], }); - String name; + /// + /// Please note: This property should have been non-nullable! Since the specification file + /// does not include a default value (using the "default:" property), however, the generated + /// source code must fall back to having a nullable type. + /// Consider adding a "default:" property in the specification file to hide this note. + /// + String? name; List permissions; @@ -29,7 +35,7 @@ class APIKeyUpdateDto { @override int get hashCode => // ignore: unnecessary_parenthesis - (name.hashCode) + + (name == null ? 0 : name!.hashCode) + (permissions.hashCode); @override @@ -37,7 +43,11 @@ class APIKeyUpdateDto { Map toJson() { final json = {}; + if (this.name != null) { json[r'name'] = this.name; + } else { + // json[r'name'] = null; + } json[r'permissions'] = this.permissions; return json; } @@ -51,7 +61,7 @@ class APIKeyUpdateDto { final json = value.cast(); return APIKeyUpdateDto( - name: mapValueOfType(json, r'name')!, + name: mapValueOfType(json, r'name'), permissions: Permission.listFromJson(json[r'permissions']), ); } @@ -100,8 +110,6 @@ class APIKeyUpdateDto { /// The list of required keys that must be present in a JSON. static const requiredKeys = { - 'name', - 'permissions', }; } diff --git a/open-api/immich-openapi-specs.json b/open-api/immich-openapi-specs.json index dee027f8386..410840388f2 100644 --- a/open-api/immich-openapi-specs.json +++ b/open-api/immich-openapi-specs.json @@ -8335,10 +8335,6 @@ "type": "array" } }, - "required": [ - "name", - "permissions" - ], "type": "object" }, "ActivityCreateDto": { diff --git a/open-api/typescript-sdk/src/fetch-client.ts b/open-api/typescript-sdk/src/fetch-client.ts index 0c0ffd97963..2b0e2849d12 100644 --- a/open-api/typescript-sdk/src/fetch-client.ts +++ b/open-api/typescript-sdk/src/fetch-client.ts @@ -415,8 +415,8 @@ export type ApiKeyCreateResponseDto = { secret: string; }; export type ApiKeyUpdateDto = { - name: string; - permissions: Permission[]; + name?: string; + permissions?: Permission[]; }; export type AssetBulkDeleteDto = { force?: boolean; diff --git a/server/src/dtos/api-key.dto.ts b/server/src/dtos/api-key.dto.ts index ac6dd25bcf5..c790ea613dd 100644 --- a/server/src/dtos/api-key.dto.ts +++ b/server/src/dtos/api-key.dto.ts @@ -15,14 +15,16 @@ export class APIKeyCreateDto { } export class APIKeyUpdateDto { + @Optional() @IsString() @IsNotEmpty() - name!: string; + name?: string; + @Optional() @IsEnum(Permission, { each: true }) @ApiProperty({ enum: Permission, enumName: 'Permission', isArray: true }) @ArrayMinSize(1) - permissions!: Permission[]; + permissions?: Permission[]; } export class APIKeyCreateResponseDto { diff --git a/web/src/lib/modals/ApiKeyModal.svelte b/web/src/lib/modals/ApiKeyModal.svelte index 4a1df0f9813..a0f8d57193b 100644 --- a/web/src/lib/modals/ApiKeyModal.svelte +++ b/web/src/lib/modals/ApiKeyModal.svelte @@ -110,7 +110,13 @@ Permission.PersonReassign, ]); - permissions.set('session', [Permission.SessionRead, Permission.SessionUpdate, Permission.SessionDelete]); + permissions.set('session', [ + Permission.SessionCreate, + Permission.SessionRead, + Permission.SessionUpdate, + Permission.SessionDelete, + Permission.SessionLock, + ]); permissions.set('sharedLink', [ Permission.SharedLinkCreate,