Block resubmission of deleted events by ID in SaveEvent and simplify deletion timestamp checks in QueryForDeleted.
This commit is contained in:
@@ -199,25 +199,12 @@ func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error) {
|
|||||||
sers = append(sers, s...)
|
sers = append(sers, s...)
|
||||||
}
|
}
|
||||||
if len(sers) > 0 {
|
if len(sers) > 0 {
|
||||||
var idPkTss []*store.IdPkTs
|
// For e-tag deletions (delete by ID), any deletion event means the event cannot be resubmitted
|
||||||
var tmp []*store.IdPkTs
|
// regardless of timestamp, since it's a specific deletion of this exact event
|
||||||
if tmp, err = d.GetFullIdPubkeyBySerials(sers); chk.E(err) {
|
err = errorf.E(
|
||||||
return
|
"blocked: %0x was deleted by ID and cannot be resubmitted",
|
||||||
}
|
ev.ID,
|
||||||
idPkTss = append(idPkTss, tmp...)
|
|
||||||
// sort by timestamp, so the first is the newest
|
|
||||||
sort.Slice(
|
|
||||||
idPkTss, func(i, j int) bool {
|
|
||||||
return idPkTss[i].Ts > idPkTss[j].Ts
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
if ev.CreatedAt < idPkTss[0].Ts {
|
|
||||||
err = errorf.E(
|
|
||||||
"blocked: %0x was deleted because it is older than the delete: event: %d delete: %d",
|
|
||||||
ev.ID, ev.CreatedAt, idPkTss[0].Ts,
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,13 @@ func (d *D) SaveEvent(c context.Context, ev *event.E) (kc, vc int, err error) {
|
|||||||
log.E.F("error checking if event exists: %s", err)
|
log.E.F("error checking if event exists: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the event has been deleted before allowing resubmission
|
||||||
|
if err = d.CheckForDeleted(ev, nil); err != nil {
|
||||||
|
log.I.F("SaveEvent: rejecting resubmission of deleted event ID=%s: %v", hex.Enc(ev.ID), err)
|
||||||
|
err = errorf.E("blocked: %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
// check for replacement
|
// check for replacement
|
||||||
if kind.IsReplaceable(ev.Kind) {
|
if kind.IsReplaceable(ev.Kind) {
|
||||||
// find the events and check timestamps before deleting
|
// find the events and check timestamps before deleting
|
||||||
|
|||||||
Reference in New Issue
Block a user