Skip to content
Snippets Groups Projects
Commit 3ee98dc9 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Implement OCS endpoint for querying

parent 0ed88e13
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
return [ return [
'routes' => [ 'routes' => [
['name' => 'SecondaryMail#setProperty', 'url' => '/settings', 'verb' => 'POST'], ['name' => 'SecondaryMail#setProperty', 'url' => '/settings', 'verb' => 'POST'],
],
'ocs' => [
['name' => 'SecondaryMail#getAddress', 'url' => '/getAddress/{id}', 'verb' => 'GET'], ['name' => 'SecondaryMail#getAddress', 'url' => '/getAddress/{id}', 'verb' => 'GET'],
['name' => 'SecondaryMail#setProperty', 'url' => '/settings', 'verb' => 'POST'],
] ]
]; ];
{ {
"name": "OpenTools/Secondary_Mail", "name": "opentools/secondary_mail",
"description": "Enter a secondary email and specify which e-Mail should be used for external communication", "description": "Enter a secondary email and specify which e-Mail should be used for external communication",
"type": "project", "type": "project",
"license": "AGPL", "license": "AGPL",
......
...@@ -20,6 +20,27 @@ ...@@ -20,6 +20,27 @@
'use strict'; 'use strict';
(function(OCA) {
/**
* @namespace OCA.Secondary_Mail
*/
OCA.Secondary_Mail = {
_submitChange: function(target) {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this._submitChange, this, target));
return;
}
var url = OC.generateUrl('/apps/secondarymail/settings');
let key = target.data('setting'),
value = target.val();
if (target.attr('type') === 'checkbox') {
value = target[0].checked ? 'true' : 'false';
}
$.post(url, {key, value});
return true;
}
}
})(OCA);
(function () { (function () {
function initialize() { function initialize() {
...@@ -33,6 +54,14 @@ ...@@ -33,6 +54,14 @@
} }
function _submitChange(e) { function _submitChange(e) {
return OCA.Secondary_Mail._submitChange($(e.target));
}
function _submitChangeOLD(e) {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(_submitChange, e));
return;
}
var url = OC.generateUrl('/apps/secondarymail/settings'); var url = OC.generateUrl('/apps/secondarymail/settings');
let target = $(e.target), let target = $(e.target),
key = target.data('setting'), key = target.data('setting'),
...@@ -47,3 +76,4 @@ ...@@ -47,3 +76,4 @@
initialize(); initialize();
})(); })();
...@@ -46,7 +46,6 @@ class SecondaryMailController extends OCSController { ...@@ -46,7 +46,6 @@ class SecondaryMailController extends OCSController {
$this->config = $config; $this->config = $config;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->user = $userSession->getUser()->getUID(); $this->user = $userSession->getUser()->getUID();
error_log('MailsSecondaryController::_construct');
} }
/** /**
...@@ -55,7 +54,7 @@ error_log('MailsSecondaryController::_construct'); ...@@ -55,7 +54,7 @@ error_log('MailsSecondaryController::_construct');
*/ */
public function setProperty($key, $value) { public function setProperty($key, $value) {
if (in_array($key, array('emailUsePrimary', 'emailUseSecondary', 'email2'))) { if (in_array($key, array('emailUsePrimary', 'emailUseSecondary', 'email2'))) {
if ($key === 'email2' && $value == "") { if ($key === 'email2' && $value === "") {
$this->config->deleteUserValue($this->user, 'settings', $key); $this->config->deleteUserValue($this->user, 'settings', $key);
} else { } else {
$this->config->setUserValue($this->user, 'settings', $key, $value); $this->config->setUserValue($this->user, 'settings', $key, $value);
...@@ -70,18 +69,28 @@ error_log('MailsSecondaryController::_construct'); ...@@ -70,18 +69,28 @@ error_log('MailsSecondaryController::_construct');
*/ */
public function getAddress($id) { public function getAddress($id) {
$mails = array(); $mails = array();
$data = array();
if ($this->config->getUserValue($id, 'settings', 'emailUsePrimary')) { $usePrimary = $this->config->getUserValue($id, 'settings', 'emailUsePrimary', 'true');
$data['usePrimary'] = $usePrimary;
if ($usePrimary === 'true' || $usePrimary === 1 || $usePrimary === "Y") {
$user = $this->userManager->get($id); $user = $this->userManager->get($id);
$email = $user->getEMailAddress(); $email = $user->getEMailAddress();
if (!is_empty($email)) { if (!empty($email)) {
$mails[] = $user->getEMailAddress(); $mails[] = $user->getEMailAddress();
} }
} }
if ($this->config->getUserValue($id, 'settings', 'emailUseSecondary')) {
$mails[] = $this->config->getUserValue($id, 'settings', 'email2'); $useSecondary = $this->config->getUserValue($id, 'settings', 'emailUseSecondary', 'true');
$data['useSecondary'] = $useSecondary;
if ($useSecondary === 'true' || $useSecondary === 1 || $useSecondary === "Y") {
$secondary = $this->config->getUserValue($id, 'settings', 'email2');
if (!empty($secondary)) {
$mails[] = $secondary;
}
} }
return join(',',$mails); $data['email'] = $mails;
return new DataResponse($data);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment