Skip to content

Commit d09c0bd

Browse files
committed
remove data from request table
1 parent 7070ef8 commit d09c0bd

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

@@ -237,14 +214,7 @@ public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true):
237214
public function approveUser(UnityUser $new_user, bool $send_mail = true): void
238215
{
239216
$request = $this->SQL->getRequest($new_user->uid, $this->gid);
240-
if (!$new_user->exists()) {
241-
$new_user->init(
242-
$request["firstname"],
243-
$request["lastname"],
244-
$request["email"],
245-
$request["org"],
246-
);
247-
}
217+
\ensure(!$new_user->exists());
248218
$this->addUserToGroup($new_user);
249219
$this->SQL->removeRequest($new_user->uid, $this->gid);
250220
if ($send_mail) {
@@ -254,9 +224,9 @@ public function approveUser(UnityUser $new_user, bool $send_mail = true): void
254224
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_user_added_owner", [
255225
"group" => $this->gid,
256226
"user" => $new_user->uid,
257-
"name" => $request["firstname"] . " " . $request["lastname"],
258-
"email" => $request["email"],
259-
"org" => $request["org"],
227+
"name" => $new_user->getFullname(),
228+
"email" => $new_user->getMail(),
229+
"org" => $new_user->getOrg(),
260230
]);
261231
}
262232
}
@@ -267,7 +237,7 @@ public function denyUser(UnityUser $new_user, bool $send_mail = true): void
267237
// remove request, this will fail silently if the request doesn't exist
268238
$this->SQL->removeRequest($new_user->uid, $this->gid);
269239
if ($send_mail) {
270-
$this->MAILER->sendMail($request["email"], "group_user_denied", [
240+
$this->MAILER->sendMail($new_user->getMail(), "group_user_denied", [
271241
"group" => $this->gid,
272242
]);
273243
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_user_denied_owner", [
@@ -304,14 +274,8 @@ public function removeUser(UnityUser $new_user, bool $send_mail = true): void
304274
}
305275
}
306276

307-
public function newUserRequest(
308-
UnityUser $new_user,
309-
string $firstname,
310-
string $lastname,
311-
string $email,
312-
string $org,
313-
bool $send_mail = true,
314-
): void {
277+
public function newUserRequest(UnityUser $new_user, bool $send_mail = true): void
278+
{
315279
if ($this->memberExists($new_user)) {
316280
UnityHTTPD::errorLog("warning", "user '$new_user' already in group");
317281
return;
@@ -324,17 +288,17 @@ public function newUserRequest(
324288
throw new Exception("user '$new_user' requested account deletion");
325289
return;
326290
}
327-
$this->addRequest($new_user->uid, $firstname, $lastname, $email, $org);
291+
$this->addRequest($new_user->uid);
328292
if ($send_mail) {
329-
$this->MAILER->sendMail($email, "group_user_request", [
293+
$this->MAILER->sendMail($new_user->getMail(), "group_user_request", [
330294
"group" => $this->gid,
331295
]);
332296
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_user_request_owner", [
333297
"group" => $this->gid,
334298
"user" => $new_user->uid,
335-
"name" => "$firstname $lastname",
336-
"email" => $email,
337-
"org" => $org,
299+
"name" => $new_user->getFullname(),
300+
"email" => $new_user->getMail(),
301+
"org" => $new_user->getOrg(),
338302
]);
339303
}
340304
}
@@ -352,14 +316,7 @@ public function getRequests(): array
352316
$this->REDIS,
353317
$this->WEBHOOK,
354318
);
355-
array_push($out, [
356-
$user,
357-
$request["timestamp"],
358-
$request["firstname"],
359-
$request["lastname"],
360-
$request["email"],
361-
$request["org"],
362-
]);
319+
array_push($out, [$user, $request["timestamp"]]);
363320
}
364321
return $out;
365322
}
@@ -471,14 +428,9 @@ public function memberExists(UnityUser $user): bool
471428
return in_array($user->uid, $this->getGroupMemberUIDs());
472429
}
473430

474-
private function addRequest(
475-
string $uid,
476-
string $firstname,
477-
string $lastname,
478-
string $email,
479-
string $org,
480-
): void {
481-
$this->SQL->addRequest($uid, $firstname, $lastname, $email, $org, $this->gid);
431+
private function addRequest(string $uid): void
432+
{
433+
$this->SQL->addRequest($uid, $this->gid);
482434
}
483435

484436
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
@@ -37,21 +37,8 @@
3737
array_push($modalErrors, "You're already in this PI group");
3838
}
3939
}
40-
if ($USER->uid != $SSO["user"]) {
41-
$sso_user = $SSO["user"];
42-
UnityHTTPD::badRequest(
43-
"cannot request due to uid mismatch: " .
44-
"USER='{$USER->uid}' SSO[user]='$sso_user'"
45-
);
46-
}
4740
if (empty($modalErrors)) {
48-
$pi_account->newUserRequest(
49-
$USER,
50-
$SSO["firstname"],
51-
$SSO["lastname"],
52-
$SSO["mail"],
53-
$SSO["org"]
54-
);
41+
$pi_account->newUserRequest($USER);
5542
}
5643
break;
5744
case "removePIForm":

webroot/panel/new_account.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
if (!isset($_POST["eula"]) || $_POST["eula"] != "agree") {
1919
UnityHTTPD::badRequest("user did not agree to EULA");
2020
}
21-
if ($USER->uid != $SSO["user"]) {
22-
$sso_user = $SSO["user"];
23-
UnityHTTPD::badRequest(
24-
"cannot request due to uid mismatch: USER='{$USER->uid}' SSO[user]='$sso_user'"
25-
);
26-
}
2721
if ($_POST["new_user_sel"] == "not_pi") {
2822
$pi_groupname = $_POST["pi"];
2923
if (substr($pi_groupname, 0, 3) !== "pi_" && str_contains($pi_groupname, "@")) {
@@ -36,25 +30,13 @@
3630
if (!$form_group->exists()) {
3731
UnityHTTPD::badRequest("The selected PI '" . $pi_groupname . "'does not exist");
3832
}
39-
$form_group->newUserRequest(
40-
$USER,
41-
$SSO["firstname"],
42-
$SSO["lastname"],
43-
$SSO["mail"],
44-
$SSO["org"]
45-
);
33+
$form_group->newUserRequest($USER);
4634
}
4735
if ($_POST["new_user_sel"] == "pi") {
4836
if (!isset($_POST["confirm_pi"]) || $_POST["confirm_pi"] != "agree") {
4937
UnityHTTPD::badRequest("user did not agree to account policy");
5038
}
51-
$USER->getPIGroup()->requestGroup(
52-
$SSO["firstname"],
53-
$SSO["lastname"],
54-
$SSO["mail"],
55-
$SSO["org"],
56-
$SEND_PIMESG_TO_ADMINS
57-
);
39+
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS);
5840
}
5941
} elseif (isset($_POST["cancel"])) {
6042
foreach ($pending_requests as $request) {

0 commit comments

Comments
 (0)