Skip to content

Commit e8f16db

Browse files
author
Vincent Petry
committed
Merge pull request #13866 from rullzer/avatar_share_dialog
Avatars in share dialog
2 parents 30ca140 + 9a6da8e commit e8f16db

File tree

5 files changed

+117
-3
lines changed

5 files changed

+117
-3
lines changed

core/css/share.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
overflow: hidden;
6969
vertical-align: middle;
7070
}
71+
#shareWithList .avatar {
72+
margin-right: 2px;
73+
display: inline-block;
74+
overflow: hidden;
75+
vertical-align: middle;
76+
}
7177
#shareWithList li label{
7278
margin-right: 8px;
7379
}

core/js/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
'session_keepalive' => \OCP\Config::getSystemValue('session_keepalive', true),
7575
'version' => implode('.', OC_Util::getVersion()),
7676
'versionstring' => OC_Util::getVersionString(),
77+
'enable_avatars' => \OC::$server->getConfig()->getSystemValue('enable_avatars', true),
7778
)
7879
),
7980
"oc_appconfig" => json_encode(

core/js/core.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
],
1010
"libraries": [
1111
"jquery-showpassword.js",
12-
"jquery-tipsy.js"
12+
"jquery-tipsy.js",
13+
"jquery.avatar.js"
1314
],
1415
"modules": [
1516
"compatibility.js",

core/js/share.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,17 @@ OC.Share={
358358
var html = '<div id="dropdown" class="drop shareDropDown" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">';
359359
if (data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) {
360360
if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) {
361-
html += '<span class="reshare">'+t('core', 'Shared with you and the group {group} by {owner}', {group: data.reshare.share_with, owner: data.reshare.displayname_owner})+'</span>';
361+
html += '<span class="reshare">'+t('core', 'Shared with you and the group {group} by {owner}', {group: data.reshare.share_with, owner: data.reshare.displayname_owner});
362+
if (oc_config.enable_avatars === true) {
363+
html += ' <div id="avatar-share-owner" style="display: inline-block"></div>';
364+
}
365+
html += '</span>';
362366
} else {
363-
html += '<span class="reshare">'+t('core', 'Shared with you by {owner}', {owner: data.reshare.displayname_owner})+'</span>';
367+
html += '<span class="reshare">'+t('core', 'Shared with you by {owner}', {owner: data.reshare.displayname_owner});
368+
if (oc_config.enable_avatars === true) {
369+
html += ' <div id="avatar-share-owner" style="display: inline-block"></div>';
370+
}
371+
html += '</span>';
364372
}
365373
html += '<br />';
366374
// reduce possible permissions to what the original share allowed
@@ -437,6 +445,12 @@ OC.Share={
437445
html += '</div>';
438446
dropDownEl = $(html);
439447
dropDownEl = dropDownEl.appendTo(appendTo);
448+
449+
//Get owner avatars
450+
if (oc_config.enable_avatars === true && data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) {
451+
$('#avatar-share-owner').avatar(data.reshare.uid_owner, 32);
452+
}
453+
440454
// Reset item shares
441455
OC.Share.itemShares = [];
442456
OC.Share.currentShares = {};
@@ -650,6 +664,13 @@ OC.Share={
650664
var html = '<li style="clear: both;" data-share-type="'+escapeHTML(shareType)+'" data-share-with="'+escapeHTML(shareWith)+'" title="' + escapeHTML(shareWith) + '">';
651665
var showCrudsButton;
652666
html += '<a href="#" class="unshare"><img class="svg" alt="'+t('core', 'Unshare')+'" title="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
667+
if (oc_config.enable_avatars === true) {
668+
if (shareType === OC.Share.SHARE_TYPE_USER) {
669+
html += '<div id="avatar-' + escapeHTML(shareWith) + '" class="avatar"></div>';
670+
} else {
671+
html += '<div class="avatar" style="padding-right: 32px"></div>';
672+
}
673+
}
653674
html += '<span class="username">' + escapeHTML(shareWithDisplayName) + '</span>';
654675
var mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val();
655676
if (mailNotificationEnabled === 'yes' && shareType !== OC.Share.SHARE_TYPE_REMOTE) {
@@ -681,6 +702,9 @@ OC.Share={
681702
html += '</div>';
682703
html += '</li>';
683704
html = $(html).appendTo('#shareWithList');
705+
if (oc_config.enable_avatars === true && shareType === OC.Share.SHARE_TYPE_USER) {
706+
$('#avatar-' + escapeHTML(shareWith)).avatar(escapeHTML(shareWith), 32);
707+
}
684708
// insert cruds button into last label element
685709
var lastLabel = html.find('>label:last');
686710
if (lastLabel.exists()){

core/js/tests/specs/shareSpec.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ describe('OC.Share tests', function() {
2626
var oldAppConfig;
2727
var loadItemStub;
2828
var autocompleteStub;
29+
var oldEnableAvatars;
30+
var avatarStub;
2931

3032
beforeEach(function() {
3133
$('#testArea').append($('<div id="shareContainer"></div>'));
@@ -54,13 +56,19 @@ describe('OC.Share tests', function() {
5456
var $el = $('<div></div>').data('ui-autocomplete', {});
5557
return $el;
5658
});
59+
60+
oldEnableAvatars = oc_config.enable_avatars;
61+
oc_config.enable_avatars = false;
62+
avatarStub = sinon.stub($.fn, 'avatar');
5763
});
5864
afterEach(function() {
5965
/* jshint camelcase:false */
6066
oc_appconfig.core = oldAppConfig;
6167
loadItemStub.restore();
6268

6369
autocompleteStub.restore();
70+
avatarStub.restore();
71+
oc_config.enable_avatars = oldEnableAvatars;
6472
$('#dropdown').remove();
6573
});
6674
it('calls loadItem with the correct arguments', function() {
@@ -405,6 +413,80 @@ describe('OC.Share tests', function() {
405413
});
406414
});
407415
});
416+
describe('check for avatar', function() {
417+
beforeEach(function() {
418+
loadItemStub.returns({
419+
reshare: [],
420+
shares: [{
421+
id: 100,
422+
item_source: 123,
423+
permissions: 31,
424+
share_type: OC.Share.SHARE_TYPE_USER,
425+
share_with: 'user1',
426+
share_with_displayname: 'User One'
427+
},{
428+
id: 101,
429+
item_source: 123,
430+
permissions: 31,
431+
share_type: OC.Share.SHARE_TYPE_GROUP,
432+
share_with: 'group',
433+
share_with_displayname: 'group'
434+
}]
435+
});
436+
});
437+
438+
describe('avatars enabled', function() {
439+
beforeEach(function() {
440+
oc_config.enable_avatars = true;
441+
OC.Share.showDropDown(
442+
'file',
443+
123,
444+
$container,
445+
true,
446+
31,
447+
'shared_file_name.txt'
448+
);
449+
});
450+
451+
afterEach(function() {
452+
oc_config.enable_avatars = false;
453+
});
454+
455+
it('test correct function call', function() {
456+
expect(avatarStub.calledOnce).toEqual(true);
457+
var args = avatarStub.getCall(0).args;
458+
459+
460+
expect($('#shareWithList').children().length).toEqual(2);
461+
462+
expect($('#avatar-user1').length).toEqual(1);
463+
expect(args.length).toEqual(2);
464+
expect(args[0]).toEqual('user1');
465+
});
466+
467+
it('test no avatar for groups', function() {
468+
expect($('#shareWithList').children().length).toEqual(2);
469+
expect($('#shareWithList li:nth-child(2) .avatar').attr('id')).not.toBeDefined();
470+
});
471+
});
472+
473+
describe('avatars disabled', function() {
474+
beforeEach(function() {
475+
OC.Share.showDropDown(
476+
'file',
477+
123,
478+
$container,
479+
true,
480+
31,
481+
'shared_file_name.txt'
482+
);
483+
});
484+
485+
it('no avatar classes', function() {
486+
expect($('.avatar').length).toEqual(0);
487+
});
488+
});
489+
});
408490
describe('"sharesChanged" event', function() {
409491
var autocompleteOptions;
410492
var handler;

0 commit comments

Comments
 (0)