Skip to content
Merged
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
1 change: 1 addition & 0 deletions resources/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
require_once __DIR__ . "/lib/exceptions/NoDieException.php";
require_once __DIR__ . "/lib/exceptions/SSOException.php";
require_once __DIR__ . "/lib/exceptions/ArrayKeyException.php";
require_once __DIR__ . "/lib/exceptions/EntryNotFoundException.php";
require_once __DIR__ . "/lib/exceptions/EnsureException.php";
require_once __DIR__ . "/lib/exceptions/EncodingUnknownException.php";
require_once __DIR__ . "/lib/exceptions/EncodingConversionException.php";
Expand Down
14 changes: 7 additions & 7 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,14 @@ public static function GID2OwnerUID(string $gid): string
return substr($gid, strlen(self::PI_PREFIX));
}

public static function ownerMail2GID($email)
/**
* @throws \UnityWebPortal\lib\exceptions\EntryNotFoundException
*/
public static function ownerMail2GID(string $email): string
{
global $LDAP;
$entry = $LDAP->getUidFromEmail($email);
if ($entry !== null) {
$ownerUid = $entry->getAttribute("cn")[0];
return self::PI_PREFIX . $ownerUid;
}
return $email; // Leave untouched
$entry = $LDAP->getUidFromEmail($email); // throws EntryNotFoundException
$ownerUid = $entry->getAttribute("cn")[0];
return self::PI_PREFIX . $ownerUid;
}
}
6 changes: 5 additions & 1 deletion resources/lib/UnityLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,16 @@ public function getOrgGroupEntry(string $gid): LDAPEntry
return $this->getEntry(UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["orggroup_ou"]);
}

public function getUidFromEmail($email)
/**
* @throws \UnityWebPortal\lib\exceptions\EntryNotFoundException
*/
public function getUidFromEmail(string $email): LDAPEntry
{
$email = ldap_escape($email, "", LDAP_ESCAPE_FILTER);
$cn = $this->search("mail=$email", CONFIG["ldap"]["user_ou"], ["cn"]);
if ($cn && count($cn) == 1) {
return $cn[0];
}
throw new exceptions\EntryNotFoundException($email);
}
}
5 changes: 5 additions & 0 deletions resources/lib/exceptions/EntryNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace UnityWebPortal\lib\exceptions;

class EntryNotFoundException extends \Exception {}
2 changes: 2 additions & 0 deletions test/functional/PIMemberRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function testRequestMembership()
$this->assertTrue($SQL->requestExists($uid, $gid));
$this->cancelRequest($gid);
$this->assertFalse($SQL->requestExists($uid, $gid));
$this->requestMembership("asdlkjasldkj");
$this->assertContains("This PI doesn't exist", $_SESSION["MODAL_ERRORS"]);
$this->requestMembership($pi_group->getOwner()->getMail());
$this->assertTrue($SQL->requestExists($uid, $gid));
} finally {
Expand Down
1 change: 1 addition & 0 deletions test/phpunit-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require_once __DIR__ . "/../resources/lib/exceptions/NoDieException.php";
require_once __DIR__ . "/../resources/lib/exceptions/SSOException.php";
require_once __DIR__ . "/../resources/lib/exceptions/ArrayKeyException.php";
require_once __DIR__ . "/../resources/lib/exceptions/EntryNotFoundException.php";
require_once __DIR__ . "/../resources/lib/exceptions/EnsureException.php";
require_once __DIR__ . "/../resources/lib/exceptions/EncodingUnknownException.php";
require_once __DIR__ . "/../resources/lib/exceptions/EncodingConversionException.php";
Expand Down
6 changes: 5 additions & 1 deletion webroot/panel/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_once __DIR__ . "/../../resources/autoload.php";

use UnityWebPortal\lib\exceptions\EntryNotFoundException;
use UnityWebPortal\lib\UnityGroup;
use UnityWebPortal\lib\UnityHTTPD;

Expand All @@ -12,7 +13,10 @@
if (isset($_POST["pi"])) {
$pi_groupname = $_POST["pi"];
if (substr($pi_groupname, 0, 3) !== "pi_" && str_contains($pi_groupname, "@")) {
$pi_groupname = UnityGroup::ownerMail2GID($pi_groupname);
try {
$pi_groupname = UnityGroup::ownerMail2GID($pi_groupname);
} catch (EntryNotFoundException) {
}
}
$pi_account = new UnityGroup($pi_groupname, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
if (!$pi_account->exists()) {
Expand Down
6 changes: 5 additions & 1 deletion webroot/panel/new_account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_once __DIR__ . "/../../resources/autoload.php";

use UnityWebPortal\lib\exceptions\EntryNotFoundException;
use UnityWebPortal\lib\UnityHTTPD;
use UnityWebPortal\lib\UnityGroup;
use UnityWebPortal\lib\UnitySQL;
Expand All @@ -26,7 +27,10 @@
if ($_POST["new_user_sel"] == "not_pi") {
$pi_groupname = $_POST["pi"];
if (substr($pi_groupname, 0, 3) !== "pi_" && str_contains($pi_groupname, "@")) {
$pi_groupname = UnityGroup::ownerMail2GID($pi_groupname);
try {
$pi_groupname = UnityGroup::ownerMail2GID($pi_groupname);
} catch (EntryNotFoundException) {
}
}
$form_group = new UnityGroup($pi_groupname, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
if (!$form_group->exists()) {
Expand Down