Skip to content

Commit dd4af9a

Browse files
committed
Updates for CORS for ownCloud 8.1
1 parent 4461fa9 commit dd4af9a

File tree

4 files changed

+149
-127
lines changed

4 files changed

+149
-127
lines changed

appinfo/routes.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@
2323

2424
$application->registerRoutes($this, array('routes' => array(
2525
array('name' => 'page#index', 'url' => '/', 'verb' => 'GET'),
26-
array('name' => 'ownnote_api#ajaxsetval', 'url' => '/api/v0.2/ajaxsetval', 'verb' => 'POST'),
26+
array('name' => 'ownnote_ajax#ajaxsetval', 'url' => '/ajax/v0.2/ajaxsetval', 'verb' => 'POST'),
2727
array('name' => 'ownnote_api#index', 'url' => '/api/v0.2/ownnote', 'verb' => 'GET'),
28-
array('name' => 'ownnote_api#ajaxindex', 'url' => '/api/v0.2/ownnote/ajaxindex', 'verb' => 'GET'),
28+
array('name' => 'ownnote_ajax#ajaxindex', 'url' => '/ajax/v0.2/ownnote/ajaxindex', 'verb' => 'GET'),
2929
array('name' => 'ownnote_api#remoteindex', 'url' => '/api/v0.2/ownnote/remoteindex', 'verb' => 'GET'),
3030
array('name' => 'ownnote_api#mobileindex', 'url' => '/api/v0.2/ownnote/mobileindex', 'verb' => 'GET'),
3131
array('name' => 'ownnote_api#announcement', 'url' => '/api/v0.2/ownnote/announcement', 'verb' => 'GET'),
32-
array('name' => 'ownnote_api#ajaxannouncement', 'url' => '/api/v0.2/ownnote/ajaxannouncement', 'verb' => 'GET'),
32+
array('name' => 'ownnote_ajax#ajaxannouncement', 'url' => '/ajax/v0.2/ownnote/ajaxannouncement', 'verb' => 'GET'),
3333
array('name' => 'ownnote_api#version', 'url' => '/api/v0.2/ownnote/version', 'verb' => 'GET'),
34-
array('name' => 'ownnote_api#ajaxversion', 'url' => '/api/v0.2/ownnote/ajaxversion', 'verb' => 'GET'),
34+
array('name' => 'ownnote_ajax#ajaxversion', 'url' => '/ajax/v0.2/ownnote/ajaxversion', 'verb' => 'GET'),
3535
array('name' => 'ownnote_api#ren', 'url' => '/api/v0.2/ownnote/ren', 'verb' => 'POST'),
36-
array('name' => 'ownnote_api#ajaxren', 'url' => '/api/v0.2/ownnote/ajaxren', 'verb' => 'POST'),
36+
array('name' => 'ownnote_ajax#ajaxren', 'url' => '/ajax/v0.2/ownnote/ajaxren', 'verb' => 'POST'),
3737
array('name' => 'ownnote_api#edit', 'url' => '/api/v0.2/ownnote/edit', 'verb' => 'POST'),
38-
array('name' => 'ownnote_api#ajaxedit', 'url' => '/api/v0.2/ownnote/ajaxedit', 'verb' => 'POST'),
38+
array('name' => 'ownnote_ajax#ajaxedit', 'url' => '/ajax/v0.2/ownnote/ajaxedit', 'verb' => 'POST'),
3939
array('name' => 'ownnote_api#del', 'url' => '/api/v0.2/ownnote/del', 'verb' => 'POST'),
40-
array('name' => 'ownnote_api#ajaxdel', 'url' => '/api/v0.2/ownnote/ajaxdel', 'verb' => 'POST'),
40+
array('name' => 'ownnote_ajax#ajaxdel', 'url' => '/ajax/v0.2/ownnote/ajaxdel', 'verb' => 'POST'),
4141
array('name' => 'ownnote_api#save', 'url' => '/api/v0.2/ownnote/save', 'verb' => 'POST'),
42-
array('name' => 'ownnote_api#ajaxsave', 'url' => '/api/v0.2/ownnote/ajaxsave', 'verb' => 'POST'),
42+
array('name' => 'ownnote_ajax#ajaxsave', 'url' => '/ajax/v0.2/ownnote/ajaxsave', 'verb' => 'POST'),
4343
array('name' => 'ownnote_api#create', 'url' => '/api/v0.2/ownnote/create', 'verb' => 'POST'),
44-
array('name' => 'ownnote_api#ajaxcreate', 'url' => '/api/v0.2/ownnote/ajaxcreate', 'verb' => 'POST'),
44+
array('name' => 'ownnote_ajax#ajaxcreate', 'url' => '/ajax/v0.2/ownnote/ajaxcreate', 'verb' => 'POST'),
4545
array('name' => 'ownnote_api#delgroup', 'url' => '/api/v0.2/ownnote/delgroup', 'verb' => 'POST'),
46-
array('name' => 'ownnote_api#ajaxdelgroup', 'url' => '/api/v0.2/ownnote/ajaxdelgroup', 'verb' => 'POST'),
46+
array('name' => 'ownnote_ajax#ajaxdelgroup', 'url' => '/ajax/v0.2/ownnote/ajaxdelgroup', 'verb' => 'POST'),
4747
array('name' => 'ownnote_api#rengroup', 'url' => '/api/v0.2/ownnote/rengroup', 'verb' => 'POST'),
48-
array('name' => 'ownnote_api#ajaxrengroup', 'url' => '/api/v0.2/ownnote/ajaxrengroup', 'verb' => 'POST'),
48+
array('name' => 'ownnote_ajax#ajaxrengroup', 'url' => '/ajax/v0.2/ownnote/ajaxrengroup', 'verb' => 'POST'),
4949
array('name' => 'ownnote_api#preflighted_cors', 'url' => '/api/v0.2/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+')),
5050
)));
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
/**
3+
* ownCloud - ownnote
4+
*
5+
* This file is licensed under the Affero General Public License version 3 or
6+
* later. See the COPYING file.
7+
*
8+
* @author Ben Curtis <[email protected]>
9+
* @copyright Ben Curtis 2015
10+
*/
11+
12+
namespace OCA\OwnNote\Controller;
13+
14+
use \OCP\AppFramework\ApiController;
15+
use \OCP\AppFramework\Http\JSONResponse;
16+
use \OCP\AppFramework\Http\Response;
17+
use \OCP\AppFramework\Http;
18+
use \OCP\IRequest;
19+
use \OCA\OwnNote\Lib\Backend;
20+
21+
\OCP\App::checkAppEnabled('ownnote');
22+
23+
24+
25+
class OwnnoteAjaxController extends ApiController {
26+
27+
private $backend;
28+
29+
30+
public function __construct($appName, IRequest $request){
31+
parent::__construct($appName, $request);
32+
$this->backend = new Backend();
33+
}
34+
35+
/**
36+
* AJAX FUNCTIONS
37+
*/
38+
39+
/**
40+
* @NoAdminRequired
41+
*/
42+
public function ajaxindex() {
43+
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
44+
return $this->backend->getListing($FOLDER, false);
45+
}
46+
47+
/**
48+
* @NoAdminRequired
49+
*/
50+
public function ajaxannouncement() {
51+
return $this->backend->getAnnouncement();
52+
}
53+
54+
/**
55+
* @NoAdminRequired
56+
*/
57+
public function ajaxcreate($name, $group) {
58+
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
59+
if (isset($name) && isset($group))
60+
return $this->backend->createNote($FOLDER, $name, $group);
61+
}
62+
63+
/**
64+
* @NoAdminRequired
65+
*/
66+
public function ajaxdel($name, $group) {
67+
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
68+
if (isset($name) && isset($group))
69+
return $this->backend->deleteNote($FOLDER, $name, $group);
70+
}
71+
72+
/**
73+
* @NoAdminRequired
74+
*/
75+
public function ajaxedit($name, $group) {
76+
if (isset($name) && isset($group))
77+
return $this->backend->editNote($name, $group);
78+
}
79+
80+
/**
81+
* @NoAdminRequired
82+
*/
83+
public function ajaxsave($name, $group, $content) {
84+
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
85+
if (isset($name) && isset($group) && isset($content))
86+
return $this->backend->saveNote($FOLDER, $name, $group, $content, 0);
87+
}
88+
89+
/**
90+
* @NoAdminRequired
91+
*/
92+
public function ajaxren($name, $group, $newname, $newgroup) {
93+
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
94+
if (isset($name) && isset($newname) && isset($group) && isset($newgroup))
95+
return $this->backend->renameNote($FOLDER, $name, $group, $newname, $newgroup);
96+
}
97+
98+
/**
99+
* @NoAdminRequired
100+
*/
101+
public function ajaxdelgroup($group) {
102+
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
103+
if (isset($group))
104+
return $this->backend->deleteGroup($FOLDER, $group);
105+
}
106+
107+
/**
108+
* @NoAdminRequired
109+
*/
110+
public function ajaxrengroup($group, $newgroup) {
111+
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
112+
if (isset($group) && isset($newgroup))
113+
return $this->backend->renameGroup($FOLDER, $group, $newgroup);
114+
}
115+
116+
/**
117+
* @NoAdminRequired
118+
*/
119+
public function ajaxversion() {
120+
return $this->backend->getVersion();
121+
}
122+
123+
/**
124+
*/
125+
public function ajaxsetval($field, $value) {
126+
return $this->backend->setAdminVal($field, $value);
127+
}
128+
}

controller/ownnoteapicontroller.php

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -32,112 +32,6 @@ public function __construct($appName, IRequest $request){
3232
$this->backend = new Backend();
3333
}
3434

35-
/**
36-
* AJAX FUNCTIONS
37-
*/
38-
39-
/**
40-
* @NoAdminRequired
41-
* @CORS
42-
*/
43-
public function ajaxindex() {
44-
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
45-
return $this->backend->getListing($FOLDER, false);
46-
}
47-
48-
/**
49-
* @NoAdminRequired
50-
* @CORS
51-
*/
52-
public function ajaxannouncement() {
53-
return $this->backend->getAnnouncement();
54-
}
55-
56-
/**
57-
* @NoAdminRequired
58-
* @CORS
59-
*/
60-
public function ajaxcreate($name, $group) {
61-
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
62-
if (isset($name) && isset($group))
63-
return $this->backend->createNote($FOLDER, $name, $group);
64-
}
65-
66-
/**
67-
* @NoAdminRequired
68-
* @CORS
69-
*/
70-
public function ajaxdel($name, $group) {
71-
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
72-
if (isset($name) && isset($group))
73-
return $this->backend->deleteNote($FOLDER, $name, $group);
74-
}
75-
76-
/**
77-
* @NoAdminRequired
78-
* @CORS
79-
*/
80-
public function ajaxedit($name, $group) {
81-
if (isset($name) && isset($group))
82-
return $this->backend->editNote($name, $group);
83-
}
84-
85-
/**
86-
* @NoAdminRequired
87-
* @CORS
88-
*/
89-
public function ajaxsave($name, $group, $content) {
90-
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
91-
if (isset($name) && isset($group) && isset($content))
92-
return $this->backend->saveNote($FOLDER, $name, $group, $content, 0);
93-
}
94-
95-
/**
96-
* @NoAdminRequired
97-
* @CORS
98-
*/
99-
public function ajaxren($name, $group, $newname, $newgroup) {
100-
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
101-
if (isset($name) && isset($newname) && isset($group) && isset($newgroup))
102-
return $this->backend->renameNote($FOLDER, $name, $group, $newname, $newgroup);
103-
}
104-
105-
/**
106-
* @NoAdminRequired
107-
* @CORS
108-
*/
109-
public function ajaxdelgroup($group) {
110-
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
111-
if (isset($group))
112-
return $this->backend->deleteGroup($FOLDER, $group);
113-
}
114-
115-
/**
116-
* @NoAdminRequired
117-
* @CORS
118-
*/
119-
public function ajaxrengroup($group, $newgroup) {
120-
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
121-
if (isset($group) && isset($newgroup))
122-
return $this->backend->renameGroup($FOLDER, $group, $newgroup);
123-
}
124-
125-
/**
126-
* @NoAdminRequired
127-
* @CORS
128-
*/
129-
public function ajaxversion() {
130-
return $this->backend->getVersion();
131-
}
132-
133-
/**
134-
* @CORS
135-
*/
136-
public function ajaxsetval($field, $value) {
137-
return $this->backend->setAdminVal($field, $value);
138-
}
139-
140-
14135
/**
14236
* MOBILE FUNCTIONS
14337
*/

js/script.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@
4949
function deleteNote(id) {
5050
var n = $(this).attr('n');
5151
var g = $(this).attr('g');
52-
$.post(ocUrl("api/v0.2/ownnote/ajaxdel"), { name: n, group: g }, function (data) {
52+
$.post(ocUrl("ajax/v0.2/ownnote/ajaxdel"), { name: n, group: g }, function (data) {
5353
loadListing();
5454
});
5555
}
5656

5757
function editNote(id) {
5858
var n = $(this).attr('n');
5959
var g = $(this).attr('g');
60-
$.post(ocUrl("api/v0.2/ownnote/ajaxedit"), { name: n, group: g }, function (data) {
60+
$.post(ocUrl("ajax/v0.2/ownnote/ajaxedit"), { name: n, group: g }, function (data) {
6161
buildEdit(n, g, data);
6262
});
6363
}
@@ -190,9 +190,9 @@
190190
if (exists) {
191191
alert(trans("Filename/group already exists."));
192192
} else
193-
$.post(ocUrl("api/v0.2/ownnote/ajaxren"), { name: originalfilename, group: originalgroup, newname: editfilename, newgroup: editgroup }, function (data) {
193+
$.post(ocUrl("ajax/v0.2/ownnote/ajaxren"), { name: originalfilename, group: originalgroup, newname: editfilename, newgroup: editgroup }, function (data) {
194194
if (data == "DONE") {
195-
$.post(ocUrl("api/v0.2/ownnote/ajaxsave"), { name: editfilename, group: editgroup, content: content }, function (data) {
195+
$.post(ocUrl("ajax/v0.2/ownnote/ajaxsave"), { name: editfilename, group: editgroup, content: content }, function (data) {
196196
if (!stayinnote)
197197
loadListing();
198198
else {
@@ -203,7 +203,7 @@
203203
}
204204
});
205205
} else {
206-
$.post(ocUrl("api/v0.2/ownnote/ajaxsave"), { name: editfilename, group: editgroup, content: content }, function (data) {
206+
$.post(ocUrl("ajax/v0.2/ownnote/ajaxsave"), { name: editfilename, group: editgroup, content: content }, function (data) {
207207
if (!stayinnote)
208208
loadListing();
209209
else {
@@ -235,7 +235,7 @@
235235
}
236236

237237
function loadListing() {
238-
var url = ocUrl("api/v0.2/ownnote/ajaxindex");
238+
var url = ocUrl("ajax/v0.2/ownnote/ajaxindex");
239239
$.get(url, function(data) {
240240
listing = data;
241241
buildNav(listingtype);
@@ -400,7 +400,7 @@
400400
group = $('#newgroupname').val();
401401
}
402402
cancelNote();
403-
$.post(ocUrl("api/v0.2/ownnote/ajaxcreate"), { name: name, group: group }, function (data) {
403+
$.post(ocUrl("ajax/v0.2/ownnote/ajaxcreate"), { name: name, group: group }, function (data) {
404404
loadListing();
405405
});
406406
return false;
@@ -528,7 +528,7 @@
528528
$('#announcement-container').html(html);
529529
}
530530
} else {
531-
var url = ocUrl("api/v0.2/ownnote/ajaxannouncement");
531+
var url = ocUrl("ajax/v0.2/ownnote/ajaxannouncement");
532532
$.ajax({
533533
url: url,
534534
success: function(data) {
@@ -611,7 +611,7 @@
611611
if (exists)
612612
alert(trans("An ungrouped file has the same name as a file in this group."));
613613
else
614-
$.post(ocUrl("api/v0.2/ownnote/ajaxdelgroup"), { group: g }, function (data) {
614+
$.post(ocUrl("ajax/v0.2/ownnote/ajaxdelgroup"), { group: g }, function (data) {
615615
switchgroup = "All";
616616
loadListing();
617617
});
@@ -642,7 +642,7 @@
642642
if (exists)
643643
alert(trans("Group already exists."));
644644
else
645-
$.post(ocUrl("api/v0.2/ownnote/ajaxrengroup"), { group: cg, newgroup: v }, function (data) {
645+
$.post(ocUrl("ajax/v0.2/ownnote/ajaxrengroup"), { group: cg, newgroup: v }, function (data) {
646646
switchgroup = v;
647647
cg = "";
648648
loadListing();

0 commit comments

Comments
 (0)