Soft Delete Resources


#1

Hello, guys! There is common practice to delete resources to trash bin or archive on delete (to have an ability to restore them) and have additional force delete command to remove them completely from the database.

Imagine the situation when you want to delete task from the project management system, but it should be only marked as deleted, but kept as archived. And need an ability to restore it with the same id as it was before.

On DELETE /tasks/1 controller will execute soft-delete command and resource will update database column archived_at with current DateTime. Then resource will be excluded from all GET /tasks responses.

Why I’ve chosen to use DELETE method instead of updating status: archived field of the resource? Because there are a lot of cases when user shouldn’t know about resource is soft-deleted and will lose access to this record completely right after it’s soft-deletion. Only privileged users will have such permissions.

There are 2 questions which I’m trying to find answer to:

  1. How we could restore soft-deleted resource.
  2. How we could force delete resource.

This thread is related to “Should you return all resources by default (when no filter specified)” but not duplicates it, because it covers soft-delete, restore soft-delete and force-delete processes and not filtering strategy.


#2
  1. I think you could simply update the status of an archived record to whatever it was before it was archived as a normal update operation.
  2. Delete a resource which is already archived, you can use ACL to check if someone can DELETE a resource in archived state just like you are restricting its display to some users.

#3

What if I don’t want to acknowledge user that resource will be archived, not really deleted?


#4

Well, I think the server can lie because from their perspective it is deleted. However if this is an end user facing application I would keep GDPR in mind when making this choice.


#5

Thank you @michaelhibay. I agree, I should rethink this functionality somehow to make application more transparent.