@@ -69,58 +69,57 @@ var fieldWhiteList = {
69
69
'parent-guardian' : parentGuardianPublicFields
70
70
} ;
71
71
72
-
73
- var youthBlackList = [ 'name' ] ;
74
-
75
- // var allowedOptionalFieldsYouth = ['dojos', 'linkedin', 'twitter', 'badges'];
76
- var allowedOptionalFieldsYouth = _ . filter ( hiddenFields , function ( field ) {
77
- if ( _ . contains ( field . allowedUserTypes , 'attendee-o13' ) ) return field . modelName ;
78
- } ) ;
79
-
80
- // var allowedOptionalFieldsChampion = ['notes', 'projects'];
81
- var allowedOptionalFieldsChampion = _ . map ( hiddenFields , function ( field ) {
82
- if ( _ . contains ( field . allowedUserTypes , 'champion' ) ) return field . modelName ;
83
- } ) ;
84
-
85
- var allowedOptionalFieldsMentor = _ . map ( hiddenFields , function ( field ) {
86
- if ( _ . contains ( field . allowedUserTypes , 'mentor' ) ) return field . modelName ;
87
- } ) ;
88
-
89
- var allowedOptionalFields = {
90
- 'champion' : allowedOptionalFieldsChampion ,
91
- 'attendee-o13' : allowedOptionalFieldsYouth ,
92
- 'mentor' : allowedOptionalFieldsMentor
93
- } ;
94
-
72
+ var youthBlackList = [ 'name' ] ;
73
+
74
+ // var allowedOptionalFieldsYouth = ['dojos', 'linkedin', 'twitter', 'badges'];
75
+ var allowedOptionalFieldsYouth = _ . filter ( hiddenFields , function ( field ) {
76
+ if ( _ . contains ( field . allowedUserTypes , 'attendee-o13' ) ) return field . modelName ;
77
+ } ) ;
78
+
79
+ // var allowedOptionalFieldsChampion = ['notes', 'projects'];
80
+ var allowedOptionalFieldsChampion = _ . map ( hiddenFields , function ( field ) {
81
+ if ( _ . contains ( field . allowedUserTypes , 'champion' ) ) return field . modelName ;
82
+ } ) ;
83
+
84
+ var allowedOptionalFieldsMentor = _ . map ( hiddenFields , function ( field ) {
85
+ if ( _ . contains ( field . allowedUserTypes , 'mentor' ) ) return field . modelName ;
86
+ } ) ;
87
+
88
+ var allowedOptionalFields = {
89
+ 'champion' : allowedOptionalFieldsChampion ,
90
+ 'attendee-o13' : allowedOptionalFieldsYouth ,
91
+ 'mentor' : allowedOptionalFieldsMentor
92
+ } ;
95
93
96
94
function cmd_user_profile_data ( args , done ) {
97
95
var seneca = this ;
98
96
var plugin = args . role ;
99
97
var query = args . query ;
98
+ var proxyProfile = args . proxyProfile ;
100
99
var ENTITY_NS = 'cd/profiles' ;
101
100
var flags = {
102
101
user : {
103
- myChild : false ,
104
- ownProfile : false ,
105
- isChampion : false ,
106
- isTicketingAdmin : false ,
107
- isDojoAdmin : false
102
+ myChild : false ,
103
+ ownProfile : false ,
104
+ isChampion : false ,
105
+ isTicketingAdmin : false ,
106
+ isDojoAdmin : false
108
107
} ,
109
108
// Is champion is a combination
110
109
requestingUser : {
111
110
isChampionOf : false ,
112
- isMentorOf : false ,
113
- isDojoAdminOf : false ,
114
- isTicketingAdminOf : false ,
111
+ isMentorOf : false ,
112
+ isDojoAdminOf : false ,
113
+ isTicketingAdminOf : false ,
115
114
canBypassPrivate : false ,
116
- isCDF : false
115
+ isCDF : false
117
116
} ,
118
117
shared : {
119
118
isChampion : false ,
120
- isMentor : false ,
121
- isDojoAdmin : false ,
122
- isTicketingAdmin : false ,
123
- isParentOf : false ,
119
+ isMentor : false ,
120
+ isDojoAdmin : false ,
121
+ isTicketingAdmin : false ,
122
+ isParentOf : false ,
124
123
isChildrenOf : false ,
125
124
isFamily : false
126
125
}
@@ -145,7 +144,7 @@ function cmd_user_profile_data (args, done) {
145
144
// Filter
146
145
privateFilter ,
147
146
publicProfilesFilter ,
148
- under13Filter ,
147
+ under13Filter
149
148
] ,
150
149
function ( err , profile ) {
151
150
if ( err ) return done ( null , { error : err } ) ;
@@ -236,7 +235,6 @@ function cmd_user_profile_data (args, done) {
236
235
}
237
236
238
237
function optionalFieldsFilter ( profile , done ) {
239
-
240
238
function getProfileDojos ( wfCb ) {
241
239
seneca . act ( { role : 'cd-dojos' , cmd : 'load_usersdojos' , query : { userId : profile . userId } } , function ( err , profileDojos ) {
242
240
if ( err ) return done ( err ) ;
@@ -251,9 +249,9 @@ function cmd_user_profile_data (args, done) {
251
249
function ( err , requestingUserDojos ) {
252
250
if ( err ) return done ( err ) ;
253
251
return wfCb ( null , profileDojos , requestingUserDojos ) ;
254
- } ) ;
252
+ } ) ;
255
253
} else {
256
- return wfCb ( null , profileDojos , null ) ;
254
+ return wfCb ( null , profileDojos , null ) ;
257
255
}
258
256
}
259
257
@@ -263,7 +261,7 @@ function cmd_user_profile_data (args, done) {
263
261
function ( err , requestingUserProfile ) {
264
262
if ( err ) return done ( err ) ;
265
263
return wfCb ( null , profileDojos , requestingUserDojos , requestingUserProfile ) ;
266
- } ) ;
264
+ } ) ;
267
265
} else {
268
266
return wfCb ( null , profileDojos , requestingUserDojos , null ) ;
269
267
}
@@ -283,21 +281,21 @@ function cmd_user_profile_data (args, done) {
283
281
_ . each ( requestingUserSharedDojos , function ( requestingUserDojo ) {
284
282
if ( _ . contains ( requestingUserDojo . userTypes , 'champion' ) ) flags . requestingUser . isChampionOf = true ;
285
283
if ( _ . contains ( requestingUserDojo . userTypes , 'mentor' ) ) flags . requestingUser . isMentorOf = true ;
286
- if ( _ . find ( requestingUserDojo . userPermissions , { 'title' :'Dojo Admin' , 'name' :'dojo-admin' } ) ) flags . requestingUser . isDojoAdminOf = true ;
287
- if ( _ . find ( requestingUserDojo . userPermissions , { 'title' :'Ticketing Admin' , 'name' :'ticketing-admin' } ) ) flags . requestingUser . isTicketingAdminOf = true ;
284
+ if ( _ . find ( requestingUserDojo . userPermissions , { 'title' : 'Dojo Admin' , 'name' : 'dojo-admin' } ) ) flags . requestingUser . isDojoAdminOf = true ;
285
+ if ( _ . find ( requestingUserDojo . userPermissions , { 'title' : 'Ticketing Admin' , 'name' : 'ticketing-admin' } ) ) flags . requestingUser . isTicketingAdminOf = true ;
288
286
} ) ;
289
287
290
288
// Viewed user flags
291
289
_ . each ( profileDojos , function ( profileDojo ) {
292
290
if ( _ . contains ( profileDojo . userTypes , 'champion' ) ) flags . user . isChampion = true ;
293
- if ( _ . find ( profileDojo . userPermissions , { 'title' :'Dojo Admin' , 'name' :'dojo-admin' } ) ) flags . user . isDojoAdmin = true ;
294
- if ( _ . find ( profileDojo . userPermissions , { 'title' :'Ticketing Admin' , 'name' :'ticketing-admin' } ) ) flags . user . isTicketingAdmin = true ;
291
+ if ( _ . find ( profileDojo . userPermissions , { 'title' : 'Dojo Admin' , 'name' : 'dojo-admin' } ) ) flags . user . isDojoAdmin = true ;
292
+ if ( _ . find ( profileDojo . userPermissions , { 'title' : 'Ticketing Admin' , 'name' : 'ticketing-admin' } ) ) flags . user . isTicketingAdmin = true ;
295
293
} ) ;
296
294
297
295
// We look at relationship between user and viewer
298
296
_ . each ( viewedUserSharedDojos , function ( sharedProfileDojo ) {
299
- if ( _ . find ( sharedProfileDojo . userPermissions , { 'title' :'Dojo Admin' , 'name' :'dojo-admin' } ) ) flags . shared . isDojoAdmin = true ;
300
- if ( _ . find ( sharedProfileDojo . userPermissions , { 'title' :'Ticketing Admin' , 'name' :'ticketing-admin' } ) ) flags . shared . isTicketingAdmin = true ;
297
+ if ( _ . find ( sharedProfileDojo . userPermissions , { 'title' : 'Dojo Admin' , 'name' : 'dojo-admin' } ) ) flags . shared . isDojoAdmin = true ;
298
+ if ( _ . find ( sharedProfileDojo . userPermissions , { 'title' : 'Ticketing Admin' , 'name' : 'ticketing-admin' } ) ) flags . shared . isTicketingAdmin = true ;
301
299
} ) ;
302
300
303
301
flags . shared . isParentOf = _ . includes ( profile . parents , requestingUser . id ) ;
@@ -343,16 +341,26 @@ function cmd_user_profile_data (args, done) {
343
341
}
344
342
345
343
function aggregateFlags ( profile , requestingUserProfile , done ) {
346
- flags . shared . isFamily = _ . some ( profile . parents , function ( parent ) {
347
- return _ . includes ( requestingUserProfile . parents , parent ) ;
348
- } ) || flags . shared . isParentOf || flags . shared . isChildrenOf ;
349
-
344
+ flags . shared . isFamily =
345
+ // Kid -> parent
346
+ _ . some ( profile . parents , function ( parent ) {
347
+ return _ . includes ( requestingUserProfile . parents , parent ) &&
348
+ ( proxyProfile ? _ . includes ( proxyProfile . children , requestingUserProfile . userId ) : true ) ;
349
+ } ) ||
350
+ flags . shared . isParentOf || flags . shared . isChildrenOf ||
351
+ // parent -> kid
352
+ // This is to connect 2 parents so that they can see each other on their kid profile
353
+ // This imply that if you share ANY kid, you'll see the other person profile
354
+ _ . some ( profile . children , function ( child ) {
355
+ return _ . includes ( requestingUserProfile . children , child ) &&
356
+ ( proxyProfile ? _ . includes ( proxyProfile . parents , requestingUserProfile . userId ) : true ) ;
357
+ } ) ;
350
358
flags . requestingUser . canBypassFilter = flags . requestingUser . isDojoAdminOf || flags . requestingUser . isChampionOf ||
351
- flags . user . ownProfile || flags . user . myChild || flags . requestingUser . isTicketingAdminOf || flags . requestingUser . isCDF || flags . shared . isFamily ;
359
+ flags . user . ownProfile || flags . user . myChild || flags . requestingUser . isTicketingAdminOf || flags . requestingUser . isCDF || flags . shared . isFamily ;
352
360
353
361
flags . requestingUser . canBypassPrivate = flags . requestingUser . canBypassFilter ||
354
362
// We exclude visibility of o13 champs
355
- ( ( flags . shared . isChampion || flags . shared . isDojoAdmin || flags . shared . isTicketingAdmin ) && ! _ . includes ( profile . userTypes , 'attendee-o13' ) ) ;
363
+ ( ( flags . shared . isChampion || flags . shared . isDojoAdmin || flags . shared . isTicketingAdmin ) && ! _ . includes ( profile . userTypes , 'attendee-o13' ) ) ;
356
364
357
365
return done ( null , profile ) ;
358
366
}
@@ -372,7 +380,6 @@ function cmd_user_profile_data (args, done) {
372
380
* @return {[type] } [description]
373
381
*/
374
382
function publicProfilesFilter ( profile , done ) {
375
-
376
383
if ( ! flags . requestingUser . canBypassFilter && ! _ . contains ( profile . userTypes , 'attendee-u13' ) ) {
377
384
// Build the list of fields to pick
378
385
_ . each ( profile . userTypes , function ( userType ) {
@@ -412,8 +419,6 @@ function cmd_user_profile_data (args, done) {
412
419
}
413
420
return done ( null , profile ) ;
414
421
}
415
-
416
422
}
417
423
418
-
419
424
module . exports = cmd_user_profile_data ;
0 commit comments