mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-19 08:52:22 +01:00
add admin settings to enable/disable ldap backend
This commit is contained in:
parent
153366bef1
commit
a3166ee452
17
admin.php
Normal file
17
admin.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ownCloud - Updater plugin
|
||||||
|
*
|
||||||
|
* @author Nicolas Mora
|
||||||
|
* @copyright 2014 Nicolas Mora mail@babelouest.org
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Updater;
|
||||||
|
|
||||||
|
\OCP\User::checkAdminUser();
|
||||||
|
$tmpl = new \OCP\Template('contacts', 'admin');
|
||||||
|
return $tmpl->fetchPage();
|
@ -53,11 +53,13 @@ $api->connectHook('OC_Calendar', 'getEvents', 'OCA\Contacts\Hooks', 'getBirthday
|
|||||||
$api->connectHook('OC_Calendar', 'getSources', 'OCA\Contacts\Hooks', 'getCalenderSources');
|
$api->connectHook('OC_Calendar', 'getSources', 'OCA\Contacts\Hooks', 'getCalenderSources');
|
||||||
|
|
||||||
\OCP\Util::addscript('contacts', 'loader');
|
\OCP\Util::addscript('contacts', 'loader');
|
||||||
|
\OCP\Util::addscript('contacts', 'admin');
|
||||||
|
|
||||||
\OC_Search::registerProvider('OCA\Contacts\SearchProvider');
|
\OC_Search::registerProvider('OCA\Contacts\SearchProvider');
|
||||||
//\OCP\Share::registerBackend('contact', 'OCA\Contacts\Share_Backend_Contact');
|
//\OCP\Share::registerBackend('contact', 'OCA\Contacts\Share_Backend_Contact');
|
||||||
\OCP\Share::registerBackend('addressbook', 'OCA\Contacts\Share\Addressbook', 'contact');
|
\OCP\Share::registerBackend('addressbook', 'OCA\Contacts\Share\Addressbook', 'contact');
|
||||||
//\OCP\App::registerPersonal('contacts','personalsettings');
|
//\OCP\App::registerPersonal('contacts','personalsettings');
|
||||||
|
\OCP\App::registerAdmin('contacts', 'admin');
|
||||||
|
|
||||||
if (\OCP\User::isLoggedIn()) {
|
if (\OCP\User::isLoggedIn()) {
|
||||||
$app = new App($api->getUserId());
|
$app = new App($api->getUserId());
|
||||||
|
@ -40,7 +40,11 @@ $principalBackend = new OC_Connector_Sabre_Principal();
|
|||||||
|
|
||||||
$addressbookbackends = array();
|
$addressbookbackends = array();
|
||||||
$addressbookbackends[] = new OCA\Contacts\Backend\Database(\OCP\User::getUser());
|
$addressbookbackends[] = new OCA\Contacts\Backend\Database(\OCP\User::getUser());
|
||||||
$carddavBackend = new OCA\Contacts\CardDAV\Backend(array('local', 'shared', 'ldap'));
|
$backends = array('local', 'shared');
|
||||||
|
if (\OCP\Config::getAppValue('contacts', 'backend_ldap', "false") === "true") {
|
||||||
|
$backends[] = 'ldap'
|
||||||
|
}
|
||||||
|
$carddavBackend = new OCA\Contacts\CardDAV\Backend($backends);
|
||||||
$requestBackend = new OC_Connector_Sabre_Request();
|
$requestBackend = new OC_Connector_Sabre_Request();
|
||||||
|
|
||||||
// Root nodes
|
// Root nodes
|
||||||
|
@ -45,6 +45,28 @@ $this->create('contacts_address_book_connectors', 'connectors/{backend}')
|
|||||||
)
|
)
|
||||||
->requirements(array('backend'));
|
->requirements(array('backend'));
|
||||||
|
|
||||||
|
$this->create('contacts_backend_enable', 'backend/{backend}/{enable}')
|
||||||
|
->get()
|
||||||
|
->action(
|
||||||
|
function($params) {
|
||||||
|
\OC::$session->close();
|
||||||
|
$dispatcher = new Dispatcher($params);
|
||||||
|
$dispatcher->dispatch('BackendController', 'enableBackend');
|
||||||
|
}
|
||||||
|
)
|
||||||
|
->requirements(array('backend', 'enable'));
|
||||||
|
|
||||||
|
$this->create('contacts_backend_status', 'backend/{backend}')
|
||||||
|
->get()
|
||||||
|
->action(
|
||||||
|
function($params) {
|
||||||
|
\OC::$session->close();
|
||||||
|
$dispatcher = new Dispatcher($params);
|
||||||
|
$dispatcher->dispatch('BackendController', 'backendStatus');
|
||||||
|
}
|
||||||
|
)
|
||||||
|
->requirements(array('backend'));
|
||||||
|
|
||||||
$this->create('contacts_address_book_add', 'addressbook/{backend}/add')
|
$this->create('contacts_address_book_add', 'addressbook/{backend}/add')
|
||||||
->post()
|
->post()
|
||||||
->action(
|
->action(
|
||||||
|
138
js/admin.js
Normal file
138
js/admin.js
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
console.log($('#contacts-ldap-enabled'));
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
$.when(
|
||||||
|
backendStatus(
|
||||||
|
'ldap'
|
||||||
|
))
|
||||||
|
.then(function(response) {
|
||||||
|
if(!response.error) {
|
||||||
|
console.log('response', response.data);
|
||||||
|
if (response.data === "true") {
|
||||||
|
$('#contacts-ldap-enabled').prop('checked', true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('Error', response.message);
|
||||||
|
}
|
||||||
|
}).fail(function(response) {
|
||||||
|
console.log(response.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#contacts-ldap-enabled').change(function() {
|
||||||
|
var enabled=$(this).prop('checked')?"true":"false";
|
||||||
|
$.when(
|
||||||
|
enableBackend(
|
||||||
|
'ldap',
|
||||||
|
enabled
|
||||||
|
))
|
||||||
|
.then(function(response) {
|
||||||
|
if(!response.error) {
|
||||||
|
console.log('response', response.data);
|
||||||
|
} else {
|
||||||
|
console.warn('Error', response.message);
|
||||||
|
}
|
||||||
|
}).fail(function(response) {
|
||||||
|
console.log(response.message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function requestRoute(route, type, routeParams, params, additionalHeaders) {
|
||||||
|
var isJSON = (typeof params === 'string');
|
||||||
|
var contentType = isJSON
|
||||||
|
? (type === 'PATCH' ? 'application/json-merge-patch' : 'application/json')
|
||||||
|
: 'application/x-www-form-urlencoded';
|
||||||
|
var processData = !isJSON;
|
||||||
|
contentType += '; charset=UTF-8';
|
||||||
|
var url = OC.generateUrl('apps/contacts/' + route, routeParams);
|
||||||
|
var headers = {
|
||||||
|
Accept : 'application/json; charset=utf-8'
|
||||||
|
};
|
||||||
|
if(typeof additionalHeaders === 'object') {
|
||||||
|
headers = $.extend(headers, additionalHeaders);
|
||||||
|
}
|
||||||
|
var ajaxParams = {
|
||||||
|
type: type,
|
||||||
|
url: url,
|
||||||
|
dataType: 'json',
|
||||||
|
headers: headers,
|
||||||
|
contentType: contentType,
|
||||||
|
processData: processData,
|
||||||
|
data: params
|
||||||
|
};
|
||||||
|
|
||||||
|
var defer = $.Deferred();
|
||||||
|
|
||||||
|
$.ajax(ajaxParams)
|
||||||
|
.done(function(response, textStatus, jqXHR) {
|
||||||
|
console.log(jqXHR);
|
||||||
|
defer.resolve(new JSONResponse(jqXHR));
|
||||||
|
})
|
||||||
|
.fail(function(jqXHR/*, textStatus, error*/) {
|
||||||
|
console.log(jqXHR);
|
||||||
|
var response = jqXHR.responseText ? $.parseJSON(jqXHR.responseText) : null;
|
||||||
|
console.log('response', response);
|
||||||
|
defer.reject(new JSONResponse(jqXHR));
|
||||||
|
});
|
||||||
|
|
||||||
|
return defer.promise();
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableBackend(backend, enable, params) {
|
||||||
|
return this.requestRoute(
|
||||||
|
'backend/{backend}/{enable}',
|
||||||
|
'GET',
|
||||||
|
{backend: backend, enable: enable},
|
||||||
|
JSON.stringify(params)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function backendStatus(backend, params) {
|
||||||
|
return this.requestRoute(
|
||||||
|
'backend/{backend}',
|
||||||
|
'GET',
|
||||||
|
{backend: backend},
|
||||||
|
JSON.stringify(params)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var JSONResponse = function(jqXHR) {
|
||||||
|
this.getAllResponseHeaders = jqXHR.getAllResponseHeaders;
|
||||||
|
this.getResponseHeader = jqXHR.getResponseHeader;
|
||||||
|
this.statusCode = jqXHR.status;
|
||||||
|
var response = jqXHR.responseJSON;
|
||||||
|
this.error = false;
|
||||||
|
console.log('jqXHR', jqXHR);
|
||||||
|
if (!response) {
|
||||||
|
// 204 == No content
|
||||||
|
// 304 == Not modified
|
||||||
|
if ([204, 304].indexOf(this.statusCode) === -1) {
|
||||||
|
this.error = true;
|
||||||
|
}
|
||||||
|
this.message = jqXHR.statusText;
|
||||||
|
} else {
|
||||||
|
// We need to allow for both the 'old' success/error status property
|
||||||
|
// with the body in the data property, and the newer where we rely
|
||||||
|
// on the status code, and the entire body is used.
|
||||||
|
if (response.status === 'error'|| this.statusCode >= 400) {
|
||||||
|
this.error = true;
|
||||||
|
if (!response.data || !response.data.message) {
|
||||||
|
this.message = t('contacts', 'Server error! Please inform system administator');
|
||||||
|
} else {
|
||||||
|
console.log('JSONResponse', response);
|
||||||
|
this.message = (response.data && response.data.message)
|
||||||
|
? response.data.message
|
||||||
|
: response;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.data = response.data || response;
|
||||||
|
// Kind of a hack
|
||||||
|
if (response.metadata) {
|
||||||
|
this.metadata = response.metadata;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
@ -54,7 +54,6 @@ class App {
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $backendClasses = array(
|
public static $backendClasses = array(
|
||||||
'ldap' => 'OCA\Contacts\Backend\Ldap',
|
|
||||||
'local' => 'OCA\Contacts\Backend\Database',
|
'local' => 'OCA\Contacts\Backend\Database',
|
||||||
'shared' => 'OCA\Contacts\Backend\Shared',
|
'shared' => 'OCA\Contacts\Backend\Shared',
|
||||||
'localusers' => 'OCA\Contacts\Backend\LocalUsers',
|
'localusers' => 'OCA\Contacts\Backend\LocalUsers',
|
||||||
@ -72,6 +71,9 @@ class App {
|
|||||||
$this->dbBackend = $dbBackend
|
$this->dbBackend = $dbBackend
|
||||||
? $dbBackend
|
? $dbBackend
|
||||||
: new Backend\Database($user);
|
: new Backend\Database($user);
|
||||||
|
if (\OCP\Config::getAppValue('contacts', 'backend_ldap', "false") === "true") {
|
||||||
|
self::$backendClasses['ldap'] = 'OCA\Contacts\Backend\Ldap';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,5 +46,28 @@ class BackendController extends Controller {
|
|||||||
}
|
}
|
||||||
return $response->setData($formats);
|
return $response->setData($formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @NoCSRFRequired
|
||||||
|
*/
|
||||||
|
public function enableBackend() {
|
||||||
|
$response = new JSONResponse();
|
||||||
|
$params = $this->request->urlParams;
|
||||||
|
$backend = $params['backend'];
|
||||||
|
$enable = $params['enable'];
|
||||||
|
return $response->setData(\OCP\Config::setAppValue('contacts', 'backend_'.$backend, $enable));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @NoCSRFRequired
|
||||||
|
*/
|
||||||
|
public function backendStatus() {
|
||||||
|
$response = new JSONResponse();
|
||||||
|
$params = $this->request->urlParams;
|
||||||
|
$backend = $params['backend'];
|
||||||
|
$enabled = \OCP\Config::getAppValue('contacts', 'backend_'.$backend, "false");
|
||||||
|
return $response->setData($enabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
templates/admin.php
Normal file
21
templates/admin.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ownCloud - Contacts
|
||||||
|
*
|
||||||
|
* @author Nicolas Mora
|
||||||
|
* @copyright 2014 Nicolas Mora mail@babelouest.org
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
*/
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="section">
|
||||||
|
<h2>Contacts</h2>
|
||||||
|
<input type="checkbox" name="contacts-ldap-enabled" id="contacts-ldap-enabled" value="checked"/>
|
||||||
|
<label for="contacts-ldap-enabled"><?php p($l->t('Enable LDAP Backend')) ?></label><br>
|
||||||
|
<em><?php p($l->t('Enable LDAP backend for the contacts application')) ?></em>
|
||||||
|
<br/><em><?php p($l->t('Warning: LDAP Backend is in beta mode, use with precautions')) ?></em>
|
||||||
|
</div>
|
@ -23,9 +23,15 @@ use OCA\Contacts\ImportManager;
|
|||||||
<ul class="addressbooklist">
|
<ul class="addressbooklist">
|
||||||
</ul>
|
</ul>
|
||||||
<input type="text" tabindex="0" autofocus id="add-address-book" placeholder="<?php p($l->t('Display name')); ?>" title="<?php p($l->t('Add Address Book')); ?>" />
|
<input type="text" tabindex="0" autofocus id="add-address-book" placeholder="<?php p($l->t('Display name')); ?>" title="<?php p($l->t('Add Address Book')); ?>" />
|
||||||
|
<?php
|
||||||
|
if (\OCP\Config::getAppValue('contacts', 'backend_'.$backend, "false")) {
|
||||||
|
?>
|
||||||
<ul class="oc-addnew">
|
<ul class="oc-addnew">
|
||||||
<li id="add-ldap-address-book-element"><a class="oc-addnew-init"><?php p($l->t('Add LDAP Address Book')); ?></a></li>
|
<li id="add-ldap-address-book-element"><a class="oc-addnew-init"><?php p($l->t('Add LDAP Address Book')); ?></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
<div id="import">
|
<div id="import">
|
||||||
<h2 data-id="import" tabindex="0" role="button"><?php p($l->t('Import')); ?></h2>
|
<h2 data-id="import" tabindex="0" role="button"><?php p($l->t('Import')); ?></h2>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user