@@ -636,14 +636,12 @@ _.assignIn(util, {
636
636
}
637
637
} ,
638
638
/**
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)
642
641
*
643
- * Email to be masked is found in the fields defined by `jsonPath` in the `data`.
644
642
* Immutable - doesn't modify data, but creates a clone.
645
643
*
646
- * @param {String } jsonPath jsonpath string
644
+ * @param {String } jsonPath jsonpath string
647
645
* @param {Object } data the data which need to process
648
646
* @param {Object } req The request object
649
647
*
@@ -668,13 +666,21 @@ _.assignIn(util, {
668
666
}
669
667
670
668
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
672
675
_ . assign ( invite , {
673
- email : isAdmin || invite . createdBy === currentUserId ? invite . email : util . maskEmail ( invite . email ) ,
676
+ email : canSeeEmail ? invite . email : util . maskEmail ( invite . email ) ,
674
677
} ) ;
675
678
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 ) {
678
684
_ . assign ( invite , {
679
685
userId : null ,
680
686
} ) ;
0 commit comments