Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generics/helpers/programSolutionUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function getUpdateObjectTOAddScope(bodyData, tenantId, orgId, userDetails) {
// Check if user is Admin or Tenant Admin
if (UTILS.validateRoles(userDetails.userInformation.roles, adminTenantAdminRole)) {
// Fetch tenant details to validate organization codes
tenantDetails = await userService.fetchTenantDetails(tenantId, userDetails.userToken)
tenantDetails = await userService.fetchTenantDetails(tenantId)
if (!tenantDetails?.success || !tenantDetails?.data?.meta) {
throw {
message: CONSTANTS.apiResponses.FAILED_TO_FETCH_TENANT_DETAILS,
Expand Down Expand Up @@ -166,7 +166,7 @@ function getUpdateObjectToRemoveScope(currentScope, bodyData, tenantId, userDeta
let tenantDetails
if (UTILS.validateRoles(userDetails.userInformation.roles, adminTenantAdminRole)) {
// Fetch tenant meta details if user is admin/tenant admin
tenantDetails = await userService.fetchTenantDetails(tenantId, userDetails.userToken)
tenantDetails = await userService.fetchTenantDetails(tenantId)
if (!tenantDetails?.success || !tenantDetails?.data?.meta) {
throw {
message: CONSTANTS.apiResponses.FAILED_TO_FETCH_TENANT_DETAILS,
Expand Down
6 changes: 1 addition & 5 deletions generics/helpers/solutionAndProjectTemplateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,7 @@ function setScope(solutionId, scopeData, userDetails) {
userDetails.userInformation.roles.includes(CONSTANTS.common.ADMIN_ROLE)
) {
// call user-service to fetch related orgs
let validOrgs = await userService.fetchTenantDetails(
userDetails.tenantAndOrgInfo.tenantId,
userDetails.userToken,
true
)
let validOrgs = await userService.fetchTenantDetails(userDetails.tenantAndOrgInfo.tenantId, true)
if (!validOrgs.success) {
throw {
success: false,
Expand Down
2 changes: 1 addition & 1 deletion generics/middleware/authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ module.exports = async function (req, res, next, token = '') {
*/
async function validateIfOrgsBelongsToTenant(tenantId, orgId, token) {
let orgIdArr = Array.isArray(orgId) ? orgId : typeof orgId === 'string' ? orgId.split(',') : []
let orgDetails = await userService.fetchTenantDetails(tenantId, token)
let orgDetails = await userService.fetchTenantDetails(tenantId)
let validOrgIds = null

if (
Expand Down
37 changes: 10 additions & 27 deletions generics/services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,35 +387,18 @@ const getOrgDetails = function (organisationIdentifier, tenantId) {
* @returns {Promise} A promise that resolves with the organization details or rejects with an error.
*/

const fetchTenantDetails = function (tenantId, userToken = '', aggregateValidOrgs = false) {
const fetchTenantDetails = function (tenantId, aggregateValidOrgs = false) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@praveenKDass update function signature

return new Promise(async (resolve, reject) => {
try {
let url, headers

if (userToken) {
// External request
url =
interfaceServiceUrl +
process.env.USER_SERVICE_BASE_URL +
CONSTANTS.endpoints.TENANT_READ +
'/' +
tenantId
headers = {
'content-type': 'application/json',
'X-auth-token': userToken,
}
} else {
// Internal request
url =
interfaceServiceUrl +
process.env.USER_SERVICE_BASE_URL +
CONSTANTS.endpoints.TENANT_READ_INTERNAL +
'/' +
tenantId
headers = {
'content-type': 'application/json',
internal_access_token: process.env.INTERNAL_ACCESS_TOKEN,
}
let url =
interfaceServiceUrl +
process.env.USER_SERVICE_BASE_URL +
CONSTANTS.endpoints.TENANT_READ_INTERNAL +
'/' +
tenantId
let headers = {
'content-type': 'application/json',
internal_access_token: process.env.INTERNAL_ACCESS_TOKEN,
}

const options = { headers }
Expand Down
6 changes: 1 addition & 5 deletions module/programs/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ module.exports = class ProgramsHelper {
userDetails.userInformation.roles.includes(CONSTANTS.common.ADMIN_ROLE)
) {
// call user-service to fetch related orgs
let validOrgs = await userService.fetchTenantDetails(
userDetails.tenantAndOrgInfo.tenantId,
userDetails.userToken,
true
)
let validOrgs = await userService.fetchTenantDetails(userDetails.tenantAndOrgInfo.tenantId, true)
if (!validOrgs.success) {
throw {
success: false,
Expand Down
2 changes: 1 addition & 1 deletion module/solutions/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ module.exports = class SolutionsHelper {
}

// fetch tenant domain by calling tenant details API
let tenantDetailsResponse = await userService.fetchTenantDetails(solution.tenantId, token)
let tenantDetailsResponse = await userService.fetchTenantDetails(solution.tenantId)
const domains = tenantDetailsResponse?.data?.domains || []

// Error handling if API failed or no domains found
Expand Down