Skip to content

Commit 40ea9cf

Browse files
committed
add users to ldap immediately
1 parent d09c0bd commit 40ea9cf

20 files changed

+467
-640
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
- `user1@org1.test` - admin, PI
6464
- `user2@org1.test` - not admin, not PI
6565
- `user2000@org2.test` - does not yet have an account
66+
- `user2005@org1.test` - 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
/**
@@ -214,7 +215,7 @@ public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true):
214215
public function approveUser(UnityUser $new_user, bool $send_mail = true): void
215216
{
216217
$request = $this->SQL->getRequest($new_user->uid, $this->gid);
217-
\ensure(!$new_user->exists());
218+
\ensure($new_user->exists());
218219
$this->addUserToGroup($new_user);
219220
$this->SQL->removeRequest($new_user->uid, $this->gid);
220221
if ($send_mail) {
@@ -229,6 +230,7 @@ public function approveUser(UnityUser $new_user, bool $send_mail = true): void
229230
"org" => $new_user->getOrg(),
230231
]);
231232
}
233+
$new_user->setIsQualified(true); // being in a group makes you qualified
232234
}
233235

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

resources/lib/UnityUser.php

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,54 @@ public function init(
105105
$org->addUser($this);
106106
}
107107

108-
$this->LDAP->getQualifiedUserGroup()->appendAttribute("memberuid", $this->uid);
109-
$this->LDAP->getQualifiedUserGroup()->write();
110-
111-
$default_value_getter = [$this->LDAP, "getSortedQualifiedUsersForRedis"];
112-
$this->REDIS->appendCacheArray(
113-
"sorted_qualified_users",
114-
"",
115-
$this->uid,
116-
$default_value_getter,
117-
);
118-
119108
$this->SQL->addLog($this->uid, $_SERVER["REMOTE_ADDR"], "user_added", $this->uid);
109+
}
120110

121-
if ($send_mail) {
122-
$this->MAILER->sendMail($this->getMail(), "user_created", [
123-
"user" => $this->uid,
124-
"org" => $this->getOrg(),
125-
]);
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+
$default_value_getter = [$this->LDAP, "getSortedQualifiedUsersForRedis"];
126+
$this->REDIS->appendCacheArray(
127+
"sorted_qualified_users",
128+
"",
129+
$this->uid,
130+
$default_value_getter,
131+
);
132+
if ($doSendMail) {
133+
$this->MAILER->sendMail($this->getMail(), "user_qualified", [
134+
"user" => $this->uid,
135+
"org" => $this->getOrg(),
136+
]);
137+
}
138+
} else {
139+
$this->LDAP
140+
->getQualifiedUserGroup()
141+
->removeAttributeEntryByValue("memberuid", $this->uid);
142+
$this->LDAP->getQualifiedUserGroup()->write();
143+
$default_value_getter = [$this->LDAP, "getSortedQualifiedUsersForRedis"];
144+
$this->REDIS->removeCacheArray(
145+
"sorted_qualified_users",
146+
"",
147+
$this->uid,
148+
$default_value_getter,
149+
);
150+
if ($doSendMail) {
151+
$this->MAILER->sendMail($this->getMail(), "user_dequalified", [
152+
"user" => $this->uid,
153+
"org" => $this->getOrg(),
154+
]);
155+
}
126156
}
127157
}
128158

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)