From 189eda7d4668f7bad5f3dfdff5319e28934386f3 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Thu, 10 Sep 2020 00:59:24 +0000 Subject: [PATCH] Fully forbid network owner deletion (#53) Allow now as second parameter of bulk delete Join Override annotation with method signature in a line Use old bulk delete method without params Update cobbzilla-wizard Do not checkout master of utils submodules on build Set bulkDelete's parameters to be non null Skip network owner account in bulk delete Co-authored-by: Kristijan Mitrovic Reviewed-on: https://git.bubblev.org/bubblev/bubble/pulls/53 --- bin/first_time_setup.sh | 2 +- .../java/bubble/dao/account/AccountDAO.java | 22 +++++++++++++++++++ utils/cobbzilla-wizard | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/bin/first_time_setup.sh b/bin/first_time_setup.sh index 832be08f..d751664e 100755 --- a/bin/first_time_setup.sh +++ b/bin/first_time_setup.sh @@ -46,7 +46,7 @@ abp-parser " pushd utils for repo in ${UTIL_REPOS} ; do - pushd ${repo} && git checkout master && mvn -DskipTests=true -Dcheckstyle.skip=true clean install && popd || die "Error installing ${repo}" + pushd ${repo} && mvn -DskipTests=true -Dcheckstyle.skip=true clean install && popd || die "Error installing ${repo}" done popd diff --git a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java index 35a7a13b..2a56ea38 100644 --- a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java +++ b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java @@ -37,7 +37,9 @@ import org.glassfish.grizzly.http.server.Request; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; +import javax.annotation.Nullable; import javax.transaction.Transactional; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -346,6 +348,26 @@ public class AccountDAO extends AbstractCRUDDAO implements SqlViewSearc log.info("copyTemplates completed: "+acct); } + private final String NETWORK_OWNER_ACCOUNT_UUID_PARAM = "__thisNetworkOwnerAccountUuid__"; + + @Override public int bulkDeleteWhere(@NonNull final String whereClause, + @Nullable final Map parameters) { + final Map enhancedParams = parameters != null ? parameters : new HashMap<>(); + enhancedParams.put(NETWORK_OWNER_ACCOUNT_UUID_PARAM, configuration.getThisNetwork().getAccount()); + + return super.bulkDeleteWhere("uuid != :" + NETWORK_OWNER_ACCOUNT_UUID_PARAM + " AND (" + whereClause + ")", + enhancedParams); + } + + @Override public void delete(@Nullable final Collection accounts) { + if (empty(accounts)) return; + final var networkOwnerUuid = configuration.getThisNetwork().getAccount(); + if (accounts.removeIf(a -> a != null && a.getUuid().equals(networkOwnerUuid))) { + log.warn("delete: skipping deletion of network owner's account: " + networkOwnerUuid); + } + super.delete(accounts); + } + @Override public void delete(@NonNull final String uuid) { // you cannot delete the account that owns the current network if (uuid.equals(configuration.getThisNetwork().getAccount())) { diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 47b03e4b..14518c3c 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 47b03e4b00490119357d8972ce7ed727266b6c35 +Subproject commit 14518c3c60a455df3542e68949d87dffc9e70ae7