Skip to content

Commit 842e447

Browse files
authored
Re-implement anonymous link code which was removed accidentally (#9276)
1 parent 85b9fda commit 842e447

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

web-ui/src/main/resources/catalog/components/toolbar/ToolbarDirective.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
scope.hasVisibletasks = false;
189189
scope.doiServers = [];
190190
scope.status = undefined;
191+
scope.anonymousAccessExists = false;
191192

192193
scope.statusEffects = {
193194
editor: [
@@ -288,6 +289,26 @@
288289
);
289290
};
290291

292+
/**
293+
* Display the anonymous access option.
294+
*
295+
* Checks:
296+
* - The user is logged in.
297+
* - The user is administrator or more.
298+
* - The metadata record is not null.
299+
* - The metadata is not published.
300+
*
301+
* @param {Object} md - The metadata record to check.
302+
* @param {Object} user - The user for whom the check is being performed.
303+
* @param {Object} pubOption - The publication option to check against.
304+
* @returns {boolean} - True if the anonymous access option should be displayed, false otherwise.
305+
*/
306+
scope.displayAnonymousAccessOption = function (md, user, pubOption) {
307+
return (
308+
user.id && user.isAdministratorOrMore() && md && !md.isPublished(pubOption)
309+
);
310+
};
311+
291312
scope.displayWorkflowStepOption = function (step, user) {
292313
return (
293314
user.id &&
@@ -363,12 +384,19 @@
363384
scope.md = md;
364385
scope.doiServers = [];
365386
scope.ownerGroupName = undefined;
387+
scope.anonymousAccessExists = false;
366388

367389
if (md) {
368390
$http.get("../api/doiservers/metadata/" + md.id).then(function (response) {
369391
scope.doiServers = response.data;
370392
});
371393

394+
$http
395+
.get("../api/anonymousAccessLink/" + md.uuid)
396+
.then(function (response) {
397+
scope.anonymousAccessExists = response.data;
398+
});
399+
372400
if (md.groupOwner) {
373401
gnMetadataActions.getGroupName(md.groupOwner).then(function (name) {
374402
scope.ownerGroupName = name;
@@ -389,6 +417,14 @@
389417
loadTasks();
390418
loadWorkflowStatus();
391419

420+
scope.$on("AnonymousAccessCreated", function () {
421+
scope.anonymousAccessExists = true;
422+
});
423+
424+
scope.$on("AnonymousAccessDeleted", function () {
425+
scope.anonymousAccessExists = false;
426+
});
427+
392428
watchRecord(
393429
scope,
394430
attrs.gnManageRecordMenu || "mdView.current.record",

web-ui/src/main/resources/catalog/components/toolbar/partials/menu-manage-record.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,26 @@
8484
</a>
8585
</li>
8686

87+
<!-- Anonymous access -->
88+
<li role="menuitem" data-ng-if="displayAnonymousAccessOption(md, user, pubOption)">
89+
<a
90+
href=""
91+
data-ng-if="!anonymousAccessExists"
92+
data-ng-click="mdService.createAnonymousAccess(md, getCatScope())"
93+
>
94+
<span class="fa fa-fw fa-eye"></span>&nbsp;
95+
<span data-translate="">createAnonymousAccess</span>
96+
</a>
97+
<a
98+
href=""
99+
data-ng-if="anonymousAccessExists"
100+
data-ng-click="mdService.deleteAnonymousAccess(md, getCatScope())"
101+
>
102+
<span class="fa fa-fw fa-eye-slash"></span>&nbsp;
103+
<span data-translate="">deleteAnonymousAccess</span>
104+
</a>
105+
</li>
106+
87107
<!-- Workflow -->
88108
<li
89109
role="menuitem"

0 commit comments

Comments
 (0)