@@ -47,6 +47,11 @@ public function equals($other_group)
47
47
return $ this ->getPIUID () == $ other_group ->getPIUID ();
48
48
}
49
49
50
+ public function __toString ()
51
+ {
52
+ return $ this ->getPIUID ();
53
+ }
54
+
50
55
/**
51
56
* Returns this group's PI UID
52
57
*
@@ -133,6 +138,12 @@ public function requestGroup($send_mail_to_admins, $send_mail = true)
133
138
*/
134
139
public function approveGroup ($ operator = null , $ send_mail = true )
135
140
{
141
+ if (!$ this ->SQL ->requestExists ($ this ->getOwner ()->getUID ())) {
142
+ throw new Exception (
143
+ "attempt to approve nonexistent request for group=' {$ this ->getPIUID ()}' uid=' $ new_user' "
144
+ );
145
+ }
146
+
136
147
// check for edge cases...
137
148
if ($ this ->exists ()) {
138
149
return ;
@@ -277,6 +288,12 @@ public function cancelGroupJoinRequest($user, $send_mail = true)
277
288
*/
278
289
public function approveUser ($ new_user , $ send_mail = true )
279
290
{
291
+ if (!$ this ->requestExists ($ new_user )) {
292
+ throw new Exception (
293
+ "attempt to approve nonexistent request for group=' {$ this ->getPIUID ()}' uid=' $ new_user' "
294
+ );
295
+ }
296
+
280
297
// check if user exists
281
298
if (!$ new_user ->exists ()) {
282
299
$ new_user ->init ();
@@ -382,15 +399,17 @@ public function removeUser($new_user, $send_mail = true)
382
399
public function newUserRequest ($ new_user , $ send_mail = true )
383
400
{
384
401
if ($ this ->userExists ($ new_user )) {
402
+ UnitySite::errorLog ("warning " , "user ' $ new_user' already in group " );
385
403
return ;
386
404
}
387
405
388
406
if ($ this ->requestExists ($ new_user )) {
407
+ UnitySite::errorLog ("warning " , "user ' $ new_user' already requested group membership " );
389
408
return ;
390
409
}
391
410
392
- // check if account deletion request already exists
393
411
if ($ this ->SQL ->accDeletionRequestExists ($ new_user ->getUID ())) {
412
+ throw new Exception ("user ' $ new_user' requested account deletion " );
394
413
return ;
395
414
}
396
415
@@ -441,22 +460,8 @@ public function getRequests()
441
460
442
461
public function getGroupMembers ($ ignorecache = false )
443
462
{
444
- if (!$ ignorecache ) {
445
- $ cached_val = $ this ->REDIS ->getCache ($ this ->getPIUID (), "members " );
446
- if (!is_null ($ cached_val )) {
447
- $ members = $ cached_val ;
448
- }
449
- }
450
-
451
- $ updatecache = false ;
452
- if (!isset ($ members )) {
453
- $ pi_group = $ this ->getLDAPPiGroup ();
454
- $ members = $ pi_group ->getAttribute ("memberuid " );
455
- $ updatecache = true ;
456
- }
457
-
463
+ $ members = $ this ->getGroupMemberUIDs ($ ignorecache );
458
464
$ out = array ();
459
- $ cache_arr = array ();
460
465
$ owner_uid = $ this ->getOwner ()->getUID ();
461
466
foreach ($ members as $ member ) {
462
467
$ user_obj = new UnityUser (
@@ -468,22 +473,28 @@ public function getGroupMembers($ignorecache = false)
468
473
$ this ->WEBHOOK
469
474
);
470
475
array_push ($ out , $ user_obj );
471
- array_push ($ cache_arr , $ user_obj ->getUID ());
472
- }
473
-
474
- if (!$ ignorecache && $ updatecache ) {
475
- sort ($ cache_arr );
476
- $ this ->REDIS ->setCache ($ this ->getPIUID (), "members " , $ cache_arr );
477
476
}
478
-
479
477
return $ out ;
480
478
}
481
479
482
- public function getGroupMemberUIDs ()
480
+ public function getGroupMemberUIDs ($ ignorecache = false )
483
481
{
484
- $ pi_group = $ this ->getLDAPPiGroup ();
485
- $ members = $ pi_group ->getAttribute ("memberuid " );
486
-
482
+ if (!$ ignorecache ) {
483
+ $ cached_val = $ this ->REDIS ->getCache ($ this ->getPIUID (), "members " );
484
+ if (!is_null ($ cached_val )) {
485
+ $ members = $ cached_val ;
486
+ }
487
+ }
488
+ $ updatecache = false ;
489
+ if (!isset ($ members )) {
490
+ $ pi_group = $ this ->getLDAPPiGroup ();
491
+ $ members = $ pi_group ->getAttribute ("memberuid " );
492
+ $ updatecache = true ;
493
+ }
494
+ if (!$ ignorecache && $ updatecache ) {
495
+ sort ($ members );
496
+ $ this ->REDIS ->setCache ($ this ->getPIUID (), "members " , $ members );
497
+ }
487
498
return $ members ;
488
499
}
489
500
0 commit comments