From 199f9222084b42be4023940fc1150e6ae9039ebe Mon Sep 17 00:00:00 2001 From: mleku Date: Sun, 21 Sep 2025 18:15:27 +0100 Subject: [PATCH] Refactor deletion checks and error handling; bump version to v0.6.4. --- app/handle-delete.go | 8 +++----- pkg/database/query-for-deleted.go | 24 ++++++++---------------- pkg/version/version | 2 +- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/app/handle-delete.go b/app/handle-delete.go index a6574e8..4109b0c 100644 --- a/app/handle-delete.go +++ b/app/handle-delete.go @@ -145,12 +145,10 @@ func (l *Listener) HandleDelete(env *eventenvelope.Submission) (err error) { if ev, err = l.FetchEventBySerial(s); chk.E(err) { continue } - // check that the author is the same as the signer of the - // delete, for the e tag case the author is the signer of - // the event. - if !utils.FastEqual(env.E.Pubkey, ev.Pubkey) { + // allow deletion if the signer is the author OR an admin/owner + if !(ownerDelete || utils.FastEqual(env.E.Pubkey, ev.Pubkey)) { log.W.F( - "HandleDelete: attempted deletion of event %s by different user - delete pubkey=%s, event pubkey=%s", + "HandleDelete: attempted deletion of event %s by unauthorized user - delete pubkey=%s, event pubkey=%s", hex.Enc(ev.ID), hex.Enc(env.E.Pubkey), hex.Enc(ev.Pubkey), ) diff --git a/pkg/database/query-for-deleted.go b/pkg/database/query-for-deleted.go index fde3430..854c8ad 100644 --- a/pkg/database/query-for-deleted.go +++ b/pkg/database/query-for-deleted.go @@ -173,10 +173,10 @@ func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error) { } } if ev.CreatedAt < maxTs { - // err = fmt.Errorf( - // "blocked: was deleted by address %s: event is older than the delete: event: %d delete: %d", - // at, ev.CreatedAt, maxTs, - // ) + err = errorf.E( + "blocked: %0x was deleted by address %s because it is older than the delete: event: %d delete: %d", + ev.ID, at, ev.CreatedAt, maxTs, + ) return } return @@ -203,22 +203,14 @@ func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error) { return } if len(s) > 0 { - // For e-tag deletions (delete by ID), any deletion event means the event cannot be resubmitted - // regardless of timestamp, since it's a specific deletion of this exact event - // err = errorf.E( - // "blocked: was deleted by ID and cannot be resubmitted", - // // ev.ID, - // ) + // Any e-tag deletion found means the exact event was deleted and cannot be resubmitted + err = errorf.E("blocked: %0x has been deleted", ev.ID) return } } if len(sers) > 0 { - // For e-tag deletions (delete by ID), any deletion event means the event cannot be resubmitted - // regardless of timestamp, since it's a specific deletion of this exact event - // err = errorf.E( - // "blocked: was deleted by ID and cannot be resubmitted", - // // ev.ID, - // ) + // Any e-tag deletion found means the exact event was deleted and cannot be resubmitted + err = errorf.E("blocked: %0x has been deleted", ev.ID) return } diff --git a/pkg/version/version b/pkg/version/version index 9885725..af53794 100644 --- a/pkg/version/version +++ b/pkg/version/version @@ -1 +1 @@ -v0.6.3 \ No newline at end of file +v0.6.4 \ No newline at end of file