Ver código fonte

Remove automatic policy creation for deleted accounts

tags/v0.10.5
Kristijan Mitrovic 4 anos atrás
pai
commit
ea83da0400
2 arquivos alterados com 17 adições e 7 exclusões
  1. +14
    -5
      bubble-server/src/main/java/bubble/dao/account/AccountPolicyDAO.java
  2. +3
    -2
      bubble-server/src/test/resources/models/tests/account_deletion/block_delete_account.json

+ 14
- 5
bubble-server/src/main/java/bubble/dao/account/AccountPolicyDAO.java Ver arquivo

@@ -8,10 +8,9 @@ import bubble.model.account.AccountPolicy;
import org.cobbzilla.wizard.validation.ValidationResult;
import org.springframework.stereotype.Repository;

import java.util.List;

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<AccountPolicy> {
@@ -32,9 +31,19 @@ public class AccountPolicyDAO extends AccountOwnedEntityDAO<AccountPolicy> {
}

public AccountPolicy findSingleByAccount(String accountUuid) {
final List<AccountPolicy> found = findByAccount(accountUuid);
return found.isEmpty() ? create(new AccountPolicy().setAccount(accountUuid))
: found.size() > 1 ? die("findSingleByAccount: "+found.size()+" found!") : found.get(0);
final var found = findByAccount(accountUuid);
if (found.size() == 1) return found.get(0);

if (found.size() > 1) {
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:
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));
}

}

+ 3
- 2
bubble-server/src/test/resources/models/tests/account_deletion/block_delete_account.json Ver arquivo

@@ -74,8 +74,9 @@
},

{
"comment": "as root, look up account policy again - it should recreated for this object with full deletion policy",
"comment": "as root, look up account policy again - it should not be found now",
"request": { "session": "rootSession", "uri": "users/{{user.uuid}}/policy" },
"response": { "check": [{ "condition": "json.getDeletionPolicy().name() == 'block_delete'" }] }
"response": { "status": 404 }
}

]

Carregando…
Cancelar
Salvar