fix(tenant-scoping): enforce tenant_id in applyTenantScope for support impersonation mode

This commit is contained in:
Inamul-hasan-tec
2026-08-08 15:15:31 +05:30
parent 95b0753f30
commit 9be6902d6b
7 changed files with 25 additions and 1 deletions
@@ -14,6 +14,10 @@ export default (sequelize) => {
primaryKey: true,
allowNull: false
},
tenant_id: {
type: DataTypes.INTEGER,
allowNull: true
},
code: {
type: DataTypes.STRING(50),
allowNull: false,
+4
View File
@@ -14,6 +14,10 @@ export default (sequelize) => {
primaryKey: true,
allowNull: false
},
tenant_id: {
type: DataTypes.INTEGER,
allowNull: true
},
code: {
type: DataTypes.STRING(50),
allowNull: false,
@@ -54,6 +54,10 @@ export default (sequelize) => {
primaryKey: true,
allowNull: false
},
tenant_id: {
type: DataTypes.INTEGER,
allowNull: true
},
code: {
type: DataTypes.STRING(50),
allowNull: false,
@@ -28,6 +28,10 @@ export default (sequelize) => {
primaryKey: true,
allowNull: false
},
tenant_id: {
type: DataTypes.INTEGER,
allowNull: true
},
parent_id: {
type: DataTypes.UUID,
allowNull: true
+4
View File
@@ -55,6 +55,10 @@ export default (sequelize) => {
primaryKey: true,
allowNull: false
},
tenant_id: {
type: DataTypes.INTEGER,
allowNull: true
},
code: {
type: DataTypes.STRING(100),
allowNull: false,
@@ -41,6 +41,10 @@ export default (sequelize) => {
primaryKey: true,
allowNull: false
},
tenant_id: {
type: DataTypes.INTEGER,
allowNull: true
},
code: {
type: DataTypes.STRING(50),
allowNull: false,
+1 -1
View File
@@ -10,7 +10,7 @@ export const formatResponse = (success, data, message = '') => {
* @returns {Object} Scoped where clause
*/
export const applyTenantScope = (where = {}, context = {}) => {
if (context && context.tenantId && context.userType !== 'platform') {
if (context && context.tenantId && (context.userType !== 'platform' || context.isImpersonating)) {
return {
...where,
tenant_id: context.tenantId