formatting remote sharer should take protocol, path into account

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2020-11-25 16:36:30 +01:00 committed by backportbot[bot]
parent 1636dfcbfa
commit e4b1d135a5
1 changed files with 120 additions and 117 deletions

View File

@ -32,7 +32,7 @@
* "user@example.com/path/to/owncloud"
* "user@anotherexample.com@example.com/path/to/owncloud
*/
_REMOTE_OWNER_REGEXP: new RegExp('^(([^@]*)@(([^@^/^\\s]*)@)?)([^[\\s/]*)([/](.*))?$'),
_REMOTE_OWNER_REGEXP: new RegExp('^(([^@]*)@(([^@^/\\s]*)@)?)((https://)?[^[\\s/]*)([/](.*))?$'),
/**
* Initialize the sharing plugin.
@ -341,137 +341,140 @@
}
icon.removeClass('icon-shared icon-public').addClass(iconClass)
},
/**
* Format a remote address
*
* @param {String} shareWith userid, full remote share, or whatever
* @param {String} shareWithDisplayName
* @param {String} message
* @returns {String} HTML code to display
*/
_formatRemoteShare: function(shareWith, shareWithDisplayName, message) {
var parts = OCA.Sharing.Util._REMOTE_OWNER_REGEXP.exec(shareWith)
if (!parts || !parts[6]) {
// display avatar of the user
var avatar = '<span class="avatar" data-username="' + escapeHTML(shareWith) + '" title="' + message + ' ' + escapeHTML(shareWithDisplayName) + '"></span>'
var hidden = '<span class="hidden-visually">' + message + ' ' + escapeHTML(shareWithDisplayName) + '</span> '
return avatar + hidden
}
/**
* Format a remote address
*
* @param {String} shareWith userid, full remote share, or whatever
* @param {String} shareWithDisplayName
* @param {String} message
* @returns {String} HTML code to display
*/
_formatRemoteShare: function(shareWith, shareWithDisplayName, message) {
var parts = OCA.Sharing.Util._REMOTE_OWNER_REGEXP.exec(shareWith)
console.error(parts);
if (!parts || !parts[7]) {
// display avatar of the user
var avatar = '<span class="avatar" data-username="' + escapeHTML(shareWith) + '" title="' + message + ' ' + escapeHTML(shareWithDisplayName) + '"></span>'
var hidden = '<span class="hidden-visually">' + message + ' ' + escapeHTML(shareWithDisplayName) + '</span> '
return avatar + hidden
}
var userName = parts[2]
var userDomain = parts[4]
var server = parts[5]
var protocol = parts[6]
var serverPath = parts[8] ? parts[7] : ''; // no trailing slash on root
var tooltip = message + ' ' + userName
if (userDomain) {
tooltip += '@' + userDomain
}
if (server) {
tooltip += '@' + server
tooltip += '@' + server.replace(protocol, '') + serverPath
}
var html = '<span class="remoteAddress" title="' + escapeHTML(tooltip) + '">'
html += '<span class="username">' + escapeHTML(userName) + '</span>'
if (userDomain) {
html += '<span class="userDomain">@' + escapeHTML(userDomain) + '</span>'
}
html += '</span> '
return html
},
/**
* Loop over all recipients in the list and format them using
* all kind of fancy magic.
*
* @param {Object} recipients array of all the recipients
* @returns {String[]} modified list of recipients
*/
_formatShareList: function(recipients) {
var _parent = this
recipients = _.toArray(recipients)
recipients.sort(function(a, b) {
return a.shareWithDisplayName.localeCompare(b.shareWithDisplayName)
})
return $.map(recipients, function(recipient) {
return _parent._formatRemoteShare(recipient.shareWith, recipient.shareWithDisplayName, t('core', 'Shared with'))
})
var html = '<span class="remoteAddress" title="' + escapeHTML(tooltip) + '">'
html += '<span class="username">' + escapeHTML(userName) + '</span>'
if (userDomain) {
html += '<span class="userDomain">@' + escapeHTML(userDomain) + '</span>'
}
html += '</span> '
return html
},
/**
* Loop over all recipients in the list and format them using
* all kind of fancy magic.
*
* @param {Object} recipients array of all the recipients
* @returns {String[]} modified list of recipients
*/
_formatShareList: function(recipients) {
var _parent = this
recipients = _.toArray(recipients)
recipients.sort(function(a, b) {
return a.shareWithDisplayName.localeCompare(b.shareWithDisplayName)
})
return $.map(recipients, function(recipient) {
return _parent._formatRemoteShare(recipient.shareWith, recipient.shareWithDisplayName, t('core', 'Shared with'))
})
},
/**
* Marks/unmarks a given file as shared by changing its action icon
* and folder icon.
*
* @param $tr file element to mark as shared
* @param hasShares whether shares are available
* @param hasLink whether link share is available
*/
markFileAsShared: function($tr, hasShares, hasLink) {
var action = $tr.find('.fileactions .action[data-action="Share"]')
var type = $tr.data('type')
var icon = action.find('.icon')
var message, recipients, avatars
var ownerId = $tr.attr('data-share-owner-id')
var owner = $tr.attr('data-share-owner')
var mountType = $tr.attr('data-mounttype')
var shareFolderIcon
var iconClass = 'icon-shared'
action.removeClass('shared-style')
// update folder icon
if (type === 'dir' && (hasShares || hasLink || ownerId)) {
if (typeof mountType !== 'undefined' && mountType !== 'shared-root' && mountType !== 'shared') {
shareFolderIcon = OC.MimeType.getIconUrl('dir-' + mountType)
} else if (hasLink) {
shareFolderIcon = OC.MimeType.getIconUrl('dir-public')
} else {
shareFolderIcon = OC.MimeType.getIconUrl('dir-shared')
}
$tr.find('.filename .thumbnail').css('background-image', 'url(' + shareFolderIcon + ')')
$tr.attr('data-icon', shareFolderIcon)
} else if (type === 'dir') {
var isEncrypted = $tr.attr('data-e2eencrypted')
// FIXME: duplicate of FileList._createRow logic for external folder,
// need to refactor the icon logic into a single code path eventually
if (isEncrypted === 'true') {
shareFolderIcon = OC.MimeType.getIconUrl('dir-encrypted')
$tr.attr('data-icon', shareFolderIcon)
} else if (mountType && mountType.indexOf('external') === 0) {
shareFolderIcon = OC.MimeType.getIconUrl('dir-external')
$tr.attr('data-icon', shareFolderIcon)
} else {
shareFolderIcon = OC.MimeType.getIconUrl('dir')
// back to default
$tr.removeAttr('data-icon')
}
$tr.find('.filename .thumbnail').css('background-image', 'url(' + shareFolderIcon + ')')
}
// update share action text / icon
if (hasShares || ownerId) {
recipients = $tr.data('share-recipient-data')
action.addClass('shared-style')
avatars = '<span>' + t('core', 'Shared') + '</span>'
// even if reshared, only show "Shared by"
if (ownerId) {
message = t('core', 'Shared by')
avatars = this._formatRemoteShare(ownerId, owner, message)
} else if (recipients) {
avatars = this._formatShareList(recipients)
}
action.html(avatars).prepend(icon)
/**
* Marks/unmarks a given file as shared by changing its action icon
* and folder icon.
*
* @param $tr file element to mark as shared
* @param hasShares whether shares are available
* @param hasLink whether link share is available
*/
markFileAsShared: function($tr, hasShares, hasLink) {
var action = $tr.find('.fileactions .action[data-action="Share"]')
var type = $tr.data('type')
var icon = action.find('.icon')
var message, recipients, avatars
var ownerId = $tr.attr('data-share-owner-id')
var owner = $tr.attr('data-share-owner')
var mountType = $tr.attr('data-mounttype')
var shareFolderIcon
var iconClass = 'icon-shared'
action.removeClass('shared-style')
// update folder icon
if (type === 'dir' && (hasShares || hasLink || ownerId)) {
if (typeof mountType !== 'undefined' && mountType !== 'shared-root' && mountType !== 'shared') {
shareFolderIcon = OC.MimeType.getIconUrl('dir-' + mountType)
} else if (hasLink) {
shareFolderIcon = OC.MimeType.getIconUrl('dir-public')
} else {
shareFolderIcon = OC.MimeType.getIconUrl('dir-shared')
}
$tr.find('.filename .thumbnail').css('background-image', 'url(' + shareFolderIcon + ')')
$tr.attr('data-icon', shareFolderIcon)
} else if (type === 'dir') {
var isEncrypted = $tr.attr('data-e2eencrypted')
// FIXME: duplicate of FileList._createRow logic for external folder,
// need to refactor the icon logic into a single code path eventually
if (isEncrypted === 'true') {
shareFolderIcon = OC.MimeType.getIconUrl('dir-encrypted')
$tr.attr('data-icon', shareFolderIcon)
} else if (mountType && mountType.indexOf('external') === 0) {
shareFolderIcon = OC.MimeType.getIconUrl('dir-external')
$tr.attr('data-icon', shareFolderIcon)
} else {
shareFolderIcon = OC.MimeType.getIconUrl('dir')
// back to default
$tr.removeAttr('data-icon')
}
$tr.find('.filename .thumbnail').css('background-image', 'url(' + shareFolderIcon + ')')
}
// update share action text / icon
if (hasShares || ownerId) {
recipients = $tr.data('share-recipient-data')
action.addClass('shared-style')
if (ownerId || recipients) {
var avatarElement = action.find('.avatar')
avatarElement.each(function() {
$(this).avatar($(this).data('username'), 32)
})
action.find('span[title]').tooltip({ placement: 'top' })
}
} else {
action.html('<span class="hidden-visually">' + t('core', 'Shared') + '</span>').prepend(icon)
}
if (hasLink) {
iconClass = 'icon-public'
}
icon.removeClass('icon-shared icon-public').addClass(iconClass)
avatars = '<span>' + t('core', 'Shared') + '</span>'
// even if reshared, only show "Shared by"
if (ownerId) {
message = t('core', 'Shared by')
avatars = this._formatRemoteShare(ownerId, owner, message)
} else if (recipients) {
avatars = this._formatShareList(recipients)
}
action.html(avatars).prepend(icon)
if (ownerId || recipients) {
var avatarElement = action.find('.avatar')
avatarElement.each(function() {
$(this).avatar($(this).data('username'), 32)
})
action.find('span[title]').tooltip({ placement: 'top' })
}
} else {
action.html('<span class="hidden-visually">' + t('core', 'Shared') + '</span>').prepend(icon)
}
if (hasLink) {
iconClass = 'icon-public'
}
icon.removeClass('icon-shared icon-public').addClass(iconClass)
},
/**