88/**
99 * Class that represents a single PI group in the Unity Cluster.
1010 */
11- class UnityGroup
11+ class UnityGroup extends PosixGroup
1212{
1313 public const string PI_PREFIX = "pi_ " ;
14-
1514 public string $ gid ;
16- private LDAPEntry $ entry ;
1715 private UnityLDAP $ LDAP ;
1816 private UnitySQL $ SQL ;
1917 private UnityMailer $ MAILER ;
@@ -26,42 +24,19 @@ public function __construct(
2624 UnityMailer $ MAILER ,
2725 UnityWebhook $ WEBHOOK ,
2826 ) {
29- $ gid = trim ($ gid );
27+ parent :: __construct ( $ LDAP -> getPIGroupEntry ( trim ($ gid)) );
3028 $ this ->gid = $ gid ;
31- $ this ->entry = $ LDAP ->getPIGroupEntry ($ gid );
32-
3329 $ this ->LDAP = $ LDAP ;
3430 $ this ->SQL = $ SQL ;
3531 $ this ->MAILER = $ MAILER ;
3632 $ this ->WEBHOOK = $ WEBHOOK ;
3733 }
3834
39- public function equals (UnityGroup $ other_group ): bool
40- {
41- if (!is_a ($ other_group , self ::class)) {
42- throw new Exception (
43- "Unable to check equality because the parameter is not a " .
44- self ::class .
45- " object " ,
46- );
47- }
48-
49- return $ this ->gid == $ other_group ->gid ;
50- }
51-
5235 public function __toString (): string
5336 {
5437 return $ this ->gid ;
5538 }
5639
57- /**
58- * Checks if the current PI is an approved and existent group
59- */
60- public function exists (): bool
61- {
62- return $ this ->entry ->exists ();
63- }
64-
6540 public function requestGroup (bool $ send_mail_to_admins , bool $ send_mail = true ): void
6641 {
6742 if ($ this ->exists ()) {
@@ -202,7 +177,7 @@ public function approveUser(UnityUser $new_user, bool $send_mail = true): void
202177 {
203178 $ request = $ this ->SQL ->getRequest ($ new_user ->uid , $ this ->gid );
204179 \ensure ($ new_user ->exists ());
205- $ this ->addUserToGroup ($ new_user );
180+ $ this ->addMemberUID ($ new_user-> uid );
206181 $ this ->SQL ->removeRequest ($ new_user ->uid , $ this ->gid );
207182 if ($ send_mail ) {
208183 $ this ->MAILER ->sendMail ($ new_user ->getMail (), "group_user_added " , [
@@ -240,14 +215,14 @@ public function denyUser(UnityUser $new_user, bool $send_mail = true): void
240215
241216 public function removeUser (UnityUser $ new_user , bool $ send_mail = true ): void
242217 {
243- if (!$ this ->memberExists ($ new_user )) {
218+ if (!$ this ->memberUIDExists ($ new_user-> uid )) {
244219 return ;
245220 }
246221 if ($ new_user ->uid == $ this ->getOwner ()->uid ) {
247222 throw new Exception ("Cannot delete group owner from group. Disband group instead " );
248223 }
249224 // remove request, this will fail silently if the request doesn't exist
250- $ this ->removeUserFromGroup ($ new_user );
225+ $ this ->removeMemberUID ($ new_user-> uid );
251226 if ($ send_mail ) {
252227 $ this ->MAILER ->sendMail ($ new_user ->getMail (), "group_user_removed " , [
253228 "group " => $ this ->gid ,
@@ -264,7 +239,7 @@ public function removeUser(UnityUser $new_user, bool $send_mail = true): void
264239
265240 public function newUserRequest (UnityUser $ new_user , bool $ send_mail = true ): void
266241 {
267- if ($ this ->memberExists ($ new_user )) {
242+ if ($ this ->memberUIDExists ($ new_user-> uid )) {
268243 UnityHTTPD::errorLog ("warning " , "user ' $ new_user' already in group " );
269244 return ;
270245 }
@@ -310,7 +285,7 @@ public function getRequests(): array
310285
311286 public function getGroupMembers (): array
312287 {
313- $ members = $ this ->getGroupMemberUIDs ();
288+ $ members = $ this ->getMemberUIDs ();
314289 $ out = [];
315290 foreach ($ members as $ member ) {
316291 $ user_obj = new UnityUser (
@@ -325,13 +300,6 @@ public function getGroupMembers(): array
325300 return $ out ;
326301 }
327302
328- public function getGroupMemberUIDs (): array
329- {
330- $ members = $ this ->entry ->getAttribute ("memberuid " );
331- sort ($ members );
332- return $ members ;
333- }
334-
335303 public function requestExists (UnityUser $ user ): bool
336304 {
337305 $ requesters = $ this ->getRequests ();
@@ -358,23 +326,6 @@ private function init(): void
358326 // we need to update the cache here with the memberuid
359327 }
360328
361- private function addUserToGroup (UnityUser $ new_user ): void
362- {
363- $ this ->entry ->appendAttribute ("memberuid " , $ new_user ->uid );
364- $ this ->entry ->write ();
365- }
366-
367- private function removeUserFromGroup (UnityUser $ old_user ): void
368- {
369- $ this ->entry ->removeAttributeEntryByValue ("memberuid " , $ old_user ->uid );
370- $ this ->entry ->write ();
371- }
372-
373- public function memberExists (UnityUser $ user ): bool
374- {
375- return in_array ($ user ->uid , $ this ->getGroupMemberUIDs ());
376- }
377-
378329 private function addRequest (string $ uid ): void
379330 {
380331 $ this ->SQL ->addRequest ($ uid , $ this ->gid );
@@ -418,7 +369,7 @@ public static function ownerMail2GID(string $email): string
418369 public function getGroupMembersAttributes (array $ attributes , array $ default_values = []): array
419370 {
420371 return $ this ->LDAP ->getUsersAttributes (
421- $ this ->getGroupMemberUIDs (),
372+ $ this ->getMemberUIDs (),
422373 $ attributes ,
423374 $ default_values ,
424375 );
0 commit comments