@@ -31,6 +31,18 @@ var logYellow = function() {
31
31
log ( Array . prototype . slice . call ( arguments ) . join ( ' ' ) , 'yellow' ) ;
32
32
} ;
33
33
34
+ var checkUser = function ( id , userId ) {
35
+ if ( ! id || ! userId || id === userId ) {
36
+ return true ;
37
+ }
38
+ var user = Meteor . users . findOne ( id , { fields : { _id : 1 } } ) ;
39
+ if ( user ) {
40
+ throw new Meteor . Error ( 'cannot-change-other-users-status' ) ;
41
+ }
42
+
43
+ return true ;
44
+ }
45
+
34
46
UserPresence = {
35
47
activeLogs : function ( ) {
36
48
logEnable = true ;
@@ -255,18 +267,21 @@ UserPresence = {
255
267
check ( id , Match . Maybe ( String ) ) ;
256
268
check ( metadata , Match . Maybe ( Object ) ) ;
257
269
this . unblock ( ) ;
270
+ checkUser ( id , this . userId ) ;
258
271
UserPresence . createConnection ( id || this . userId , this . connection , 'online' , metadata ) ;
259
272
} ,
260
273
261
274
'UserPresence:away' : function ( id ) {
262
275
check ( id , Match . Maybe ( String ) ) ;
263
276
this . unblock ( ) ;
277
+ checkUser ( id , this . userId ) ;
264
278
UserPresence . setConnection ( id || this . userId , this . connection , 'away' ) ;
265
279
} ,
266
280
267
281
'UserPresence:online' : function ( id ) {
268
282
check ( id , Match . Maybe ( String ) ) ;
269
283
this . unblock ( ) ;
284
+ checkUser ( id , this . userId ) ;
270
285
UserPresence . setConnection ( id || this . userId , this . connection , 'online' ) ;
271
286
} ,
272
287
@@ -275,11 +290,12 @@ UserPresence = {
275
290
check ( status , Match . Maybe ( String ) ) ;
276
291
this . unblock ( ) ;
277
292
278
- // backward compatible
293
+ // backward compatible (receives status as first argument)
279
294
if ( arguments . length === 1 ) {
280
- status = id ;
281
- id = this . userId ;
295
+ UserPresence . setDefaultStatus ( this . userId , id ) ;
296
+ return ;
282
297
}
298
+ checkUser ( id , this . userId ) ;
283
299
UserPresence . setDefaultStatus ( id || this . userId , status ) ;
284
300
}
285
301
} ) ;
0 commit comments