Skip to content

Commit fe14506

Browse files
committed
enforce qualified user group
1 parent 11daf0e commit fe14506

17 files changed

+269
-194
lines changed

LDAP.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Terminology:
22

33
- **qualified user**: a user who is currently a PI or a member of at least one PI group
4-
- **native user**: a user who's entries exist in the OUs given in `config.ini`
5-
- it is up to the administrator to ensure that no non-native entries exist in these OUs
4+
- **unqualified user**: inverse of qualified
5+
- **native user**: a user created by this account portal
6+
- **non-native user**: inverse of native
7+
- users created for administrative purposes should not be mixed with native users in the LDAP OUs given in `config.ini` or else this account portal may get confused
8+
- **ghost user**: a user who is effectively deleted

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ parameters:
44
- resources
55
- webroot
66
- test
7+
excludePaths:
8+
- test/Template.php
79
ignoreErrors:
810
# $this, $data comes from UnityMailer
911
- messages:
@@ -21,6 +23,7 @@ parameters:
2123
- '#Negated boolean expression is always false\.#'
2224
paths:
2325
- test/functional/PiRemoveUserTest.php
26+
- test/functional/LeaveGroupTest.php
2427
- messages:
2528
- '#If condition is always false\.#'
2629
paths:

resources/init.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
$_SESSION["is_pi"] = $USER->isPI();
7373

7474
$SQL->addLog("user_login", $OPERATOR->uid);
75+
76+
$USER->updateIsQualified(); // in case manual changes have been made to PI groups
7577
}
7678

7779
$LOC_HEADER = __DIR__ . "/templates/header.php";

resources/lib/PosixGroup.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@ public function memberUIDExists(string $uid): bool
6868
{
6969
return in_array($uid, $this->getMemberUIDs());
7070
}
71+
72+
public function overwriteMemberUIDs(array $uids): void
73+
{
74+
$this->entry->setAttribute("memberuid", $uids);
75+
}
7176
}

resources/lib/UnityGroup.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function approveGroup(bool $send_mail = true): void
8181
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_created");
8282
}
8383
// having your own group makes you qualified
84-
$this->getOwner()->setFlag(UserFlag::QUALIFIED, true);
84+
$this->getOwner()->updateIsQualified($send_mail);
8585
}
8686

8787
/**
@@ -188,13 +188,7 @@ public function approveUser(UnityUser $new_user, bool $send_mail = true): void
188188
"org" => $new_user->getOrg(),
189189
]);
190190
}
191-
// being in a group makes you qualified
192-
$new_user->setFlag(
193-
UserFlag::QUALIFIED,
194-
true,
195-
doSendMail: $send_mail,
196-
doSendMailAdmin: false,
197-
);
191+
$new_user->updateIsQualified($send_mail); // being in a group makes you qualified
198192
}
199193

200194
public function denyUser(UnityUser $new_user, bool $send_mail = true): void
@@ -245,6 +239,8 @@ public function removeUser(UnityUser $new_user, bool $send_mail = true): void
245239
"org" => $new_user->getOrg(),
246240
]);
247241
}
242+
// if user is no longer in any PI group, disqualify them
243+
$new_user->updateIsQualified($send_mail);
248244
}
249245

250246
public function newUserRequest(UnityUser $new_user, bool $send_mail = true): void

resources/lib/UnityUser.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,14 @@ public function isInGroup(string $uid, UnityGroup $group): bool
417417
{
418418
return in_array($uid, $group->getMemberUIDs());
419419
}
420+
421+
public function updateIsQualified(bool $send_mail = true)
422+
{
423+
$this->setFlag(
424+
UserFlag::QUALIFIED,
425+
count($this->getPIGroupGIDs()) !== 0,
426+
doSendMail: $send_mail,
427+
doSendMailAdmin: false,
428+
);
429+
}
420430
}

resources/mail/user_flag_added.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php use UnityWebPortal\lib\UserFlag; ?>
22
<?php switch ($data["flag"]):
33
case UserFlag::QUALIFIED: ?>
4-
<?php $this->Subject = "User Activated"; ?>
4+
<?php $this->Subject = "User Qualified"; ?>
55
<p>Hello,</p>
6-
<p>Your account on the UnityHPC Platform has been activated. Your account details are below:</p>
6+
<p>
7+
Your account on the UnityHPC Platform has been qualified.
8+
You should now be able to access UnityHPC Platform services.
9+
Your account details are below:
10+
</p>
711
<p>
812
<strong>Username</strong> <?php echo $data["user"]; ?>
913
<br>

resources/mail/user_flag_removed.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php use UnityWebPortal\lib\UserFlag; ?>
22
<?php switch ($data["flag"]):
33
case UserFlag::QUALIFIED: ?>
4-
<?php $this->Subject = "User Deactivated"; ?>
4+
<?php $this->Subject = "User Disqualified"; ?>
55
<p>Hello,</p>
6-
<p>Your account on the UnityHPC Platform has been deactivated.</p>
6+
<p>
7+
Your account on the UnityHPC Platform has been disqualified.
8+
You should no longer be able to access UnityHPC Platform services.
9+
</p>
10+
<p>In order to be qualified, you must be a PI or be a member of at least one PI group.</p>
711
<p>If you believe this to be a mistake, please reply to this email as soon as possible.</p>
812
<?php break; ?>
913

resources/mail/user_flag_removed_admin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php use UnityWebPortal\lib\UserFlag; ?>
22
<?php switch ($data["flag"]):
33
case UserFlag::QUALIFIED: ?>
4-
<?php $this->Subject = "User Dequalified"; ?>
4+
<?php $this->Subject = "User Disqualified"; ?>
55
<p>Hello,</p>
6-
<p>User "<?php echo $data["user"] ?>" has been dequalified. </p>
6+
<p>User "<?php echo $data["user"] ?>" has been disqualified. </p>
77
<?php break; ?>
88

99
<?php /////////////////////////////////////////////////////////////////////////////////////////// ?>

test/Template.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use PHPUnit\Framework\Attributes\DataProvider;
4+
use TRegx\PhpUnit\DataProviders\DataProvider as TRegxDataProvider;
5+
6+
class FoobarTest extends UnityWebPortalTestCase
7+
{
8+
public static function provider(): TRegxDataProvider
9+
{
10+
return TRegxDataProvider::list("foo", "bar");
11+
}
12+
13+
#[DataProvider("provider")]
14+
public function testFoobar(string $x)
15+
{
16+
$this->assertTrue(true);
17+
}
18+
}

0 commit comments

Comments
 (0)