From 9e21fb8a4a0770ab753cf826d935d1d7e3cc169d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 4 Jun 2012 10:22:48 +0200 Subject: [PATCH] API CHANGE Moved SapphireSoapServer and SOAPModelAccess into its own module at https://github.com/silverstripe/silverstripe-soapserver (fixes #7282) --- api/SOAPModelAccess.php | 249 --------------------------- api/SapphireSoapServer.php | 103 ----------- api/SapphireSoapServer_wsdl.ss | 46 ----- docs/en/changelogs/3.0.0.md | 3 +- tests/api/SapphireSoapServerTest.php | 31 ---- tests/api/SoapModelAccessTest.php | 162 ----------------- tests/api/SoapModelAccessTest.yml | 38 ---- 7 files changed, 2 insertions(+), 630 deletions(-) delete mode 100644 api/SOAPModelAccess.php delete mode 100644 api/SapphireSoapServer.php delete mode 100644 api/SapphireSoapServer_wsdl.ss delete mode 100644 tests/api/SapphireSoapServerTest.php delete mode 100644 tests/api/SoapModelAccessTest.php delete mode 100644 tests/api/SoapModelAccessTest.yml diff --git a/api/SOAPModelAccess.php b/api/SOAPModelAccess.php deleted file mode 100644 index ba7cf34e6..000000000 --- a/api/SOAPModelAccess.php +++ /dev/null @@ -1,249 +0,0 @@ - - * $c = new SoapClient('http://mysite.com/soap/v1/wsdl'); - * echo $c->getXML("MyClassName", 99); // gets record #99 as xml - * - * - * Usage - Updating a record: - * - * $c = new SoapClient('http://mysite.com/soap/v1/wsdl'); - * $data = array('MyProperty' => 'MyUpdatedValue'); - * echo $c->putXML("MyClassName", 99, null, $data); - * - * - * Usage - Creating a record: - * - * $c = new SoapClient('http://mysite.com/soap/v1/wsdl'); - * $data = array('MyProperty' => 'MyValue'); - * echo $c->putXML("MyClassName", null, null, $data); - * - * - * Usage - Creating a record: - * - * $c = new SoapClient('http://mysite.com/soap/v1/wsdl'); - * echo $c->deleteXML("MyClassName"); - * - * - * @todo Test relation methods - * - * @package framework - * @subpackage api - */ -class SOAPModelAccess extends SapphireSoapServer { - - public static $methods = array( - 'getXML' => array( - 'class' => 'string', - 'id' => 'int', - 'relation' => 'string', - '_returns' => 'string', - ), - 'getJSON' => array( - 'class' => 'string', - 'id' => 'int', - 'relation' => 'string', - '_returns' => 'string', - ), - 'putXML' => array( - 'class' => 'string', - 'id' => 'int', - 'relation' => 'string', - 'data' => 'string', - 'username' => 'string', - 'password' => 'string', - '_returns' => 'boolean', - ), - 'putJSON' => array( - 'class' => 'string', - 'id' => 'int', - 'relation' => 'string', - '_returns' => 'boolean', - ), - ); - - function Link($action = null) { - return Controller::join_links("soap/v1/", $action); - } - - /** - * Used to emulate RESTful GET requests with XML data. - * - * @param string $class - * @param Number $id - * @param string $relation Relation name - * @return string - */ - function getXML($class, $id, $relation = false, $username = null, $password = null) { - $this->authenticate($username, $password); - - $response = Director::test( - $this->buildRestfulURL($class, $id, $relation, 'xml'), - null, - null, - 'GET' - ); - - return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody(); - } - - /** - * Used to emulate RESTful GET requests with JSON data. - * - * @param string $class - * @param Number $id - * @param string $relation Relation name - * @param string $username - * @param string $password - * @return string - */ - function getJSON($class, $id, $relation = false, $username = null, $password = null) { - $this->authenticate($username, $password); - - $response = Director::test( - $this->buildRestfulURL($class, $id, $relation, 'json'), - null, - null, - 'GET' - ); - - return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody(); - } - - /** - * Used to emulate RESTful POST and PUT requests with XML data. - * - * @param string $class - * @param Number $id - * @param string $relation Relation name - * @param array $data - * @param string $username - * @param string $password - * @return string - */ - function putXML($class, $id = false, $relation = false, $data, $username = null, $password = null) { - $this->authenticate($username, $password); - - $response = Director::test( - $this->buildRestfulURL($class, $id, $relation, 'xml'), - array(), - null, - ($id) ? 'PUT' : 'POST', - $data - ); - - return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody(); - } - - /** - * Used to emulate RESTful POST and PUT requests with JSON data. - * - * @param string $class - * @param Number $id - * @param string $relation Relation name - * @param array $data - * @param string $username - * @param string $password - * @return string - */ - function putJSON($class = false, $id = false, $relation = false, $data, $username = null, $password = null) { - $this->authenticate($username, $password); - - $response = Director::test( - $this->buildRestfulURL($class, $id, $relation, 'json'), - array(), - null, - ($id) ? 'PUT' : 'POST', - $data - ); - - return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody(); - } - - /** - * Used to emulate RESTful DELETE requests. - * - * @param string $class - * @param Number $id - * @param string $relation Relation name - * @param string $username - * @param string $password - * @return string - */ - function deleteXML($class, $id, $relation = false, $username = null, $password = null) { - $this->authenticate($username, $password); - - $response = Director::test( - $this->buildRestfulURL($class, $id, $relation, 'xml'), - null, - null, - 'DELETE' - ); - - return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody(); - } - - /** - * Used to emulate RESTful DELETE requests. - * - * @param string $class - * @param Number $id - * @param string $relation Relation name - * @param string $username - * @param string $password - * @return string - */ - function deleteJSON($class, $id, $relation = false, $username = null, $password = null) { - $this->authenticate($username, $password); - - $response = Director::test( - $this->buildRestfulURL($class, $id, $relation, 'json'), - null, - null, - 'DELETE' - ); - - return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody(); - } - - /** - * Faking an HTTP Basicauth login in the PHP environment - * that RestfulServer can pick up. - * - * @param string $username Username - * @param string $password Plaintext password - */ - protected function authenticate($username, $password) { - if(is_string($username)) $_SERVER['PHP_AUTH_USER'] = $username; - if(is_string($password)) $_SERVER['PHP_AUTH_PW'] = $password; - } - - /** - * @param string $class - * @param Number $id - * @param string $relation - * @param string $extension - * @return string - */ - protected function buildRestfulURL($class, $id, $relation, $extension) { - $url = "api/v1/{$class}"; - if($id) $url .= "/{$id}"; - if($relation) $url .= "/{$relation}"; - if($extension) $url .= "/.{$extension}"; - return $url; - } - - /** - * @param SS_HTTPResponse $response - * @return string XML string containing the HTTP error message - */ - protected function getErrorMessage($response) { - return "getStatusCode() . "\">" . $response->getStatusDescription() . ""; - } -} - diff --git a/api/SapphireSoapServer.php b/api/SapphireSoapServer.php deleted file mode 100644 index b871c048f..000000000 --- a/api/SapphireSoapServer.php +++ /dev/null @@ -1,103 +0,0 @@ - 'xsd:int', - 'boolean' => 'xsd:boolean', - 'string' => 'xsd:string', - 'binary' => 'xsd:base64Binary', - ); - - static $allowed_actions = array( - 'index', - 'wsdl' - ); - - function wsdl() { - $this->getResponse()->addHeader("Content-Type", "text/xml"); - - return array(); - } - - /** - * @return string - */ - function getWSDLURL() { - return Director::absoluteBaseURLWithAuth() . $this->Link() . "wsdl"; - } - - /** - * @return SS_List Collection of ArrayData elements describing - * the method (keys: 'Name', 'Arguments', 'ReturnType') - */ - function Methods() { - $methods = array(); - - foreach($this->stat('methods') as $methodName => $arguments) { - $returnType = $arguments['_returns']; - unset($arguments['_returns']); - - $processedArguments = array(); - foreach($arguments as $argument => $type) { - $processedArguments[] = new ArrayData(array( - "Name" => $argument, - "Type" => self::$xsd_types[$type], - )); - - } - $methods[] = new ArrayData(array( - "Name" => $methodName, - "Arguments" => new ArrayList($processedArguments), - "ReturnType" => self::$xsd_types[$returnType], - )); - } - - return new ArrayList($methods); - } - - /** - * @return string - */ - function TargetNamespace() { - return Director::absoluteBaseURL(); - } - - /** - * @return string - */ - function ServiceURL() { - return Director::absoluteBaseURLWithAuth() . $this->class . '/'; - } - - function index() { - $wsdl = $this->getViewer('wsdl')->process($this); - $wsdlFile = TEMP_FOLDER . '/sapphire-wsdl-' . $this->class; - $fh = fopen($wsdlFile, 'w'); - fwrite($fh, $wsdl); - fclose($fh); - - $s = new SoapServer($wsdlFile, array('cache_wsdl' => WSDL_CACHE_NONE)); - $s->setClass($this->class); - $s->handle(); - } -} - - diff --git a/api/SapphireSoapServer_wsdl.ss b/api/SapphireSoapServer_wsdl.ss deleted file mode 100644 index e8e8acffe..000000000 --- a/api/SapphireSoapServer_wsdl.ss +++ /dev/null @@ -1,46 +0,0 @@ - - - <% loop Methods %> - - <% loop Arguments %> - - <% end_loop %> - - - - - <% end_loop %> - - - <% loop Methods %> - - - - - <% end_loop %> - - - - <% loop Methods %> - - - - - - - - - - <% end_loop %> - - - - - - - - diff --git a/docs/en/changelogs/3.0.0.md b/docs/en/changelogs/3.0.0.md index c8b9da46e..2f687145b 100644 --- a/docs/en/changelogs/3.0.0.md +++ b/docs/en/changelogs/3.0.0.md @@ -520,7 +520,8 @@ See [module on github](https://github.com/silverstripe/silverstripe-widgets). ### Moved `RestfulServer` and `SapphireSoapServer` API into new modules### -See ["restfulserver"] and ["soapserver"] modules on github. +See ["restfulserver"](https://github.com/silverstripe/silverstripe-restfulserver) +and ["soapserver"](https://github.com/silverstripe/silverstripe-soapserver) modules on github. ### Moved `Translatable` extension into new 'translatable' module ### diff --git a/tests/api/SapphireSoapServerTest.php b/tests/api/SapphireSoapServerTest.php deleted file mode 100644 index b4c2d5f38..000000000 --- a/tests/api/SapphireSoapServerTest.php +++ /dev/null @@ -1,31 +0,0 @@ -get('SapphireSoapServerTest_MyServer/wsdl'); - - $this->assertEquals( - $response->getHeader('Content-Type'), - 'text/xml', - 'wsdl request returns with correct XML content type' - ); - } -} - -/** - * @package framework - * @subpackage tests - */ -class SapphireSoapServerTest_MyServer extends SapphireSoapServer { - - function Link($action = null) { - return Controller::join_links('SapphireSoapServerTest_MyServer', $action); - } -} diff --git a/tests/api/SoapModelAccessTest.php b/tests/api/SoapModelAccessTest.php deleted file mode 100644 index 4178503bb..000000000 --- a/tests/api/SoapModelAccessTest.php +++ /dev/null @@ -1,162 +0,0 @@ -getTestSoapConnection(); - $soapResponse = $c->getXML( - "SoapModelAccessTest_Comment", - 1, - null, - null, - 'editor@test.com', - 'editor' - ); - - $responseArr = Convert::xml2array($soapResponse); - $this->assertEquals($responseArr['ID'], 1); - $this->assertEquals($responseArr['Name'], 'Joe'); - } - - public function testAuthenticatedPUT() { - $comment1 = $this->objFromFixture('SoapModelAccessTest_Comment', 'comment1'); - $comment1ID = $comment1->ID; - - // test wrong details - $c = $this->getTestSoapConnection(); - - $updateXML = << - - $comment1ID - Jimmy - -XML; - - $soapResponse = $c->putXML( - "SoapModelAccessTest_Comment", - $comment1->ID, - null, - $updateXML, - 'editor@test.com', - 'wrongpassword' - ); - $this->assertEquals('Unauthorized', $soapResponse); - - // Check that the details weren't saved - $c = $this->getTestSoapConnection(); - $soapResponse = $c->getXML("SoapModelAccessTest_Comment", $comment1->ID, null, 'editor@test.com', 'editor'); - $responseArr = Convert::xml2array($soapResponse); - $this->assertEquals($comment1->ID, $responseArr['ID']); - $this->assertEquals('Joe', $responseArr['Name']); - - // Now do an update with the right password - $soapResponse = $c->putXML( - "SoapModelAccessTest_Comment", - $comment1->ID, - null, - $updateXML, - 'editor@test.com', - 'editor' - ); - - // Check that the details were saved - $c = $this->getTestSoapConnection(); - $soapResponse = $c->getXML("SoapModelAccessTest_Comment", $comment1->ID, null, 'editor@test.com', 'editor'); - $responseArr = Convert::xml2array($soapResponse); - $this->assertEquals($comment1->ID, $responseArr['ID']); - $this->assertEquals('Jimmy', $responseArr['Name']); - } - - public function testAuthenticatedPOST() { - /* - $c = $this->getTestSoapConnection(); - $soapResponse = $c->getXML( - "SoapModelAccessTest_Comment", - null, - null, - 'editor@test.com', - 'editor' - ); - Debug::message($soapResponse); - $responseArr = Convert::xml2array($soapResponse); - Debug::show($responseArr); - $this->assertEquals($responseArr['Name'], 'Created Name'); - */ - } -} - -/** - * Everybody can view comments, logged in members in the "users" group can create comments, - * but only "editors" can edit or delete them. - * - */ -class SoapModelAccessTest_Comment extends DataObject implements PermissionProvider,TestOnly { - - static $api_access = true; - - static $db = array( - "Name" => "Varchar(255)", - "Comment" => "Text" - ); - - static $has_many = array(); - - public function providePermissions(){ - return array( - 'EDIT_Comment' => 'Edit Comment Objects', - 'CREATE_Comment' => 'Create Comment Objects', - 'DELETE_Comment' => 'Delete Comment Objects', - ); - } - - public function canView($member = null) { - return true; - } - - public function canEdit($member = null) { - return Permission::checkMember($member, 'EDIT_Comment'); - } - - public function canDelete($member = null) { - return Permission::checkMember($member, 'DELETE_Comment'); - } - - public function canCreate($member = null) { - return Permission::checkMember($member, 'CREATE_Comment'); - } - -} - -class SoapModelAccessTest_Page extends DataObject implements TestOnly { - - static $api_access = false; - - static $db = array( - 'Title' => 'Text', - 'Content' => 'HTMLText', - ); -} diff --git a/tests/api/SoapModelAccessTest.yml b/tests/api/SoapModelAccessTest.yml deleted file mode 100644 index 11b4f7b49..000000000 --- a/tests/api/SoapModelAccessTest.yml +++ /dev/null @@ -1,38 +0,0 @@ -SoapModelAccessTest_Comment: - comment1: - Name: Joe - Comment: This is a test comment -Member: - editor: - FirstName: Editor - Email: editor@test.com - Password: editor - user: - FirstName: User - Email: user@test.com - Password: user -Group: - editorgroup: - Title: Editors - Code: editors - Members: =>Member.editor - usergroup: - Title: Users - Code: users - Members: =>Member.user -Permission: - perm1: - Code: CREATE_Comment - Group: =>Group.usergroup - perm3: - Code: EDIT_Comment - Group: =>Group.editorgroup - perm4: - Code: DELETE_Comment - Group: =>Group.editorgroup - perm5: - Code: CREATE_Comment - Group: =>Group.editorgroup -SoapModelAccessTest_Page: - page1: - Title: Testpage without API Access \ No newline at end of file