Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

FIX CMS permission checks for subsite are now handled in the state context #388

Merged

Conversation

robbieaverill
Copy link
Contributor

We now check the subsite state for the context and validate it against the current member's group permissions using the SilverStripe ORM relationships instead of using SQL queries.

More granular permission checks e.g. canView etc are still up to data models to define and handle.

I think this is semver patch safe. I've used a workaround in LeftAndMainSubsites::canAccess to allow a passed member argument without adding it to the method signature (not semver safe).

Also the removal of SubsiteXHRControllerTest may be a little semver unsafe, but it falls back to calling the method from LeftAndMainSubsites so I'm OK with it.

Fixes #358

…ntext

We now check the subsite state for the context and validate it against the current member's
group permissions using the SilverStripe ORM relationships instead of using SQL queries.

More granular permission checks e.g. canView etc are still up to data models to define and
handle.
*/
public function canAccess()
{
// Allow us to accept a Member object passed in as an argument without breaking semver
$passedMember = func_get_args() ? func_get_arg(0) : null;
Copy link
Member

Choose a reason for hiding this comment

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

func_num_args?

}
// Check whether we have any subsites
if (!$subsites->exists()) {
return $accessibleSubsites;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be an empty set here or return $subsites?

Copy link
Member

Choose a reason for hiding this comment

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

Also, won't it always return true for ->exists when including the main site?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah you're right since it returns an ArrayList which includes a stub for the main site. I think I wrote this when it was a DataList (which wouldn't). I've removed it anyway, it's not needed


if ($canAccess === false) {
// Explicitly denied
continue;
Copy link
Member

Choose a reason for hiding this comment

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

We spoke about this - but I would consider the idea of looping groups here. Pseudo:

foreach ($groups as $group) {
	if ($group->accessAllSubsites) {
		return $allSites;
    }
	$accessibleSites->merge($group->accessibleSites)
}

The only reason I suggest it is that I feel it's likely there's less groups than subsites and therefore less loops.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part is a wrapper that's calling deeper logic in LeftAndMainSubsites::canAccess so it's not dealing with groups directly at this point

// Check if any of the current user's groups have been given explicit access to the current subsite
$groupSubsiteIds = $group->Subsites()->column('ID');
if (in_array($currentSubsiteId, $groupSubsiteIds)) {
$allowedInSubsite = true;
Copy link
Member

Choose a reason for hiding this comment

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

break;?

Copy link
Member

Choose a reason for hiding this comment

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

Also the breaks could be just return null at this point - although might be confusing in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'd considered that. I think the reason I left it like this is because the two if statements contribute to the same criteria of "is allowed in subsite" so I left them separate for readability. That OK?

Copy link
Member

Choose a reason for hiding this comment

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

Sure - I'm just happy the break is in now :)

@ScopeyNZ
Copy link
Member

ScopeyNZ commented Aug 24, 2018

I put "Requested Changes" but you could probably convince me there's no changes needed... Except that last one.

Copy link
Contributor

@raissanorth raissanorth left a comment

Choose a reason for hiding this comment

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

Really like the code quality changes you made such as using create::, fixing imports, using namespaces and === where appropriate!

@ScopeyNZ
Copy link
Member

Do you want to ask for any additional testing by the original reporter?

@robbieaverill
Copy link
Contributor Author

Nope, I'd rather merge and make follow ups as necessary

@robbieaverill
Copy link
Contributor Author

@ScopeyNZ FYI I've restored the original branch for next time we pick this issue up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants