mirror of
https://github.com/silverstripe/silverstripe-restfulserver
synced 2024-10-22 14:05:58 +02:00
Add global option to enable or disable API
This commit is contained in:
parent
0ceaccf30d
commit
5ce3273ee5
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
Object::add_extension('SiteConfig', 'RestfulSiteConfig');
|
@ -76,6 +76,10 @@ class RestfulServer extends Controller {
|
||||
* Since no $Action url-param is set, all requests are sent here.
|
||||
*/
|
||||
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();
|
||||
$className = $this->urlParams['ClassName'];
|
||||
$id = (isset($this->urlParams['ID'])) ? $this->urlParams['ID'] : null;
|
||||
|
21
code/RestfulSiteConfig.php
Normal file
21
code/RestfulSiteConfig.php
Normal 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'));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user