Commit ebf4da9 1 parent 4b30050 commit ebf4da9 Copy full SHA for ebf4da9
File tree 1 file changed +8
-6
lines changed
server/modules/authentication/oidc
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -31,12 +31,14 @@ module.exports = {
31
31
} )
32
32
if ( conf . mapGroups ) {
33
33
const groups = _ . get ( profile , '_json.' + conf . groupsClaim )
34
- if ( groups ) {
35
- const groupIDs = Object . values ( WIKI . auth . groups )
36
- . filter ( g => groups . includes ( g . name ) )
37
- . map ( g => g . id )
38
- for ( let groupID of groupIDs ) {
39
- await user . $relatedQuery ( 'groups' ) . relate ( groupID )
34
+ if ( groups && _ . isArray ( groups ) ) {
35
+ const currentGroups = ( await user . $relatedQuery ( 'groups' ) . select ( 'groups.id' ) ) . groups . map ( g => g . id )
36
+ const expectedGroups = Object . values ( WIKI . auth . groups ) . filter ( g => groups . includes ( g . name ) ) . map ( g => g . id )
37
+ for ( const groupId of _ . difference ( expectedGroups , currentGroups ) ) {
38
+ await user . $relatedQuery ( 'groups' ) . relate ( groupId )
39
+ }
40
+ for ( const groupId of _ . difference ( currentGroups , expectedGroups ) ) {
41
+ await user . $relatedQuery ( 'groups' ) . unrelate ( groupId )
40
42
}
41
43
}
42
44
}
You can’t perform that action at this time.
0 commit comments