Skip to content

Commit ffc9def

Browse files
committed
remove qualification from init
1 parent ece5b29 commit ffc9def

File tree

5 files changed

+49
-12
lines changed

5 files changed

+49
-12
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ rm "$prod" && ln -s "$old" "$prod"
117117
### 1.3 -> 1.4
118118

119119
- the `[ldap]user_group` option has been renamed to `[ldap]qualified_user_group`
120+
- the `user_created ` mail template has been renamed to `user_qualified`
121+
- the `user_dequalified` mail template has been added
120122

121123
### 1.2 -> 1.3
122124

resources/lib/UnityGroup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public function approveUser(UnityUser $new_user, bool $send_mail = true): void
222222
"org" => $new_user->getOrg(),
223223
]);
224224
}
225+
$new_user->setIsQualified(true); // being in a group makes you qualified
225226
}
226227

227228
public function denyUser(UnityUser $new_user, bool $send_mail = true): void

resources/lib/UnityUser.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,42 @@ public function init(
105105
$org->addUser($this);
106106
}
107107

108-
$this->LDAP->getQualifiedUserGroup()->appendAttribute("memberuid", $this->uid);
109-
$this->LDAP->getQualifiedUserGroup()->write();
110-
111-
$this->REDIS->appendCacheArray("sorted_qualified_users", "", $this->uid);
112-
113108
$this->SQL->addLog($this->uid, $_SERVER["REMOTE_ADDR"], "user_added", $this->uid);
109+
}
114110

115-
if ($send_mail) {
116-
$this->MAILER->sendMail($this->getMail(), "user_created", [
117-
"user" => $this->uid,
118-
"org" => $this->getOrg(),
119-
]);
111+
public function isQualified(): bool
112+
{
113+
return $this->LDAP->getQualifiedUserGroup()->attributeValueExists("memberUid", $this->uid);
114+
}
115+
116+
public function setIsQualified(bool $newIsQualified, bool $doSendMail = true): void
117+
{
118+
$oldIsQualified = $this->isQualified();
119+
if ($oldIsQualified == $newIsQualified) {
120+
return;
121+
}
122+
if ($newIsQualified) {
123+
$this->LDAP->getQualifiedUserGroup()->appendAttribute("memberuid", $this->uid);
124+
$this->LDAP->getQualifiedUserGroup()->write();
125+
$this->REDIS->appendCacheArray("sorted_users", "", $this->uid);
126+
if ($doSendMail) {
127+
$this->MAILER->sendMail($this->getMail(), "user_qualified", [
128+
"user" => $this->uid,
129+
"org" => $this->getOrg(),
130+
]);
131+
}
132+
} else {
133+
$this->LDAP
134+
->getQualifiedUserGroup()
135+
->removeAttributeEntryByValue("memberuid", $this->uid);
136+
$this->LDAP->getQualifiedUserGroup()->write();
137+
$this->REDIS->removeCacheArray("sorted_users", "", $this->uid);
138+
if ($doSendMail) {
139+
$this->MAILER->sendMail($this->getMail(), "user_dequalified", [
140+
"user" => $this->uid,
141+
"org" => $this->getOrg(),
142+
]);
143+
}
120144
}
121145
}
122146

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// this template is sent when a user account is no longer qualified
4+
$this->Subject = "User Deactivated"; ?>
5+
6+
<p>Hello,</p>
7+
8+
<p>Your account on the Unity cluster has been deactivated.</p>
9+
10+
<p>If you believe this to be a mistake, please reply to this email as soon as possible.</p>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3-
// this template is sent when a user account gets created
4-
$this->Subject = "User Created"; ?>
3+
// this template is sent when a user account becomes qualified
4+
$this->Subject = "User Activated"; ?>
55

66
<p>Hello,</p>
77

0 commit comments

Comments
 (0)