Skip to content

Commit

Permalink
Updates for CORS for ownCloud 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Fmstrat committed Jul 8, 2015
1 parent 4461fa9 commit dd4af9a
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 127 deletions.
22 changes: 11 additions & 11 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@

$application->registerRoutes($this, array('routes' => array(
array('name' => 'page#index', 'url' => '/', 'verb' => 'GET'),
array('name' => 'ownnote_api#ajaxsetval', 'url' => '/api/v0.2/ajaxsetval', 'verb' => 'POST'),
array('name' => 'ownnote_ajax#ajaxsetval', 'url' => '/ajax/v0.2/ajaxsetval', 'verb' => 'POST'),
array('name' => 'ownnote_api#index', 'url' => '/api/v0.2/ownnote', 'verb' => 'GET'),
array('name' => 'ownnote_api#ajaxindex', 'url' => '/api/v0.2/ownnote/ajaxindex', 'verb' => 'GET'),
array('name' => 'ownnote_ajax#ajaxindex', 'url' => '/ajax/v0.2/ownnote/ajaxindex', 'verb' => 'GET'),
array('name' => 'ownnote_api#remoteindex', 'url' => '/api/v0.2/ownnote/remoteindex', 'verb' => 'GET'),
array('name' => 'ownnote_api#mobileindex', 'url' => '/api/v0.2/ownnote/mobileindex', 'verb' => 'GET'),
array('name' => 'ownnote_api#announcement', 'url' => '/api/v0.2/ownnote/announcement', 'verb' => 'GET'),
array('name' => 'ownnote_api#ajaxannouncement', 'url' => '/api/v0.2/ownnote/ajaxannouncement', 'verb' => 'GET'),
array('name' => 'ownnote_ajax#ajaxannouncement', 'url' => '/ajax/v0.2/ownnote/ajaxannouncement', 'verb' => 'GET'),
array('name' => 'ownnote_api#version', 'url' => '/api/v0.2/ownnote/version', 'verb' => 'GET'),
array('name' => 'ownnote_api#ajaxversion', 'url' => '/api/v0.2/ownnote/ajaxversion', 'verb' => 'GET'),
array('name' => 'ownnote_ajax#ajaxversion', 'url' => '/ajax/v0.2/ownnote/ajaxversion', 'verb' => 'GET'),
array('name' => 'ownnote_api#ren', 'url' => '/api/v0.2/ownnote/ren', 'verb' => 'POST'),
array('name' => 'ownnote_api#ajaxren', 'url' => '/api/v0.2/ownnote/ajaxren', 'verb' => 'POST'),
array('name' => 'ownnote_ajax#ajaxren', 'url' => '/ajax/v0.2/ownnote/ajaxren', 'verb' => 'POST'),
array('name' => 'ownnote_api#edit', 'url' => '/api/v0.2/ownnote/edit', 'verb' => 'POST'),
array('name' => 'ownnote_api#ajaxedit', 'url' => '/api/v0.2/ownnote/ajaxedit', 'verb' => 'POST'),
array('name' => 'ownnote_ajax#ajaxedit', 'url' => '/ajax/v0.2/ownnote/ajaxedit', 'verb' => 'POST'),
array('name' => 'ownnote_api#del', 'url' => '/api/v0.2/ownnote/del', 'verb' => 'POST'),
array('name' => 'ownnote_api#ajaxdel', 'url' => '/api/v0.2/ownnote/ajaxdel', 'verb' => 'POST'),
array('name' => 'ownnote_ajax#ajaxdel', 'url' => '/ajax/v0.2/ownnote/ajaxdel', 'verb' => 'POST'),
array('name' => 'ownnote_api#save', 'url' => '/api/v0.2/ownnote/save', 'verb' => 'POST'),
array('name' => 'ownnote_api#ajaxsave', 'url' => '/api/v0.2/ownnote/ajaxsave', 'verb' => 'POST'),
array('name' => 'ownnote_ajax#ajaxsave', 'url' => '/ajax/v0.2/ownnote/ajaxsave', 'verb' => 'POST'),
array('name' => 'ownnote_api#create', 'url' => '/api/v0.2/ownnote/create', 'verb' => 'POST'),
array('name' => 'ownnote_api#ajaxcreate', 'url' => '/api/v0.2/ownnote/ajaxcreate', 'verb' => 'POST'),
array('name' => 'ownnote_ajax#ajaxcreate', 'url' => '/ajax/v0.2/ownnote/ajaxcreate', 'verb' => 'POST'),
array('name' => 'ownnote_api#delgroup', 'url' => '/api/v0.2/ownnote/delgroup', 'verb' => 'POST'),
array('name' => 'ownnote_api#ajaxdelgroup', 'url' => '/api/v0.2/ownnote/ajaxdelgroup', 'verb' => 'POST'),
array('name' => 'ownnote_ajax#ajaxdelgroup', 'url' => '/ajax/v0.2/ownnote/ajaxdelgroup', 'verb' => 'POST'),
array('name' => 'ownnote_api#rengroup', 'url' => '/api/v0.2/ownnote/rengroup', 'verb' => 'POST'),
array('name' => 'ownnote_api#ajaxrengroup', 'url' => '/api/v0.2/ownnote/ajaxrengroup', 'verb' => 'POST'),
array('name' => 'ownnote_ajax#ajaxrengroup', 'url' => '/ajax/v0.2/ownnote/ajaxrengroup', 'verb' => 'POST'),
array('name' => 'ownnote_api#preflighted_cors', 'url' => '/api/v0.2/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+')),
)));
128 changes: 128 additions & 0 deletions controller/ownnoteajaxcontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
/**
* ownCloud - ownnote
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Ben Curtis <ownclouddev@nosolutions.com>
* @copyright Ben Curtis 2015
*/

namespace OCA\OwnNote\Controller;

use \OCP\AppFramework\ApiController;
use \OCP\AppFramework\Http\JSONResponse;
use \OCP\AppFramework\Http\Response;
use \OCP\AppFramework\Http;
use \OCP\IRequest;
use \OCA\OwnNote\Lib\Backend;

\OCP\App::checkAppEnabled('ownnote');



class OwnnoteAjaxController extends ApiController {

private $backend;


public function __construct($appName, IRequest $request){
parent::__construct($appName, $request);
$this->backend = new Backend();
}

/**
* AJAX FUNCTIONS
*/

/**
* @NoAdminRequired
*/
public function ajaxindex() {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
return $this->backend->getListing($FOLDER, false);
}

/**
* @NoAdminRequired
*/
public function ajaxannouncement() {
return $this->backend->getAnnouncement();
}

/**
* @NoAdminRequired
*/
public function ajaxcreate($name, $group) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($name) && isset($group))
return $this->backend->createNote($FOLDER, $name, $group);
}

/**
* @NoAdminRequired
*/
public function ajaxdel($name, $group) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($name) && isset($group))
return $this->backend->deleteNote($FOLDER, $name, $group);
}

/**
* @NoAdminRequired
*/
public function ajaxedit($name, $group) {
if (isset($name) && isset($group))
return $this->backend->editNote($name, $group);
}

/**
* @NoAdminRequired
*/
public function ajaxsave($name, $group, $content) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($name) && isset($group) && isset($content))
return $this->backend->saveNote($FOLDER, $name, $group, $content, 0);
}

/**
* @NoAdminRequired
*/
public function ajaxren($name, $group, $newname, $newgroup) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($name) && isset($newname) && isset($group) && isset($newgroup))
return $this->backend->renameNote($FOLDER, $name, $group, $newname, $newgroup);
}

/**
* @NoAdminRequired
*/
public function ajaxdelgroup($group) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($group))
return $this->backend->deleteGroup($FOLDER, $group);
}

/**
* @NoAdminRequired
*/
public function ajaxrengroup($group, $newgroup) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($group) && isset($newgroup))
return $this->backend->renameGroup($FOLDER, $group, $newgroup);
}

/**
* @NoAdminRequired
*/
public function ajaxversion() {
return $this->backend->getVersion();
}

/**
*/
public function ajaxsetval($field, $value) {
return $this->backend->setAdminVal($field, $value);
}
}
106 changes: 0 additions & 106 deletions controller/ownnoteapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,112 +32,6 @@ public function __construct($appName, IRequest $request){
$this->backend = new Backend();
}

/**
* AJAX FUNCTIONS
*/

/**
* @NoAdminRequired
* @CORS
*/
public function ajaxindex() {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
return $this->backend->getListing($FOLDER, false);
}

/**
* @NoAdminRequired
* @CORS
*/
public function ajaxannouncement() {
return $this->backend->getAnnouncement();
}

/**
* @NoAdminRequired
* @CORS
*/
public function ajaxcreate($name, $group) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($name) && isset($group))
return $this->backend->createNote($FOLDER, $name, $group);
}

/**
* @NoAdminRequired
* @CORS
*/
public function ajaxdel($name, $group) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($name) && isset($group))
return $this->backend->deleteNote($FOLDER, $name, $group);
}

/**
* @NoAdminRequired
* @CORS
*/
public function ajaxedit($name, $group) {
if (isset($name) && isset($group))
return $this->backend->editNote($name, $group);
}

/**
* @NoAdminRequired
* @CORS
*/
public function ajaxsave($name, $group, $content) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($name) && isset($group) && isset($content))
return $this->backend->saveNote($FOLDER, $name, $group, $content, 0);
}

/**
* @NoAdminRequired
* @CORS
*/
public function ajaxren($name, $group, $newname, $newgroup) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($name) && isset($newname) && isset($group) && isset($newgroup))
return $this->backend->renameNote($FOLDER, $name, $group, $newname, $newgroup);
}

/**
* @NoAdminRequired
* @CORS
*/
public function ajaxdelgroup($group) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($group))
return $this->backend->deleteGroup($FOLDER, $group);
}

/**
* @NoAdminRequired
* @CORS
*/
public function ajaxrengroup($group, $newgroup) {
$FOLDER = \OCP\Config::getAppValue('ownnote', 'folder', 'Notes');
if (isset($group) && isset($newgroup))
return $this->backend->renameGroup($FOLDER, $group, $newgroup);
}

/**
* @NoAdminRequired
* @CORS
*/
public function ajaxversion() {
return $this->backend->getVersion();
}

/**
* @CORS
*/
public function ajaxsetval($field, $value) {
return $this->backend->setAdminVal($field, $value);
}


/**
* MOBILE FUNCTIONS
*/
Expand Down
20 changes: 10 additions & 10 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
function deleteNote(id) {
var n = $(this).attr('n');
var g = $(this).attr('g');
$.post(ocUrl("api/v0.2/ownnote/ajaxdel"), { name: n, group: g }, function (data) {
$.post(ocUrl("ajax/v0.2/ownnote/ajaxdel"), { name: n, group: g }, function (data) {
loadListing();
});
}

function editNote(id) {
var n = $(this).attr('n');
var g = $(this).attr('g');
$.post(ocUrl("api/v0.2/ownnote/ajaxedit"), { name: n, group: g }, function (data) {
$.post(ocUrl("ajax/v0.2/ownnote/ajaxedit"), { name: n, group: g }, function (data) {
buildEdit(n, g, data);
});
}
Expand Down Expand Up @@ -190,9 +190,9 @@
if (exists) {
alert(trans("Filename/group already exists."));
} else
$.post(ocUrl("api/v0.2/ownnote/ajaxren"), { name: originalfilename, group: originalgroup, newname: editfilename, newgroup: editgroup }, function (data) {
$.post(ocUrl("ajax/v0.2/ownnote/ajaxren"), { name: originalfilename, group: originalgroup, newname: editfilename, newgroup: editgroup }, function (data) {
if (data == "DONE") {
$.post(ocUrl("api/v0.2/ownnote/ajaxsave"), { name: editfilename, group: editgroup, content: content }, function (data) {
$.post(ocUrl("ajax/v0.2/ownnote/ajaxsave"), { name: editfilename, group: editgroup, content: content }, function (data) {
if (!stayinnote)
loadListing();
else {
Expand All @@ -203,7 +203,7 @@
}
});
} else {
$.post(ocUrl("api/v0.2/ownnote/ajaxsave"), { name: editfilename, group: editgroup, content: content }, function (data) {
$.post(ocUrl("ajax/v0.2/ownnote/ajaxsave"), { name: editfilename, group: editgroup, content: content }, function (data) {
if (!stayinnote)
loadListing();
else {
Expand Down Expand Up @@ -235,7 +235,7 @@
}

function loadListing() {
var url = ocUrl("api/v0.2/ownnote/ajaxindex");
var url = ocUrl("ajax/v0.2/ownnote/ajaxindex");
$.get(url, function(data) {
listing = data;
buildNav(listingtype);
Expand Down Expand Up @@ -400,7 +400,7 @@
group = $('#newgroupname').val();
}
cancelNote();
$.post(ocUrl("api/v0.2/ownnote/ajaxcreate"), { name: name, group: group }, function (data) {
$.post(ocUrl("ajax/v0.2/ownnote/ajaxcreate"), { name: name, group: group }, function (data) {
loadListing();
});
return false;
Expand Down Expand Up @@ -528,7 +528,7 @@
$('#announcement-container').html(html);
}
} else {
var url = ocUrl("api/v0.2/ownnote/ajaxannouncement");
var url = ocUrl("ajax/v0.2/ownnote/ajaxannouncement");
$.ajax({
url: url,
success: function(data) {
Expand Down Expand Up @@ -611,7 +611,7 @@
if (exists)
alert(trans("An ungrouped file has the same name as a file in this group."));
else
$.post(ocUrl("api/v0.2/ownnote/ajaxdelgroup"), { group: g }, function (data) {
$.post(ocUrl("ajax/v0.2/ownnote/ajaxdelgroup"), { group: g }, function (data) {
switchgroup = "All";
loadListing();
});
Expand Down Expand Up @@ -642,7 +642,7 @@
if (exists)
alert(trans("Group already exists."));
else
$.post(ocUrl("api/v0.2/ownnote/ajaxrengroup"), { group: cg, newgroup: v }, function (data) {
$.post(ocUrl("ajax/v0.2/ownnote/ajaxrengroup"), { group: cg, newgroup: v }, function (data) {
switchgroup = v;
cg = "";
loadListing();
Expand Down

0 comments on commit dd4af9a

Please sign in to comment.