Skip to content

Commit a9a9908

Browse files
committed
UnityOrg as well
1 parent f46cc39 commit a9a9908

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

resources/lib/UnityOrg.php

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

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

2123
$this->LDAP = $LDAP;
2224
$this->SQL = $SQL;
@@ -27,27 +29,20 @@ public function __construct($orgid, $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->getOrgID());
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->orgid);
45+
return $this->entry->exists();
5146
}
5247

5348
public function getOrgID()
@@ -89,8 +84,7 @@ public function getOrgMemberUIDs($ignorecache = false)
8984
}
9085
$updatecache = false;
9186
if (!isset($members)) {
92-
$org_group = $this->getLDAPOrgGroup();
93-
$members = $org_group->getAttribute("memberuid");
87+
$members = $this->entry->getAttribute("memberuid");
9488
$updatecache = true;
9589
}
9690
if (!$ignorecache && $updatecache) {
@@ -102,17 +96,15 @@ public function getOrgMemberUIDs($ignorecache = false)
10296

10397
public function addUser($user)
10498
{
105-
$org_group = $this->getLDAPOrgGroup();
106-
$org_group->appendAttribute("memberuid", $user->getUID());
107-
$org_group->write();
108-
$this->REDIS->appendCacheArray($this->getOrgID(), "members", $user->getUID());
99+
$this->entry->appendAttribute("memberuid", $user->getUID());
100+
$this->entry->write();
101+
$this->REDIS->appendCacheArray($this->getOrgID(), "members", $user->uid);
109102
}
110103

111104
public function removeUser($user)
112105
{
113-
$org_group = $this->getLDAPOrgGroup();
114-
$org_group->removeAttributeEntryByValue("memberuid", $user->getUID());
115-
$org_group->write();
106+
$this->entry->removeAttributeEntryByValue("memberuid", $user->getUID());
107+
$this->entry->write();
116108
$this->REDIS->removeCacheArray($this->getOrgID(), "members", $user->getUID());
117109
}
118110
}

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)