Skip to content

Commit 8b01414

Browse files
committed
UnityOrg as well
1 parent 5b0169c commit 8b01414

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

resources/lib/UnityOrg.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class UnityOrg
88
{
99
public $gid;
10+
private $entry;
1011

1112
private $MAILER;
1213
private $SQL;
@@ -17,6 +18,7 @@ class UnityOrg
1718
public function __construct($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK)
1819
{
1920
$this->gid = $gid;
21+
$this->entry = $LDAP->getOrgGroupEntry($this->gid);
2022

2123
$this->LDAP = $LDAP;
2224
$this->SQL = $SQL;
@@ -27,27 +29,20 @@ public function __construct($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK)
2729

2830
public function init()
2931
{
30-
$org_group = $this->getLDAPOrgGroup();
31-
32-
if (!$org_group->exists()) {
32+
if (!$this->entry->exists()) {
3333
$nextGID = $this->LDAP->getNextOrgGIDNumber($this->SQL);
3434

35-
$org_group->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
36-
$org_group->setAttribute("gidnumber", strval($nextGID));
37-
$org_group->write();
35+
$this->entry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
36+
$this->entry->setAttribute("gidnumber", strval($nextGID));
37+
$this->entry->write();
3838
}
3939

4040
$this->REDIS->appendCacheArray("sorted_orgs", "", $this->gid);
4141
}
4242

4343
public function exists()
4444
{
45-
return $this->getLDAPOrgGroup()->exists();
46-
}
47-
48-
public function getLDAPOrgGroup()
49-
{
50-
return $this->LDAP->getOrgGroupEntry($this->gid);
45+
return $this->entry->exists();
5146
}
5247

5348
public function inOrg($user, $ignorecache = false)
@@ -83,8 +78,7 @@ public function getOrgMemberUIDs($ignorecache = false)
8378
}
8479
$updatecache = false;
8580
if (!isset($members)) {
86-
$org_group = $this->getLDAPOrgGroup();
87-
$members = $org_group->getAttribute("memberuid");
81+
$members = $this->entry->getAttribute("memberuid");
8882
$updatecache = true;
8983
}
9084
if (!$ignorecache && $updatecache) {
@@ -96,17 +90,15 @@ public function getOrgMemberUIDs($ignorecache = false)
9690

9791
public function addUser($user)
9892
{
99-
$org_group = $this->getLDAPOrgGroup();
100-
$org_group->appendAttribute("memberuid", $user->uid);
101-
$org_group->write();
93+
$this->entry->appendAttribute("memberuid", $user->uid);
94+
$this->entry->write();
10295
$this->REDIS->appendCacheArray($this->gid, "members", $user->uid);
10396
}
10497

10598
public function removeUser($user)
10699
{
107-
$org_group = $this->getLDAPOrgGroup();
108-
$org_group->removeAttributeEntryByValue("memberuid", $user->uid);
109-
$org_group->write();
100+
$this->entry->removeAttributeEntryByValue("memberuid", $user->uid);
101+
$this->entry->write();
110102
$this->REDIS->removeCacheArray($this->gid, "members", $user->uid);
111103
}
112104
}

test/functional/NewUserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ private function ensureUserDoesNotExist()
8484
private function ensureOrgGroupDoesNotExist()
8585
{
8686
global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK;
87-
$org_group = new UnityOrg($SSO["org"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
87+
$org_group = $LDAP->getOrgGroupEntry($SSO["org"]);
8888
if ($org_group->exists()) {
89-
$org_group->getLDAPOrgGroup()->delete();
89+
$org_group->delete();
9090
assert(!$org_group->exists());
9191
}
9292
}

0 commit comments

Comments
 (0)