Skip to content

Commit

Permalink
Merge pull request #30987 from owncloud/select2-link-share-email-auto…
Browse files Browse the repository at this point in the history
…complete

Email autocomplete for link shares
  • Loading branch information
Vincent Petry authored Apr 3, 2018
2 parents 6e2b8aa + a6aebb5 commit da41f5b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
10 changes: 7 additions & 3 deletions apps/dav/lib/CardDAV/AddressBookImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,13 @@ protected function vCard2Array($uri, VCard $vCard) {
$result[$property->name] = $property->getValue();
}
}
if ($this->addressBookInfo['principaluri'] === 'principals/system/system' &&
$this->addressBookInfo['uri'] === 'system') {
$result['isLocalSystemBook'] = true;
if ($this->addressBookInfo['principaluri'] === 'principals/system/system' ) {
$result['isSystemBook'] = true;
if ($this->addressBookInfo['uri'] === 'system') {
$result['isLocalSystemBook'] = true;
} else {
$result['isFederatedSystemBook'] = true;
}
}
return $result;
}
Expand Down
19 changes: 15 additions & 4 deletions core/ajax/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,23 @@ function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
if (isset($_GET['search'])) {
$cm = OC::$server->getContactsManager();

$userEnumerationAllowed = OC::$server->getConfig()
->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') == 'yes';
$config = OC::$server->getConfig();
$userEnumerationAllowed = $config
->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
$pattern = (string)$_GET['search'];
$searchConfig = new \OCP\Util\UserSearch($config);
if (!$searchConfig->isSearchable($pattern)) {
OC_JSON::error();
return;
}

if (!is_null($cm) && $cm->isEnabled() && $userEnumerationAllowed) {
$contacts = $cm->search((string)$_GET['search'], ['FN', 'EMAIL']);
if ($cm !== null && $cm->isEnabled() && $userEnumerationAllowed) {
$contacts = $cm->search($pattern, ['FN', 'EMAIL']);
foreach ($contacts as $contact) {
// We don't want contacts from system address books
if (isset($contact['isSystemBook'])) {
continue;
}
if (!isset($contact['EMAIL'])) {
continue;
}
Expand Down
36 changes: 29 additions & 7 deletions core/js/sharedialogmailview.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,37 @@
containerCssClass: 'emailPrivateLinkForm--dropDown',
tags: true,
tokenSeparators:[","],
xhr: null,
query: function(query) {
// directly from search
query.callback({
results: [{
"id" : query.term,
"text" : query.term,
"disabled" : !_this.validateEmail(query.term)
}]
});
var data = [{
"id": query.term,
"text" : query.term
}];

// return query data ASAP
query.callback({results: data});

if (query.term.length >= OC.getCapabilities().files_sharing.search_min_length) {
if (this.xhr != null)
this.xhr.abort();

var xhr = $.get(OC.generateUrl('core/ajax/share.php'), {
'fetch' : 'getShareWithEmail',
'search': query.term
}).done(function(result) {
// enrich with share results
ajaxData = _.map(result.data, function(item) {
return {
'id' : item.email,
'text' : item.displayname + ' (' + item.email + ')'
}
});

query.callback({results: data.concat(ajaxData)});
})
this.xhr = xhr;
}
}
}).on("change", function(e) {
if (e.added)
Expand Down

0 comments on commit da41f5b

Please sign in to comment.