Skip to content

Commit 3af2be6

Browse files
committed
add users to ldap immediately
1 parent 64becf2 commit 3af2be6

20 files changed

+458
-642
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Notable users:
6363
- `[email protected]` - admin, PI
6464
- `[email protected]` - not admin, not PI
6565
- `[email protected]` - does not yet have an account
66+
- `[email protected]` - regsitered but not qualified (not a PI or in a PI group)
6667

6768
### Changes to Dev Environment
6869

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function approveGroup(?UnityUser $operator = null, bool $send_mail = true
100100
if ($this->exists()) {
101101
return;
102102
}
103-
\ensure(!$this->getOwner()->exists());
103+
\ensure($this->getOwner()->exists());
104104
$this->init();
105105
$this->SQL->removeRequest($this->getOwner()->uid);
106106
$operator = is_null($operator) ? $this->getOwner()->uid : $operator->uid;
@@ -113,6 +113,7 @@ public function approveGroup(?UnityUser $operator = null, bool $send_mail = true
113113
if ($send_mail) {
114114
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_created");
115115
}
116+
$this->getOwner()->setIsQualified(true); // having your own group makes you qualified
116117
}
117118

118119
/**
@@ -207,7 +208,7 @@ public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true):
207208
public function approveUser(UnityUser $new_user, bool $send_mail = true): void
208209
{
209210
$request = $this->SQL->getRequest($new_user->uid, $this->gid);
210-
\ensure(!$new_user->exists());
211+
\ensure($new_user->exists());
211212
$this->addUserToGroup($new_user);
212213
$this->SQL->removeRequest($new_user->uid, $this->gid);
213214
if ($send_mail) {
@@ -222,6 +223,7 @@ public function approveUser(UnityUser $new_user, bool $send_mail = true): void
222223
"org" => $new_user->getOrg(),
223224
]);
224225
}
226+
$new_user->setIsQualified(true); // being in a group makes you qualified
225227
}
226228

227229
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_qualified_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_qualified_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)