Skip to content

Commit ece5b29

Browse files
committed
remove data from request table
1 parent 31d0221 commit ece5b29

File tree

9 files changed

+68
-165
lines changed

9 files changed

+68
-165
lines changed

resources/lib/UnityGroup.php

Lines changed: 32 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -65,43 +65,28 @@ public function exists(): bool
6565
return $this->entry->exists();
6666
}
6767

68-
public function requestGroup(
69-
string $firstname,
70-
string $lastname,
71-
string $email,
72-
string $org,
73-
bool $send_mail_to_admins,
74-
bool $send_mail = true,
75-
): void {
68+
public function requestGroup(bool $send_mail_to_admins, bool $send_mail = true): void
69+
{
7670
if ($this->exists()) {
7771
return;
7872
}
7973
if ($this->SQL->accDeletionRequestExists($this->getOwner()->uid)) {
8074
return;
8175
}
82-
$this->SQL->addRequest($this->getOwner()->uid, $firstname, $lastname, $email, $org);
76+
$context = [
77+
"user" => $this->getOwner()->uid,
78+
"org" => $this->getOwner()->getOrg(),
79+
"name" => $this->getOwner()->getFullName(),
80+
"email" => $this->getOwner()->getMail(),
81+
];
82+
$this->SQL->addRequest($this->getOwner()->uid);
8383
if ($send_mail) {
84-
$this->MAILER->sendMail($email, "group_request");
85-
$this->WEBHOOK->sendWebhook("group_request_admin", [
86-
"user" => $this->getOwner()->uid,
87-
"org" => $org,
88-
"name" => "$firstname $lastname",
89-
"email" => $email,
90-
]);
84+
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_request");
85+
$this->WEBHOOK->sendWebhook("group_request_admin", $context);
9186
if ($send_mail_to_admins) {
92-
$this->MAILER->sendMail("admin", "group_request_admin", [
93-
"user" => $this->getOwner()->uid,
94-
"org" => $org,
95-
"name" => "$firstname $lastname",
96-
"email" => $email,
97-
]);
87+
$this->MAILER->sendMail("admin", "group_request_admin", $context);
9888
}
99-
$this->MAILER->sendMail("pi_approve", "group_request_admin", [
100-
"user" => $this->getOwner()->uid,
101-
"org" => $org,
102-
"name" => "$firstname $lastname",
103-
"email" => $email,
104-
]);
89+
$this->MAILER->sendMail("pi_approve", "group_request_admin", $context);
10590
}
10691
}
10792

@@ -115,15 +100,7 @@ public function approveGroup(?UnityUser $operator = null, bool $send_mail = true
115100
if ($this->exists()) {
116101
return;
117102
}
118-
if (!$this->getOwner()->exists()) {
119-
$this->getOwner()->init(
120-
$request["firstname"],
121-
$request["lastname"],
122-
$request["email"],
123-
$request["org"],
124-
$send_mail,
125-
);
126-
}
103+
\ensure(!$this->getOwner()->exists());
127104
$this->init();
128105
$this->SQL->removeRequest($this->getOwner()->uid);
129106
$operator = is_null($operator) ? $this->getOwner()->uid : $operator->uid;
@@ -134,7 +111,7 @@ public function approveGroup(?UnityUser $operator = null, bool $send_mail = true
134111
$this->getOwner()->uid,
135112
);
136113
if ($send_mail) {
137-
$this->MAILER->sendMail($request["email"], "group_created");
114+
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_created");
138115
}
139116
}
140117

@@ -156,7 +133,7 @@ public function denyGroup(?UnityUser $operator = null, bool $send_mail = true):
156133
$this->getOwner()->uid,
157134
);
158135
if ($send_mail) {
159-
$this->MAILER->sendMail($request["email"], "group_denied");
136+
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_denied");
160137
}
161138
}
162139

@@ -230,14 +207,7 @@ public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true):
230207
public function approveUser(UnityUser $new_user, bool $send_mail = true): void
231208
{
232209
$request = $this->SQL->getRequest($new_user->uid, $this->gid);
233-
if (!$new_user->exists()) {
234-
$new_user->init(
235-
$request["firstname"],
236-
$request["lastname"],
237-
$request["email"],
238-
$request["org"],
239-
);
240-
}
210+
\ensure(!$new_user->exists());
241211
$this->addUserToGroup($new_user);
242212
$this->SQL->removeRequest($new_user->uid, $this->gid);
243213
if ($send_mail) {
@@ -247,9 +217,9 @@ public function approveUser(UnityUser $new_user, bool $send_mail = true): void
247217
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_user_added_owner", [
248218
"group" => $this->gid,
249219
"user" => $new_user->uid,
250-
"name" => $request["firstname"] . " " . $request["lastname"],
251-
"email" => $request["email"],
252-
"org" => $request["org"],
220+
"name" => $new_user->getFullname(),
221+
"email" => $new_user->getMail(),
222+
"org" => $new_user->getOrg(),
253223
]);
254224
}
255225
}
@@ -260,7 +230,7 @@ public function denyUser(UnityUser $new_user, bool $send_mail = true): void
260230
// remove request, this will fail silently if the request doesn't exist
261231
$this->SQL->removeRequest($new_user->uid, $this->gid);
262232
if ($send_mail) {
263-
$this->MAILER->sendMail($request["email"], "group_user_denied", [
233+
$this->MAILER->sendMail($new_user->getMail(), "group_user_denied", [
264234
"group" => $this->gid,
265235
]);
266236
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_user_denied_owner", [
@@ -297,14 +267,8 @@ public function removeUser(UnityUser $new_user, bool $send_mail = true): void
297267
}
298268
}
299269

300-
public function newUserRequest(
301-
UnityUser $new_user,
302-
string $firstname,
303-
string $lastname,
304-
string $email,
305-
string $org,
306-
bool $send_mail = true,
307-
): void {
270+
public function newUserRequest(UnityUser $new_user, bool $send_mail = true): void
271+
{
308272
if ($this->memberExists($new_user)) {
309273
UnityHTTPD::errorLog("warning", "user '$new_user' already in group");
310274
return;
@@ -317,17 +281,17 @@ public function newUserRequest(
317281
throw new Exception("user '$new_user' requested account deletion");
318282
return;
319283
}
320-
$this->addRequest($new_user->uid, $firstname, $lastname, $email, $org);
284+
$this->addRequest($new_user->uid);
321285
if ($send_mail) {
322-
$this->MAILER->sendMail($email, "group_user_request", [
286+
$this->MAILER->sendMail($new_user->getMail(), "group_user_request", [
323287
"group" => $this->gid,
324288
]);
325289
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_user_request_owner", [
326290
"group" => $this->gid,
327291
"user" => $new_user->uid,
328-
"name" => "$firstname $lastname",
329-
"email" => $email,
330-
"org" => $org,
292+
"name" => $new_user->getFullname(),
293+
"email" => $new_user->getMail(),
294+
"org" => $new_user->getOrg(),
331295
]);
332296
}
333297
}
@@ -345,14 +309,7 @@ public function getRequests(): array
345309
$this->REDIS,
346310
$this->WEBHOOK,
347311
);
348-
array_push($out, [
349-
$user,
350-
$request["timestamp"],
351-
$request["firstname"],
352-
$request["lastname"],
353-
$request["email"],
354-
$request["org"],
355-
]);
312+
array_push($out, [$user, $request["timestamp"]]);
356313
}
357314
return $out;
358315
}
@@ -443,14 +400,9 @@ public function memberExists(UnityUser $user): bool
443400
return in_array($user->uid, $this->getGroupMemberUIDs());
444401
}
445402

446-
private function addRequest(
447-
string $uid,
448-
string $firstname,
449-
string $lastname,
450-
string $email,
451-
string $org,
452-
): void {
453-
$this->SQL->addRequest($uid, $firstname, $lastname, $email, $org, $this->gid);
403+
private function addRequest(string $uid): void
404+
{
405+
$this->SQL->addRequest($uid, $this->gid);
454406
}
455407

456408
public function getOwner(): UnityUser

resources/lib/UnitySQL.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,17 @@ public function getConn(): PDO
3434
//
3535
// requests table methods
3636
//
37-
public function addRequest(
38-
string $requestor,
39-
string $firstname,
40-
string $lastname,
41-
string $email,
42-
string $org,
43-
string $dest = self::REQUEST_BECOME_PI,
44-
): void {
37+
public function addRequest(string $requestor, string $dest = self::REQUEST_BECOME_PI): void
38+
{
4539
if ($this->requestExists($requestor, $dest)) {
4640
return;
4741
}
4842

4943
$stmt = $this->conn->prepare(
50-
"INSERT INTO " .
51-
self::TABLE_REQS .
52-
" " .
53-
"(uid, firstname, lastname, email, org, request_for) VALUES " .
54-
"(:uid, :firstname, :lastname, :email, :org, :request_for)",
44+
"INSERT INTO " . self::TABLE_REQS . " (uid, request_for) VALUES (:uid, :request_for)",
5545
);
5646
$stmt->bindParam(":uid", $requestor);
5747
$stmt->bindParam(":request_for", $dest);
58-
$stmt->bindParam(":firstname", $firstname);
59-
$stmt->bindParam(":lastname", $lastname);
60-
$stmt->bindParam(":email", $email);
61-
$stmt->bindParam(":org", $org);
62-
6348
$stmt->execute();
6449
}
6550

tools/docker-dev/sql/bootstrap.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ CREATE TABLE `requests` (
124124
`id` int(11) NOT NULL,
125125
`request_for` varchar(131) NOT NULL,
126126
`uid` varchar(128) NOT NULL,
127-
`firstname` varchar(768) NOT NULL,
128-
`lastname` varchar(768) NOT NULL,
129-
`email` varchar(768) NOT NULL,
130-
`org` varchar(768) NOT NULL,
131127
`timestamp` timestamp NOT NULL DEFAULT current_timestamp()
132128
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
133129

webroot/admin/ajax/get_group_members.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,24 @@
5454
$i++;
5555
}
5656

57-
foreach ($requests as $i => [$user, $timestamp, $firstname, $lastname, $email, $org]) {
57+
foreach ($requests as $i => [$user, $timestamp]) {
5858
if ($i >= $count - 1) {
5959
echo "<tr class='expanded $i last'>";
6060
} else {
6161
echo "<tr class='expanded $i'>";
6262
}
63-
$uid = $user->uid;
64-
echo "<td>" . $firstname . " " . $lastname . "</td>";
65-
echo "<td>" . $uid . "</td>";
66-
echo "<td><a href='mailto:" . $email . "'>" . $email . "</a></td>";
63+
$name = $user->getFullName();
64+
$email = $user->getMail();
65+
echo "<td>$name</td>";
66+
echo "<td>$user->uid</td>";
67+
echo "<td><a href='mailto:$email'>$email</a></td>";
6768
echo "<td>";
6869
echo
6970
"<form action='' method='POST'
70-
onsubmit='return confirm(\"Are you sure you want to approve " . $uid . "?\");'>
71+
onsubmit='return confirm(\"Are you sure you want to approve $user->uid ?\");'>
7172
<input type='hidden' name='form_type' value='reqChild'>
72-
<input type='hidden' name='uid' value='" . $uid . "'>
73-
<input type='hidden' name='pi' value='" . $group->gid . "'>
73+
<input type='hidden' name='uid' value='$user->uid'>
74+
<input type='hidden' name='pi' value='$group->gid'>
7475
<input type='submit' name='action' value='Approve'>
7576
<input type='submit' name='action' value='Deny'></form>";
7677
echo "</td>";

webroot/admin/pi-mgmt.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,24 @@
6565
$requests = $SQL->getRequests();
6666

6767
foreach ($requests as $request) {
68+
$uid = $request["uid"];
69+
$request_user = new UnityUser($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
70+
$name = $request_user->getFullname();
71+
$email = $request_user->getMail();
6872
echo "<tr>";
69-
echo "<td>" . $request["firstname"] . " " . $request["lastname"] . "</td>";
70-
echo "<td>" . $request["uid"] . "</td>";
71-
echo "<td><a href='mailto:" . $request["email"] . "'>" . $request["email"] . "</a></td>";
73+
echo "<td>$name</td>";
74+
echo "<td>$uid</td>";
75+
echo "<td><a href='mailto:$email'>$email</a></td>";
7276
echo "<td>" . date("jS F, Y", strtotime($request['timestamp'])) . "</td>";
7377
echo "<td>";
7478
echo
7579
"<form action='' method='POST'>
7680
<input type='hidden' name='form_type' value='req'>
77-
<input type='hidden' name='uid' value='" . $request["uid"] . "'>
81+
<input type='hidden' name='uid' value='$uid'>
7882
<input type='submit' name='action' value='Approve'
79-
onclick='return confirm(\"Are you sure you want to approve " . $request["uid"] . "?\");'>
83+
onclick='return confirm(\"Are you sure you want to approve $uid?\");'>
8084
<input type='submit' name='action' value='Deny'
81-
onclick='return confirm(\"Are you sure you want to deny " . $request["uid"] . "?\");'>
85+
onclick='return confirm(\"Are you sure you want to deny $uid?\");'>
8286
</form>";
8387
echo "</td>";
8488
echo "</tr>";

webroot/panel/account.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,7 @@
7979
"USER='{$USER->uid}' SSO[user]='{$SSO["user"]}'"
8080
);
8181
}
82-
$USER->getPIGroup()->requestGroup(
83-
$SSO["firstname"],
84-
$SSO["lastname"],
85-
$SSO["mail"],
86-
$SSO["org"],
87-
$SEND_PIMESG_TO_ADMINS
88-
);
82+
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS);
8983
break;
9084
case "cancel_pi_request":
9185
$USER->getPIGroup()->cancelGroupRequest();

webroot/panel/groups.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,8 @@
2525
if ($pi_account->memberExists($USER)) {
2626
array_push($modalErrors, "You\'re already in this PI group");
2727
}
28-
if ($USER->uid != $SSO["user"]) {
29-
$sso_user = $SSO["user"];
30-
UnityHTTPD::badRequest(
31-
"cannot request due to uid mismatch: " .
32-
"USER='{$USER->uid}' SSO[user]='$sso_user'"
33-
);
34-
}
3528
if (empty($modalErrors)) {
36-
$pi_account->newUserRequest(
37-
$USER,
38-
$SSO["firstname"],
39-
$SSO["lastname"],
40-
$SSO["mail"],
41-
$SSO["org"]
42-
);
29+
$pi_account->newUserRequest($USER);
4330
}
4431
break;
4532
case "removePIForm":

webroot/panel/new_account.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,18 @@
1717
if (!isset($_POST["eula"]) || $_POST["eula"] != "agree") {
1818
UnityHTTPD::badRequest("user did not agree to EULA");
1919
}
20-
if ($USER->uid != $SSO["user"]) {
21-
$sso_user = $SSO["user"];
22-
UnityHTTPD::badRequest(
23-
"cannot request due to uid mismatch: USER='{$USER->uid}' SSO[user]='$sso_user'"
24-
);
25-
}
2620
if ($_POST["new_user_sel"] == "not_pi") {
2721
$form_group = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
2822
if (!$form_group->exists()) {
2923
UnityHTTPD::badRequest("The selected PI '" . $_POST["pi"] . "'does not exist");
3024
}
31-
$form_group->newUserRequest(
32-
$USER,
33-
$SSO["firstname"],
34-
$SSO["lastname"],
35-
$SSO["mail"],
36-
$SSO["org"]
37-
);
25+
$form_group->newUserRequest($USER);
3826
}
3927
if ($_POST["new_user_sel"] == "pi") {
4028
if (!isset($_POST["confirm_pi"]) || $_POST["confirm_pi"] != "agree") {
4129
UnityHTTPD::badRequest("user did not agree to account policy");
4230
}
43-
$USER->getPIGroup()->requestGroup(
44-
$SSO["firstname"],
45-
$SSO["lastname"],
46-
$SSO["mail"],
47-
$SSO["org"],
48-
$SEND_PIMESG_TO_ADMINS
49-
);
31+
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS);
5032
}
5133
} elseif (isset($_POST["cancel"])) {
5234
foreach ($pending_requests as $request) {

0 commit comments

Comments
 (0)