IDEMPIERE-4733 2Pack - -Cannot export and import data from one client to another client (#626)

* IDEMPIERE-4733 2Pack - -Cannot export and import data from one client to another client

* Fix Cross tenant PO reading request ...

* IDEMPIERE-4733

* Add control for importing records with official IDs, to show a clearer message to the user
This commit is contained in:
Carlos Ruiz 2021-03-12 11:37:59 +01:00 committed by GitHub
parent 2e4daa8930
commit 1ffe76b595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -86,7 +86,14 @@ public class POFinder {
uuid = uuid.trim();
String targetUUID = Env.getAD_Client_ID(ctx.ctx) > 0 ? getTargetUUID(ctx.ctx, tableName, uuid, ctx.trx.getTrxName()) : uuid;
Query query = new Query(ctx.ctx, tableName, uuidColumn+"=?", getTrxName(ctx));
/* Is possible to read here from source tenant to create in a new tenant, so safe to allow reading
* writing in wrong tenant is controlled later */
try {
PO.setCrossTenantSafe();
po = query.setParameters(targetUUID).firstOnly();
} finally {
PO.clearCrossTenantSafe();
}
if (po != null && po.getAD_Client_ID() > 0) {
if (po.getAD_Client_ID() > 0 && po.getAD_Client_ID() != Env.getAD_Client_ID(ctx.ctx)) {
targetUUID = UUID.randomUUID().toString();
@ -101,7 +108,15 @@ public class POFinder {
String id = element.properties.get(idColumn).contents.toString();
if (id != null && id.trim().length() > 0) {
Query query = new Query(ctx.ctx, tableName, idColumn+"=?", getTrxName(ctx));
/* Allow reading from a different tenant to show user a clearer error message below
* This is, instead of "Cross tenant PO reading request" the user will see a message
* "2Pack cannot update/access record that belongs to another client" which is more explanatory */
try {
PO.setCrossTenantSafe();
po = query.setParameters(Integer.valueOf(id.trim())).firstOnly();
} finally {
PO.clearCrossTenantSafe();
}
if (po != null && po.getAD_Client_ID() > 0) {
if (po.getAD_Client_ID() != Env.getAD_Client_ID(ctx.ctx)) {
throw new IllegalStateException("2Pack cannot update/access record that belongs to another client. TableName="+po.get_TableName()

View File

@ -214,7 +214,14 @@ public class PoFiller{
}
if (id > 0 && refTableName != null) {
if (foreignTable != null) {
PO subPo = foreignTable.getPO(id, po.get_TrxName());
/* Allow to read here from another tenant, cross tenant control is implemented later in a safe way */
PO subPo = null;
try {
PO.setCrossTenantSafe();
subPo = foreignTable.getPO(id, po.get_TrxName());
} finally {
PO.clearCrossTenantSafe();
}
if (subPo != null && subPo.getAD_Client_ID() != Env.getAD_Client_ID(ctx.ctx)) {
String accessLevel = foreignTable.getAccessLevel();
if ((MTable.ACCESSLEVEL_All.equals(accessLevel)