@@ -14,7 +14,7 @@ import {
14
14
} from '../../common' ;
15
15
import { ConfigService , ILogger , Loader , LoaderOf , Logger } from '../../core' ;
16
16
import { Power , Privileges } from '../authorization' ;
17
- import { User , UserLoader } from '../user' ;
17
+ import { User , UserLoader , UserService } from '../user' ;
18
18
import { AuthenticationService } from './authentication.service' ;
19
19
import { SessionOutput } from './dto' ;
20
20
import { SessionInterceptor } from './session.interceptor' ;
@@ -26,6 +26,7 @@ export class SessionResolver {
26
26
private readonly privileges : Privileges ,
27
27
private readonly config : ConfigService ,
28
28
private readonly sessionInt : SessionInterceptor ,
29
+ private readonly users : UserService ,
29
30
@Logger ( 'session:resolver' ) private readonly logger : ILogger ,
30
31
) { }
31
32
@@ -105,12 +106,18 @@ export class SessionResolver {
105
106
} )
106
107
async impersonator (
107
108
@Parent ( ) { session } : SessionOutput ,
108
- @Loader ( UserLoader ) users : LoaderOf < UserLoader > ,
109
109
) : Promise < User | null > {
110
110
if ( session . anonymous || ! session . impersonator ) {
111
111
return null ;
112
112
}
113
- return await users . load ( session . impersonator . userId ) ;
113
+ // Edge case: Load the impersonator, as the impersonator, rather than the impersonatee.
114
+ // They should still be able to see their own props from this field.
115
+ // Otherwise, it could be that the impersonatee can't see the impersonator's roles,
116
+ // and now the UI can't stop impersonating because it doesn't know the impersonator's roles.
117
+ return await this . users . readOne (
118
+ session . impersonator . userId ,
119
+ session . impersonator , // instead of `session`
120
+ ) ;
114
121
}
115
122
116
123
@ResolveField ( ( ) => [ Power ] , { nullable : true } )
0 commit comments