Add global option to enable or disable API

This commit is contained in:
Robert Curry 2013-02-28 15:38:08 +13:00
parent 0ceaccf30d
commit 5ce3273ee5
3 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,3 @@
<?php
Object::add_extension('SiteConfig', 'RestfulSiteConfig');

View File

@ -76,6 +76,10 @@ class RestfulServer extends Controller {
* Since no $Action url-param is set, all requests are sent here. * Since no $Action url-param is set, all requests are sent here.
*/ */
function index() { function index() {
// if api is disabled globally, don't proceed
if (!SiteConfig::current_site_config()->EnableRESTAPI)
return $this->permissionFailure();
if(!isset($this->urlParams['ClassName'])) return $this->notFound(); if(!isset($this->urlParams['ClassName'])) return $this->notFound();
$className = $this->urlParams['ClassName']; $className = $this->urlParams['ClassName'];
$id = (isset($this->urlParams['ID'])) ? $this->urlParams['ID'] : null; $id = (isset($this->urlParams['ID'])) ? $this->urlParams['ID'] : null;

View File

@ -0,0 +1,21 @@
<?php
/**
* Adds new global settings.
*/
class RestfulSiteConfig extends DataExtension {
function extraStatics($class = null, $extension = null) {
return array(
'db' => array(
'EnableRESTAPI' => 'Boolean'
),
'defaults' => array(
'EnableRESTAPI' => false
)
);
}
function updateCMSFields(FieldList $fields) {
$fields->addFieldToTab('Root.Main', new CheckboxField('EnableRESTAPI', 'Enable the REST API'));
}
}