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: check if user has attributes before accessing attributes #3759

Merged
merged 2 commits into from
Jul 3, 2024
Merged
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
1 change: 1 addition & 0 deletions services/api/src/apolloServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ const apolloServer = new ApolloServer({
currentUser = await User.User(modelClients).loadUserById(keycloakGrant.access_token.content.sub);
// grab the users project ids and roles in the first request
groupRoleProjectIds = await User.User(modelClients).getAllProjectsIdsForUser(currentUser.id, keycloakUsersGroups);
await User.User(modelClients).userLastAccessed(currentUser);
}

// do a permission check to see if the user is platform admin/owner, or has permission for `viewAll` on certain resources
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const User = (clients: {
for (const user of users) {
// set the lastaccessed attribute
let date = null;
if (user['attributes']['last_accessed']) {
if (user['attributes'] && user['attributes']['last_accessed']) {
date = new Date(user['attributes']['last_accessed']*1000).toISOString()
}
usersWithGitlabIdFetch.push({
Expand Down
2 changes: 0 additions & 2 deletions services/api/src/util/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ export const keycloakHasPermission = (grant, requestCache, modelClients, service
currentUser: [currentUser.id]
};

await UserModel.userLastAccessed(currentUser);

const usersAttribute = R.prop('users', attributes);
if (usersAttribute && usersAttribute.length) {
claims = {
Expand Down