Skip to content

Commit 49b9872

Browse files
committed
YDA-6263: disable write actions when folder is locked
1 parent ab860c2 commit 49b9872

File tree

8 files changed

+47
-29
lines changed

8 files changed

+47
-29
lines changed

research/static/research/js/research.js

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ let currentFolder
1919
let currentFile
2020
let filenames = []
2121
let hasReadRights = true
22+
let hasWriteRights = true
23+
let status = ''
2224
let uploadFolder = false
2325

2426
$(function () {
@@ -1141,7 +1143,31 @@ function startBrowsing () {
11411143
serverSide: true,
11421144
iDeferLoading: 0,
11431145
order: [[1, 'asc']],
1144-
pageLength: parseInt(Yoda.storage.session.get('pageLength') === null ? Yoda.settings.number_of_items : Yoda.storage.session.get('pageLength'))
1146+
pageLength: parseInt(Yoda.storage.session.get('pageLength') === null ? Yoda.settings.number_of_items : Yoda.storage.session.get('pageLength')),
1147+
drawCallback: function (settings) {
1148+
const actions = {
1149+
multi: ['a.multiple-copy', 'a.multiple-move', 'a.multiple-delete'],
1150+
folder: ['a.folder-delete', 'a.folder-rename', 'a.folder-copy', 'a.folder-move'],
1151+
file: ['a.file-delete', 'a.file-rename', 'a.file-copy', 'a.file-move']
1152+
}
1153+
1154+
// Toggle disabled class.
1155+
const toggle = (sels, enable) =>
1156+
sels.flat().forEach(s => $(s).toggleClass('disabled', !enable))
1157+
1158+
// Disable all actions.
1159+
toggle(Object.values(actions), false)
1160+
1161+
if (hasReadRights) {
1162+
// Enable copy actions.
1163+
toggle(Object.values(actions).map(arr => arr.filter(s => s.endsWith('-copy'))), true)
1164+
}
1165+
1166+
if (hasWriteRights && (status === '' || status === 'REJECTED' || status === 'SECURED' || status === 'FOLDER')) {
1167+
// Enable all actions.
1168+
toggle(Object.values(actions), true)
1169+
}
1170+
}
11451171
})
11461172
$('#file-browser').on('length.dt', function (e, settings, len) {
11471173
Yoda.storage.session.set('pageLength', len)
@@ -1264,12 +1290,11 @@ function topInformation (dir, showAlert) {
12641290
const data = dataRaw.data
12651291
let statusText = ''
12661292
const basename = data.basename
1267-
const status = data.status
12681293
const userType = data.member_type
1269-
let hasWriteRights = true
12701294
const isDatamanager = data.is_datamanager
12711295
const lockCount = data.lock_count
12721296
const isLocked = data.is_locked
1297+
status = data.status
12731298
let actions = []
12741299

12751300
$('.btn-group button.metadata-form').hide()
@@ -1279,16 +1304,6 @@ function topInformation (dir, showAlert) {
12791304
$('.btn-group button.folder-create').attr('data-path', '')
12801305
$('.btn-group button.folder-create').prop('disabled', true)
12811306

1282-
$('a.folder-delete').addClass('disabled')
1283-
$('a.folder-rename').addClass('disabled')
1284-
$('a.folder-copy').addClass('disabled')
1285-
$('a.folder-move').addClass('disabled')
1286-
1287-
$('a.file-delete').addClass('disabled')
1288-
$('a.file-rename').addClass('disabled')
1289-
$('a.file-copy').addClass('disabled')
1290-
$('a.file-move').addClass('disabled')
1291-
12921307
$('.top-information').hide()
12931308
$('.top-info-buttons').hide()
12941309

@@ -1337,6 +1352,8 @@ function topInformation (dir, showAlert) {
13371352

13381353
if (isLocked) {
13391354
hasWriteRights = false
1355+
} else {
1356+
hasWriteRights = true
13401357
}
13411358

13421359
if (userType === 'reader' || userType === 'none') {
@@ -1366,7 +1383,9 @@ function topInformation (dir, showAlert) {
13661383
if (uploadMenuTooltip) {
13671384
uploadMenuTooltip.enable()
13681385
}
1369-
} else if (hasWriteRights && (status === '' || status === 'REJECTED' || status === 'SECURED' || status === 'FOLDER')) {
1386+
}
1387+
1388+
if (hasWriteRights && (status === '' || status === 'REJECTED' || status === 'SECURED' || status === 'FOLDER')) {
13701389
// Check if folder is writable.
13711390
// Enable uploads.
13721391
$('.btn-group button.upload').attr('data-path', dir)
@@ -1375,15 +1394,6 @@ function topInformation (dir, showAlert) {
13751394
// Enable folder / file manipulations.
13761395
$('.btn-group button.folder-create').attr('data-path', dir)
13771396
$('.btn-group button.folder-create').prop('disabled', false)
1378-
1379-
$('a.folder-rename').removeClass('disabled')
1380-
$('a.folder-copy').removeClass('disabled')
1381-
$('a.folder-move').removeClass('disabled')
1382-
$('a.folder-delete').removeClass('disabled')
1383-
$('a.file-rename').removeClass('disabled')
1384-
$('a.file-copy').removeClass('disabled')
1385-
$('a.file-move').removeClass('disabled')
1386-
$('a.file-delete').removeClass('disabled')
13871397
}
13881398

13891399
// Lock icon
@@ -1421,6 +1431,10 @@ function topInformation (dir, showAlert) {
14211431
const icon = '<i class="fa-regular fa-folder-open" aria-hidden="true"></i>'
14221432
$('.top-information h2').html(`<span class="icon">${icon}</span> ${folderName}${lockIcon}${systemMetadataIcon}${actionLogIcon}${statusBadge}`)
14231433

1434+
// Redraw file browser to update context menus.
1435+
const fileBrowser = $('#file-browser').DataTable()
1436+
fileBrowser.draw(false)
1437+
14241438
// Show top information and buttons.
14251439
if (typeof status !== 'undefined') {
14261440
$('.top-information').show()

static/css/yoda-portal.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/css/yoda-portal.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/src/components/index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
color: var(--bs-white);
6666
}
6767

68+
.dropdown-item.disabled {
69+
color: var(--bs-dropdown-link-disabled-color) !important;
70+
}
71+
6872
/* Select 2 selectors */
6973
.select2-container, .select2-search-container, .select2-input, .select2-chosen, .select2-drop, .select2-drop-mask {
7074
color: var(--bs-body-color);

themes/vu/static/css/yoda-portal.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

themes/vu/static/css/yoda-portal.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

themes/wur/static/css/yoda-portal.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

themes/wur/static/css/yoda-portal.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)