Skip to content

Commit

Permalink
I can't execute all the test in a single call, with it.only works but…
Browse files Browse the repository at this point in the history
… without it not
  • Loading branch information
idelcano committed Oct 18, 2024
1 parent 6c4eb98 commit 7d80920
Show file tree
Hide file tree
Showing 3 changed files with 382 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ export class RunUserPermissionUseCase {

const allUserTemplatesId = allUserTemplates.map(templateUser => templateUser.id);

log.info(JSON.stringify(allUser));
//excluded users and template users to the proccess
const usersToProcessGroups = allUser.filter(user => {
return excludedUsersId.includes(user.id) === false && allUserTemplatesId.includes(user.id);
log.info(user.username);
return (
excludedUsersId.includes(user.id) === false && allUserTemplatesId.includes(user.id) === false
);
});

const templatesWithAuthorities = await this.templateRepository.getTemplateAuthorities(
Expand All @@ -81,6 +86,7 @@ export class RunUserPermissionUseCase {
true;

log.info(`Processing userGroups (all users must have at least one template user group)`);
log.info(JSON.stringify(options));
const responseUserGroups = await this.processUserGroups(
options,
templatesWithAuthorities,
Expand All @@ -90,17 +96,20 @@ export class RunUserPermissionUseCase {
//todo: second call, to have the users in the last version after update the missing usergroups, review if it is required
log.info(`Run user Role monitoring`);
const allUserAfterProccessgGroups = await this.userRepository.getAllUsers();

const usersToProcessRoles = allUserAfterProccessgGroups.filter(user => {
return excludedUsersId.includes(user.id) === false && allUserTemplatesId.includes(user.id);
log.info(JSON.stringify(allUserTemplatesId));
return (
excludedUsersId.includes(user.id) === false && allUserTemplatesId.includes(user.id) === false
);
});

log.info("process 2roles" + usersToProcessRoles.length);
const responseUserRolesProcessed = await this.processUserRoles(
options,
templatesWithAuthorities,
usersToProcessRoles
);

log.info(JSON.stringify(responseUserRolesProcessed));
const finalUserGroup = responseUserGroups ?? {
listOfAffectedUsers: [],
invalidUsersCount: 0,
Expand All @@ -120,11 +129,15 @@ export class RunUserPermissionUseCase {
(finalUserGroup.invalidUsersCount > 0 || finalUserRoles.invalidUsersCount > 0)
) {
log.info(`Sending user-monitoring user-permissions report results`);
log.info(JSON.stringify(finalUserGroup));
log.info(JSON.stringify(finalUserRoles));
const response = await this.reportRepository.save(
programMetadata,
finalUserGroup,
finalUserRoles
);
log.info(JSON.stringify(response));
log.info("---------------------------------------");

return {
message: response,
Expand Down Expand Up @@ -166,6 +179,7 @@ export class RunUserPermissionUseCase {
);
return usersWithForcedMinimalGroup;
} else {
log.info("forceMinimalGroupForUsersWithoutGroup is disabled.");
return allUsers;
}
}
Expand All @@ -184,13 +198,16 @@ export class RunUserPermissionUseCase {
excludedRolesByGroup,
} = options;

log.info("Preprocess users..." + JSON.stringify(options));
log.info("Preprocess users..." + allUsers.length);
const allPreProcessedUsers = this.preProcessUsers(
allUsers,
completeTemplateGroups,
forceMinimalGroupForUsersWithoutGroup,
minimalGroup.id
);

log.info("Validating users..." + allPreProcessedUsers.length);
this.validateUsers(allPreProcessedUsers, completeTemplateGroups, minimalGroup.id);
const userinfo: UserMonitoringUserResponse[] = this.processUsers(
allPreProcessedUsers,
Expand Down Expand Up @@ -428,7 +445,9 @@ export class RunUserPermissionUseCase {
minimalGroupId: string
) {
log.info("Validating users...");
log.info("Lenght" + allUsers.length);
allUsers.map(user => {
log.info(user.username);
const templateGroupMatch = this.findTemplateGroupMatch(completeTemplateGroups, user);
if (templateGroupMatch == undefined) {
//template not found -> all roles are invalid except the minimal role
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,48 @@ export const metadataConfigDisabledUsergroupFix: PermissionFixerMetadataConfig =
},
permissionFixerConfig: configFixUserGroupDisabled,
};
export const metadataConfigWrongMinimaLUserGroup: PermissionFixerMetadataConfig = {
templates: [templateGroup],
excludedRoles: [],
excludedUsers: [],
excludedRolesByUser: [],
excludedRolesByGroup: [],
excludedRolesByRole: [],
pushProgram: {
id: "IKpEgoQ4S0r",
name: "Event program uid",
},
minimalGroup: {
id: "IKpEgoQ4S03",
name: "WrongMinimal group uid",
},
minimalRole: {
id: "IKpEgoQ4S03",
name: "Minimal role uid",
},
permissionFixerConfig: config,
};
export const metadataConfigEnabledUsergroupFix: PermissionFixerMetadataConfig = {
templates: [templateGroup],
excludedRoles: [],
excludedUsers: [],
excludedRolesByUser: [],
excludedRolesByGroup: [],
excludedRolesByRole: [],
pushProgram: {
id: "IKpEgoQ4S0r",
name: "Event program uid",
},
minimalGroup: {
id: "IKpEgoQ4S02",
name: "Minimal group uid",
},
minimalRole: {
id: "IKpEgoQ4S03",
name: "Minimal role uid",
},
permissionFixerConfig: config,
};

export const metadataConfig: PermissionFixerMetadataConfig = {
templates: [templateGroup],
Expand Down Expand Up @@ -98,6 +140,75 @@ export const programMetadata: UserMonitoringProgramMetadata = {
orgUnitId: "wLoK6XpZq8I",
};

export const fakeTemplateUser: PermissionFixerUser = {
//lastUpdated: "2024-09-16T14:51:06.958",
id: "CHbcHcmgoZ7",
//href: "https://server/api/users/CHbcHcmgoZ5",
//created: "2018-05-02T11:33:24.434",
//lastLogin: "2024-09-16T14:51:06.955",
twoFA: false,
invitation: false,
//selfRegistered: false,
firstName: "Fake",
name: "Fake Dummy TEMPLATE",
favorite: false,
//openId: "[email protected]",
displayName: "Fake Dummy TEMPLATE",
externalAuth: false,
externalAccess: false,
surname: "TEMPLATE",
disabled: false,
email: "[email protected]",
username: "TEMPLATE",
lastUpdatedBy: {
displayName: "fake complete name",
name: "fake complete name",
id: "TuqkLj1igOH",
username: "fakeusername",
},
userCredentials: {
//openId: "[email protected]",
lastLogin: "2024-09-16T14:51:06.955",
invitation: false,
disabled: false,
twoFA: false,
username: "TEMPLATE",
userRoles: [
{
id: "IKpEgoQ4S03",
name: "Minimal role uid",
},
],
//this is a bit different in 2.38.7
lastUpdated: "",
passwordLastUpdated: "",
selfRegisterd: false,
uid: "",
twoFactorEnabled: false,
},
createdBy: {
displayName: "fake complete name",
name: "fake complete name",
id: "TuqkLj1igOH",
username: "fakeusername",
},
userGroups: [
{
id: "dhWMtH5yC2h",
name: "userGroup name",
},
],
userRoles: [
{
id: "IKpEgoQ4S03",
name: "Minimal role uid",
},
],
selftRefistered: false,
phoneNumber: "",
passwordLastUpdated: "",
};

export const fakeValidUser: PermissionFixerUser = {
//lastUpdated: "2024-09-16T14:51:06.958",
id: "CHbcHcmgoZ5",
Expand Down Expand Up @@ -166,7 +277,149 @@ export const fakeValidUser: PermissionFixerUser = {
phoneNumber: "",
passwordLastUpdated: "",
};

export const fakeInvalidUser: PermissionFixerUser = {
//lastUpdated: "2024-09-16T14:51:06.958",
id: "CHbcHcmgoZ5",
//href: "https://server/api/users/CHbcHcmgoZ5",
//created: "2018-05-02T11:33:24.434",
//lastLogin: "2024-09-16T14:51:06.955",
twoFA: false,
invitation: false,
//selfRegistered: false,
firstName: "Fake",
name: "Fake Dummy",
favorite: false,
//openId: "[email protected]",
displayName: "Fake Dummy",
externalAuth: false,
externalAccess: false,
surname: "Dummy",
disabled: false,
email: "[email protected]",
username: "userusername",
lastUpdatedBy: {
displayName: "fake complete name",
name: "fake complete name",
id: "TuqkLj1igOH",
username: "fakeusername",
},
userCredentials: {
//openId: "[email protected]",
lastLogin: "2024-09-16T14:51:06.955",
invitation: false,
disabled: false,
twoFA: false,
username: "userusername",
userRoles: [
{
id: "invalidRoleId",
name: "invalid userRole name",
},
{
id: "tocVqzvmpI0",
name: "userRole name",
},
],
//this is a bit different in 2.38.7
lastUpdated: "",
passwordLastUpdated: "",
selfRegisterd: false,
uid: "",
twoFactorEnabled: false,
},
createdBy: {
displayName: "fake complete name",
name: "fake complete name",
id: "TuqkLj1igOH",
username: "fakeusername",
},
userGroups: [
{
id: "dhWMtH5yC2h",
name: "userGroup name",
},
],
userRoles: [
{
id: "invalidRoleId",
name: "invalid userRole name",
},
{
id: "tocVqzvmpI0",
name: "userRole name",
},
],
selftRefistered: false,
phoneNumber: "",
passwordLastUpdated: "",
};

export const fakeUserWithoutUserGroup: PermissionFixerUser = {
//lastUpdated: "2024-09-16T14:51:06.958",
id: "CHbcHcmgoZ5",
//href: "https://server/api/users/CHbcHcmgoZ5",
//created: "2018-05-02T11:33:24.434",
//lastLogin: "2024-09-16T14:51:06.955",
twoFA: false,
invitation: false,
//selfRegistered: false,
firstName: "Fake",
name: "Fake Dummy",
favorite: false,
//openId: "[email protected]",
displayName: "Fake Dummy",
externalAuth: false,
externalAccess: false,
surname: "Dummy",
disabled: false,
email: "[email protected]",
username: "userusername",
lastUpdatedBy: {
displayName: "fake complete name",
name: "fake complete name",
id: "TuqkLj1igOH",
username: "fakeusername",
},
userCredentials: {
//openId: "[email protected]",
lastLogin: "2024-09-16T14:51:06.955",
invitation: false,
disabled: false,
twoFA: false,
username: "userusername",
userRoles: [
{
id: "tocVqzvmpI0",
name: "userRole name",
},
],
//this is a bit different in 2.38.7
lastUpdated: "",
passwordLastUpdated: "",
selfRegisterd: false,
uid: "",
twoFactorEnabled: false,
},
createdBy: {
displayName: "fake complete name",
name: "fake complete name",
id: "TuqkLj1igOH",
username: "fakeusername",
},
userGroups: [],
userRoles: [
{
id: "tocVqzvmpI0",
name: "userRole name",
},
],
selftRefistered: false,
phoneNumber: "",
passwordLastUpdated: "",
};

export const fakeUserWithOnlyNotTemplateUserGroup: PermissionFixerUser = {
//lastUpdated: "2024-09-16T14:51:06.958",
id: "CHbcHcmgoZ5",
//href: "https://server/api/users/CHbcHcmgoZ5",
Expand Down
Loading

0 comments on commit 7d80920

Please sign in to comment.