@@ -636,14 +636,12 @@ _.assignIn(util, {
636636 }
637637 } ,
638638 /**
639- * Post-process given invite(s) with following constraints:
640- * - email field will be omitted from invite if the invite has defined userId
641- * - email field (if existed) will be masked UNLESS current user has admin permissions OR current user created this invite
639+ * Post-process given invite(s)
640+ * Mask `email` and hide `userId` to prevent leaking Personally Identifiable Information (PII)
642641 *
643- * Email to be masked is found in the fields defined by `jsonPath` in the `data`.
644642 * Immutable - doesn't modify data, but creates a clone.
645643 *
646- * @param {String } jsonPath jsonpath string
644+ * @param {String } jsonPath jsonpath string
647645 * @param {Object } data the data which need to process
648646 * @param {Object } req The request object
649647 *
@@ -668,13 +666,21 @@ _.assignIn(util, {
668666 }
669667
670668 if ( invite . email ) {
671- // mask email if non-admin or not own invite
669+ const canSeeEmail = (
670+ isAdmin || // admin
671+ invite . createdBy === currentUserId || // user who created invite
672+ invite . userId === currentUserId // user who is invited
673+ ) ;
674+ // mask email if user cannot see it
672675 _ . assign ( invite , {
673- email : isAdmin || invite . createdBy === currentUserId ? invite . email : util . maskEmail ( invite . email ) ,
676+ email : canSeeEmail ? invite . email : util . maskEmail ( invite . email ) ,
674677 } ) ;
675678
676- // for non-admin users don't return `userId` for invites created by `email`
677- if ( invite . userId && ! isAdmin ) {
679+ const canGetUserId = (
680+ isAdmin || // admin
681+ invite . userId === currentUserId // user who is invited
682+ ) ;
683+ if ( invite . userId && ! canGetUserId ) {
678684 _ . assign ( invite , {
679685 userId : null ,
680686 } ) ;
0 commit comments