Skip to content

Commit 6253ea5

Browse files
committed
shorten lines
1 parent 8961b75 commit 6253ea5

28 files changed

+331
-125
lines changed

resources/init.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@
107107
$errorid = uniqid("sso-");
108108
$eppn = $_SERVER["REMOTE_USER"];
109109
UnitySite::errorLog("SSO Failure", "{$e} ($errorid)");
110-
UnitySite::die("Invalid eppn: '$eppn'. Please contact {$CONFIG["mail"]["support"]} (id: $errorid)", true);
110+
UnitySite::die(
111+
"Invalid eppn: '$eppn'. Please contact {$CONFIG["mail"]["support"]} (id: $errorid)",
112+
true
113+
);
111114
}
112115
$_SESSION["SSO"] = $SSO;
113116

resources/lib/UnityGroup.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public function __construct($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK)
4444
public function equals($other_group)
4545
{
4646
if (!is_a($other_group, self::class)) {
47-
throw new Exception("Unable to check equality because the parameter is not a " . self::class . " object");
47+
throw new Exception(
48+
"Unable to check equality because the parameter is not a " . self::class . " object"
49+
);
4850
}
4951

5052
return $this->gid == $other_group->gid;
@@ -69,8 +71,14 @@ public function exists()
6971
// Portal-facing methods, these are the methods called by scripts in webroot
7072
//
7173

72-
public function requestGroup($firstname, $lastname, $email, $org, $send_mail_to_admins, $send_mail = true)
73-
{
74+
public function requestGroup(
75+
$firstname,
76+
$lastname,
77+
$email,
78+
$org,
79+
$send_mail_to_admins,
80+
$send_mail = true
81+
) {
7482
// check for edge cases...
7583
if ($this->exists()) {
7684
return;
@@ -150,7 +158,8 @@ public function approveGroup($operator = null, $send_mail = true)
150158
);
151159
}
152160

153-
// initialize ldap objects, if this fails the script will crash, but nothing will persistently break
161+
// initialize ldap objects, if this fails the script will crash,
162+
// but nothing will persistently break
154163
$this->init();
155164

156165
// remove the request from the sql table
@@ -279,7 +288,8 @@ public function cancelGroupJoinRequest($user, $send_mail = true)
279288
// }
280289

281290
/**
282-
* This method is executed when a user is approved to join the group (either by admin or the group owner)
291+
* This method is executed when a user is approved to join the group
292+
* (either by admin or the group owner)
283293
*/
284294
public function approveUser($new_user, $send_mail = true)
285295
{
@@ -388,8 +398,14 @@ public function removeUser($new_user, $send_mail = true)
388398
}
389399
}
390400

391-
public function newUserRequest($new_user, $firstname, $lastname, $email, $org, $send_mail = true)
392-
{
401+
public function newUserRequest(
402+
$new_user,
403+
$firstname,
404+
$lastname,
405+
$email,
406+
$org,
407+
$send_mail = true
408+
) {
393409
if ($this->userExists($new_user)) {
394410
UnitySite::errorLog("warning", "user '$new_user' already in group");
395411
return;
@@ -532,7 +548,8 @@ private function init()
532548

533549
$this->REDIS->appendCacheArray("sorted_groups", "", $this->gid);
534550

535-
// TODO if we ever make this project based, we need to update the cache here with the memberuid
551+
// TODO if we ever make this project based,
552+
// we need to update the cache here with the memberuid
536553
}
537554

538555
private function addUserToGroup($new_user)

resources/lib/UnityLDAP.php

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,30 @@ public function getAllUsersUIDs()
234234
//
235235
// Functions that return user/group objects
236236
//
237-
public function getAllUsers($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
238-
{
237+
public function getAllUsers(
238+
$UnitySQL,
239+
$UnityMailer,
240+
$UnityRedis,
241+
$UnityWebhook,
242+
$ignorecache = false
243+
) {
239244
$out = array();
240245

241246
if (!$ignorecache) {
242247
$users = $UnityRedis->getCache("sorted_users", "");
243248
if (!is_null($users)) {
244249
foreach ($users as $user) {
245-
array_push($out, new UnityUser($user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook));
250+
array_push(
251+
$out,
252+
new UnityUser(
253+
$user,
254+
$this,
255+
$UnitySQL,
256+
$UnityMailer,
257+
$UnityRedis,
258+
$UnityWebhook
259+
)
260+
);
246261
}
247262
return $out;
248263
}
@@ -273,15 +288,22 @@ public function getAllUsersAttributes($attributes)
273288
return $user_attributes;
274289
}
275290

276-
public function getAllPIGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
277-
{
291+
public function getAllPIGroups(
292+
$UnitySQL,
293+
$UnityMailer,
294+
$UnityRedis,
295+
$UnityWebhook,
296+
$ignorecache = false
297+
) {
278298
$out = array();
279299

280300
if (!$ignorecache) {
281301
$groups = $UnityRedis->getCache("sorted_groups", "");
282302
if (!is_null($groups)) {
283303
foreach ($groups as $group) {
284-
$params = array($group, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook);
304+
$params = array(
305+
$group, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook
306+
);
285307
array_push($out, new UnityGroup(...$params));
286308
}
287309

@@ -362,17 +384,31 @@ public function getAllUID2PIGIDs()
362384
return $uid2pigids;
363385
}
364386

365-
public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
366-
{
387+
public function getAllOrgGroups(
388+
$UnitySQL,
389+
$UnityMailer,
390+
$UnityRedis,
391+
$UnityWebhook,
392+
$ignorecache = false
393+
) {
367394
$out = array();
368395

369396
if (!$ignorecache) {
370397
$orgs = $UnityRedis->getCache("sorted_orgs", "");
371398
if (!is_null($orgs)) {
372399
foreach ($orgs as $org) {
373-
array_push($out, new UnityOrg($org, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook));
400+
array_push(
401+
$out,
402+
new UnityOrg(
403+
$org,
404+
$this,
405+
$UnitySQL,
406+
$UnityMailer,
407+
$UnityRedis,
408+
$UnityWebhook
409+
)
410+
);
374411
}
375-
376412
return $out;
377413
}
378414
}

resources/lib/UnityMailer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public function __construct(
5757

5858
$security_conf_valid = empty($security) || $security == "tls" || $security == "ssl";
5959
if (!$security_conf_valid) {
60-
throw new Exception("SMTP security is not set correctly, leave empty, use 'tls', or 'ssl'");
60+
throw new Exception(
61+
"SMTP security is not set correctly, leave empty, use 'tls', or 'ssl'"
62+
);
6163
}
6264
$this->SMTPSecure = $security;
6365

resources/lib/UnityPerms.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public function checkApproveUser($uid, $operated_on, $group)
2121

2222
$role = $this->SQL->getRole($uid, $group);
2323

24-
if ($this->SQL->hasPerm($role, 'unity.admin') || $this->SQL->hasPerm($role, 'unity.admin_no_grant')) {
24+
if (
25+
$this->SQL->hasPerm($role, 'unity.admin')
26+
|| $this->SQL->hasPerm($role, 'unity.admin_no_grant')
27+
) {
2528
return true;
2629
}
2730

@@ -46,7 +49,10 @@ public function checkDenyUser($uid, $operated_on, $group)
4649

4750
$role = $this->SQL->getRole($uid, $group);
4851

49-
if ($this->SQL->hasPerm($role, 'unity.admin') || $this->SQL->hasPerm($role, 'unity.admin_no_grant')) {
52+
if (
53+
$this->SQL->hasPerm($role, 'unity.admin')
54+
|| $this->SQL->hasPerm($role, 'unity.admin_no_grant')
55+
) {
5056
return true;
5157
}
5258

@@ -79,7 +85,10 @@ public function checkGrantRole($uid, $group, $role)
7985
return false;
8086
}
8187

82-
if ($this->SQL->hasPerm($user_role, 'unity.admin') || $this->SQL->hasPerm($user_role, 'unity.admin_no_grant')) {
88+
if (
89+
$this->SQL->hasPerm($user_role, 'unity.admin')
90+
|| $this->SQL->hasPerm($user_role, 'unity.admin_no_grant')
91+
) {
8392
return true;
8493
}
8594

@@ -112,7 +121,10 @@ public function checkRevokeRole($uid, $group, $role)
112121
return false;
113122
}
114123

115-
if ($this->SQL->hasPerm($user_role, 'unity.admin') || $this->SQL->hasPerm($user_role, 'unity.admin_no_grant')) {
124+
if (
125+
$this->SQL->hasPerm($user_role, 'unity.admin')
126+
|| $this->SQL->hasPerm($user_role, 'unity.admin_no_grant')
127+
) {
116128
return true;
117129
}
118130

resources/lib/UnitySQL.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class UnitySQL
1919
private const TABLE_GROUP_JOIN_REQUESTS = "groupJoinRequests";
2020

2121

22-
// FIXME this string should be changed to something more intuitive, requires production sql change
22+
// FIXME this string should be changed to something more intuitive, requires production change
2323
public const REQUEST_BECOME_PI = "admin";
2424

2525
private $conn;
@@ -38,8 +38,14 @@ public function getConn()
3838
//
3939
// requests table methods
4040
//
41-
public function addRequest($requestor, $firstname, $lastname, $email, $org, $dest = self::REQUEST_BECOME_PI)
42-
{
41+
public function addRequest(
42+
$requestor,
43+
$firstname,
44+
$lastname,
45+
$email,
46+
$org,
47+
$dest = self::REQUEST_BECOME_PI
48+
) {
4349
if ($this->requestExists($requestor, $dest)) {
4450
return;
4551
}
@@ -156,8 +162,9 @@ public function deleteRequestsByUser($user)
156162

157163
public function addNotice($title, $date, $content, $operator)
158164
{
165+
$table = self::TABLE_NOTICES;
159166
$stmt = $this->conn->prepare(
160-
"INSERT INTO " . self::TABLE_NOTICES . " (date, title, message) VALUES (:date, :title, :message)"
167+
"INSERT INTO $table (date, title, message) VALUES (:date, :title, :message)"
161168
);
162169
$stmt->bindParam(":date", $date);
163170
$stmt->bindParam(":title", $title);
@@ -175,8 +182,9 @@ public function addNotice($title, $date, $content, $operator)
175182

176183
public function editNotice($id, $title, $date, $content)
177184
{
185+
$table = self::TABLE_NOTICES;
178186
$stmt = $this->conn->prepare(
179-
"UPDATE " . self::TABLE_NOTICES . " SET date=:date, title=:title, message=:message WHERE id=:id"
187+
"UPDATE $table SET date=:date, title=:title, message=:message WHERE id=:id"
180188
);
181189
$stmt->bindParam(":date", $date);
182190
$stmt->bindParam(":title", $title);
@@ -261,8 +269,9 @@ public function editPage($id, $content, $operator)
261269
// audit log table methods
262270
public function addLog($operator, $operator_ip, $action_type, $recipient)
263271
{
272+
$table = self::TABLE_AUDIT_LOG;
264273
$stmt = $this->conn->prepare(
265-
"INSERT INTO " . self::TABLE_AUDIT_LOG . " (operator, operator_ip, action_type, recipient)
274+
"INSERT INTO $table (operator, operator_ip, action_type, recipient)
266275
VALUE (:operator, :operator_ip, :action_type, :recipient)"
267276
);
268277
$stmt->bindParam(":operator", $operator);
@@ -332,9 +341,8 @@ public function updateSiteVar($name, $value)
332341

333342
public function getRole($uid, $group)
334343
{
335-
$stmt = $this->conn->prepare(
336-
"SELECT * FROM " . self::TABLE_GROUP_ROLE_ASSIGNMENTS . " WHERE user=:uid AND `group`=:group"
337-
);
344+
$table = self::TABLE_GROUP_ROLE_ASSIGNMENTS;
345+
$stmt = $this->conn->prepare("SELECT * FROM $table WHERE user=:uid AND `group`=:group");
338346
$stmt->bindParam(":uid", $uid);
339347
$stmt->bindParam(":group", $group);
340348

@@ -372,9 +380,8 @@ public function getPriority($role)
372380

373381
public function roleAvailableInGroup($uid, $group, $role)
374382
{
375-
$stmt = $this->conn->prepare(
376-
"SELECT * FROM " . self::TABLE_GROUP_ROLE_ASSIGNMENTS . " WHERE user=:uid AND `group`=:group"
377-
);
383+
$table = self::TABLE_GROUP_ROLE_ASSIGNMENTS;
384+
$stmt = $this->conn->prepare("SELECT * FROM $table WHERE user=:uid AND `group`=:group");
378385
$stmt->bindParam(":uid", $uid);
379386
$stmt->bindParam(":group", $group);
380387

resources/lib/UnityUser.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public function __construct($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK)
3535
public function equals($other_user)
3636
{
3737
if (!is_a($other_user, self::class)) {
38-
throw new Exception("Unable to check equality because the parameter is not a " . self::class . " object");
38+
throw new Exception(
39+
"Unable to check equality because the parameter is not a " . self::class . " object"
40+
);
3941
}
4042

4143
return $this->uid == $other_user->uid;
@@ -594,7 +596,8 @@ public function getPIGroupGIDs($ignorecache = false)
594596
}
595597

596598
/**
597-
* Sends an email to admins about account deletion request and also adds it to a table in the database
599+
* Sends an email to admins about account deletion request
600+
* and also adds it to a table in the database
598601
*/
599602
public function requestAccountDeletion()
600603
{

resources/mail/footer.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
<footer style="text-align: center; font-size: 8pt; color: #aaaaaa; border-top: 1px solid #dddddd; padding-top: 10px;">
2-
<span>You are receiving this email because you have an account
3-
on the <a target='_blank' href='<?php echo $this->MSG_LINKREF; ?>'>Unity Cluster</a>.
4-
If you would like to stop receiving these emails,
5-
you may request to close your account by replying to this email.</span>
1+
<footer
2+
style="text-align:center; font-size:8pt; color:#aaa; border-top:1px solid #ddd; padding-top:10px;"
3+
>
4+
<span>
5+
You are receiving this email because you have an account
6+
on the <a target='_blank' href='<?php echo $this->MSG_LINKREF; ?>'>Unity Cluster</a>.
7+
If you would like to stop receiving these emails,
8+
you may request to close your account by replying to this email.
9+
</span>
610
</footer>

resources/mail/group_created.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
<p>Hello,</p>
88

9-
<p>Your request for a PI account on the Unity cluster has been approved. You can access the management
10-
page for your group <a href="<?php echo $this->MSG_LINKREF; ?>/panel/pi.php">on this page</a>.</p>
9+
<p>
10+
Your request for a PI account on the Unity cluster has been approved.
11+
You can access the management page for your group
12+
<a href="<?php echo $this->MSG_LINKREF; ?>/panel/pi.php">on this page</a>.
13+
</p>
1114

12-
<p>Do not hesitate to reply if you have any questions!</p>
15+
<p>Do not hesitate to reply if you have any questions!</p>

resources/mail/group_request.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
<p>Hello,</p>
88

9-
<p>You have requested a PI account on the Unity Cluster.
10-
The admin team is reviewing this request, and you will receive an email soon with more details.</p>
9+
<p>
10+
You have requested a PI account on the Unity Cluster.
11+
The admin team is reviewing this request, and you will receive an email soon with more details.
12+
</p>
1113

12-
<p>Do not hesitate to reply if you have any questions!</p>
14+
<p>Do not hesitate to reply if you have any questions!</p>

0 commit comments

Comments
 (0)