@@ -47,6 +47,11 @@ public function equals($other_group)
4747 return $ this ->getPIUID () == $ other_group ->getPIUID ();
4848 }
4949
50+ public function __toString ()
51+ {
52+ return $ this ->getPIUID ();
53+ }
54+
5055 /**
5156 * Returns this group's PI UID
5257 *
@@ -133,6 +138,12 @@ public function requestGroup($send_mail_to_admins, $send_mail = true)
133138 */
134139 public function approveGroup ($ operator = null , $ send_mail = true )
135140 {
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+
136147 // check for edge cases...
137148 if ($ this ->exists ()) {
138149 return ;
@@ -277,6 +288,12 @@ public function cancelGroupJoinRequest($user, $send_mail = true)
277288 */
278289 public function approveUser ($ new_user , $ send_mail = true )
279290 {
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+
280297 // check if user exists
281298 if (!$ new_user ->exists ()) {
282299 $ new_user ->init ();
@@ -382,15 +399,17 @@ public function removeUser($new_user, $send_mail = true)
382399 public function newUserRequest ($ new_user , $ send_mail = true )
383400 {
384401 if ($ this ->userExists ($ new_user )) {
402+ UnitySite::errorLog ("warning " , "user ' $ new_user' already in group " );
385403 return ;
386404 }
387405
388406 if ($ this ->requestExists ($ new_user )) {
407+ UnitySite::errorLog ("warning " , "user ' $ new_user' already requested group membership " );
389408 return ;
390409 }
391410
392- // check if account deletion request already exists
393411 if ($ this ->SQL ->accDeletionRequestExists ($ new_user ->getUID ())) {
412+ throw new Exception ("user ' $ new_user' requested account deletion " );
394413 return ;
395414 }
396415
@@ -441,22 +460,8 @@ public function getRequests()
441460
442461 public function getGroupMembers ($ ignorecache = false )
443462 {
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 );
458464 $ out = array ();
459- $ cache_arr = array ();
460465 $ owner_uid = $ this ->getOwner ()->getUID ();
461466 foreach ($ members as $ member ) {
462467 $ user_obj = new UnityUser (
@@ -468,22 +473,28 @@ public function getGroupMembers($ignorecache = false)
468473 $ this ->WEBHOOK
469474 );
470475 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 );
477476 }
478-
479477 return $ out ;
480478 }
481479
482- public function getGroupMemberUIDs ()
480+ public function getGroupMemberUIDs ($ ignorecache = false )
483481 {
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+ }
487498 return $ members ;
488499 }
489500
0 commit comments