Skip to content

Commit

Permalink
Merge pull request #3561 from uselagoon/self-user-by-email
Browse files Browse the repository at this point in the history
refactor: allow user to request user-by-email for self if requested
  • Loading branch information
tobybellwood authored Oct 10, 2023
2 parents e5fc509 + af726e5 commit eb889df
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions services/api/src/resources/user/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import * as R from 'ramda';
import { ResolverFn } from '../';
import { query, isPatchEmpty } from '../../util/db';
import { logger } from '../../loggers/logger';
import { Helpers as organizationHelpers } from '../organization/helpers';
import { Sql } from './sql';

Expand Down Expand Up @@ -112,11 +111,21 @@ export const getAllUsers: ResolverFn = async (
export const getUserByEmail: ResolverFn = async (
_root,
{ email },
{ sqlClientPool, models, hasPermission },
{ sqlClientPool, models, hasPermission, keycloakGrant },
) => {
await hasPermission('user', 'viewAll');

const user = await models.UserModel.loadUserByUsername(email);
if (keycloakGrant) {
if (keycloakGrant.access_token.content.sub == user.id) {
await hasPermission('ssh_key', 'view:user', {
users: [user.id]
});
} else {
await hasPermission('user', 'viewAll');
}
} else {
await hasPermission('user', 'viewAll');
}

return user;
};
Expand Down

0 comments on commit eb889df

Please sign in to comment.