Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth when reading deleted records #820

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/dwn-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,5 @@ export enum DwnErrorCode {
UrlProtocolNotNormalized = 'UrlProtocolNotNormalized',
UrlProtocolNotNormalizable = 'UrlProtocolNotNormalizable',
UrlSchemaNotNormalized = 'UrlSchemaNotNormalized',
RecordsReadInitialWriteNotFound = 'RecordsReadInitialWriteNotFound',
};
16 changes: 16 additions & 0 deletions src/handlers/records-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ export class RecordsReadHandler implements MethodHandler {
if (matchedMessage.descriptor.method === DwnMethodName.Delete) {
const recordsDeleteMessage = matchedMessage as RecordsDeleteMessage;
const initialWrite = await RecordsWrite.fetchInitialRecordsWriteMessage(this.messageStore, tenant, recordsDeleteMessage.descriptor.recordId);

if (initialWrite === undefined) {
return messageReplyFromError(new DwnError(
DwnErrorCode.RecordsReadInitialWriteNotFound,
'Initial write for deleted record not found'
), 400);
}

// Perform authorization before returning the delete and initial write messages
const parsedInitialWrite = await RecordsWrite.parse(initialWrite);
try {
await RecordsReadHandler.authorizeRecordsRead(tenant, recordsRead, parsedInitialWrite, this.messageStore);
} catch (error) {
return messageReplyFromError(error, 401);
}
thehenrytsai marked this conversation as resolved.
Show resolved Hide resolved

return {
status : { code: 404, detail: 'Not Found' },
delete : recordsDeleteMessage,
Expand Down