BUGFIX: If you log into a subsite that you don't have access to on a section that you don't have access to, redirect to both the section and the subsite that you can access.

quote> BUGFIX: Fixed SiteConfig selection for subsites. (from r90019)
This commit is contained in:
Tom Rix 2010-03-01 21:39:19 +00:00
parent df1eb95a2a
commit 8049ead131
2 changed files with 21 additions and 3 deletions

View File

@ -117,7 +117,6 @@ class LeftAndMainSubsites extends Extension {
public function alternateAccessCheck() { public function alternateAccessCheck() {
$className = $this->owner->class; $className = $this->owner->class;
// Switch to the subsite of the current page // Switch to the subsite of the current page
if ($this->owner->class == 'CMSMain' && $currentPage = $this->owner->currentPage()) { if ($this->owner->class == 'CMSMain' && $currentPage = $this->owner->currentPage()) {
if (Subsite::currentSubsiteID() != $currentPage->SubsiteID) { if (Subsite::currentSubsiteID() != $currentPage->SubsiteID) {
@ -133,8 +132,24 @@ class LeftAndMainSubsites extends Extension {
return true; return true;
} }
if(!$sites) return null; // Switch to a different top-level menu item
$menu = CMSMenu::get_menu_items();
foreach($menu as $candidate) {
if($candidate->controller != $this->owner->class) {
$sites = Subsite::accessible_sites("CMS_ACCESS_{$candidate->controller}")->toDropdownMap();
if($sites && !isset($sites[Subsite::currentSubsiteID()])) {
$siteIDs = array_keys($sites);
Subsite::changeSubsite($siteIDs[0]);
$cClass = $candidate->controller;
$cObj = new $cClass();
Director::redirect($cObj->Link());
return null;
}
}
}
// If all of those fail, you really don't have access to the CMS
return null; return null;
} }

View File

@ -19,7 +19,10 @@ class SiteConfigSubsites extends DataObjectDecorator {
if(Subsite::$disable_subsite_filter) return; if(Subsite::$disable_subsite_filter) return;
// If you're querying by ID, ignore the sub-site - this is a bit ugly... // If you're querying by ID, ignore the sub-site - this is a bit ugly...
if (!$query->where || (!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]))) { if (!$query->where || (
!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]) &&
!preg_match('/\.?(\'|"|`|)SubsiteID(\'|"|`|)( ?)=/', $query->where[0])
)) {
if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID; if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else $subsiteID = (int)Subsite::currentSubsiteID(); else $subsiteID = (int)Subsite::currentSubsiteID();