mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-22 21:50:13 +00:00
Preserve stored cipher permission flags in responses
This commit is contained in:
+20
-6
@@ -48,6 +48,22 @@ function normalizeOptionalId(value: unknown): string | null {
|
|||||||
return normalized ? normalized : null;
|
return normalized ? normalized : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readBooleanOrFallback(value: unknown, fallback: boolean): boolean {
|
||||||
|
return typeof value === 'boolean' ? value : fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildCipherPermissions(passthrough: Record<string, unknown>): { delete: boolean; restore: boolean } {
|
||||||
|
const raw = passthrough.permissions;
|
||||||
|
const source = raw && typeof raw === 'object' && !Array.isArray(raw)
|
||||||
|
? raw as Record<string, unknown>
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
delete: readBooleanOrFallback(source?.delete, true),
|
||||||
|
restore: readBooleanOrFallback(source?.restore, true),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function notifyVaultSyncForRequest(
|
function notifyVaultSyncForRequest(
|
||||||
request: Request,
|
request: Request,
|
||||||
env: Env,
|
env: Env,
|
||||||
@@ -705,6 +721,7 @@ export function cipherToResponse(
|
|||||||
? normalizeCipherSecureNoteForCompatibility((passthrough as any).secureNote ?? null) ?? { type: 0 }
|
? normalizeCipherSecureNoteForCompatibility((passthrough as any).secureNote ?? null) ?? { type: 0 }
|
||||||
: null;
|
: null;
|
||||||
const responseAttachments = applyCipherEmbeddedAttachmentMetadata(cipher, attachments);
|
const responseAttachments = applyCipherEmbeddedAttachmentMetadata(cipher, attachments);
|
||||||
|
const responsePermissions = buildCipherPermissions(passthrough);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// Pass through ALL stored cipher fields (known + unknown)
|
// Pass through ALL stored cipher fields (known + unknown)
|
||||||
@@ -718,12 +735,9 @@ export function cipherToResponse(
|
|||||||
revisionDate: updatedAt,
|
revisionDate: updatedAt,
|
||||||
deletedDate: deletedAt,
|
deletedDate: deletedAt,
|
||||||
archivedDate: archivedAt ?? null,
|
archivedDate: archivedAt ?? null,
|
||||||
edit: true,
|
edit: readBooleanOrFallback((passthrough as any).edit, true),
|
||||||
viewPassword: true,
|
viewPassword: readBooleanOrFallback((passthrough as any).viewPassword, true),
|
||||||
permissions: {
|
permissions: responsePermissions,
|
||||||
delete: true,
|
|
||||||
restore: true,
|
|
||||||
},
|
|
||||||
object: 'cipherDetails',
|
object: 'cipherDetails',
|
||||||
collectionIds: Array.isArray((passthrough as any).collectionIds) ? (passthrough as any).collectionIds : [],
|
collectionIds: Array.isArray((passthrough as any).collectionIds) ? (passthrough as any).collectionIds : [],
|
||||||
attachments: formatAttachments(responseAttachments),
|
attachments: formatAttachments(responseAttachments),
|
||||||
|
|||||||
Reference in New Issue
Block a user