diff --git a/appinfo/routes.php b/appinfo/routes.php index f50aca1a..b7083d4e 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -34,7 +34,7 @@ $this->create('contacts_address_books_for_user', 'addressbooks/') } ); -$this->create('contacts_address_books_get_ldap_connectors', 'addressbook/connector') +$this->create('contacts_address_book_connectors', 'connectors/{backend}') ->get() ->action( function($params) { @@ -42,7 +42,8 @@ $this->create('contacts_address_books_get_ldap_connectors', 'addressbook/connect $dispatcher = new Dispatcher($params); $dispatcher->dispatch('AddressBookController', 'getLdapConnectors'); } - ); + ) + ->requirements(array('backend')); $this->create('contacts_address_book_add', 'addressbook/{backend}/add') ->post() diff --git a/css/contacts.css b/css/contacts.css index 52c964ee..31fe74cb 100644 --- a/css/contacts.css +++ b/css/contacts.css @@ -825,6 +825,11 @@ tbody tr.contact.active, tbody tr.contact:hover { display: inline-block; } +#calendar-ui > p > textarea { + width:200px; + display: inline-block; +} + #calendar-ui > p > label { width:200px; display: inline-block; diff --git a/formats/backend_ldap_inet_org_person_connector.xml b/formats/backend_ldap_inet_org_person_connector.xml new file mode 100644 index 00000000..34f0905a --- /dev/null +++ b/formats/backend_ldap_inet_org_person_connector.xml @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/formats/backend_ldap_mock_connector.xml b/formats/backend_ldap_mock_connector.xml new file mode 100644 index 00000000..81cebf07 --- /dev/null +++ b/formats/backend_ldap_mock_connector.xml @@ -0,0 +1,3 @@ + + + diff --git a/js/addressbooks.js b/js/addressbooks.js index d24608fa..332a7bab 100644 --- a/js/addressbooks.js +++ b/js/addressbooks.js @@ -67,7 +67,30 @@ OC.Contacts = OC.Contacts || {}; }); }); this.$li.find('a.action.edit').on('click keypress', function(event) { - if($(this).data('open')) { + var addressbook = self.storage.getAddressBook(self.getBackend(), self.getId(), false); + // TODO: remove this mock value + var addressbook = JSON.parse('{"uri":"hector","displayname":"hector","description":"Hector LDAP","ldapurl":"ldaps:\/\/hector.babelouest.org\/","ldapanonymous":false,"ldapreadonly":false,"ldapuser":"cn=Radio Radio,ou=private,ou=Addressbook,dc=babelouest,dc=org","ldappass":"Z291Z291","ldappagesize":"20","ldapbasednsearch":"cn=Radio Radio,ou=private,ou=Addressbook,dc=babelouest,dc=org","ldapfilter":"(objectclass=VCardUnassigned)","ldapbasednmodify":"cn=Radio Radio,ou=private,ou=Addressbook,dc=babelouest,dc=org","ldap_vcard_connector":"","id":"local","owner":"nico","permissions":31,"lastmodified":null}'); + addressbook.backend=self.getBackend(); + addressbook.addressbookid=self.getId(); + $("#calendar-ui") + .dialog({ + title:"Edit Addressbook", + close: function() { $(this).hide() }, + modal: false, + width: 'auto', + height: 'auto', + position: ['top', 100], + buttons: { + Ok: function() { + calendarUiEditOk(); + }, + Cancel: function() { + calendarUiCancel(); + } + }, + open: editCalendarUI(addressbook) + }); + /*if($(this).data('open')) { return; } var editor = this; @@ -100,7 +123,7 @@ OC.Contacts = OC.Contacts || {}; $(editor).data('open', false); } }); - $(this).data('open', true); + $(this).data('open', true);*/ }); return this.$li; }; @@ -652,30 +675,65 @@ OC.Contacts = OC.Contacts || {}; })(window, jQuery, OC); function openCalendarUi() { + $("#calendar-ui-backend option[value='local']").prop('selected', true); + $("#calendar-ui-uri").attr('disabled', false); + $("#calendar-ui-name").removeProp("required"); + $("#calendar-ui-name").val(""); + $("#calendar-ui-name").prop("required", ""); + $("#calendar-ui-uri").removeProp("required"); + $("#calendar-ui-uri").val(""); + $("#calendar-ui-uri").prop("required", ""); + $("#calendar-ui-description").removeProp("required"); + $("#calendar-ui-description").val(""); + $("#calendar-ui-description").prop("required", ""); + $("#calendar-ui-ldapurl").removeProp("required"); + $("#calendar-ui-ldapurl").val(""); + $("#calendar-ui-ldapurl").prop("required", ""); + $("#calendar-ui-ldapanonymous").attr('checked', false); + $("#calendar-ui-ldapreadonly").attr('checked', false); + $("#calendar-ui-ldapuser").removeProp("required"); + $("#calendar-ui-ldapuser").val(""); + $("#calendar-ui-ldapuser").prop("required", ""); + $("#calendar-ui-ldappass").removeProp("required"); + $("#calendar-ui-ldappass").val(atob("")); + $("#calendar-ui-ldappass").prop("required", ""); + $("#calendar-ui-ldapbasednsearch").removeProp("required"); + $("#calendar-ui-ldapbasednsearch").val(""); + $("#calendar-ui-ldapbasednsearch").prop("required", ""); + $("#calendar-ui-ldapfilter").removeProp("required"); + $("#calendar-ui-ldapfilter").val(""); + $("#calendar-ui-ldapfilter").prop("required", ""); + $("#calendar-ui-ldapbasednmodify").removeProp("required"); + $("#calendar-ui-ldapbasednmodify").val(""); + $("#calendar-ui-ldapbasednmodify").prop("required", ""); calendarUiInit(); $("#calendar-ui-backend").change(function() { + storage = new OC.Contacts.Storage(); calendarUiInit(); + var connectors = storage.getConnectors(); + alert(JSON.stringify(connectors)); }); - $("#calendar-ui-ldapanonymous").change(function() { - if ($("#calendar-ui-ldapanonymous").prop('checked')) { - $("#calendar-ui-ldapuser").attr('disabled', true); - $("#calendar-ui-ldappass").attr('disabled', true); - } else { - $("#calendar-ui-ldapuser").removeAttr('disabled'); - $("#calendar-ui-ldappass").removeAttr('disabled'); - } - }); - $("#calendar-ui-ldapbasednsearch").change(function() { - if ($("#calendar-ui-ldapbasednmodify").val() == '') { - $("#calendar-ui-ldapbasednmodify").val($("#calendar-ui-ldapbasednsearch").val()); - } - }); - $("#calendar-ui-ldapbasednmodify").change(function() { - if ($("#calendar-ui-ldapbasednsearch").val() == '') { - $("#calendar-ui-ldapbasednsearch").val($("#calendar-ui-ldapbasednmodify").val()); - } - }); +} + +function editCalendarUI(addressbook) { + $("#calendar-ui-addressbookid").val(addressbook.addressbookid); + $("#calendar-ui-backend option[value="+addressbook.backend+"]").prop('selected', true); + $("#calendar-ui-name").val(addressbook.displayname); + $("#calendar-ui-uri").val(addressbook.uri); + $("#calendar-ui-description").val(addressbook.description); + $("#calendar-ui-ldapurl").val(addressbook.ldapurl); + $("#calendar-ui-ldapanonymous").attr('checked', (addressbook.ldapanonymous==true)); + $("#calendar-ui-ldapreadonly").attr('checked', (addressbook.ldapreadonly==true)); + $("#calendar-ui-ldapuser").val(addressbook.ldapuser); + $("#calendar-ui-ldappass").val(atob(addressbook.ldappass)); + $("#calendar-ui-ldappagesize").val(addressbook.ldappagesize); + $("#calendar-ui-ldapbasednsearch").val(addressbook.ldapbasednsearch); + $("#calendar-ui-ldapfilter").val(addressbook.ldapfilter); + $("#calendar-ui-ldapbasednmodify").val(addressbook.ldapbasednmodify); + $("#calendar-ui-uri").attr('disabled', true); + //$("#calendar-ui-ldapvcardconnector").hide(); + calendarUiInit(); } function calendarUiOk() { @@ -727,6 +785,56 @@ function calendarUiOk() { }); } +function calendarUiEditOk() { + storage = new OC.Contacts.Storage(); + var defer = $.Deferred(); + + $.when(storage.updateAddressBook($("#calendar-ui-backend").val(), $("#calendar-ui-addressbookid").val(), + { + //addressBookId: $("#calendar-ui-addressbookid").val(), + displayname: $("#calendar-ui-name").val(), + description: $("#calendar-ui-description").val(), + uri: $("#calendar-ui-uri").val(), + ldapurl: $("#calendar-ui-ldapurl").val(), + ldapanonymous: $("#calendar-ui-ldapanonymous").prop('checked')==true?"true":"false", + ldapreadonly: $("#calendar-ui-ldapreadonly").prop('checked')==true?"true":"false", + ldapuser: $("#calendar-ui-ldapuser").val(), + ldappass: $("#calendar-ui-ldappass").val(), + ldappagesize: $("#calendar-ui-ldappagesize").val(), + ldapbasednsearch: $("#calendar-ui-ldapbasednsearch").val(), + ldapfilter: $("#calendar-ui-ldapfilter").val(), + ldapbasednmodify: $("#calendar-ui-ldapbasednmodify").val(), + ldapvcardconnector: $("#calendar-ui-ldapvcardconnector").val(), + } + )).then(function(response) { + if(response.error) { + error = response.message; + if(typeof cb === 'function') { + cb({error:true, message:error}); + } + defer.reject(response); + } else { + /*var book = addressbook.insertAddressBook(response.data); + $(document).trigger('status.addressbook.added'); + if(typeof cb === 'function') { + cb({error:false, addressbook: book}); + } + defer.resolve({error:false, addressbook: book});*/ + $("#calendar-ui").dialog('close'); + } + }) + .fail(function(jqxhr, textStatus, error) { + $(this).removeClass('loading'); + var err = textStatus + ', ' + error; + console.log('Request Failed', + err); + error = t('contacts', 'Failed adding address book: {error}', {error:err}); + if(typeof cb === 'function') { + cb({error:true, message:error}); + } + defer.reject({error:true, message:error}); + }); +} + function calendarUiCancel() { $("#calendar-ui").dialog('close'); } @@ -745,6 +853,7 @@ function calendarUiInit() { $("#calendar-ui-ldapfilter-p").hide(); $("#calendar-ui-ldapbasednmodify-p").hide(); $("#calendar-ui-ldapvcardconnector-p").hide(); + $("#calendar-ui-ldapvcardconnector-value-p").hide(); } else if ($("#calendar-ui-backend").val() == "ldap") { $("#calendar-ui-uri-p").show(); $("#calendar-ui-description-p").show(); @@ -758,5 +867,30 @@ function calendarUiInit() { $("#calendar-ui-ldapfilter-p").show(); $("#calendar-ui-ldapbasednmodify-p").show(); $("#calendar-ui-ldapvcardconnector-p").show(); + $("#calendar-ui-ldapvcardconnector-value-p").hide(); } + $("#calendar-ui-ldapanonymous").change(function() { + if ($("#calendar-ui-ldapanonymous").prop('checked')) { + $("#calendar-ui-ldapuser").attr('disabled', true); + $("#calendar-ui-ldappass").attr('disabled', true); + } else { + $("#calendar-ui-ldapuser").removeAttr('disabled'); + $("#calendar-ui-ldappass").removeAttr('disabled'); + } + }); + $("#calendar-ui-ldapbasednsearch").change(function() { + if ($("#calendar-ui-ldapbasednmodify").val() == '') { + $("#calendar-ui-ldapbasednmodify").val($("#calendar-ui-ldapbasednsearch").val()); + } + }); + $("#calendar-ui-ldapbasednmodify").change(function() { + if ($("#calendar-ui-ldapbasednsearch").val() == '') { + $("#calendar-ui-ldapbasednsearch").val($("#calendar-ui-ldapbasednmodify").val()); + } + }); + $("#calendar-ui-ldapvcardconnector").change(function() { + if ($("#calendar-ui-ldapvcardconnector").val() == 'custom') { + $("#calendar-ui-ldapvcardconnector-value-p").show(); + } + }); } diff --git a/js/storage.js b/js/storage.js index 4f155306..51b151e9 100644 --- a/js/storage.js +++ b/js/storage.js @@ -176,6 +176,33 @@ OC.Contacts = OC.Contacts || {}; JSON.stringify({state: state}) ); }; + + /** + * Update an address book in a specific backend + * + * @param string backend + * @param string addressBookId Address book ID + * @param object params An object {displayname:"My contacts", description:""} + * @return An array containing contact data e.g.: + * { + * metadata: + * { + * id:'1234' + * permissions:31, + * displayname:'My contacts', + * lastmodified: (unix timestamp), + * owner: 'joye', + * } + */ + Storage.prototype.getConnectors = function(backend) { + console.log('Storage.getConnectors', backend); + return this.requestRoute( + 'connectors/{backend}', + 'GET', + {backend: backend}, + JSON.stringify(properties) + ); + }; /** * Get contacts from an address book from a specific backend diff --git a/lib/addressbook.php b/lib/addressbook.php index d15dd39d..1a54c1a0 100644 --- a/lib/addressbook.php +++ b/lib/addressbook.php @@ -407,6 +407,7 @@ class Addressbook extends AbstractPIMCollection { * @return bool */ public function update(array $data) { + error_log(__METHOD__." enter"); if (!$this->hasPermission(\OCP\PERMISSION_UPDATE)) { throw new \Exception( self::$l10n->t('Access denied'), @@ -421,6 +422,7 @@ class Addressbook extends AbstractPIMCollection { ); } + error_log(__METHOD__." count ".count($data)); if (count($data) === 0) { return false; } @@ -436,6 +438,7 @@ class Addressbook extends AbstractPIMCollection { } } + error_log(__METHOD__); return $this->backend->updateAddressBook($this->getId(), $data); } diff --git a/lib/backend/ldap.php b/lib/backend/ldap.php index b1662866..f664b154 100644 --- a/lib/backend/ldap.php +++ b/lib/backend/ldap.php @@ -272,6 +272,16 @@ class Ldap extends AbstractBackend { * @return array $properties */ public function getAddressBook($addressbookid, array $options = array()) { + $backtrace = debug_backtrace(); + $trace=array(); + foreach ($backtrace as $elt) { + foreach ($elt as $key => $line) { + if ($key == "file" || $key == "line") { + $trace[] = $line; + } + } + } + //error_log(__METHOD__." ".print_r($trace,1)); //\OC_Log::write('contacts', __METHOD__.' id: ' // . $addressbookid, \OC_Log::DEBUG); if($this->addressbooks && isset($this->addressbooks[$addressbookid])) { @@ -281,7 +291,12 @@ class Ldap extends AbstractBackend { // Hmm, not found. Lets query the db. $preferences = (array)self::getPreferences($addressbookid); if ($preferences != false) { - $current = array(); + $preferences['id'] = (string)$addressbookid; + $preferences['owner'] = $this->userid; + $preferences['permissions'] = \OCP\PERMISSION_ALL; + $preferences['lastmodified'] = self::lastModifiedAddressBook($addressbookid); + return $preferences; + /*$current = array(); $current['id'] = (string)$addressbookid; $current['displayname'] = (string)$preferences['displayname']; $current['description'] = (string)$preferences['description']; @@ -289,7 +304,8 @@ class Ldap extends AbstractBackend { $current['uri'] = (string)$preferences['uri']; $current['permissions'] = \OCP\PERMISSION_ALL; $current['lastmodified'] = self::lastModifiedAddressBook($addressbookid); - return $current; + error_log(print_r($current, 1)); + return $current;*/ } else { return array(); } @@ -316,12 +332,18 @@ class Ldap extends AbstractBackend { * * @param string $addressbookid * @param array $properties - * @return bool + * @return string|false The ID if the modified AddressBook or false on error. */ public function updateAddressBook($addressbookid, array $properties, array $options = array()) { - // TODO: use backend settings - - return true; + error_log("where am i ?"); + if ($this->hasAddressBook($addressbookid)) { + error_log("was here ?"); + // Addressbook exists, modify it through the create function + return $this->createAddressBook($properties); + } else { + error_log("nope, was here"); + return false; + } } /** @@ -405,7 +427,7 @@ class Ldap extends AbstractBackend { * @returns int | null */ public function lastModifiedAddressBook($addressbookid, array $options = array()) { - return null; + return null; } /** @@ -435,6 +457,18 @@ class Ldap extends AbstractBackend { * @return array */ public function getContacts($addressbookid, array $options = array()) { + //error_log("was here ".__METHOD__); + $backtrace = debug_backtrace(); + $trace=array(); + foreach ($backtrace as $elt) { + foreach ($elt as $key => $line) { + if ($key == "file" || $key == "line") { + $trace[] = $line; + } + } + } + //error_log(__METHOD__." ".print_r($trace,1)); + $cards = array(); $vcards = array(); if(is_array($addressbookid) && count($addressbookid)) { diff --git a/lib/carddav/backend.php b/lib/carddav/backend.php index 851b50b6..90d010ee 100644 --- a/lib/carddav/backend.php +++ b/lib/carddav/backend.php @@ -189,7 +189,6 @@ class Backend extends \Sabre_CardDAV_Backend_Abstract { 'etag' => '"' . md5($contact['carddata']) . '"', 'uri' => urlencode($contact['uri']), 'lastmodified' => $contact['lastmodified'] ); - error_log("backend.getCards(".urlencode($contact['uri'])."): ".md5($contact['carddata'])." - ".$contact['carddata']); } return $cards; @@ -213,7 +212,6 @@ class Backend extends \Sabre_CardDAV_Backend_Abstract { } if(is_array($contact) ) { $contact['etag'] = '"' . md5($contact['carddata']) . '"'; - error_log("backend.getCard($carduri): ".$contact['etag']." - ".$contact['carddata']); return $contact; } //throw new \Sabre_DAV_Exception('Error retrieving the card'); diff --git a/lib/controller/addressbookcontroller.php b/lib/controller/addressbookcontroller.php index 9550e5a9..4a19ac2a 100644 --- a/lib/controller/addressbookcontroller.php +++ b/lib/controller/addressbookcontroller.php @@ -151,8 +151,10 @@ class AddressBookController extends Controller { $response = new JSONResponse(); + error_log(__METHOD__.print_r($this->request, true)); $addressBook = $this->app->getAddressBook($params['backend'], $params['addressBookId']); - $addressBook->update($this->request['properties']); + //$addressBook->update($this->request['properties']); + $addressBook->update($this->request->post); return $response->setParams($addressBook->getMetaData()); } @@ -338,10 +340,11 @@ class AddressBookController extends Controller { /** * @NoAdminRequired + * @NoCSRFRequired */ public function getLdapConnectors() { $params = $this->request->urlParams; - $targetInfo = $this->request->post['target']; + //$targetInfo = $this->request->post['target']; $response = new JSONResponse(); $prefix = "backend_ldap_"; diff --git a/templates/contacts.php b/templates/contacts.php index 73ca8ba2..fe3feed9 100644 --- a/templates/contacts.php +++ b/templates/contacts.php @@ -509,6 +509,7 @@ use OCA\Contacts\ImportManager;
+

+

+ + +