Skip to content

Commit 683e5d6

Browse files
authored
Don't show download button to users without download access (#1626)
1 parent b47e339 commit 683e5d6

File tree

6 files changed

+56
-58
lines changed

6 files changed

+56
-58
lines changed

static/js/vue-cdr-access/package-lock.json

Lines changed: 25 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/js/vue-cdr-access/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@vue/test-utils": "2.3.2",
4444
"@vue/vue3-jest": "^29.2.3",
4545
"babel-jest": "^29.5.0",
46-
"caniuse-lite": "^1.0.30001474",
46+
"caniuse-lite": "^1.0.30001564",
4747
"jest-environment-jsdom": "^29.5.0",
4848
"jest-localstorage-mock": "^2.4.26",
4949
"moxios": "^0.4.0",

static/js/vue-cdr-access/src/components/full_record/aggregateRecord.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<file-list v-if="childCount > 0"
7676
:child-count="childCount"
7777
:work-id="recordData.briefObject.id"
78+
:download-access="hasPermission(recordData,'viewOriginal')"
7879
:edit-access="hasPermission(recordData,'editDescription')">
7980
</file-list>
8081
<metadata-display :uuid="recordData.briefObject.id"

static/js/vue-cdr-access/src/components/full_record/fileList.vue

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ force it to reload
1919
<th>{{ $t('full_record.file_type') }}</th>
2020
<th>{{ $t('full_record.filesize') }}</th>
2121
<th><span class="sr-only">{{ $t('full_record.view_file') }}</span></th>
22-
<th><span class="sr-only">{{ $t('full_record.download_file') }}</span></th>
22+
<th v-if="downloadAccess"><span class="sr-only">{{ $t('full_record.download_file') }}</span></th>
2323
<th v-if="editAccess"><span class="sr-only">{{ $t('full_record.mods') }}</span></th>
2424
</tr>
2525
</thead>
@@ -45,6 +45,10 @@ export default {
4545
4646
props: {
4747
childCount: Number,
48+
downloadAccess: {
49+
default: false,
50+
type: Boolean
51+
},
4852
editAccess: {
4953
default: false,
5054
type: Boolean
@@ -63,8 +67,7 @@ export default {
6367
{ data: this.$t('full_record.title') },
6468
{ data: this.$t('full_record.file_type') },
6569
{ data: this.$t('full_record.filesize') },
66-
{ data: this.$t('full_record.view_file') },
67-
{ data: this.$t('full_record.download_file') }
70+
{ data: this.$t('full_record.view_file') }
6871
]
6972
}
7073
},
@@ -122,7 +125,7 @@ export default {
122125
},
123126
124127
columnDefs() {
125-
const excluded_columns = [0, 4, 5];
128+
const excluded_columns = [0, 4];
126129
127130
let column_defs = [
128131
{ orderable: false, targets: excluded_columns },
@@ -187,18 +190,29 @@ export default {
187190
` <i class="fa fa-search-plus is-icon" title="${view}"></i></a>`;
188191
},
189192
targets: 4
190-
},
191-
{
193+
}
194+
];
195+
196+
if (this.downloadAccess) {
197+
this.columns.push({ data: this.$t('full_record.download_file') });
198+
excluded_columns.push(5); // download button
199+
200+
// Add to orderable, searchable exclusions
201+
[0, 1].forEach((d) => column_defs[d].targets = excluded_columns);
202+
203+
column_defs.push({
192204
render: (data, type, row) => {
193205
return this.downloadButtonHtml(row);
194206
},
195207
targets: 5
196-
}
197-
];
208+
});
209+
}
198210
199211
if (this.editAccess) {
212+
// Check for the correct column number, in the unlikely event a user has edit access, but not download access
213+
const column_number = (this.downloadAccess) ? 6 : 5;
200214
this.columns.push({ data: this.$t('full_record.mods') });
201-
excluded_columns.push(6); // edit button
215+
excluded_columns.push(column_number); // edit button
202216
203217
// Add to orderable, searchable exclusions
204218
[0, 1].forEach((d) => column_defs[d].targets = excluded_columns);
@@ -209,7 +223,7 @@ export default {
209223
return `<a href="/admin/describe/${row.id}" aria-label="${this.ariaLabelText(row)}">` +
210224
'<i class="fa fa-edit is-icon" title="Edit"></i></a>'
211225
},
212-
targets: 6
226+
targets: column_number
213227
}
214228
);
215229
}

static/js/vue-cdr-access/src/mixins/fileDownloadUtils.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ export default {
7272

7373
return html;
7474
} else {
75-
return `<div class="dropdown actionlink image-download-options">
76-
<button class="button download-images" title="${this.$t('full_record.download_unavailable')}" disabled>
77-
<i class="fa fa-download"></i> ${this.$t('full_record.download')}
78-
</button>
79-
</div>`;
75+
return '';
8076
}
8177
},
8278

static/js/vue-cdr-access/tests/unit/fileList.spec.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,6 @@ describe('fileList.vue', () => {
9595
expect(wrapper.vm.showBadge({ status: [''] })).toEqual({ markDeleted: false, restricted: true });
9696
});
9797

98-
// @TODO TDB whether viewAccessCopies allows a user to download anything
99-
/* it("sets download button html for image files with canViewAccess permission", () => {
100-
const download = wrapper.vm.downloadButtonHtml(briefObject);
101-
// Download button
102-
expect(download).toEqual(expect.stringContaining('button id="dcr-download-4db695c0-5fd5-4abf-9248-2e115d43f57d"'));
103-
// Options
104-
expect(download).toEqual(expect.stringContaining('Small JPG (800px)'));
105-
expect(download).toEqual(expect.stringContaining('Medium JPG (1600px)'));
106-
expect(download).toEqual(expect.not.stringContaining('Full Size JPG'));
107-
expect(download).toEqual(expect.not.stringContaining('Original File'));
108-
});*/
109-
11098
it("sets download button html for image files with canViewOriginal permission", async () => {
11199
let updatedBriefObj = cloneDeep(briefObject);
112100
updatedBriefObj.permissions = [
@@ -149,25 +137,21 @@ describe('fileList.vue', () => {
149137
expect(download).toEqual(expect.stringContaining('<a class="download button action"'));
150138
});
151139

152-
it("sets a disabled button for non-image files without showImageDownload permission", () => {
140+
it("does not show a button for non-image files without viewOriginal permission", () => {
153141
let updatedBriefObj = cloneDeep(briefObject);
154142
updatedBriefObj.fileType = ['application/pdf']
155143
updatedBriefObj.format = ['Text']
156144
updatedBriefObj.datastream = ['original_file|application/pdf|pdf file||416330|urn:sha1:4945153c9f5ce152ef8eda495deba043f536f388||'];
157145

158-
const download = wrapper.vm.downloadButtonHtml(updatedBriefObj);
159-
// Disabled download button
160-
expect(download).toEqual(expect.stringContaining('button class="button download-images" title="Download Unavailable" disabled'));
146+
expect(wrapper.find('div.download').exists()).toBe(false);
161147
});
162148

163-
it("sets a disabled download button for image files without viewAccessCopies permission", () => {
149+
it("does not show a button for image files without viewOriginal permission", () => {
164150
let updatedBriefObj = cloneDeep(briefObject);
165151
updatedBriefObj.permissions = [
166152
"viewMetadata"
167153
];
168154

169-
const download = wrapper.vm.downloadButtonHtml(updatedBriefObj);
170-
// Disabled download button
171-
expect(download).toEqual(expect.stringContaining('button class="button download-images" title="Download Unavailable" disabled'));
155+
expect(wrapper.find('div.image-download-options').exists()).toBe(false);
172156
});
173157
});

0 commit comments

Comments
 (0)