Skip to content

Commit c8b6763

Browse files
committed
#11087 remove UserUserGroupMastheadStatus, consider UserMastheadStatus
1 parent 8970716 commit c8b6763

File tree

6 files changed

+63
-97
lines changed

6 files changed

+63
-97
lines changed

classes/invitation/invitations/userRoleAssignment/handlers/api/UserRoleAssignmentReceiveController.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use PKP\invitation\invitations\userRoleAssignment\UserRoleAssignmentInvite;
3030
use PKP\security\authorization\AnonymousUserPolicy;
3131
use PKP\security\authorization\UserRequiredPolicy;
32-
use PKP\userGroup\relationships\enums\UserUserGroupMastheadStatus;
3332
use PKPRequest;
3433
use Validation;
3534

@@ -126,9 +125,7 @@ public function finalize(Request $illuminateRequest): JsonResponse
126125
$userGroupHelper->userGroupId,
127126
$effectiveDateStart,
128127
$userGroupHelper->dateEnd,
129-
isset($userGroupHelper->masthead) && $userGroupHelper->masthead
130-
? UserUserGroupMastheadStatus::STATUS_ON
131-
: UserUserGroupMastheadStatus::STATUS_OFF
128+
(isset($userGroupHelper->masthead) && $userGroupHelper->masthead)
132129
);
133130
}
134131

classes/user/Collector.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @file classes/user/Collector.php
45
*
@@ -30,7 +31,7 @@
3031
use PKP\facades\Locale;
3132
use PKP\identity\Identity;
3233
use PKP\plugins\Hook;
33-
use PKP\userGroup\relationships\enums\UserUserGroupMastheadStatus;
34+
use PKP\user\enums\UserMastheadStatus;
3435
use PKP\userGroup\relationships\enums\UserUserGroupStatus;
3536

3637
/**
@@ -80,7 +81,7 @@ class Collector implements CollectorInterface
8081
public ?int $count = null;
8182
public ?int $offset = null;
8283
public UserUserGroupStatus $userUserGroupStatus = UserUserGroupStatus::STATUS_ACTIVE;
83-
public UserUserGroupMastheadStatus $userUserGroupMastheadStatus = UserUserGroupMastheadStatus::STATUS_ALL;
84+
public UserMastheadStatus $userMastheadStatus = UserMastheadStatus::STATUS_ALL;
8485

8586
/**
8687
* Constructor
@@ -281,9 +282,9 @@ public function filterByUserUserGroupStatus(UserUserGroupStatus $userUserGroupSt
281282
/**
282283
* Filter by user's masthead status for the given role
283284
*/
284-
public function filterByUserUserGroupMastheadStatus(UserUserGroupMastheadStatus $userUserGroupMastheadStatus): self
285+
public function filterByUserMastheadStatus(UserMastheadStatus $userMastheadStatus): self
285286
{
286-
$this->userUserGroupMastheadStatus = $userUserGroupMastheadStatus;
287+
$this->userMastheadStatus = $userMastheadStatus;
287288
return $this;
288289
}
289290

@@ -481,7 +482,7 @@ protected function buildUserGroupFilter(Builder $query): self
481482
$this->roleIds === null &&
482483
$this->contextIds === null &&
483484
$this->workflowStageIds === null &&
484-
$this->userUserGroupMastheadStatus === UserUserGroupMastheadStatus::STATUS_ALL) {
485+
$this->userMastheadStatus === UserMastheadStatus::STATUS_ALL) {
485486

486487
return $this;
487488
}
@@ -524,21 +525,21 @@ protected function buildUserGroupFilter(Builder $query): self
524525
->where('uug.date_end', '<=', $currentDateTime)
525526
)
526527
->when(
527-
$this->userUserGroupMastheadStatus === UserUserGroupMastheadStatus::STATUS_NULL,
528+
$this->userMastheadStatus === UserMastheadStatus::STATUS_NULL,
528529
fn (Builder $subQuery) =>
529530
$subQuery->whereNull('uug.masthead')
530531
)
531532
->when(
532-
$this->userUserGroupMastheadStatus === UserUserGroupMastheadStatus::STATUS_ON,
533+
$this->userMastheadStatus === UserMastheadStatus::STATUS_ON,
533534
fn (Builder $subQuery) =>
534535
$subQuery->where('ug.masthead', 1)
535536
->where('uug.masthead', 1)
536537
)
537538
->when(
538-
$this->userUserGroupMastheadStatus === UserUserGroupMastheadStatus::STATUS_OFF,
539+
$this->userMastheadStatus === UserMastheadStatus::STATUS_OFF,
539540
fn (Builder $subQuery) =>
540541
$subQuery->where('ug.masthead', 0)
541-
->orWhere('uug.masthead', 0)
542+
->orWhere('uug.masthead', 1)
542543
->orWhereNull('uug.masthead')
543544
);
544545

@@ -610,19 +611,19 @@ protected function buildExcludedSubmissionStagesFilter(Builder $query): self
610611
->where('uug.date_end', '<=', $currentDateTime)
611612
)
612613
->when(
613-
$this->userUserGroupMastheadStatus === UserUserGroupMastheadStatus::STATUS_NULL,
614+
$this->userMastheadStatus === UserMastheadStatus::STATUS_NULL,
614615
fn (Builder $query) =>
615616
$query->whereNull('uug.masthead')
616617
)
617618
->when(
618-
$this->userUserGroupMastheadStatus === UserUserGroupMastheadStatus::STATUS_ON,
619+
$this->userMastheadStatus === UserMastheadStatus::STATUS_ON,
619620
fn (Builder $query) =>
620621
$query->where('uug.masthead', 1)
621622
)
622623
->when(
623-
$this->userUserGroupMastheadStatus === UserUserGroupMastheadStatus::STATUS_OFF,
624+
$this->userMastheadStatus === UserMastheadStatus::STATUS_OFF,
624625
fn (Builder $query) =>
625-
$query->where('uug.masthead', 0)
626+
$query->where('uug.masthead', 1)
626627
)
627628
);
628629
return $this;
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* @file classes/user/enums/UserMastheadStatus.php
5+
*
6+
* Copyright (c) 2024-2025 Simon Fraser University
7+
* Copyright (c) 2024-2025 John Willinsky
8+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
9+
*
10+
* @class UserMastheadStatus
11+
*
12+
* @brief Enumeration for user masthead statuses
13+
*/
14+
15+
namespace PKP\user\enums;
16+
17+
enum UserMastheadStatus: string
18+
{
19+
case STATUS_NULL = 'null'; // Users that have an undefined masthead
20+
case STATUS_ON = 'on'; // Users that will be displayed on masthead
21+
case STATUS_OFF = 'off'; // Users that will not be displayed on masthead
22+
case STATUS_ALL = 'all'; // Help and default status to considering all users, no matter what masthead status they have
23+
24+
/**
25+
* These statuses are connected with both, user_group and user_user_group masthead column.
26+
*
27+
* Direct after the first upgrade to 3.5 or next release, all active users in user groups
28+
* that are not per default on masthead will first have STATUS_NULL. Also, when a review role
29+
* is assigned to a user using the old UserForm under 'Administration'.
30+
*
31+
* When filtering users by STATUS_OFF (to get the users that will not be displayed on masthead),
32+
* also the users with STATUS_NULL in user_user_groups table will be considered (because they are also not displayed on masthead).
33+
*
34+
* If a user group is on masthead, the user_user_group's masthead column defines
35+
* if the user having that group will be displayed on masthead.
36+
* If a user group is not on masthead, the users having that group will not be displayed,
37+
* no matter what user_user_group's masthead column contains.
38+
*/
39+
}

classes/userGroup/Repository.php

+8-38
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use PKP\security\Role;
2929
use PKP\services\PKPSchemaService;
3030
use PKP\site\SiteDAO;
31-
use PKP\userGroup\relationships\enums\UserUserGroupMastheadStatus;
31+
use PKP\user\enums\UserMastheadStatus;
3232
use PKP\userGroup\relationships\enums\UserUserGroupStatus;
3333
use PKP\userGroup\relationships\UserGroupStage;
3434
use PKP\userGroup\relationships\UserUserGroup;
@@ -257,41 +257,18 @@ public function userOnMasthead(int $userId, ?int $userGroupId = null): bool
257257
* Update UserUserGroup masthead status for a UserGroup the user is currently active in
258258
*
259259
*/
260-
public function updateUserUserGroupMastheadStatus(int $userId, int $userGroupId, UserUserGroupMastheadStatus $mastheadStatus): void
260+
public function updateUserUserGroupMasthead(int $userId, int $userGroupId, bool $masthead): void
261261
{
262-
$masthead = match ($mastheadStatus) {
263-
UserUserGroupMastheadStatus::STATUS_ON => 1,
264-
UserUserGroupMastheadStatus::STATUS_OFF => 0,
265-
default => null
266-
};
267262
UserUserGroup::query()
268263
->withUserId($userId)
269264
->withUserGroupIds([$userGroupId])
270265
->withActive()
271266
->update(['masthead' => $masthead]);
272267

273268
$userGroup = UserGroup::find($userGroupId);
274-
self::forgetEditorialCache($userGroup->contextId);
275-
}
276-
277-
/**
278-
* Get UserUserGroup masthead status for a UserGroup the user is currently active in
279-
*
280-
*/
281-
public function getUserUserGroupMastheadStatus(int $userId, int $userGroupId): UserUserGroupMastheadStatus
282-
{
283-
$masthead = UserUserGroup::query()
284-
->withUserId($userId)
285-
->withUserGroupIds([$userGroupId])
286-
->withActive()
287-
->pluck('masthead')
288-
->first();
289-
290-
return match ($masthead) {
291-
true => UserUserGroupMastheadStatus::STATUS_ON,
292-
false => UserUserGroupMastheadStatus::STATUS_OFF,
293-
default => UserUserGroupMastheadStatus::STATUS_NULL,
294-
};
269+
if ($userGroup?->masthead) {
270+
self::forgetEditorialCache($userGroup->contextId);
271+
}
295272
}
296273

297274
/**
@@ -317,7 +294,7 @@ public function assignUserToGroup(
317294
int $userGroupId,
318295
?string $startDate = null,
319296
?string $endDate = null,
320-
?UserUserGroupMastheadStatus $mastheadStatus = null
297+
?bool $masthead = null
321298
): ?UserUserGroup {
322299
if ($endDate && !Carbon::parse($endDate)->isFuture()) {
323300
return null;
@@ -330,15 +307,8 @@ public function assignUserToGroup(
330307
return null;
331308
}
332309

333-
// Determine masthead status
334-
$masthead = match ($mastheadStatus) {
335-
UserUserGroupMastheadStatus::STATUS_ON => true,
336-
UserUserGroupMastheadStatus::STATUS_OFF => false,
337-
default => null,
338-
};
339-
340310
// Clear editorial masthead cache if a new user is assigned to a masthead role
341-
if ($userGroup->masthead) {
311+
if ($userGroup->masthead && $masthead) {
342312
self::forgetEditorialCache($userGroup->contextId);
343313
}
344314

@@ -600,7 +570,7 @@ public function getMastheadUserIdsByRoleIds(array $mastheadRoles, int $contextId
600570
->filterByContextIds([$contextId])
601571
->filterByUserGroupIds($mastheadRoleIds)
602572
->filterByUserUserGroupStatus($userUserGroupStatus)
603-
->filterByUserUserGroupMastheadStatus(UserUserGroupMastheadStatus::STATUS_ON)
573+
->filterByUserMastheadStatus(UserMastheadStatus::STATUS_ON)
604574
->orderBy(
605575
$usersCollector::ORDERBY_FAMILYNAME,
606576
$usersCollector::ORDER_DIR_ASC,

classes/userGroup/relationships/enums/UserUserGroupMastheadStatus.php

-36
This file was deleted.

controllers/grid/settings/user/form/UserForm.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use APP\template\TemplateManager;
2222
use PKP\form\Form;
2323
use PKP\security\Role;
24-
use PKP\userGroup\relationships\enums\UserUserGroupMastheadStatus;
2524
use PKP\userGroup\relationships\UserUserGroup;
2625
use PKP\userGroup\UserGroup;
2726

@@ -190,11 +189,7 @@ function ($userGroupId) use ($reviewerUserGroupIds) {
190189
)
191190
->each(
192191
function ($userGroupId) use ($mastheadUserGroupIds) {
193-
$masthead = match (in_array($userGroupId, $mastheadUserGroupIds)) {
194-
true => UserUserGroupMastheadStatus::STATUS_ON,
195-
false => UserUserGroupMastheadStatus::STATUS_OFF
196-
};
197-
Repo::userGroup()->updateUserUserGroupMastheadStatus($this->userId, $userGroupId, $masthead);
192+
Repo::userGroup()->updateUserUserGroupMasthead($this->userId, $userGroupId, in_array($userGroupId, $mastheadUserGroupIds));
198193
}
199194
);
200195
}

0 commit comments

Comments
 (0)