API CHANGE: Added canView() to CMSBatchAction so that you could hide certain batch actions from some users. (from r94846)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@96823 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-01-13 00:09:30 +00:00
parent c124dd23fa
commit 27907e4ced
3 changed files with 18 additions and 8 deletions

View File

@ -101,7 +101,7 @@ abstract class CMSBatchAction extends Object {
if($page->$methodName()) $applicableIDs[] = $page->ID; if($page->$methodName()) $applicableIDs[] = $page->ID;
} }
} }
return $applicableIDs; return $applicableIDs;
} }
@ -109,6 +109,13 @@ abstract class CMSBatchAction extends Object {
function getParameterFields() { function getParameterFields() {
return false; return false;
} }
/**
* If you wish to restrict the batch action to some users, overload this function.
*/
function canView() {
return true;
}
} }
/** /**

View File

@ -117,12 +117,14 @@ class CMSBatchActionHandler extends RequestHandler {
foreach($actions as $urlSegment => $actionClass) { foreach($actions as $urlSegment => $actionClass) {
$actionObj = new $actionClass(); $actionObj = new $actionClass();
$actionDef = new ArrayData(array( if($actionObj->canView()) {
"Link" => Controller::join_links($this->Link(), $urlSegment), $actionDef = new ArrayData(array(
"Title" => $actionObj->getActionTitle(), "Link" => Controller::join_links($this->Link(), $urlSegment),
"DoingText" => $actionObj->getDoingText(), "Title" => $actionObj->getActionTitle(),
)); "DoingText" => $actionObj->getDoingText(),
$actionList->push($actionDef); ));
$actionList->push($actionDef);
}
} }
return $actionList; return $actionList;

View File

@ -1027,7 +1027,8 @@ JS;
$forms = array(); $forms = array();
foreach($batchActions as $urlSegment => $batchAction) { foreach($batchActions as $urlSegment => $batchAction) {
if ($fieldset = singleton($batchAction)->getParameterFields()) { $SNG_action = singleton($batchAction);
if ($SNG_action->canView() && $fieldset = $SNG_action->getParameterFields()) {
$formHtml = ''; $formHtml = '';
foreach($fieldset as $field) { foreach($fieldset as $field) {
$formHtml .= $field->Field(); $formHtml .= $field->Field();