1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-02-12 06:54:28 +01:00

Now loads with OCP\AppFramework

This commit is contained in:
Thomas Tanghus 2013-09-17 18:46:59 +02:00
parent 5a32805dc1
commit cfd8cd02b3
16 changed files with 261 additions and 131 deletions

View File

@ -8,8 +8,8 @@
*/ */
namespace OCA\Contacts; namespace OCA\Contacts;
use OCA\AppFramework\App as Main; //use OCA\AppFramework\App as Main;
use OCA\Contacts\DIContainer; use OCA\Contacts\Dispatcher;
//define the routes //define the routes
//for the index //for the index
@ -32,7 +32,8 @@ $this->create('contacts_address_books_for_user', 'addressbooks/')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('AddressBookController', 'userAddressBooks', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('AddressBookController', 'userAddressBooks', $params);
} }
); );
@ -41,7 +42,8 @@ $this->create('contacts_address_book_add', 'addressbook/{backend}/add')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('AddressBookController', 'addAddressBook', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('AddressBookController', 'addAddressBook', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -51,7 +53,8 @@ $this->create('contacts_address_book', 'addressbook/{backend}/{addressbookid}')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('AddressBookController', 'getAddressBook', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('AddressBookController', 'getAddressBook', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -61,7 +64,8 @@ $this->create('contacts_address_book_export', 'addressbook/{backend}/{addressboo
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('AddressBookController', 'exportAddressBook', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('AddressBookController', 'exportAddressBook', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -71,7 +75,8 @@ $this->create('contacts_address_book_update', 'addressbook/{backend}/{addressboo
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('AddressBookController', 'updateAddressBook', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('AddressBookController', 'updateAddressBook', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -80,8 +85,9 @@ $this->create('contacts_address_book_delete', 'addressbook/{backend}/{addressboo
->delete() ->delete()
->action( ->action(
function($params) { function($params) {
$dispatcher = new Dispatcher($params);
session_write_close(); session_write_close();
Main::main('AddressBookController', 'deleteAddressBook', $params, new DIContainer()); $dispatcher->dispatch('AddressBookController', 'deleteAddressBook', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -91,7 +97,8 @@ $this->create('contacts_address_book_activate', 'addressbook/{backend}/{addressb
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('AddressBookController', 'activateAddressBook', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('AddressBookController', 'activateAddressBook', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -101,7 +108,8 @@ $this->create('contacts_address_book_add_contact', 'addressbook/{backend}/{addre
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('AddressBookController', 'addChild', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('AddressBookController', 'addChild', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -111,7 +119,8 @@ $this->create('contacts_address_book_delete_contact', 'addressbook/{backend}/{ad
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('AddressBookController', 'deleteChild', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('AddressBookController', 'deleteChild', $params);
} }
) )
->requirements(array('backend', 'addressbookid', 'contactid')); ->requirements(array('backend', 'addressbookid', 'contactid'));
@ -121,7 +130,8 @@ $this->create('contacts_address_book_delete_contacts', 'addressbook/{backend}/{a
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('AddressBookController', 'deleteChildren', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('AddressBookController', 'deleteChildren', $params);
} }
) )
->requirements(array('backend', 'addressbookid', 'contactid')); ->requirements(array('backend', 'addressbookid', 'contactid'));
@ -131,7 +141,8 @@ $this->create('contacts_address_book_move_contact', 'addressbook/{backend}/{addr
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('AddressBookController', 'moveChild', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('AddressBookController', 'moveChild', $params);
} }
) )
->requirements(array('backend', 'addressbookid', 'contactid')); ->requirements(array('backend', 'addressbookid', 'contactid'));
@ -141,7 +152,8 @@ $this->create('contacts_import_upload', 'addressbook/{backend}/{addressbookid}/i
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ImportController', 'upload', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ImportController', 'upload', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -151,7 +163,8 @@ $this->create('contacts_import_prepare', 'addressbook/{backend}/{addressbookid}/
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ImportController', 'prepare', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ImportController', 'prepare', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -161,7 +174,8 @@ $this->create('contacts_import_start', 'addressbook/{backend}/{addressbookid}/im
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ImportController', 'start', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ImportController', 'start', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -171,7 +185,8 @@ $this->create('contacts_import_status', 'addressbook/{backend}/{addressbookid}/i
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ImportController', 'status', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ImportController', 'status', $params);
} }
) )
->requirements(array('backend', 'addressbookid')); ->requirements(array('backend', 'addressbookid'));
@ -181,7 +196,8 @@ $this->create('contacts_contact_photo', 'addressbook/{backend}/{addressbookid}/c
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactPhotoController', 'getPhoto', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactPhotoController', 'getPhoto', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid')); ->requirements(array('backend', 'addressbook', 'contactid'));
@ -191,7 +207,8 @@ $this->create('contacts_upload_contact_photo', 'addressbook/{backend}/{addressbo
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactPhotoController', 'uploadPhoto', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactPhotoController', 'uploadPhoto', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid')); ->requirements(array('backend', 'addressbook', 'contactid'));
@ -201,7 +218,8 @@ $this->create('contacts_cache_contact_photo', 'addressbook/{backend}/{addressboo
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactPhotoController', 'cacheCurrentPhoto', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactPhotoController', 'cacheCurrentPhoto', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid')); ->requirements(array('backend', 'addressbook', 'contactid'));
@ -211,7 +229,8 @@ $this->create('contacts_cache_fs_photo', 'addressbook/{backend}/{addressbookid}/
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactPhotoController', 'cacheFileSystemPhoto', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactPhotoController', 'cacheFileSystemPhoto', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid')); ->requirements(array('backend', 'addressbook', 'contactid'));
@ -221,7 +240,8 @@ $this->create('contacts_tmp_contact_photo', 'addressbook/{backend}/{addressbooki
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactPhotoController', 'getTempPhoto', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactPhotoController', 'getTempPhoto', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid', 'key')); ->requirements(array('backend', 'addressbook', 'contactid', 'key'));
@ -231,7 +251,8 @@ $this->create('contacts_crop_contact_photo', 'addressbook/{backend}/{addressbook
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactPhotoController', 'cropPhoto', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactPhotoController', 'cropPhoto', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid', 'key')); ->requirements(array('backend', 'addressbook', 'contactid', 'key'));
@ -241,7 +262,8 @@ $this->create('contacts_contact_export', 'addressbook/{backend}/{addressbookid}/
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactController', 'exportContact', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactController', 'exportContact', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid')); ->requirements(array('backend', 'addressbook', 'contactid'));
@ -251,7 +273,8 @@ $this->create('contacts_contact_delete_property', 'addressbook/{backend}/{addres
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactController', 'deleteProperty', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactController', 'deleteProperty', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid')); ->requirements(array('backend', 'addressbook', 'contactid'));
@ -262,7 +285,8 @@ $this->create('contacts_contact_save_property', 'addressbook/{backend}/{addressb
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactController', 'saveProperty', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactController', 'saveProperty', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid')); ->requirements(array('backend', 'addressbook', 'contactid'));
@ -272,7 +296,8 @@ $this->create('contacts_contact_get', 'addressbook/{backend}/{addressbookid}/con
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactController', 'getContact', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactController', 'getContact', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid')); ->requirements(array('backend', 'addressbook', 'contactid'));
@ -283,7 +308,8 @@ $this->create('contacts_contact_save_all', 'addressbook/{backend}/{addressbookid
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('ContactController', 'saveContact', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('ContactController', 'saveContact', $params);
} }
) )
->requirements(array('backend', 'addressbook', 'contactid')); ->requirements(array('backend', 'addressbook', 'contactid'));
@ -293,7 +319,8 @@ $this->create('contacts_categories_list', 'groups/')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('GroupController', 'getGroups', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('GroupController', 'getGroups', $params);
} }
); );
@ -302,7 +329,8 @@ $this->create('contacts_categories_add', 'groups/add')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('GroupController', 'addGroup', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('GroupController', 'addGroup', $params);
} }
); );
@ -311,7 +339,8 @@ $this->create('contacts_categories_delete', 'groups/delete')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('GroupController', 'deleteGroup', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('GroupController', 'deleteGroup', $params);
} }
); );
@ -320,7 +349,8 @@ $this->create('contacts_categories_rename', 'groups/rename')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('GroupController', 'renameGroup', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('GroupController', 'renameGroup', $params);
} }
); );
@ -329,7 +359,8 @@ $this->create('contacts_categories_addto', 'groups/addto/{categoryid}')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('GroupController', 'addToGroup', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('GroupController', 'addToGroup', $params);
} }
); );
@ -338,7 +369,8 @@ $this->create('contacts_categories_removefrom', 'groups/removefrom/{categoryid}'
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('GroupController', 'removeFromGroup', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('GroupController', 'removeFromGroup', $params);
} }
) )
->requirements(array('categoryid')); ->requirements(array('categoryid'));
@ -348,7 +380,8 @@ $this->create('contacts_setpreference', 'preference/set')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
Main::main('SettingsController', 'set', $params, new DIContainer()); $dispatcher = new Dispatcher($params);
$dispatcher->dispatch('SettingsController', 'set', $params);
} }
); );

View File

@ -619,12 +619,11 @@ OC.Contacts = OC.Contacts || {};
$(document).trigger('status.contacts.error', response); $(document).trigger('status.contacts.error', response);
} }
}) })
.fail(function(jqxhr, textStatus, error) { .fail(function(response) {
var err = textStatus + ', ' + error; console.warn( "Request Failed:", response);
console.warn( "Request Failed: " + err);
defer.reject({ defer.reject({
error: true, error: true,
message: t('contacts', 'Failed loading address books: {error}', {error:err}) message: t('contacts', 'Failed loading address books: {error}', {error:response.message})
}); });
}); });
return defer.promise(); return defer.promise();

View File

@ -772,7 +772,7 @@ OC.Contacts = OC.Contacts || {};
} }
}) })
.fail(function(response) { .fail(function(response) {
console.log( "Request Failed: " + response); console.log( "Request Failed:", response);
response.message = t('contacts', 'Failed loading groups: {error}', {error:response.message}); response.message = t('contacts', 'Failed loading groups: {error}', {error:response.message});
$(document).trigger('status.contacts.error', response); $(document).trigger('status.contacts.error', response);
}); });

View File

@ -130,6 +130,11 @@ OC.ContactsImporter = OC.ContactsImporter || {
$(document).ready(function(){ $(document).ready(function(){
// If the app is already active there's no need for the FileActions
if(OC.Contacts) {
return;
}
$(document).bind('status.contacts.error', function(e, data) { $(document).bind('status.contacts.error', function(e, data) {
console.warn(data.message); console.warn(data.message);
//console.trace(); //console.trace();

View File

@ -8,6 +8,7 @@ OC.Contacts = OC.Contacts || {};
this.getResponseHeader = jqXHR.getResponseHeader; this.getResponseHeader = jqXHR.getResponseHeader;
this.statusCode = jqXHR.status; this.statusCode = jqXHR.status;
// 204 == No content // 204 == No content
// 304 == Not modified
if(!response) { if(!response) {
if([204, 304].indexOf(this.statusCode) === -1) { if([204, 304].indexOf(this.statusCode) === -1) {
console.log('jqXHR', jqXHR); console.log('jqXHR', jqXHR);
@ -598,7 +599,7 @@ OC.Contacts = OC.Contacts || {};
}) })
.fail(function(jqXHR, textStatus, error) { .fail(function(jqXHR, textStatus, error) {
console.log(jqXHR); console.log(jqXHR);
var response = $.parseJSON(jqXHR.responseText); var response = jqXHR.responseText ? $.parseJSON(jqXHR.responseText) : null;
console.log('response', response); console.log('response', response);
defer.reject(new JSONResponse(response, jqXHR)); defer.reject(new JSONResponse(response, jqXHR));
}); });

View File

@ -8,7 +8,14 @@
namespace OCA\Contacts; namespace OCA\Contacts;
use Sabre\VObject; use Sabre\VObject,
OCP\AppFramework,
OCA\Contacts\Controller\AddressBookController,
OCA\Contacts\Controller\GroupController,
OCA\Contacts\Controller\ContactController,
OCA\Contacts\Controller\ContactPhotoController,
OCA\Contacts\Controller\SettingsController,
OCA\Contacts\Controller\ImportController;
/** /**
* This class manages our app actions * This class manages our app actions

43
lib/controller.php Normal file
View File

@ -0,0 +1,43 @@
<?php
/**
* @author Thomas Tanghus
* Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Contacts;
use OCP\AppFramework\IApi,
OC\AppFramework\Controller\Controller as BaseController,
OCP\IRequest,
OCA\Contacts\App;
/**
* Base Controller class for Contacts App
*/
class Controller extends BaseController {
/**
* @var Api
*/
protected $api;
/**
* @var IRequest
*/
protected $request;
/**
* @var App
*/
protected $app;
public function __construct(IApi $api, IRequest $request, App $app) {
$this->api = $api;
$this->request = $request;
$this->app = $app;
}
}

View File

@ -12,23 +12,19 @@ namespace OCA\Contacts\Controller;
use OCA\Contacts\App, use OCA\Contacts\App,
OCA\Contacts\JSONResponse, OCA\Contacts\JSONResponse,
OCA\Contacts\Utils\JSONSerializer, OCA\Contacts\Utils\JSONSerializer,
OCA\AppFramework\Controller\Controller as BaseController, OCA\Contacts\Controller,
OCA\AppFramework\Http\TextDownloadResponse; OCA\AppFramework\Http\TextDownloadResponse;
/** /**
* Controller class For Address Books * Controller class For Address Books
*/ */
class AddressBookController extends BaseController { class AddressBookController extends Controller {
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption
* @Ajax
*/ */
public function userAddressBooks() { public function userAddressBooks() {
$app = new App($this->api->getUserId()); $addressBooks = $this->app->getAddressBooksForUser();
$addressBooks = $app->getAddressBooksForUser();
$response = array(); $response = array();
$lastModified = 0; $lastModified = 0;
foreach($addressBooks as $addressBook) { foreach($addressBooks as $addressBook) {
@ -52,16 +48,13 @@ class AddressBookController extends BaseController {
} }
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption
* @Ajax
*/ */
public function getAddressBook() { public function getAddressBook() {
\OCP\Util::writeLog('contacts', __METHOD__, \OCP\Util::DEBUG); \OCP\Util::writeLog('contacts', __METHOD__, \OCP\Util::DEBUG);
$params = $this->request->urlParams; $params = $this->request->urlParams;
$app = new App($this->api->getUserId());
$addressBook = $app->getAddressBook($params['backend'], $params['addressbookid']); $addressBook = $this->app->getAddressBook($params['backend'], $params['addressbookid']);
$lastModified = $addressBook->lastModified(); $lastModified = $addressBook->lastModified();
$response = new JSONResponse(); $response = new JSONResponse();
@ -86,16 +79,14 @@ class AddressBookController extends BaseController {
} }
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption * @NoCSRFRequired
* @CSRFExemption
*/ */
public function exportAddressBook() { public function exportAddressBook() {
\OCP\Util::writeLog('contacts', __METHOD__, \OCP\Util::DEBUG); \OCP\Util::writeLog('contacts', __METHOD__, \OCP\Util::DEBUG);
$params = $this->request->urlParams; $params = $this->request->urlParams;
$app = new App($this->api->getUserId());
$addressBook = $app->getAddressBook($params['backend'], $params['addressbookid']); $addressBook = $this->app->getAddressBook($params['backend'], $params['addressbookid']);
$lastModified = $addressBook->lastModified(); $lastModified = $addressBook->lastModified();
$response = new JSONResponse(); $response = new JSONResponse();
@ -114,17 +105,15 @@ class AddressBookController extends BaseController {
} }
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption * @NoCSRFRequired
* @Ajax
*/ */
public function addAddressBook() { public function addAddressBook() {
$app = new App($this->api->getUserId());
$params = $this->request->urlParams; $params = $this->request->urlParams;
$response = new JSONResponse(); $response = new JSONResponse();
$backend = $app->getBackend($params['backend']); $backend = $this->app->getBackend($params['backend']);
if(!$backend->hasAddressBookMethodFor(\OCP\PERMISSION_CREATE)) { if(!$backend->hasAddressBookMethodFor(\OCP\PERMISSION_CREATE)) {
throw new \Exception('Not implemented'); throw new \Exception('Not implemented');
} }
@ -145,17 +134,14 @@ class AddressBookController extends BaseController {
} }
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption
* @Ajax
*/ */
public function updateAddressBook() { public function updateAddressBook() {
$params = $this->request->urlParams; $params = $this->request->urlParams;
$app = new App($this->api->getUserId());
$response = new JSONResponse(); $response = new JSONResponse();
$addressBook = $app->getAddressBook($params['backend'], $params['addressbookid']); $addressBook = $this->app->getAddressBook($params['backend'], $params['addressbookid']);
try { try {
if(!$addressBook->update($this->request['properties'])) { if(!$addressBook->update($this->request['properties'])) {
$response->bailOut(App::$l10n->t('Error updating address book')); $response->bailOut(App::$l10n->t('Error updating address book'));
@ -170,17 +156,14 @@ class AddressBookController extends BaseController {
} }
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption
* @Ajax
*/ */
public function deleteAddressBook() { public function deleteAddressBook() {
$params = $this->request->urlParams; $params = $this->request->urlParams;
$app = new App($this->api->getUserId());
$response = new JSONResponse(); $response = new JSONResponse();
$backend = $app->getBackend($params['backend']); $backend = $this->app->getBackend($params['backend']);
if(!$backend->hasAddressBookMethodFor(\OCP\PERMISSION_DELETE)) { if(!$backend->hasAddressBookMethodFor(\OCP\PERMISSION_DELETE)) {
throw new \Exception( throw new \Exception(
@ -206,17 +189,14 @@ class AddressBookController extends BaseController {
} }
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption
* @Ajax
*/ */
public function activateAddressBook() { public function activateAddressBook() {
$params = $this->request->urlParams; $params = $this->request->urlParams;
$app = new App($this->api->getUserId());
$response = new JSONResponse(); $response = new JSONResponse();
$addressBook = $app->getAddressBook($params['backend'], $params['addressbookid']); $addressBook = $this->app->getAddressBook($params['backend'], $params['addressbookid']);
$addressBook->setActive($this->request->post['state']); $addressBook->setActive($this->request->post['state']);
@ -224,17 +204,14 @@ class AddressBookController extends BaseController {
} }
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption
* @Ajax
*/ */
public function addChild() { public function addChild() {
$params = $this->request->urlParams; $params = $this->request->urlParams;
$app = new App($this->api->getUserId());
$response = new JSONResponse(); $response = new JSONResponse();
$addressBook = $app->getAddressBook($params['backend'], $params['addressbookid']); $addressBook = $this->app->getAddressBook($params['backend'], $params['addressbookid']);
try { try {
$id = $addressBook->addChild(); $id = $addressBook->addChild();
@ -266,17 +243,14 @@ class AddressBookController extends BaseController {
} }
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption
* @Ajax
*/ */
public function deleteChild() { public function deleteChild() {
$params = $this->request->urlParams; $params = $this->request->urlParams;
$app = new App($this->api->getUserId());
$response = new JSONResponse(); $response = new JSONResponse();
$addressBook = $app->getAddressBook($params['backend'], $params['addressbookid']); $addressBook = $this->app->getAddressBook($params['backend'], $params['addressbookid']);
try { try {
$result = $addressBook->deleteChild($params['contactid']); $result = $addressBook->deleteChild($params['contactid']);
@ -293,17 +267,14 @@ class AddressBookController extends BaseController {
} }
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption
* @Ajax
*/ */
public function deleteChildren() { public function deleteChildren() {
$params = $this->request->urlParams; $params = $this->request->urlParams;
$app = new App($this->api->getUserId());
$response = new JSONResponse(); $response = new JSONResponse();
$addressBook = $app->getAddressBook($params['backend'], $params['addressbookid']); $addressBook = $this->app->getAddressBook($params['backend'], $params['addressbookid']);
$contacts = $this->request->post['contacts']; $contacts = $this->request->post['contacts'];
try { try {
@ -318,21 +289,18 @@ class AddressBookController extends BaseController {
} }
/** /**
* @IsAdminExemption * @NoAdminRequired
* @IsSubAdminExemption
* @Ajax
*/ */
public function moveChild() { public function moveChild() {
$params = $this->request->urlParams; $params = $this->request->urlParams;
$targetInfo = $this->request->post['target']; $targetInfo = $this->request->post['target'];
$app = new App($this->api->getUserId());
$response = new JSONResponse(); $response = new JSONResponse();
// TODO: Check if the backend supports move (is 'local' or 'shared') and use that operation instead. // TODO: Check if the backend supports move (is 'local' or 'shared') and use that operation instead.
// If so, set status 204 and don't return the serialized contact. // If so, set status 204 and don't return the serialized contact.
$fromAddressBook = $app->getAddressBook($params['backend'], $params['addressbookid']); $fromAddressBook = $this->app->getAddressBook($params['backend'], $params['addressbookid']);
$targetAddressBook = $app->getAddressBook($targetInfo['backend'], $targetInfo['id']); $targetAddressBook = $this->app->getAddressBook($targetInfo['backend'], $targetInfo['id']);
$contact = $fromAddressBook->getChild($params['contactid']); $contact = $fromAddressBook->getChild($params['contactid']);
if(!$contact) { if(!$contact) {
$response->bailOut(App::$l10n->t('Error retrieving contact.')); $response->bailOut(App::$l10n->t('Error retrieving contact.'));

View File

@ -14,15 +14,15 @@ use OCA\Contacts\App,
OCA\Contacts\ImageResponse, OCA\Contacts\ImageResponse,
OCA\Contacts\Utils\JSONSerializer, OCA\Contacts\Utils\JSONSerializer,
OCA\Contacts\Utils\Properties, OCA\Contacts\Utils\Properties,
OCA\AppFramework\Controller\Controller as BaseController, OCA\Contacts\Controller;
OCA\AppFramework\Core\API, //OCA\AppFramework\Core\API,
OCA\AppFramework\Http\TextDownloadResponse; //OCA\AppFramework\Http\TextDownloadResponse;
/** /**
* Controller class For Contacts * Controller class For Contacts
*/ */
class ContactController extends BaseController { class ContactController extends Controller {
/** /**
* @IsAdminExemption * @IsAdminExemption

View File

@ -13,12 +13,12 @@ use OCA\Contacts\App,
OCA\Contacts\JSONResponse, OCA\Contacts\JSONResponse,
OCA\Contacts\ImageResponse, OCA\Contacts\ImageResponse,
OCA\Contacts\Utils\Properties, OCA\Contacts\Utils\Properties,
OCA\AppFramework\Controller\Controller as BaseController; OCA\Contacts\Controller;
/** /**
* Controller class For Contacts * Controller class For Contacts
*/ */
class ContactPhotoController extends BaseController { class ContactPhotoController extends Controller {
/** /**
* @IsAdminExemption * @IsAdminExemption

View File

@ -9,16 +9,14 @@
namespace OCA\Contacts\Controller; namespace OCA\Contacts\Controller;
use OCA\Contacts\App; use OCA\Contacts\App,
use OCA\Contacts\JSONResponse; OCA\Contacts\JSONResponse,
use OCA\AppFramework\Controller\Controller as BaseController; OCA\Contacts\Controller;
use OCA\AppFramework\Core\API;
/** /**
* Controller class for groups/categories * Controller class for groups/categories
*/ */
class GroupController extends BaseController { class GroupController extends Controller {
/** /**
* @IsAdminExemption * @IsAdminExemption

View File

@ -10,15 +10,14 @@
namespace OCA\Contacts\Controller; namespace OCA\Contacts\Controller;
use OCA\Contacts\App; use OCA\Contacts\App;
use OCA\Contacts\JSONResponse; OCA\Contacts\JSONResponse,
use OCA\AppFramework\Controller\Controller as BaseController; OCA\Contacts\Controller,
use OCA\AppFramework\Core\API; Sabre\VObject;
use Sabre\VObject;
/** /**
* Controller importing contacts * Controller importing contacts
*/ */
class ImportController extends BaseController { class ImportController extends Controller {
/** /**
* @IsAdminExemption * @IsAdminExemption

View File

@ -9,16 +9,16 @@
namespace OCA\Contacts\Controller; namespace OCA\Contacts\Controller;
use OCA\Contacts\App; use OCA\Contacts\App,
use OCA\Contacts\JSONResponse; OCA\Contacts\JSONResponse,
use OCA\AppFramework\Controller\Controller as BaseController; OCA\Contacts\Controller,
use OCA\AppFramework\Core\API; OCA\AppFramework\Core\API;
/** /**
* Controller class for groups/categories * Controller class for groups/categories
*/ */
class SettingsController extends BaseController { class SettingsController extends Controller {
/** /**
* @IsAdminExemption * @IsAdminExemption

68
lib/dispatcher.php Normal file
View File

@ -0,0 +1,68 @@
<?php
/**
* Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Contacts;
use OCP\AppFramework\App as MainApp,
OCP\AppFramework\IAppContainer,
OCA\Contacts\App,
OCA\Contacts\Middleware\Http as HttpMiddleware,
OCA\Contacts\Controller\AddressBookController,
OCA\Contacts\Controller\GroupController,
OCA\Contacts\Controller\ContactController,
OCA\Contacts\Controller\ContactPhotoController,
OCA\Contacts\Controller\SettingsController,
OCA\Contacts\Controller\ImportController;
/**
* This class manages our app actions
*/
class Dispatcher extends MainApp {
/**
* @var App
*/
protected $app;
public function __construct(array $params) {
parent::__construct('contacts');
$this->container = $this->getContainer();
// TODO: Remove this once sorted out.
// When querying the middleware dispatcher Request gets instantiated
// but urlParams isn't set yet
$this->container['urlParams'] = $params;
$this->middleware = $this->container->query('MiddlewareDispatcher');
$this->middleware->registerMiddleware(new HttpMiddleware($this->container->query('API')));
$this->api = $this->container->query('API');
$this->request = $this->container->query('Request');
$this->app = new App($this->api->getUserId());
$this->registerServices();
}
public function registerServices() {
$this->container->registerService('AddressBookController', function(IAppContainer $container) {
return new AddressBookController($this->api, $this->request, $this->app);
});
$this->container->registerService('GroupController', function(IAppContainer $container) {
return new GroupController($this->api, $this->request, $this->app);
});
$this->container->registerService('ContactController', function(IAppContainer $container) {
return new ContactController($this->api, $this->request, $this->app);
});
$this->container->registerService('ContactPhotoController', function(IAppContainer $container) {
return new ContactPhotoController($this->api, $this->request, $this->app);
});
$this->container->registerService('SettingsController', function(IAppContainer $container) {
return new SettingsController($this->api, $this->request, $this->app);
});
$this->container->registerService('ImportController', function(IAppContainer $container) {
return new ImportController($this->api, $this->request, $this->app);
});
}
}

View File

@ -8,8 +8,8 @@
*/ */
namespace OCA\Contacts; namespace OCA\Contacts;
use OCA\AppFramework\Http\JSONResponse as OriginalResponse, use OCP\AppFramework\Http\JSONResponse as OriginalResponse,
OCA\AppFramework\Http\Http; OCP\AppFramework\Http\Http;
/** /**
@ -19,11 +19,20 @@ class JSONResponse extends OriginalResponse {
public function __construct($params = array(), $statusCode=Http::STATUS_OK) { public function __construct($params = array(), $statusCode=Http::STATUS_OK) {
parent::__construct(array(), $statusCode); parent::__construct(array(), $statusCode);
//\OCP\Util::writeLog('contacts', __METHOD__.' request: '.print_r($request, true), \OCP\Util::DEBUG);
parent::__construct();
$this->data['data'] = $params; $this->data['data'] = $params;
} }
/**
* Sets values in the data json array
* @param array|object $params an array or object which will be transformed
* to JSON
*/
public function setParams(array $params){
$this->data['data'] = $params;
$this->data['status'] = 'success';
}
/** /**
* in case we want to render an error message, also logs into the owncloud log * in case we want to render an error message, also logs into the owncloud log
* @param string $message the error message * @param string $message the error message

View File

@ -24,16 +24,16 @@
namespace OCA\Contacts\Middleware; namespace OCA\Contacts\Middleware;
use OCA\AppFramework\Controller\Controller; use OCA\Contacts\Controller;
use OCA\AppFramework\Middleware\Middleware; use OC\AppFramework\Middleware\Middleware;
use OCA\AppFramework\Core\API; use OC\AppFramework\Core\API;
use OCA\Contacts\JSONResponse; use OCA\Contacts\JSONResponse;
/** /**
* Used to intercept exceptions thrown in controllers and backends * Used to intercept exceptions thrown in controllers and backends
* and transform them into valid HTTP responses. * and transform them into valid HTTP responses.
*/ */
class HTTP extends Middleware { class Http extends Middleware {
private $api; private $api;