-
Notifications
You must be signed in to change notification settings - Fork 19
Tenant code changes bbb #828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
70a8a85
9309429
6f12178
bb5cbc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,8 @@ module.exports = { | |
| '/user/v1/account/validateUserSession', | ||
| '/user/v1/account/validatingEmailIds', | ||
| '/user/v1/tenant/list', | ||
| '/user/v1/tenant/read/', | ||
| '/user/v1/tenant/domain/', | ||
| '/user/v1/tenant/readInternal/', | ||
|
Comment on lines
+33
to
35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify whitelist matching for new internalAccessUrls entries If the whitelist checks exact matches (not prefix), trailing slashes and missing route params could block access. Ensure middleware matches these paths correctly and the routes exist. 🏁 Script executed: #!/bin/bash
# 1) Find where internalAccessUrls is used to verify matching logic (exact vs prefix).
rg -n -C3 'internalAccessUrls' --type js --type ts
# 2) Locate tenant controller routes to confirm endpoints exist and match patterns.
rg -n -C3 '/tenant/(read|domain)' --type js --type ts
# 3) List all router definitions mentioning tenant to confirm exact paths.
rg -n -C3 'router\.(get|post|patch|put|delete)\(.*tenant' --type js --type tsLength of output: 4508 Normalize whitelist matching for internalAccessUrls 🤖 Prompt for AI Agents |
||
| '/v1/cloud-services/file/getDownloadableUrl', | ||
| ], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -188,7 +188,7 @@ module.exports = class Admin { | |
| }) | ||
| } | ||
|
|
||
| const result = await adminService.deactivateUser(req.body, req.decodedToken.id) | ||
| const result = await adminService.deactivateUser(req.body, req.decodedToken.id, req.decodedToken.tenant_code, req.decodedToken.organization_code) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need these changes here? |
||
|
|
||
| return result | ||
| } catch (error) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -188,7 +188,8 @@ module.exports = class Organization { | |
| try { | ||
| const result = await orgService.addRelatedOrg( | ||
| req.params.id ? req.params.id : '', | ||
| req.body.related_orgs ? req.body.related_orgs : [] | ||
| req.body.related_orgs ? req.body.related_orgs : [], | ||
| req?.decodedToken?.tenant_code | ||
|
Comment on lines
+191
to
+192
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cannot have |
||
| ) | ||
| return result | ||
| } catch (error) { | ||
|
|
@@ -199,7 +200,8 @@ module.exports = class Organization { | |
| try { | ||
| const result = await orgService.removeRelatedOrg( | ||
| req.params.id ? req.params.id : '', | ||
| req.body.related_orgs ? req.body.related_orgs : [] | ||
| req.body.related_orgs ? req.body.related_orgs : [], | ||
| req?.decodedToken?.tenant_code | ||
|
Comment on lines
+203
to
+204
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above comment in |
||
| ) | ||
| return result | ||
| } catch (error) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ const notificationUtils = require('@utils/notification') | |
| const tenantDomainQueries = require('@database/queries/tenantDomain') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need changes in userInvite? |
||
| const tenantQueries = require('@database/queries/tenants') | ||
| const userSessionsService = require('@services/user-sessions') | ||
| const { organization } = require('@constants/blacklistConfig') | ||
| let defaultOrg = {} | ||
| let modelName = '' | ||
| let externalEntityNameIdMap = {} | ||
|
|
@@ -960,6 +961,7 @@ module.exports = class UserInviteHelper { | |
| user_id: existingUser.id, | ||
| organization_id: user.organization_id, | ||
| roles: currentRoles, | ||
| organization_code: user.organization_code, | ||
| }, | ||
| }) | ||
| } | ||
|
|
@@ -970,6 +972,8 @@ module.exports = class UserInviteHelper { | |
| user_id: existingUser.id, | ||
| new_roles: newRoles, | ||
| current_roles: currentRoles, | ||
| tenant_code: user.tenant_code, | ||
| organization_code: user.organization_code | ||
| } | ||
| if (isOrgUpdate) requestBody.organization_id = user.organization_id | ||
| eventBroadcaster('roleChange', { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -607,6 +607,7 @@ module.exports = class AdminHelper { | |
| user_id: user.id, | ||
| organization_id: organizationId, | ||
| roles: roleData.map((r) => r.title), | ||
| organization_code: organization.code, | ||
| }, | ||
| }) | ||
| ) | ||
|
|
@@ -714,7 +715,7 @@ module.exports = class AdminHelper { | |
|
|
||
| // Broadcast to end upcoming sessions | ||
| eventBroadcaster('deactivateUpcomingSession', { | ||
| requestBody: { user_ids: userIds }, | ||
| requestBody: { user_ids: userIds , tenant_code: tenantCode, organization_code: organizationCode}, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the old event, right? Are we not moving to new event structure in this release? |
||
| }) | ||
| } | ||
|
|
||
|
|
@@ -740,7 +741,7 @@ module.exports = class AdminHelper { | |
| * @param {Object} loggedInUserId - logged in user id | ||
| * @returns {JSON} - Deactivated user data | ||
| */ | ||
| static async deactivateUser(bodyData, loggedInUserId) { | ||
| static async deactivateUser(bodyData, loggedInUserId, tenantCode, orgCode) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue as mentioned as above, the admins org and tenant code might not match with the user he's deactivating as of now. |
||
| try { | ||
| let filterQuery = {} | ||
| for (let item in bodyData) { | ||
|
|
@@ -783,6 +784,8 @@ module.exports = class AdminHelper { | |
| eventBroadcaster('deactivateUpcomingSession', { | ||
| requestBody: { | ||
| user_ids: userIds, | ||
| tenant_code: tenantCode, | ||
| organization_code: orgCode | ||
| }, | ||
| }) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -512,7 +512,7 @@ module.exports = class OrganizationsHelper { | |
| } | ||
| } | ||
|
|
||
| static async addRelatedOrg(id, relatedOrgs = []) { | ||
| static async addRelatedOrg(id, relatedOrgs = [], tenantCode) { | ||
| try { | ||
| // fetch organization details before update | ||
| const orgDetailsBeforeUpdate = await organizationQueries.findOne({ id }) | ||
|
|
@@ -553,6 +553,7 @@ module.exports = class OrganizationsHelper { | |
| delta_organization_ids: deltaOrgs, | ||
| organization_id: id, | ||
| action: 'PUSH', | ||
| tenant_code: tenantCode | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, the admin tenant might not match with related orgs tenant. |
||
| }, | ||
| }) | ||
| } | ||
|
|
@@ -565,7 +566,7 @@ module.exports = class OrganizationsHelper { | |
| throw error | ||
| } | ||
| } | ||
| static async removeRelatedOrg(id, relatedOrgs = []) { | ||
| static async removeRelatedOrg(id, relatedOrgs = [], tenantCode) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue as addRelatedOrg |
||
| try { | ||
| // fetch organization details before update | ||
| const orgDetailsBeforeUpdate = await organizationQueries.findOne({ id }) | ||
|
|
@@ -625,6 +626,7 @@ module.exports = class OrganizationsHelper { | |
| delta_organization_ids: relatedOrgs, | ||
| organization_id: id, | ||
| action: 'POP', | ||
| tenant_code:tenantCode | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -784,4 +784,55 @@ module.exports = class tenantHelper { | |
| throw error // Re-throw other errors | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get primary domain for tenant | ||
| * @method | ||
| * @name getDomain | ||
| * @param {string} tenantCode - code of the tenant | ||
| * @returns {JSON} - tenant domain information | ||
| */ | ||
|
Comment on lines
+788
to
+794
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A proper doc string would be helpful, including information about the internal access nature of this endpoint. |
||
| static async getDomain(tenantCode) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is the controlled for this ednpoint ? |
||
| try { | ||
| // Validate tenant exists | ||
| const tenantDetails = await tenantQueries.findOne({ | ||
| code: tenantCode, | ||
| }) | ||
|
|
||
| if (!tenantDetails) { | ||
| return responses.failureResponse({ | ||
| statusCode: httpStatusCode.not_found, | ||
| message: 'TENANT_NOT_FOUND', | ||
| responseCode: 'CLIENT_ERROR', | ||
| }) | ||
| } | ||
|
|
||
| // Get the first domain (primary domain) for the tenant | ||
| const domain = await tenantDomainQueries.findOne({ | ||
| tenant_code: tenantCode, | ||
| verified: true, | ||
| }) | ||
|
|
||
| if (!domain) { | ||
| return responses.failureResponse({ | ||
| statusCode: httpStatusCode.not_found, | ||
| message: 'TENANT_DOMAIN_NOT_FOUND', | ||
| responseCode: 'CLIENT_ERROR', | ||
| }) | ||
| } | ||
|
|
||
| return responses.successResponse({ | ||
| statusCode: httpStatusCode.ok, | ||
| message: 'TENANT_DOMAIN_FETCHED', | ||
| result: { | ||
| domain: domain.domain, | ||
| tenant_code: tenantCode, | ||
| verified: domain.verified, | ||
| }, | ||
| }) | ||
| } catch (error) { | ||
| console.log(error) | ||
| throw error | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,6 +370,7 @@ module.exports = class UserInviteHelper { | |
| user_id: existingUser.id, | ||
| organization_id: user.organization_id, | ||
| roles: currentRoles, | ||
| organization_code: user.organization_code | ||
| }, | ||
| }) | ||
| } | ||
|
|
@@ -380,6 +381,8 @@ module.exports = class UserInviteHelper { | |
| user_id: existingUser.id, | ||
| new_roles: newRoles, | ||
| current_roles: currentRoles, | ||
| tenant_code: user.tenant_code, | ||
| organization_code: user.organization_code | ||
|
Comment on lines
+384
to
+385
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User invites is no longer used as of now, and might not work as intended. |
||
| } | ||
| if (isOrgUpdate) requestBody.organization_id = user.organization_id | ||
| eventBroadcaster('roleChange', { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot have public facing API (tenant/read) to be used an internal API, please add a new endpoint if needed.