Skip to content

Commit

Permalink
BUG Move the SubsiteList PJAX request to a dedicated Controller.
Browse files Browse the repository at this point in the history
Currently the request cannot be made if one doesn't have access to the
SubsiteAdmin section, which often happens with subsite-specific admins.
  • Loading branch information
mateusz committed Oct 16, 2013
1 parent fc07486 commit 91cca0c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
13 changes: 0 additions & 13 deletions code/SubsiteAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,4 @@ public function getEditForm($id = null, $fields = null) {
return $form;
}

public function getResponseNegotiator() {
$negotiator = parent::getResponseNegotiator();
$self = $this;
// Register a new callback
$negotiator->setCallback('SubsiteList', function() use(&$self) {
return $self->SubsiteList();
});
return $negotiator;
}

public function SubsiteList() {
return $this->renderWith('SubsiteList');
}
}
38 changes: 38 additions & 0 deletions code/SubsiteXHRController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* Section-agnostic PJAX controller.
*/
class SubsiteXHRController extends LeftAndMain {

/**
* Relax the access permissions, so anyone who has access to any CMS subsite can access this controller.
*/
public function canView($member = null) {
if (parent::canView()) return true;

if (Subsite::all_accessible_sites()->count()>0) return true;

return false;
}

public function getResponseNegotiator() {
$negotiator = parent::getResponseNegotiator();
$self = $this;

// Register a new callback
$negotiator->setCallback('SubsiteList', function() use(&$self) {
return $self->SubsiteList();
});

return $negotiator;
}

/**
* Provide the list of available subsites as a cms-section-agnostic PJAX handler.
*/
public function SubsiteList() {
return $this->renderWith('SubsiteList');
}

}
6 changes: 3 additions & 3 deletions javascript/LeftAndMain_Subsites.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
*/
$('.cms-container .cms-menu-list li a').entwine({
onclick: function(e) {
$('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList');
$('.cms-container').subsiteFetchPjaxFragment('SubsiteXHRController', 'SubsiteList');
this._super(e);
}
});
Expand All @@ -68,7 +68,7 @@
*/
$('.cms-container .SubsiteAdmin .cms-edit-form fieldset.ss-gridfield').entwine({
onreload: function(e) {
$('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList');
$('.cms-container').subsiteFetchPjaxFragment('SubsiteXHRController', 'SubsiteList');
this._super(e);
}
});
Expand All @@ -81,7 +81,7 @@
*/
$('.cms-container .cms-content-fields .subsite-model').entwine({
onadd: function(e) {
$('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList');
$('.cms-container').subsiteFetchPjaxFragment('SubsiteXHRController', 'SubsiteList');
this._super(e);
}
});
Expand Down

0 comments on commit 91cca0c

Please sign in to comment.