Skip to content

Commit 45fb9b3

Browse files
committed
inherit from LDAPEntry
1 parent 126ec72 commit 45fb9b3

File tree

6 files changed

+89
-105
lines changed

6 files changed

+89
-105
lines changed

resources/lib/UnityGroup.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* Class that represents a single PI group in the Unity Cluster.
1010
*/
11-
class UnityGroup
11+
class UnityGroup extends LDAPEntry
1212
{
1313
public const string PI_PREFIX = "pi_";
1414

@@ -26,9 +26,9 @@ public function __construct(
2626
UnityMailer $MAILER,
2727
UnityWebhook $WEBHOOK,
2828
) {
29+
parent::__construct($LDAP, $LDAP->getPIGroupDN($gid));
2930
$gid = trim($gid);
3031
$this->gid = $gid;
31-
$this->entry = $LDAP->getPIGroupEntry($gid);
3232

3333
$this->LDAP = $LDAP;
3434
$this->SQL = $SQL;
@@ -54,14 +54,6 @@ public function __toString(): string
5454
return $this->gid;
5555
}
5656

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-
6557
public function requestGroup(bool $send_mail_to_admins, bool $send_mail = true): void
6658
{
6759
if ($this->exists()) {
@@ -179,8 +171,8 @@ public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true):
179171
// $users = $this->getGroupMembers();
180172

181173
// // now we delete the ldap entry
182-
// $this->entry->ensureExists();
183-
// $this->entry->delete();
174+
// $this->ensureExists();
175+
// $this->delete();
184176

185177
// // send email to every user of the now deleted PI group
186178
// if ($send_mail) {
@@ -327,7 +319,7 @@ public function getGroupMembers(): array
327319

328320
public function getGroupMemberUIDs(): array
329321
{
330-
$members = $this->entry->getAttribute("memberuid");
322+
$members = $this->getAttribute("memberuid");
331323
sort($members);
332324
return $members;
333325
}
@@ -348,26 +340,26 @@ public function requestExists(UnityUser $user): bool
348340
private function init(): void
349341
{
350342
$owner = $this->getOwner();
351-
\ensure(!$this->entry->exists());
343+
\ensure(!$this->exists());
352344
$nextGID = $this->LDAP->getNextPIGIDNumber();
353-
$this->entry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
354-
$this->entry->setAttribute("gidnumber", strval($nextGID));
355-
$this->entry->setAttribute("memberuid", [$owner->uid]);
356-
$this->entry->write();
345+
$this->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
346+
$this->setAttribute("gidnumber", strval($nextGID));
347+
$this->setAttribute("memberuid", [$owner->uid]);
348+
$this->write();
357349
// TODO if we ever make this project based,
358350
// we need to update the cache here with the memberuid
359351
}
360352

361353
private function addUserToGroup(UnityUser $new_user): void
362354
{
363-
$this->entry->appendAttribute("memberuid", $new_user->uid);
364-
$this->entry->write();
355+
$this->appendAttribute("memberuid", $new_user->uid);
356+
$this->write();
365357
}
366358

367359
private function removeUserFromGroup(UnityUser $old_user): void
368360
{
369-
$this->entry->removeAttributeEntryByValue("memberuid", $old_user->uid);
370-
$this->entry->write();
361+
$this->removeAttributeEntryByValue("memberuid", $old_user->uid);
362+
$this->write();
371363
}
372364

373365
public function memberExists(UnityUser $user): bool

resources/lib/UnityLDAP.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,28 +363,28 @@ public function getAllOrgGroupsAttributes(array $attributes, array $default_valu
363363
);
364364
}
365365

366-
public function getUserEntry(string $uid): LDAPEntry
366+
public function getUserDN(string $uid): string
367367
{
368368
$uid = ldap_escape($uid, "", LDAP_ESCAPE_DN);
369-
return $this->getEntry(UnityLDAP::RDN . "=$uid," . CONFIG["ldap"]["user_ou"]);
369+
return UnityLDAP::RDN . "=$uid," . CONFIG["ldap"]["user_ou"];
370370
}
371371

372-
public function getGroupEntry(string $gid): LDAPEntry
372+
public function getUserGroupDN(string $gid): string
373373
{
374374
$gid = ldap_escape($gid, "", LDAP_ESCAPE_DN);
375-
return $this->getEntry(UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["group_ou"]);
375+
return UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["group_ou"];
376376
}
377377

378-
public function getPIGroupEntry(string $gid): LDAPEntry
378+
public function getPIGroupDN(string $gid): string
379379
{
380380
$gid = ldap_escape($gid, "", LDAP_ESCAPE_DN);
381-
return $this->getEntry(UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["pigroup_ou"]);
381+
return UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["pigroup_ou"];
382382
}
383383

384-
public function getOrgGroupEntry(string $gid): LDAPEntry
384+
public function getOrgGroupDN(string $gid): string
385385
{
386386
$gid = ldap_escape($gid, "", LDAP_ESCAPE_DN);
387-
return $this->getEntry(UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["orggroup_ou"]);
387+
return UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["orggroup_ou"];
388388
}
389389

390390
/**

resources/lib/UnityOrg.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace UnityWebPortal\lib;
44
use PHPOpenLDAPer\LDAPEntry;
55

6-
class UnityOrg
6+
class UnityOrg extends LDAPEntry
77
{
88
public string $gid;
99
private LDAPEntry $entry;
@@ -19,9 +19,9 @@ public function __construct(
1919
UnityMailer $MAILER,
2020
UnityWebhook $WEBHOOK,
2121
) {
22+
parent::__construct($LDAP, $LDAP->getOrgGroupDN($this->gid));
2223
$gid = trim($gid);
2324
$this->gid = $gid;
24-
$this->entry = $LDAP->getOrgGroupEntry($this->gid);
2525

2626
$this->LDAP = $LDAP;
2727
$this->SQL = $SQL;
@@ -31,16 +31,11 @@ public function __construct(
3131

3232
public function init(): void
3333
{
34-
\ensure(!$this->entry->exists());
34+
\ensure(!$this->exists());
3535
$nextGID = $this->LDAP->getNextOrgGIDNumber();
36-
$this->entry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
37-
$this->entry->setAttribute("gidnumber", strval($nextGID));
38-
$this->entry->write();
39-
}
40-
41-
public function exists(): bool
42-
{
43-
return $this->entry->exists();
36+
$this->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
37+
$this->setAttribute("gidnumber", strval($nextGID));
38+
$this->write();
4439
}
4540

4641
public function inOrg(UnityUser $user): bool
@@ -67,20 +62,20 @@ public function getOrgMembers(): array
6762

6863
public function getOrgMemberUIDs(): array
6964
{
70-
$members = $this->entry->getAttribute("memberuid");
65+
$members = $this->getAttribute("memberuid");
7166
sort($members);
7267
return $members;
7368
}
7469

7570
public function addUser(UnityUser $user): void
7671
{
77-
$this->entry->appendAttribute("memberuid", $user->uid);
78-
$this->entry->write();
72+
$this->appendAttribute("memberuid", $user->uid);
73+
$this->write();
7974
}
8075

8176
public function removeUser(UnityUser $user): void
8277
{
83-
$this->entry->removeAttributeEntryByValue("memberuid", $user->uid);
84-
$this->entry->write();
78+
$this->removeAttributeEntryByValue("memberuid", $user->uid);
79+
$this->write();
8580
}
8681
}

0 commit comments

Comments
 (0)