Skip to content

Conversation

Hafsa-Naeem
Copy link
Contributor

for #11791

@Hafsa-Naeem Hafsa-Naeem force-pushed the i11791-stable-3_5_0-fix branch 2 times, most recently from 6522192 to 32a431b Compare September 8, 2025 11:05
Copy link
Member

@asmecher asmecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hafsa-Naeem, a few changes to suggest, thanks!

// compute the page wide coverage map
private function loadUserContextPermissions(Enumerable $collection): void
{
$request = Application::get()->getRequest();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the $auxiliaryData pattern already exists in this class to provide information like this, which would avoid us having to create another entanglement with Application::getRequest from the storage layer, which is a pattern I'd like to avoid. Better for calling code to send in the current user via $auxiliaryData. Then we can also avoid the Schema::$currentUserId property; it's a little unclear when that can be expected to contain a value.

// ensure cache has entries for ad hoc lookups
private function loadUserContextMap(array $targetIds): void
{
$targetIds = array_values(array_unique(array_map('intval', $targetIds)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It's better to use first-class callable syntax: intval(...) rather than 'intval')

THEN 0 ELSE 1 END AS manages_all',
[ (int) Role::ROLE_ID_MANAGER, (int) $managerId ]
)
->whereIn('u.user_id', array_map('intval', $targetIds))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, use first-class callable syntax.

/**
* extend $this->managesAllMap for the given manager and target ids
*/
private function buildUserContextManagementMap(int $managerId, array $targetIds): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$targetIds is not clear; call it e.g. $managedUserIds instead.

->get();

foreach ($rows as $r) {
$this->managesAllMap[(int) $r->user_id] = ((int) $r->manages_all) === 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use an exact === test; some DBMS configurations return numeric types as strings.

public string $schema = PKPSchemaService::SCHEMA_USER;

// page scoped cache to check if current user manage all contexts of target user
private array $managesAllMap = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than using a class property that can be set in some (but not all) cases, and which might get left around and accidentally affect re-use of the Schema object, use a local variable in cases where this is useful. (In other circumstances we use properties, but I think those are appropriate because the values are not as arbitrary as they are here -- where they are only relevant to a single user ID.)

@Hafsa-Naeem Hafsa-Naeem force-pushed the i11791-stable-3_5_0-fix branch 2 times, most recently from 56130bb to 9c34b62 Compare September 19, 2025 02:13
@Hafsa-Naeem Hafsa-Naeem force-pushed the i11791-stable-3_5_0-fix branch from 9c34b62 to 10ea169 Compare October 14, 2025 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants