From 291bd841ed44a9ae2b4c6f8efb5a8cfbd2372082 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Wed, 15 Apr 2020 11:42:34 +0200 Subject: [PATCH] Add back creation of policy for deleted account --- .../bubble/dao/account/AccountPolicyDAO.java | 12 +++++------ .../block_delete_account.json | 21 ++++++++++++++++--- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/bubble-server/src/main/java/bubble/dao/account/AccountPolicyDAO.java b/bubble-server/src/main/java/bubble/dao/account/AccountPolicyDAO.java index 47d0ffa1..a627f11c 100644 --- a/bubble-server/src/main/java/bubble/dao/account/AccountPolicyDAO.java +++ b/bubble-server/src/main/java/bubble/dao/account/AccountPolicyDAO.java @@ -8,9 +8,9 @@ import bubble.model.account.AccountPolicy; import org.cobbzilla.wizard.validation.ValidationResult; import org.springframework.stereotype.Repository; +import static bubble.model.account.AccountDeletionPolicy.full_delete; import static org.cobbzilla.util.daemon.ZillaRuntime.die; import static org.cobbzilla.wizard.resources.ResourceUtil.invalidEx; -import static org.cobbzilla.wizard.resources.ResourceUtil.notFoundEx; @Repository public class AccountPolicyDAO extends AccountOwnedEntityDAO { @@ -38,12 +38,12 @@ public class AccountPolicyDAO extends AccountOwnedEntityDAO { die("findSingleByAccount: More than 1 policy found for account " + accountUuid + " - " + found.size()); } - // If there's no policy, and the account is marked as deleted - just return not found: + // If there's no policy, create one. Note that is account is marked as deleted, the new policy will be with full + // deletion set in. + final var newPolicy = new AccountPolicy().setAccount(accountUuid); final var account = getConfiguration().getBean(AccountDAO.class).findById(accountUuid); - if (account.deleted()) throw notFoundEx(); - - // Else, create a policy for existing account: - return create(new AccountPolicy().setAccount(accountUuid)); + if (account.deleted()) newPolicy.setDeletionPolicy(full_delete); + return create(newPolicy); } } diff --git a/bubble-server/src/test/resources/models/tests/account_deletion/block_delete_account.json b/bubble-server/src/test/resources/models/tests/account_deletion/block_delete_account.json index 304317e5..3d6269ae 100644 --- a/bubble-server/src/test/resources/models/tests/account_deletion/block_delete_account.json +++ b/bubble-server/src/test/resources/models/tests/account_deletion/block_delete_account.json @@ -74,9 +74,24 @@ }, { - "comment": "as root, look up account policy again - it should not be found now", + "comment": "as root, look up account policy again - it should recreated for this object with full deletion policy", "request": { "session": "rootSession", "uri": "users/{{user.uuid}}/policy" }, - "response": { "status": 404 } - } + "response": { "check": [{ "condition": "json.getDeletionPolicy().name() == 'full_delete'" }] } + }, + + { + "comment": "try deleting the same account again - expect fully deletion this time even without policy", + "request": { "uri": "users/{{user.uuid}}", "method": "delete" } + }, + { + "comment": "lookup user, expect there's no such user now", + "request": { "uri": "users/{{user.uuid}}" }, + "response": { "status": 404 } + }, + { + "comment": "as root, look up account policy again - not found, and account uuid reported as not found resource", + "request": { "session": "rootSession", "uri": "users/{{user.uuid}}/policy" }, + "response": { "status": 404, "check": [{ "condition": "json.get('resource') == user.getUuid()" }] } + } ]