diff --git a/appinfo/routes.php b/appinfo/routes.php index 509095e6..0d3aa354 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -167,6 +167,16 @@ $this->create('contacts_contact_save_property', 'addressbook/{backend}/{addressb ) ->requirements(array('backend', 'addressbook', 'contactid')); +$this->create('contacts_contact_get', 'addressbook/{backend}/{addressbookid}/contact/{contactid}/') + ->get() + ->action( + function($params) { + session_write_close(); + Main::main('ContactController', 'getContact', $params, new DIContainer()); + } + ) + ->requirements(array('backend', 'addressbook', 'contactid')); + // Save all properties. Used for merging contacts. $this->create('contacts_contact_save_all', 'addressbook/{backend}/{addressbookid}/contact/{contactid}/save') ->post() diff --git a/lib/controller/contactcontroller.php b/lib/controller/contactcontroller.php index a00cb4ac..14d6f249 100644 --- a/lib/controller/contactcontroller.php +++ b/lib/controller/contactcontroller.php @@ -24,6 +24,34 @@ use OCA\AppFramework\Core\API; */ class ContactController extends BaseController { + /** + * @IsAdminExemption + * @IsSubAdminExemption + * @Ajax + */ + public function getContact() { + $app = new App($this->api->getUserId()); + + $request = $this->request; + $response = new JSONResponse(); + + $contact = $app->getContact( + $request->parameters['backend'], + $request->parameters['addressbookid'], + $request->parameters['contactid'] + ); + + if(!$contact) { + $response->bailOut(App::$l10n->t('Couldn\'t find contact.')); + } + + $data = JSONSerializer::serializeContact($contact); + + $response->setParams($data); + + return $response; + } + /** * @IsAdminExemption * @IsSubAdminExemption