Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[user] Add getSites functions in User class #9102

Merged
merged 6 commits into from
Mar 13, 2024

Conversation

CamilleBeau
Copy link
Contributor

@CamilleBeau CamilleBeau commented Feb 27, 2024

Brief summary of changes

This PR adds 2 functions to the user class. One returns an array of Site objects that the user has access to. The other returns an associative array with the format CenterID => SiteName for all of the sites that the user has access to.

  • Have you updated related documentation?

Testing instructions (if applicable)

Link(s) to related issue(s)

if ($user->hasPermission('user_accounts_multisite')) {
$sites = \Utility::getSiteList(false);
} else {
$sites = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you should be using $user->getStudySites() instead of reimplementing the logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeffersoncasimir getStudySites only includes study sites, but I believe in this case we want all sites that the user has access to

@CamilleBeau
Copy link
Contributor Author

@jeffersoncasimir @driusan (and @ridz1208 because you seem interested in this development) I added 2 functions to the User class:

  1. getSites() that returns an array of Site objects for all sites that the user has
  2. getSitesNamesList() that returns an associative array of centerID => centerName

I'm still trying to set up Docker on my VM to be able to debug the test suites (it was failing yesterday), but I'm trying something out in my last commit.

Copy link
Contributor

@jeffersoncasimir jeffersoncasimir left a comment

Choose a reason for hiding this comment

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

This has been tested and works as expected. Great work!

@jeffersoncasimir jeffersoncasimir added Passed Manual Tests PR has undergone proper testing by at least one peer 26.0.0-bugs Issues that were raised during the release testing for 26.0.0 labels Mar 7, 2024
} else {
$siteLimitQuery = '';
$params = [];
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand why this is necessary.

user_accounts.class.inc already has:

    /**
     * Tells the base class that this page's provisioner can support the
     * HasAnyPermissionOrUserSiteMatch filter.
     *
     * @return ?array of permissions or null
     */
    public function allSitePermissionNames() : ?array
    {
        return ['user_accounts_multisite'];
    }

so shouldn't the HasAnyPermissionOrUserSiteMatch filter take care of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

allSitePermissionNames function takes care of filtering out users who don't belong to one of the user's sites, but this code makes it so that only the user's sites are shown in the "Site" column of the table.
image

With the change from user_accounts.class.inc but without this change, there were empty strings in between commas:
image

@CamilleBeau CamilleBeau changed the title [user_accounts] Limit sites in table filters [user] Add getSites functions in User class Mar 12, 2024
@CamilleBeau
Copy link
Contributor Author

@jeffersoncasimir @driusan I removed all of the user_accounts code, changed the name, and the description. The PR now only includes the 2 functions that can be used elsewhere in the code.

@driusan driusan merged commit df103b6 into aces:main Mar 13, 2024
28 checks passed
@ridz1208 ridz1208 added this to the 26.0.0 milestone Apr 9, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
26.0.0-bugs Issues that were raised during the release testing for 26.0.0 Passed Manual Tests PR has undergone proper testing by at least one peer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants