diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2014-08-22 21:11:20 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2014-08-22 21:11:20 +0200 |
| commit | cd37bde4ef0747a11c1221e937027fe17f2894fe (patch) | |
| tree | 4ff92d03f4b01c5b5c6f4d5a391f2982ceaae616 /controller | |
| parent | f7ecfa21088175bc236b1136c1a4b2aa2488f37c (diff) | |
| download | grauphel-cd37bde4ef0747a11c1221e937027fe17f2894fe.tar.gz grauphel-cd37bde4ef0747a11c1221e937027fe17f2894fe.zip | |
link api from web interface, make single note fetching work, redo note storage username
Diffstat (limited to 'controller')
| -rw-r--r-- | controller/apicontroller.php | 53 | ||||
| -rw-r--r-- | controller/guicontroller.php | 16 |
2 files changed, 40 insertions, 29 deletions
diff --git a/controller/apicontroller.php b/controller/apicontroller.php index a4361ef..691d8ab 100644 --- a/controller/apicontroller.php +++ b/controller/apicontroller.php @@ -148,7 +148,7 @@ class ApiController extends Controller ) ) ); - $syncdata = $this->notes->loadSyncData($username); + $syncdata = $this->notes->loadSyncData(); $data = array( 'user-name' => $username, @@ -185,8 +185,8 @@ class ApiController extends Controller ) ) ); - $syncdata = $this->notes->loadSyncData($username); - return $this->fetchNotes($username, $syncdata); + $syncdata = $this->notes->loadSyncData(); + return $this->fetchNotes($syncdata); } /** @@ -206,17 +206,17 @@ class ApiController extends Controller ) ) ); - $syncdata = $this->notes->loadSyncData($username); + $syncdata = $this->notes->loadSyncData(); $res = $this->handleNoteSave($username, $syncdata); if ($res instanceof \OCP\AppFramework\Http\Response) { return $res; } - return $this->fetchNotes($username, $syncdata); + return $this->fetchNotes($syncdata); } - protected function fetchNotes($username, $syncdata) + protected function fetchNotes($syncdata) { $since = null; if (isset($_GET['since'])) { @@ -224,9 +224,9 @@ class ApiController extends Controller } if (isset($_GET['include_notes']) && $_GET['include_notes']) { - $notes = $this->notes->loadNotesFull($username, $since); + $notes = $this->notes->loadNotesFull($since); } else { - $notes = $this->notes->loadNotesOverview($username, $since); + $notes = $this->notes->loadNotesOverview($since); } //work around bug https://bugzilla.gnome.org/show_bug.cgi?id=734313 @@ -283,18 +283,18 @@ class ApiController extends Controller //owncloud converts object to array, so we reverse $noteUpdate = (object) $noteUpdate; - $note = $this->notes->load($username, $noteUpdate->guid); + $note = $this->notes->load($noteUpdate->guid); if (isset($noteUpdate->command) && $noteUpdate->command == 'delete') { - $this->notes->delete($username, $noteUpdate->guid); + $this->notes->delete($noteUpdate->guid); } else { $this->notes->update( $note, $noteUpdate, $syncdata->latestSyncRevision ); - $this->notes->save($username, $note); + $this->notes->save($note); } } - $this->notes->saveSyncData($username, $syncdata); + $this->notes->saveSyncData($syncdata); } /** @@ -304,17 +304,19 @@ class ApiController extends Controller * @NoCSRFRequired * @PublicPage */ - public function note() + public function note($username, $guid) { - //FIXME - $deps = Dependencies::get(); - $username = $deps->urlGen->loadUsername(); - $guid = $deps->urlGen->loadGuid(); - $oauth = new \OAuth(); - $oauth->setDeps($deps); - $oauth->verifyOAuthUser($username, $deps->urlGen->note($username, $guid)); + $this->verifyUser( + $username, + $this->deps->urlGen->getAbsoluteURL( + $this->deps->urlGen->linkToRoute( + 'grauphel.api.note', + array('username' => $username, 'guid' => $guid) + ) + ) + ); - $note = $this->notes->load($username, $guid, false); + $note = $this->notes->load($guid, false); if ($note === null) { header('HTTP/1.0 404 Not Found'); header('Content-type: text/plain'); @@ -322,8 +324,7 @@ class ApiController extends Controller exit(1); } - $data = array('note' => array($note)); - $deps->renderer->sendJson($data); + return new JSONResponse($note); } /** @@ -335,13 +336,17 @@ class ApiController extends Controller */ protected function verifyUser($username, $curUrl) { - if ($this->user !== null && $this->user->getUID() == $username) { + if ($this->user !== null && $this->user->getUid() == $username) { + $this->notes->setUsername($username); return true; } $oauth = new OAuth(); $oauth->setDeps($this->deps); $oauth->verifyOAuthUser($username, $curUrl); + + $this->notes->setUsername($username); + return true; } } ?> diff --git a/controller/guicontroller.php b/controller/guicontroller.php index 2c05750..b92d374 100644 --- a/controller/guicontroller.php +++ b/controller/guicontroller.php @@ -59,7 +59,12 @@ class GuiController extends Controller $this->checkDeps(); $res = new TemplateResponse('grauphel', 'index'); - $res->setParams(array('apiurl' => $this->getApiUrl())); + $res->setParams( + array( + 'apiroot' => $this->getApiRootUrl(), + 'apiurl' => $this->urlGen->linkToRoute('grauphel.api.index') + ) + ); $this->addNavigation($res); $this->addStats($res); return $res; @@ -68,7 +73,7 @@ class GuiController extends Controller protected function addNavigation(TemplateResponse $res) { $nav = new \OCP\Template('grauphel', 'appnavigation', ''); - $nav->assign('apiurl', $this->getApiUrl()); + $nav->assign('apiroot', $this->getApiRootUrl()); $params = $res->getParams(); $params['appNavigation'] = $nav; @@ -83,11 +88,12 @@ class GuiController extends Controller $username = $this->user->getUid(); $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen); + $notes->setUsername($username); $tokens = new \OCA\Grauphel\Lib\TokenStorage(); $nav = new \OCP\Template('grauphel', 'indexStats', ''); - $nav->assign('notes', count($notes->loadNotesOverview($username))); - $nav->assign('syncrev', $notes->loadSyncData($username)->latestSyncRevision); + $nav->assign('notes', count($notes->loadNotesOverview())); + $nav->assign('syncrev', $notes->loadSyncData()->latestSyncRevision); $nav->assign('tokens', count($tokens->loadForUser($username, 'access'))); $params = $res->getParams(); @@ -102,7 +108,7 @@ class GuiController extends Controller } } - protected function getApiUrl() + protected function getApiRootUrl() { //we need to remove the trailing / for tomdroid and conboy return rtrim( |
