import { IRequestUserInfo } from '@sharedtypes/express' ; import _ from 'lodash' ; function normalizeGroup ( userOrGroup ) { const domain = '@netflix.com' ; if ( ! userOrGroup . endsWith ( domain ) ) { return `${ userOrGroup }${ domain }` ; } return userOrGroup ; } param user param allowedGroups export function isUserAuthorized ( user , allowedGroups = new Array < string > ( ) ) { if ( user . isAdmin ) { return true ; } if ( ! user . googleGroups || user . googleGroups . length === 0 ) { throw new Error ( 'Could not find user group information. Please log out and log back in again.' ) ; } const userGroups = _ . concat ( user . email , user . googleGroups . map ( normalizeGroup ) ) ; return ( _ . intersection ( userGroups , allowedGroups . map ( normalizeGroup ) ) . length > 0 ) ; }