Skip to content

Commit 6acdf9b

Browse files
committed
Properly set the status text in the ocs response for v2 calls - fixes owncloud/notifications#103
1 parent b5a2f86 commit 6acdf9b

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

lib/private/AppFramework/Http/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
120120
*/
121121
public function __construct(array $vars= [],
122122
ISecureRandom $secureRandom = null,
123-
IConfig $config,
123+
IConfig $config = null,
124124
CsrfTokenManager $csrfTokenManager = null,
125125
$stream = 'php://input') {
126126
$this->inputStream = $stream;

lib/public/AppFramework/Http/OCSResponse.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
*/
3030

3131
namespace OCP\AppFramework\Http;
32-
33-
use OCP\AppFramework\Http;
32+
use OC\OCS\Result;
3433

3534
/**
3635
* A renderer for OCS responses
@@ -44,26 +43,30 @@ class OCSResponse extends Response {
4443
private $message;
4544
private $itemscount;
4645
private $itemsperpage;
46+
private $isV2;
4747

4848
/**
4949
* generates the xml or json response for the API call from an multidimenional data array.
50+
*
5051
* @param string $format
5152
* @param int $statuscode
5253
* @param string $message
5354
* @param array $data
5455
* @param int|string $itemscount
5556
* @param int|string $itemsperpage
57+
* @param bool $isV2
5658
* @since 8.1.0
5759
*/
5860
public function __construct($format, $statuscode, $message,
5961
$data=[], $itemscount='',
60-
$itemsperpage='') {
62+
$itemsperpage='', $isV2 = false) {
6163
$this->format = $format;
6264
$this->statuscode = $statuscode;
6365
$this->message = $message;
6466
$this->data = $data;
6567
$this->itemscount = $itemscount;
6668
$this->itemsperpage = $itemsperpage;
69+
$this->isV2 = $isV2;
6770

6871
// set the correct header based on the format parameter
6972
if ($format === 'json') {
@@ -82,11 +85,15 @@ public function __construct($format, $statuscode, $message,
8285
* @since 8.1.0
8386
*/
8487
public function render() {
85-
$r = new \OC_OCS_Result($this->data, $this->statuscode, $this->message);
88+
$r = new Result($this->data, $this->statuscode, $this->message);
8689
$r->setTotalItems($this->itemscount);
8790
$r->setItemsPerPage($this->itemsperpage);
91+
$meta = $r->getMeta();
92+
if ($this->isV2 && $this->statuscode === 200) {
93+
$meta['status'] = 'ok';
94+
}
8895

89-
return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData());
96+
return \OC_API::renderResult($this->format, $meta, $r->getData());
9097
}
9198

9299
/**

lib/public/AppFramework/OCSController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ private function buildOCSResponse($format, $data) {
105105
$params[$key] = $value;
106106
}
107107

108+
$isV2 = substr($this->request->getScriptName(), -11) === '/ocs/v2.php';
109+
108110
$resp = new OCSResponse(
109111
$format, $params['statuscode'],
110112
$params['message'], $params['data'],
111-
$params['itemscount'], $params['itemsperpage']
113+
$params['itemscount'], $params['itemsperpage'], $isV2
112114
);
113115
if (isset($data['headers'])) {
114116
foreach ($data['headers'] as $key => $value) {

tests/lib/AppFramework/Controller/OCSControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function testStatusCodeMapping() {
191191
$this->createMock(ISecureRandom::class),
192192
$configMock
193193
));
194-
$expected = '{"ocs":{"meta":{"status":"failure","statuscode":200,"message":"OK",' .
194+
$expected = '{"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK",' .
195195
'"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}';
196196
$params = [
197197
'data' => [

0 commit comments

Comments
 (0)