-
Notifications
You must be signed in to change notification settings - Fork 5
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
NON-270: Improve REST client #238
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { URLSearchParams } from 'url' | ||
|
||
import superagent from 'superagent' | ||
|
||
import type TokenStore from './tokenStore' | ||
|
@@ -32,8 +33,14 @@ function getSystemClientTokenFromHmppsAuth(username?: string): Promise<superagen | |
} | ||
|
||
export interface User { | ||
name: string | ||
activeCaseLoadId: string | ||
username: string | ||
name?: string | ||
active?: boolean | ||
authSource?: string | ||
uuid?: string | ||
userId?: string | ||
staffId?: number // deprecated, use userId | ||
activeCaseLoadId?: string // deprecated, use user roles api | ||
Comment on lines
+36
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slightly odd that some of these fields are prison specific - though activeCaseLoadId was here before anyway There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine for now as it matches the auth response. I guess auth ideally would expose this as a union type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it took me quite a while to unpick what user-type info comes from where (the stuff in non-associations is more complex as it also loads caseloads) and this is the simplest thing i felt was meaningful… it's what hmpps-auth (allegedly) returns. in practice, i dunno whether all "auth sources" provide some of these fields. it felt like a sensible thing to mark the nullable ones in hmpps-auth as possibly-undefined here. the link to the UserDetail object above suggests getting caseload stuff from other apis. still, whether this set of fields is good or good enough, i think it's nice to wire it up into
<3 |
||
} | ||
|
||
export interface UserRole { | ||
|
@@ -48,14 +55,14 @@ export default class HmppsAuthClient { | |
} | ||
|
||
getUser(token: string): Promise<User> { | ||
logger.info(`Getting user details: calling HMPPS Auth`) | ||
return HmppsAuthClient.restClient(token).get({ path: '/api/user/me' }) as Promise<User> | ||
logger.info('Getting user details: calling HMPPS Auth') | ||
return HmppsAuthClient.restClient(token).get<User>({ path: '/api/user/me' }) | ||
} | ||
|
||
getUserRoles(token: string): Promise<string[]> { | ||
return HmppsAuthClient.restClient(token) | ||
.get({ path: '/api/user/me/roles' }) | ||
.then(roles => (<UserRole[]>roles).map(role => role.roleCode)) | ||
.get<UserRole[]>({ path: '/api/user/me/roles' }) | ||
.then(roles => roles.map(role => role.roleCode)) | ||
} | ||
|
||
async getSystemClientToken(username?: string): Promise<string> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
setUpCurrentUser
middleware always populatesres.locals.user
via the user service