Browse Source

Show hint if there is no delete permission

* add class .no-permission which shows the default delete icon
* fixes #15172
* add unit test for no permission and for delete permission
tags/v8.1.0beta1
Morris Jobke 9 years ago
parent
commit
f4bc852db3

+ 3
- 1
apps/files/css/files.css View File

#fileList tr:hover a.action, #fileList tr:hover a.action,
#fileList a.action.permanent, #fileList a.action.permanent,
#fileList tr:focus a.action, #fileList tr:focus a.action,
#fileList a.action.permanent
#fileList a.action.permanent,
#fileList tr:hover a.action.no-permission:hover,
#fileList tr:focus a.action.no-permission:focus
/*#fileList .name:focus .action*/ { /*#fileList .name:focus .action*/ {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=50); filter: alpha(opacity=50);

+ 13
- 2
apps/files/js/fileactions.js View File

} else if (mountType === 'shared-root') { } else if (mountType === 'shared-root') {
deleteTitle = t('files', 'Unshare'); deleteTitle = t('files', 'Unshare');
} }
var cssClasses = 'action delete icon-delete';
if((context.$file.data('permissions') & OC.PERMISSION_DELETE) === 0) {
// add css class no-permission to delete icon
cssClasses += ' no-permission';
deleteTitle = t('files', 'No permission to delete');
}
var $actionLink = $('<a href="#" original-title="' + var $actionLink = $('<a href="#" original-title="' +
escapeHTML(deleteTitle) + escapeHTML(deleteTitle) +
'" class="action delete icon-delete">' +
'" class="' +cssClasses + '">' +
'<span class="hidden-visually">' + escapeHTML(deleteTitle) + '</span>' + '<span class="hidden-visually">' + escapeHTML(deleteTitle) + '</span>' +
'</a>' '</a>'
); );
name: 'Delete', name: 'Delete',
displayName: '', displayName: '',
mime: 'all', mime: 'all',
permissions: OC.PERMISSION_DELETE,
// permission is READ because we show a hint instead if there is no permission
permissions: OC.PERMISSION_READ,
icon: function() { icon: function() {
return OC.imagePath('core', 'actions/delete'); return OC.imagePath('core', 'actions/delete');
}, },
render: _.bind(this._renderDeleteAction, this), render: _.bind(this._renderDeleteAction, this),
actionHandler: function(fileName, context) { actionHandler: function(fileName, context) {
// if there is no permission to delete do nothing
if((context.$file.data('permissions') & OC.PERMISSION_DELETE) === 0) {
return;
}
context.fileList.do_delete(fileName, context.dir); context.fileList.do_delete(fileName, context.dir);
$('.tipsy').remove(); $('.tipsy').remove();
} }

+ 42
- 0
apps/files/tests/js/fileactionsSpec.js View File

expect(deleteStub.getCall(0).args[1]).toEqual('/somepath/dir'); expect(deleteStub.getCall(0).args[1]).toEqual('/somepath/dir');
deleteStub.restore(); deleteStub.restore();
}); });
it('shows delete hint when no permission to delete', function() {
var deleteStub = sinon.stub(fileList, 'do_delete');
var fileData = {
id: 18,
type: 'file',
name: 'testName.txt',
path: '/somepath/dir',
mimetype: 'text/plain',
size: '1234',
etag: 'a01234c',
mtime: '123456',
permissions: OC.PERMISSION_READ
};
var $tr = fileList.add(fileData);
FileActions.display($tr.find('td.filename'), true, fileList);

var $action = $tr.find('.action.delete');

expect($action.hasClass('no-permission')).toEqual(true);
deleteStub.restore();
});
it('shows delete hint not when permission to delete', function() {
var deleteStub = sinon.stub(fileList, 'do_delete');
var fileData = {
id: 18,
type: 'file',
name: 'testName.txt',
path: '/somepath/dir',
mimetype: 'text/plain',
size: '1234',
etag: 'a01234c',
mtime: '123456',
permissions: OC.PERMISSION_DELETE
};
var $tr = fileList.add(fileData);
FileActions.display($tr.find('td.filename'), true, fileList);

var $action = $tr.find('.action.delete');

expect($action.hasClass('no-permission')).toEqual(false);
deleteStub.restore();
});
it('passes context to action handler', function() { it('passes context to action handler', function() {
var actionStub = sinon.stub(); var actionStub = sinon.stub();
var fileData = { var fileData = {

+ 1
- 1
apps/files_external/tests/js/mountsfilelistSpec.js View File

'?dir=/another%20mount%20points/sftp%20mount' '?dir=/another%20mount%20points/sftp%20mount'
); );
expect($tr.find('.nametext').text().trim()).toEqual('sftp mount'); expect($tr.find('.nametext').text().trim()).toEqual('sftp mount');
expect($tr.find('.column-scope').text().trim()).toEqual('System');
expect($tr.find('.column-scope > span').text().trim()).toEqual('System');
expect($tr.find('.column-backend').text().trim()).toEqual('SFTP'); expect($tr.find('.column-backend').text().trim()).toEqual('SFTP');


$tr = $rows.eq(1); $tr = $rows.eq(1);

+ 3
- 1
core/css/icons.css View File

background-image: url('../img/actions/confirm.svg'); background-image: url('../img/actions/confirm.svg');
} }


.icon-delete {
.icon-delete,
.icon-delete.no-permission:hover,
.icon-delete.no-permission:focus {
background-image: url('../img/actions/delete.svg'); background-image: url('../img/actions/delete.svg');
} }
.icon-delete:hover, .icon-delete:hover,

Loading…
Cancel
Save