Skip to content

Commit

Permalink
Merge pull request #128 from bcgov/feature/deseng755
Browse files Browse the repository at this point in the history
Feature/deseng755: Added stricter checking for permissions list entries
  • Loading branch information
jareth-whitney authored Jan 17, 2025
2 parents 9d5997d + 670fb46 commit 08fd515
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class PermissionsTableRowsComponent implements OnInit, TableComponent {
* @returns {boolean}
*/
hasProjectPermission(user: User): boolean {
return user.projectPermissions.includes(this.currentProject._id);
return this.currentProject?._id && user.projectPermissions?.includes(this.currentProject._id);
}

/**
Expand All @@ -82,14 +82,14 @@ export class PermissionsTableRowsComponent implements OnInit, TableComponent {
let validatedUsers = [];
if (Array.isArray(this.entries)) {
returnedUsers.forEach(user => {
if (!userNames.includes(user.displayName)) {
if (user.displayName && !userNames.includes(user.displayName)) {
// If no duplicate name is found, validate the user
userNames.push(user.displayName);
validatedUsers.push(user);
} else if (user.projectPermissions.includes(this.currentProject._id)) {
} else if (user.displayName && this.currentProject?._id && user.projectPermissions.includes(this.currentProject._id)) {
// If a duplicate user is found and they have project permission, replace matching entry if it doesn't have permissions
const matchingUserIndex = validatedUsers.findIndex((usr) => usr.displayName === user.displayName);
validatedUsers[matchingUserIndex] = validatedUsers[matchingUserIndex]?.projectPermissions?.includes(this.currentProject._id) ? validatedUsers[matchingUserIndex] : user;
validatedUsers[matchingUserIndex] = this.currentProject?._id && validatedUsers[matchingUserIndex]?.projectPermissions?.includes(this.currentProject._id) ? validatedUsers[matchingUserIndex] : user;
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ export class ProjectPermissionsComponent implements OnInit {
let validatedUsers = [];
if (Array.isArray(this.userVault)) {
this.userVault.forEach(user => {
if (!userNames.includes(user.displayName)) {
if (user.displayName && !userNames.includes(user.displayName)) {
// If no duplicate name is found, validate the user
userNames.push(user.displayName);
validatedUsers.push(user);
} else if (user.projectPermissions?.includes(this.currentProject._id)) {
} else if (user.displayName && this.currentProject._id && user.projectPermissions?.includes(this.currentProject._id)) {
// If a duplicate user is found and they have project permission, replace matching entry if it doesn't have permissions
const matchingUserIndex = validatedUsers.findIndex((usr) => usr.displayName === user.displayName);
validatedUsers[matchingUserIndex] = validatedUsers[matchingUserIndex].projectPermissions.includes(this.currentProject._id) ? validatedUsers[matchingUserIndex] : user;
validatedUsers[matchingUserIndex] = validatedUsers[matchingUserIndex]?.projectPermissions?.includes(this.currentProject._id) ? validatedUsers[matchingUserIndex] : user;
}
})
}
Expand Down

0 comments on commit 08fd515

Please sign in to comment.