fix(entries): 404 on PUT when the row no longer exists
The UPDATE matched nothing but the handler still answered 200 Updated, so the editor reported Saved for an edit that went nowhere - the entry had been deleted by a sync or a purge after the editor opened it. Silent data loss; the client already surfaces a failed save as an error toast.
This commit is contained in:
@@ -514,6 +514,7 @@ var
|
||||
LSiteEnc, LSiteIv, LTitleEnc, LTitleIv, LTagsEnc, LTagsIv: string;
|
||||
LHasTemplate: Boolean;
|
||||
LQ: TFDQuery;
|
||||
LRows: Integer;
|
||||
begin
|
||||
try
|
||||
LUserId := Authenticate(ARequest, AResponse);
|
||||
@@ -664,6 +665,7 @@ begin
|
||||
LQ.ParamByName('id').AsInteger := LId;
|
||||
LQ.ParamByName('uid').AsInteger := LUserId;
|
||||
LQ.ExecSQL;
|
||||
LRows := LQ.RowsAffected;
|
||||
finally
|
||||
LQ.Free;
|
||||
end;
|
||||
@@ -671,6 +673,15 @@ begin
|
||||
DB.Unlock;
|
||||
end;
|
||||
|
||||
// No row matched: the entry was deleted (another device's sync, a purge)
|
||||
// between the editor opening it and this save. Reporting 200 here made the
|
||||
// client show "Saved" for an edit that went nowhere — silent data loss.
|
||||
if LRows <= 0 then
|
||||
begin
|
||||
TJSONHelper.SendError(AResponse, 404, 'Entry no longer exists');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
LogAudit(LUserId, 'edit_entry', GetClientIP(ARequest));
|
||||
TJSONHelper.SendOK(AResponse, 'Updated');
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user