Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Class that represents a single PI group in the Unity Cluster.
*/
class UnityGroup
class UnityGroup extends LDAPEntry
{
public const string PI_PREFIX = "pi_";

Expand All @@ -26,9 +26,9 @@ public function __construct(
UnityMailer $MAILER,
UnityWebhook $WEBHOOK,
) {
parent::__construct($LDAP, $LDAP->getPIGroupDN($gid));
$gid = trim($gid);
$this->gid = $gid;
$this->entry = $LDAP->getPIGroupEntry($gid);

$this->LDAP = $LDAP;
$this->SQL = $SQL;
Expand All @@ -54,14 +54,6 @@ public function __toString(): string
return $this->gid;
}

/**
* Checks if the current PI is an approved and existent group
*/
public function exists(): bool
{
return $this->entry->exists();
}

public function requestGroup(bool $send_mail_to_admins, bool $send_mail = true): void
{
if ($this->exists()) {
Expand Down Expand Up @@ -179,8 +171,8 @@ public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true):
// $users = $this->getGroupMembers();

// // now we delete the ldap entry
// $this->entry->ensureExists();
// $this->entry->delete();
// $this->ensureExists();
// $this->delete();

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

public function getGroupMemberUIDs(): array
{
$members = $this->entry->getAttribute("memberuid");
$members = $this->getAttribute("memberuid");
sort($members);
return $members;
}
Expand All @@ -348,26 +340,26 @@ public function requestExists(UnityUser $user): bool
private function init(): void
{
$owner = $this->getOwner();
\ensure(!$this->entry->exists());
\ensure(!$this->exists());
$nextGID = $this->LDAP->getNextPIGIDNumber();
$this->entry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
$this->entry->setAttribute("gidnumber", strval($nextGID));
$this->entry->setAttribute("memberuid", [$owner->uid]);
$this->entry->write();
$this->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
$this->setAttribute("gidnumber", strval($nextGID));
$this->setAttribute("memberuid", [$owner->uid]);
$this->write();
// TODO if we ever make this project based,
// we need to update the cache here with the memberuid
}

private function addUserToGroup(UnityUser $new_user): void
{
$this->entry->appendAttribute("memberuid", $new_user->uid);
$this->entry->write();
$this->appendAttribute("memberuid", $new_user->uid);
$this->write();
}

private function removeUserFromGroup(UnityUser $old_user): void
{
$this->entry->removeAttributeEntryByValue("memberuid", $old_user->uid);
$this->entry->write();
$this->removeAttributeEntryByValue("memberuid", $old_user->uid);
$this->write();
}

public function memberExists(UnityUser $user): bool
Expand Down
16 changes: 8 additions & 8 deletions resources/lib/UnityLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,28 +363,28 @@ public function getAllOrgGroupsAttributes(array $attributes, array $default_valu
);
}

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

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

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

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

/**
Expand Down
27 changes: 11 additions & 16 deletions resources/lib/UnityOrg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace UnityWebPortal\lib;
use PHPOpenLDAPer\LDAPEntry;

class UnityOrg
class UnityOrg extends LDAPEntry
{
public string $gid;
private LDAPEntry $entry;
Expand All @@ -19,9 +19,9 @@ public function __construct(
UnityMailer $MAILER,
UnityWebhook $WEBHOOK,
) {
parent::__construct($LDAP, $LDAP->getOrgGroupDN($this->gid));
$gid = trim($gid);
$this->gid = $gid;
$this->entry = $LDAP->getOrgGroupEntry($this->gid);

$this->LDAP = $LDAP;
$this->SQL = $SQL;
Expand All @@ -31,16 +31,11 @@ public function __construct(

public function init(): void
{
\ensure(!$this->entry->exists());
\ensure(!$this->exists());
$nextGID = $this->LDAP->getNextOrgGIDNumber();
$this->entry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
$this->entry->setAttribute("gidnumber", strval($nextGID));
$this->entry->write();
}

public function exists(): bool
{
return $this->entry->exists();
$this->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
$this->setAttribute("gidnumber", strval($nextGID));
$this->write();
}

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

public function getOrgMemberUIDs(): array
{
$members = $this->entry->getAttribute("memberuid");
$members = $this->getAttribute("memberuid");
sort($members);
return $members;
}

public function addUser(UnityUser $user): void
{
$this->entry->appendAttribute("memberuid", $user->uid);
$this->entry->write();
$this->appendAttribute("memberuid", $user->uid);
$this->write();
}

public function removeUser(UnityUser $user): void
{
$this->entry->removeAttributeEntryByValue("memberuid", $user->uid);
$this->entry->write();
$this->removeAttributeEntryByValue("memberuid", $user->uid);
$this->write();
}
}
Loading
Loading