示例#1
0
 /**
  * @return string
  * @since 8.1.0
  */
 public function render()
 {
     $r = new \OC_OCS_Result($this->data, $this->statuscode, $this->message);
     $r->setTotalItems($this->itemscount);
     $r->setItemsPerPage($this->itemsperpage);
     return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData());
 }
示例#2
0
文件: sharees.php 项目: gvde/core
 /**
  * Testable search function that does not need globals
  *
  * @param string $search
  * @param string $itemType
  * @param array $shareTypes
  * @param int $page
  * @param int $perPage
  * @return \OC_OCS_Result
  */
 protected function searchSharees($search, $itemType, array $shareTypes, $page, $perPage)
 {
     // Verify arguments
     if ($itemType === null) {
         return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST, 'Missing itemType');
     }
     // Get users
     if (in_array(Share::SHARE_TYPE_USER, $shareTypes)) {
         $this->getUsers($search);
     }
     // Get groups
     if (in_array(Share::SHARE_TYPE_GROUP, $shareTypes)) {
         $this->getGroups($search);
     }
     // Get remote
     if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes)) {
         $this->getRemote($search);
     }
     $response = new \OC_OCS_Result($this->result);
     $response->setItemsPerPage($perPage);
     if (sizeof($this->reachedEndFor) < 3) {
         $response->addHeader('Link', $this->getPaginationLink($page, ['search' => $search, 'itemType' => $itemType, 'shareType' => $shareTypes, 'perPage' => $perPage]));
     }
     return $response;
 }
示例#3
0
 public function testUpdateOtherPermissions()
 {
     $ocs = $this->mockFormatShare();
     $file = $this->getMock('\\OCP\\Files\\File');
     $share = \OC::$server->getShareManager()->newShare();
     $share->setPermissions(\OCP\Constants::PERMISSION_ALL)->setSharedBy($this->currentUser->getUID())->setShareType(\OCP\Share::SHARE_TYPE_USER)->setNode($file);
     $this->request->method('getParam')->will($this->returnValueMap([['permissions', null, '31']]));
     $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
     $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
     $this->shareManager->expects($this->once())->method('updateShare')->with($this->callback(function (\OCP\Share\IShare $share) {
         return $share->getPermissions() === \OCP\Constants::PERMISSION_ALL;
     }))->will($this->returnArgument(0));
     $expected = new \OC_OCS_Result(null);
     $result = $ocs->updateShare(42);
     $this->assertEquals($expected->getMeta(), $result->getMeta());
     $this->assertEquals($expected->getData(), $result->getData());
 }
示例#4
0
文件: api.php 项目: nem0xff/core
 /**
  * respond to a call
  * @param OC_OCS_Result $result
  * @param string $format the format xml|json
  */
 public static function respond($result, $format = 'xml')
 {
     // Send 401 headers if unauthorised
     if ($result->getStatusCode() === API::RESPOND_UNAUTHORISED) {
         header('WWW-Authenticate: Basic realm="Authorisation Required"');
         header('HTTP/1.0 401 Unauthorized');
     }
     foreach ($result->getHeaders() as $name => $value) {
         header($name . ': ' . $value);
     }
     $meta = $result->getMeta();
     $data = $result->getData();
     if (self::isV2(\OC::$server->getRequest())) {
         $statusCode = self::mapStatusCodes($result->getStatusCode());
         if (!is_null($statusCode)) {
             $meta['statuscode'] = $statusCode;
             OC_Response::setStatus($statusCode);
         }
     }
     self::setContentType($format);
     $body = self::renderResult($format, $meta, $data);
     echo $body;
 }
示例#5
0
 /**
  * @param string $message
  */
 function buildResponse($shipped, $data, $code, $message = null)
 {
     $resp = new \OC_OCS_Result($data, $code, $message);
     $resp->addHeader('KEY', 'VALUE');
     return ['shipped' => $shipped, 'response' => $resp, 'app' => $this->getUniqueID('testapp_')];
 }
示例#6
0
 /**
  * @param \OC_OCS_Result $result
  * @param integer $expectedArraySize
  */
 public function assertOcsResult($expectedArraySize, $result)
 {
     $this->assertEquals(100, $result->getStatusCode());
     $data = $result->getData();
     $this->assertTrue(is_array($data));
     $this->assertEquals($expectedArraySize, sizeof($data));
 }
示例#7
0
 /**
  * @param \OC_OCS_Result $ocs
  * @param string $message
  */
 protected function assertOCSError(\OC_OCS_Result $ocs, $message)
 {
     $this->assertSame(Http::STATUS_BAD_REQUEST, $ocs->getStatusCode(), 'Expected status code 400');
     $this->assertSame([], $ocs->getData(), 'Expected that no data is send');
     $meta = $ocs->getMeta();
     $this->assertNotEmpty($meta);
     $this->assertArrayHasKey('message', $meta);
     $this->assertSame($message, $meta['message']);
 }
示例#8
0
 public function testCreateShareGroup()
 {
     $share = $this->getMock('\\OC\\Share20\\IShare');
     $this->shareManager->method('newShare')->willReturn($share);
     $ocs = $this->getMockBuilder('OCA\\Files_Sharing\\API\\Share20OCS')->setConstructorArgs([$this->shareManager, $this->groupManager, $this->userManager, $this->request, $this->rootFolder, $this->urlGenerator, $this->currentUser])->setMethods(['formatShare'])->getMock();
     $this->request->method('getParam')->will($this->returnValueMap([['path', null, 'valid-path'], ['permissions', null, \OCP\Constants::PERMISSION_ALL], ['shareType', '-1', \OCP\Share::SHARE_TYPE_GROUP], ['shareWith', null, 'validGroup']]));
     $userFolder = $this->getMock('\\OCP\\Files\\Folder');
     $this->rootFolder->expects($this->once())->method('getUserFolder')->with('currentUser')->willReturn($userFolder);
     $path = $this->getMock('\\OCP\\Files\\Folder');
     $userFolder->expects($this->once())->method('get')->with('valid-path')->willReturn($path);
     $group = $this->getMock('\\OCP\\IGroup');
     $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true);
     $this->groupManager->method('get')->with('validGroup')->willReturn($group);
     $share->method('setPath')->with($path);
     $share->method('setPermissions')->with(\OCP\Constants::PERMISSION_ALL);
     $share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_GROUP);
     $share->method('setSharedWith')->with($group);
     $share->method('setSharedBy')->with($this->currentUser);
     $expected = new \OC_OCS_Result();
     $result = $ocs->createShare();
     $this->assertEquals($expected->getMeta(), $result->getMeta());
     $this->assertEquals($expected->getData(), $result->getData());
 }
示例#9
0
 /**
  * respond to a call
  * @param OC_OCS_Result $result
  * @param string $format the format xml|json
  */
 public static function respond($result, $format = 'xml')
 {
     // Send 401 headers if unauthorised
     if ($result->getStatusCode() === self::RESPOND_UNAUTHORISED) {
         header('WWW-Authenticate: Basic realm="Authorisation Required"');
         header('HTTP/1.0 401 Unauthorized');
     }
     $response = array('ocs' => array('meta' => $result->getMeta(), 'data' => $result->getData()));
     if ($format == 'json') {
         OC_JSON::encodedPrint($response);
     } else {
         if ($format == 'xml') {
             header('Content-type: text/xml; charset=UTF-8');
             $writer = new XMLWriter();
             $writer->openMemory();
             $writer->setIndent(true);
             $writer->startDocument();
             self::toXML($response, $writer);
             $writer->endDocument();
             echo $writer->outputMemory(true);
         }
     }
 }
示例#10
0
 /**
  * @dataProvider dataGetShare
  */
 public function testGetShare(\OC\Share20\IShare $share, array $result)
 {
     $this->shareManager->expects($this->once())->method('getShareById')->with($share->getId())->willReturn($share);
     $this->userFolder->method('getRelativePath')->will($this->returnArgument(0));
     $this->urlGenerator->method('linkToRouteAbsolute')->willReturn('url');
     $expected = new \OC_OCS_Result($result);
     $this->assertEquals($expected->getData(), $this->ocs->getShare($share->getId())->getData());
 }
示例#11
0
 /**
  * @param \OC_OCS_Result $ocsResult
  * @return JSONResponse
  */
 protected function ocsToJsonResponse(\OC_OCS_Result $ocsResult)
 {
     $response = new JSONResponse(['ocs' => ['meta' => ['status' => 'ok', 'statuscode' => 100, 'message' => null], 'data' => $ocsResult->getData()]], $ocsResult->getStatusCode() === 100 ? Http::STATUS_OK : $ocsResult->getStatusCode());
     $response->setHeaders(array_merge($ocsResult->getHeaders(), ['Content-Type' => 'application/json; charset=utf-8']));
     return $response;
 }
示例#12
0
 /**
  * @dataProvider dataGetShare
  */
 public function testGetShare(\OC\Share20\IShare $share, array $result)
 {
     $ocs = $this->getMockBuilder('OCA\\Files_Sharing\\API\\Share20OCS')->setConstructorArgs([$this->shareManager, $this->groupManager, $this->userManager, $this->request, $this->rootFolder, $this->urlGenerator, $this->currentUser])->setMethods(['canAccessShare'])->getMock();
     $ocs->method('canAccessShare')->willReturn(true);
     $this->shareManager->expects($this->once())->method('getShareById')->with($share->getId())->willReturn($share);
     $userFolder = $this->getMock('OCP\\Files\\Folder');
     $userFolder->method('getRelativePath')->will($this->returnArgument(0));
     $this->rootFolder->method('getUserFolder')->with($share->getShareOwner()->getUID())->willReturn($userFolder);
     $this->urlGenerator->method('linkToRouteAbsolute')->willReturn('url');
     $expected = new \OC_OCS_Result($result);
     $this->assertEquals($expected->getData(), $ocs->getShare($share->getId())->getData());
 }
示例#13
0
文件: api.php 项目: Bullnados/core
 /**
  * @param OC_OCS_Result $result
  * @param string $format
  * @return string
  */
 public static function renderResult($result, $format)
 {
     $response = array('ocs' => array('meta' => $result->getMeta(), 'data' => $result->getData()));
     if ($format == 'json') {
         return OC_JSON::encode($response);
     }
     $writer = new XMLWriter();
     $writer->openMemory();
     $writer->setIndent(true);
     $writer->startDocument();
     self::toXML($response, $writer);
     $writer->endDocument();
     return $writer->outputMemory(true);
 }