-
Notifications
You must be signed in to change notification settings - Fork 106
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
FIX CMS permission checks for subsite are now handled in the state context #388
Conversation
…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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break;
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the break
s could be just return null
at this point - although might be confusing in the future.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
I put "Requested Changes" but you could probably convince me there's no changes needed... Except that last one. |
There was a problem hiding this 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!
…nd add break to loop
Do you want to ask for any additional testing by the original reporter? |
Nope, I'd rather merge and make follow ups as necessary |
@ScopeyNZ FYI I've restored the original branch for next time we pick this issue up |
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 fromLeftAndMainSubsites
so I'm OK with it.Fixes #358