IDEMPIERE-4770: Cross tenant issue while broadcasting message to System tenant role (#806)

This commit is contained in:
Deepak Pansheriya 2021-07-30 14:47:43 +05:30 committed by GitHub
parent db22889fa1
commit 3c8e05c9d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View File

@ -0,0 +1,10 @@
--Updating dynamic validation to User on Role with same client
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Jul 30, 2021, 12:16:46 AM IST
UPDATE AD_Column SET AD_Val_Rule_ID=200066,Updated=TO_DATE('2021-07-30 00:16:46','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=200991
;
SELECT register_migration_script('202107301015_IDEMPIERE-4770.sql') FROM dual
;

View File

@ -0,0 +1,7 @@
--Updating dynamic validation to User on Role with same client
-- Jul 30, 2021, 12:16:46 AM IST
UPDATE AD_Column SET AD_Val_Rule_ID=200066,Updated=TO_TIMESTAMP('2021-07-30 00:16:46','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=200991
;
SELECT register_migration_script('202107301015_IDEMPIERE-4770.sql') FROM dual
;

View File

@ -27,6 +27,7 @@ import org.adempiere.exceptions.DBException;
import org.adempiere.model.MBroadcastMessage;
import org.compiere.Adempiere;
import org.compiere.model.MNote;
import org.compiere.model.MRole;
import org.compiere.model.MUser;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
@ -59,12 +60,15 @@ public class BroadcastMsgUtil
if (MBroadcastMessage.BROADCASTTYPE_Login.equals(broadcastType)
|| MBroadcastMessage.BROADCASTTYPE_ImmediatePlusLogin.equals(broadcastType)) {
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
// get list of users based on rule
if (mbMessage.getTarget() != null) {
String sql = "SELECT DISTINCT(AD_User_ID) FROM AD_User_Roles WHERE IsActive='Y'";
// Role
if (mbMessage.getTarget().equals(MBroadcastMessage.TARGET_Role)) {
sql += " AND AD_Role_ID=" + mbMessage.getAD_Role_ID();
MRole role = MRole.get(Env.getCtx(), mbMessage.getAD_Role_ID());
AD_Client_ID = role.getAD_Client_ID();
} else if (mbMessage.getTarget().equals(MBroadcastMessage.TARGET_User)) {
sql += " AND AD_User_ID=" + mbMessage.getAD_User_ID();
} else if (mbMessage.getTarget().equals(MBroadcastMessage.TARGET_Client)) {
@ -77,8 +81,12 @@ public class BroadcastMsgUtil
MUser user = MUser.get(Env.getCtx(), userID);
if (! user.isActive())
continue;
if (mbMessage.getTarget().equals(MBroadcastMessage.TARGET_User) || mbMessage.getTarget().equals(MBroadcastMessage.TARGET_Everybody))
{
AD_Client_ID = user.getAD_Client_ID();
}
MNote note = new MNote(Env.getCtx(), 0, trxName);
note.setClientOrg(user.getAD_Client_ID(), 0);
note.setClientOrg(AD_Client_ID, 0);
note.setAD_BroadcastMessage_ID(messageID);
note.setAD_User_ID(userID);
note.setAD_Message_ID(0);