Skip to content
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

fix: CE-1146-role-functionality-only-works-for-50-users #736

Merged
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
45 changes: 27 additions & 18 deletions backend/src/external_api/css/css.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class CssService implements ExternalApiService {
readonly clientSecret: string;
readonly grantType: string;
readonly env: string;
readonly maxPages: number;

@Inject(ConfigurationService)
readonly configService: ConfigurationService;
Expand All @@ -25,6 +26,7 @@ export class CssService implements ExternalApiService {
this.clientSecret = process.env.CSS_CLIENT_SECRET;
this.grantType = "client_credentials";
this.env = process.env.ENVIRONMENT;
this.maxPages = 20;
}

authenticate = async (): Promise<string> => {
Expand Down Expand Up @@ -116,7 +118,7 @@ export class CssService implements ExternalApiService {
}
};

getUserRoleMapping = async (): Promise<AxiosResponse> => {
getUserRoleMapping = async (): Promise<AxiosResponse> => {
try {
const apiToken = await this.authenticate();
//Get all roles from NatCom CSS integation
Expand All @@ -135,26 +137,33 @@ getUserRoleMapping = async (): Promise<AxiosResponse> => {

//Get all users for each role
let usersUrl: string = "";
const pages = Array.from(Array(this.maxPages), (_, i) => i + 1);
const usersRoles = await Promise.all(
roleList.map(async (role) => {
usersUrl = `${this.baseUri}/api/v1/integrations/4794/${this.env}/roles/${role.name}/users`;
const userRes = await get(apiToken, encodeURI(usersUrl), config);
if (userRes?.data.data.length > 0) {
const {
data: { data: users },
} = userRes;
let usersRolesTemp = await Promise.all(
users.map((user) => {
return {
userId: user.username
.replace(/@idir$/i, "")
.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5"),
role: role.name,
};
}),
);
return usersRolesTemp;
let usersRolesTemp = [];
for (const page of pages) {
usersUrl = `${this.baseUri}/api/v1/integrations/4794/${this.env}/roles/${role.name}/users?page=${page}`;
const userRes = await get(apiToken, encodeURI(usersUrl), config);
if (userRes?.data.data.length > 0) {
const {
data: { data: users },
} = userRes;
let usersRolesSinglePage = await Promise.all(
users.map((user) => {
return {
userId: user.username
.replace(/@idir$/i, "")
.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5"),
role: role.name,
};
}),
);
usersRolesTemp.push(...usersRolesSinglePage);
} else {
break;
}
}
return usersRolesTemp;
}),
);

Expand Down
Loading