Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/files_sharing/js/additionalScripts.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files_sharing/js/additionalScripts.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/files_sharing/lib/Controller/ShareesAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class ShareesAPIController extends OCSController {
'lookup' => [],
'circles' => [],
'rooms' => [],
'lookupEnabled' => false,
];

protected $reachedEndFor = [];
Expand Down Expand Up @@ -212,6 +213,7 @@ public function search(string $search = '', string $itemType = null, int $page =
$result['exact'] = array_merge($this->result['exact'], $result['exact']);
}
$this->result = array_merge($this->result, $result);
$this->result['lookupEnabled'] = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes') === 'yes';
$response = new DataResponse($this->result);

if ($hasMoreResults) {
Expand Down
5 changes: 5 additions & 0 deletions apps/files_sharing/src/style/sharetabview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
opacity: .7;
margin-right: 7px;
}
.icon.search-globally {
width: 32px;
height: 32px;
margin-right: 0;
}
}

.shareTabView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,13 @@ public function testSearch($getData, $apiSetting, $enumSetting, $remoteSharingEn

/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject $config */
$config = $this->createMock(IConfig::class);
$config->expects($this->exactly(2))
$config->expects($this->exactly(3))
->method('getAppValue')
->with('core', $this->anything(), $this->anything())
->with($this->anything(), $this->anything(), $this->anything())
->willReturnMap([
['core', 'shareapi_only_share_with_group_members', 'no', $apiSetting],
['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', $enumSetting],
['files_sharing', 'lookupServerEnabled', 'yes', 'yes'],
]);

$this->shareManager->expects($itemType === 'file' || $itemType === 'folder' ? $this->once() : $this->never())
Expand Down
2 changes: 1 addition & 1 deletion core/js/dist/share_backend.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/share_backend.js.map

Large diffs are not rendered by default.

71 changes: 48 additions & 23 deletions core/js/sharedialogview.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
/** @type {boolean} **/
_showLink: true,

_lookup: false,

_lookupAllowed: false,

/** @type {string} **/
tagName: 'div',

Expand Down Expand Up @@ -125,24 +129,28 @@

/* trigger search after the field was re-selected */
onShareWithFieldFocus: function() {
this.$el.find('.shareWithField').autocomplete("search");
var $shareWithField = this.$el.find('.shareWithField');
$shareWithField.autocomplete("search", $shareWithField.val());
},

_getSuggestions: function(searchTerm, perPage, model) {
_getSuggestions: function(searchTerm, perPage, model, lookup) {
if (this._lastSuggestions &&
this._lastSuggestions.searchTerm === searchTerm &&
this._lastSuggestions.lookup === lookup &&
this._lastSuggestions.perPage === perPage &&
this._lastSuggestions.model === model) {
return this._lastSuggestions.promise;
}

var deferred = $.Deferred();
var view = this;

$.get(
OC.linkToOCS('apps/files_sharing/api/v1') + 'sharees',
{
format: 'json',
search: searchTerm,
lookup: lookup,
perPage: perPage,
itemType: model.get('itemType')
},
Expand Down Expand Up @@ -300,6 +308,7 @@
var remotes = result.ocs.data.remotes;
var remoteGroups = result.ocs.data.remote_groups;
var lookup = result.ocs.data.lookup;
var lookupEnabled = result.ocs.data.lookupEnabled;
var emails = [];
if (typeof(result.ocs.data.emails) !== 'undefined') {
emails = result.ocs.data.emails;
Expand Down Expand Up @@ -365,8 +374,17 @@
lookup.length
)
);
if (!view._lookup && lookupEnabled) {
result.push(
{
label: t('core', 'Search globally'),
value: {},
lookup: true
}
)
}

deferred.resolve(result, exactMatches, moreResultsAvailable);
deferred.resolve(result, exactMatches, moreResultsAvailable, lookupEnabled);
} else {
deferred.reject(result.ocs.meta.message);
}
Expand All @@ -377,6 +395,7 @@

this._lastSuggestions = {
searchTerm: searchTerm,
lookup: lookup,
perPage: perPage,
model: model,
promise: deferred.promise()
Expand Down Expand Up @@ -641,14 +660,8 @@
var $shareWithField = $('.shareWithField');
this._getRecommendations(
view.model
).done(function(suggestions, exactMatches) {
view._pendingOperationsCount--;
if (view._pendingOperationsCount === 0) {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');
}

).done(function(suggestions) {
console.info('recommendations', suggestions);
if (suggestions.length > 0) {
$shareWithField
.autocomplete("option", "autoFocus", true);
Expand All @@ -659,13 +672,6 @@
response();
}
}).fail(function(message) {
view._pendingOperationsCount--;
if (view._pendingOperationsCount === 0) {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');
}

console.error('could not load recommendations', message)
});
},
Expand All @@ -674,6 +680,7 @@
// If nothing is entered we show recommendations instead of search
// results
if (search.term.length === 0) {
console.info(search.term, 'empty search term -> using recommendations');
this.recommendationHandler(response);
return;
}
Expand Down Expand Up @@ -716,7 +723,8 @@
this._getSuggestions(
search.term.trim(),
perPage,
view.model
view.model,
view._lookup
).done(function(suggestions, exactMatches, moreResultsAvailable) {
view._pendingOperationsCount--;
if (view._pendingOperationsCount === 0) {
Expand Down Expand Up @@ -747,7 +755,7 @@
.attr('data-original-title', title)
.tooltip('hide')
.tooltip({
placement: 'bottom',
placement: 'top',
trigger: 'manual'
})
.tooltip('fixTitle')
Expand Down Expand Up @@ -818,6 +826,10 @@
insert.addClass('merged');
text = item.value.shareWith;
description = type;
} else if (item.lookup) {
text = item.label;
icon = false;
insert.append('<span class="icon icon-search search-globally"></span>');
} else {
var avatar = $("<div class='avatardiv'></div>").appendTo(insert);
if (item.value.shareType === OC.Share.SHARE_TYPE_USER || item.value.shareType === OC.Share.SHARE_TYPE_CIRCLE) {
Expand All @@ -843,7 +855,9 @@
)
.appendTo(insert);
insert.attr('title', item.value.shareWith);
insert.append('<span class="icon '+icon+'" title="' + text + '"></span>');
if (icon) {
insert.append('<span class="icon ' + icon + '" title="' + text + '"></span>');
}
insert = $("<a>")
.append(insert);
return $("<li>")
Expand All @@ -869,6 +883,18 @@
return false;
}

if (s.item.lookup) {
// Retrigger search but with global lookup this time
this._lookup = true;
var $shareWithField = this.$el.find('.shareWithField');
var val = $shareWithField.val();
setTimeout(function() {
console.debug('searching again, but globally. search term: ' + val);
$shareWithField.autocomplete("search", val);
}, 0);
return false;
}

e.preventDefault();
// Ensure that the keydown handler for the input field is not
// called; otherwise it would try to add the recipient again, which
Expand Down Expand Up @@ -947,12 +973,11 @@
};

var perPage = parseInt(oc_config['sharing.maxAutocompleteResults'], 10) || 200;
var onlyExactMatches = true;
this._getSuggestions(
$shareWithField.val(),
perPage,
this.model,
onlyExactMatches
this._lookup
).done(function(suggestions, exactMatches) {
if (suggestions.length === 0) {
restoreUI();
Expand Down
Loading