Skip to content

Commit

Permalink
Check for restricted content, not downloadable images, and pass the f…
Browse files Browse the repository at this point in the history
…ile's info into the restriction check instead of using the work's info.
  • Loading branch information
lfarrell committed Nov 5, 2024
1 parent ede09b2 commit 8d29f15
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="!isLoggedIn && (showNonImageDownload(recordData) || showImageDownload(recordData))" class="actionlink download">
<div v-if="!isLoggedIn && restrictedFiles(recordData)" class="actionlink download">
<a @click.prevent="modal_open = true" class="download login-modal-link button action" href="#">Contact Wilson/Log in to access</a>
</div>
<div v-else-if="showNonImageDownload(recordData)" class="actionlink download">
Expand Down Expand Up @@ -27,7 +27,7 @@
</div>
</div>

<div v-if="!isLoggedIn && (showNonImageDownload(recordData) || showImageDownload(recordData))" class="modal" :class="{ 'is-active': modal_open }">
<div v-if="!isLoggedIn && restrictedFiles(recordData)" class="modal" :class="{ 'is-active': modal_open }">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
Expand Down Expand Up @@ -79,6 +79,22 @@ export default {
},
methods: {
restrictedFiles(recordData) {
if (!this.hasGroups(recordData) ||
recordData.groupRoleMap.everyone === undefined) {
return false;
}
if (recordData.groupRoleMap.everyone.includes('canViewOriginals')) {
return false;
}
// For File objects, content is not restricted if the user can at least download low res files
// Record is assumed to be a file
if (this.hasDownloadAccess(recordData)) {
return false;
}
return true;
},
toggleDownloadOptions() {
this.download_options_open = !this.download_options_open;
},
Expand Down
28 changes: 8 additions & 20 deletions static/js/vue-cdr-access/src/components/full_record/fileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ force it to reload
<th>{{ $t('full_record.file_type') }}</th>
<th>{{ $t('full_record.filesize') }}</th>
<th><span class="sr-only">{{ $t('full_record.view_file') }}</span></th>
<th v-if="downloadAccess"><span class="sr-only">{{ $t('full_record.download_file') }}</span></th>
<th><span class="sr-only">{{ $t('full_record.download_file') }}</span></th>
<th v-if="editAccess"><span class="sr-only">{{ $t('full_record.mods') }}</span></th>
</tr>
</thead>
Expand Down Expand Up @@ -71,7 +71,11 @@ export default {
{ data: this.$t('full_record.title') },
{ data: this.$t('full_record.file_type') },
{ data: this.$t('full_record.filesize') },
{ data: this.$t('full_record.view_file') }
{ data: this.$t('full_record.view_file') },
{ data: null, width: '120px', render: {
display: '#downloads'
}
}
]
}
},
Expand Down Expand Up @@ -129,7 +133,7 @@ export default {
},
columnDefs() {
const excluded_columns = [0, 4];
const excluded_columns = [0, 4, 5];
let column_defs = [
{ orderable: false, targets: excluded_columns },
Expand Down Expand Up @@ -197,25 +201,9 @@ export default {
}
];
if (this.downloadAccess) {
this.columns.push({ data: null });
excluded_columns.push(5); // download button
// Add to orderable, searchable exclusions
[0, 1].forEach((d) => column_defs[d].targets = excluded_columns);
column_defs.push({
render: {
display: '#downloads'
},
width: '120px',
targets: 5
});
}
if (this.editAccess) {
// Check for the correct column number, in the unlikely event a user has edit access, but not download access
const column_number = (this.downloadAccess) ? 6 : 5;
const column_number = 6;
this.columns.push({ data: this.$t('full_record.mods') });
excluded_columns.push(column_number); // edit button
Expand Down
6 changes: 3 additions & 3 deletions static/js/vue-cdr-access/tests/unit/downloadOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ describe('downloadOption.vue', () => {
});

it('shows a login modal', async () => {
await setRecordPermissions(record, ['viewAccessCopies', 'viewReducedResImages', 'viewOriginal']);
await setRecordPermissions(record, ['viewAccessCopies', 'viewReducedResImages']);
await store.$patch({ username: '' })
await store.$patch({ isLoggedIn: false })
await wrapper.find('.login-modal-link').trigger('click'); // Open
expect(wrapper.find('.modal').classes('is-active')).toBe(true);
});

it('closes the login modal', async () => {
await setRecordPermissions(record, ['viewAccessCopies', 'viewReducedResImages', 'viewOriginal']);
await setRecordPermissions(record, ['viewAccessCopies', 'viewReducedResImages']);
await store.$patch({ username: '' });
await store.$patch({ isLoggedIn: false });
await wrapper.find('.login-modal-link').trigger('click'); // Open
Expand All @@ -291,7 +291,7 @@ describe('downloadOption.vue', () => {
});

it('closes the modal when the "ESC" key is hit', async () => {
await setRecordPermissions(record, ['viewAccessCopies', 'viewReducedResImages', 'viewOriginal']);
await setRecordPermissions(record, ['viewAccessCopies', 'viewReducedResImages']);
await store.$patch({ username: '' });
await store.$patch({ isLoggedIn: false });
await wrapper.find('.login-modal-link').trigger('click'); // Open
Expand Down

0 comments on commit 8d29f15

Please sign in to comment.