Skip to content

Commit 0f0555e

Browse files
UoE/datashare: add "Keep embargo policies" option to the move-item screen
UoE/datashare: add "Keep embargo policies" option to the move-item screen
2 parents 4b9d11e + cb72ccd commit 0f0555e

6 files changed

Lines changed: 78 additions & 8 deletions

File tree

src/app/core/data/item-data.service.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,27 @@ describe('ItemDataService', () => {
133133
});
134134
});
135135

136+
describe('getMoveItemEndpoint', () => {
137+
beforeEach(() => {
138+
service = initTestService();
139+
});
140+
141+
it('should append keepEmbargoPolicies when inheriting policies', (done) => {
142+
service.getMoveItemEndpoint('item-id', true, false).subscribe((href) => {
143+
expect(href).toContain('item-id/owningCollection?inheritPolicies=true&keepEmbargoPolicies=false');
144+
done();
145+
});
146+
});
147+
148+
it('should omit keepEmbargoPolicies when not inheriting policies', (done) => {
149+
service.getMoveItemEndpoint('item-id', false, true).subscribe((href) => {
150+
expect(href).toContain('item-id/owningCollection?inheritPolicies=false');
151+
expect(href).not.toContain('keepEmbargoPolicies');
152+
done();
153+
});
154+
});
155+
});
156+
136157
describe('removeMappingFromCollection', () => {
137158
let result;
138159

src/app/core/data/item-data.service.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,27 +272,40 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
272272
/**
273273
* Get the endpoint to move the item
274274
* @param itemId
275+
* @param inheritPolicies whether to inherit the destination collection's default policies
276+
* @param keepEmbargoPolicies when inheriting, keep an existing embargo instead of letting it be lifted
275277
*/
276-
public getMoveItemEndpoint(itemId: string, inheritPolicies: boolean): Observable<string> {
278+
public getMoveItemEndpoint(itemId: string, inheritPolicies: boolean, keepEmbargoPolicies = true): Observable<string> {
277279
return this.halService.getEndpoint(this.linkPath).pipe(
278280
map((endpoint: string) => this.getIDHref(endpoint, itemId)),
279-
map((endpoint: string) => `${endpoint}/owningCollection?inheritPolicies=${inheritPolicies}`),
281+
map((endpoint: string) => {
282+
let href = `${endpoint}/owningCollection?inheritPolicies=${inheritPolicies}`;
283+
// Only relevant when inheriting.
284+
if (inheritPolicies) {
285+
href += `&keepEmbargoPolicies=${keepEmbargoPolicies}`;
286+
}
287+
return href;
288+
}),
280289
);
281290
}
282291

283292
/**
284293
* Move the item to a different owning collection
285294
* @param itemId
286295
* @param collection
296+
* @param inheritPolicies whether to inherit the destination collection's default policies
297+
* @param keepEmbargoPolicies when inheriting, whether to keep an existing embargo
287298
*/
288-
public moveToCollection(itemId: string, collection: Collection, inheritPolicies: boolean): Observable<RemoteData<any>> {
299+
public moveToCollection(
300+
itemId: string, collection: Collection, inheritPolicies: boolean, keepEmbargoPolicies = true,
301+
): Observable<RemoteData<any>> {
289302
const options: HttpOptions = Object.create({});
290303
let headers = new HttpHeaders();
291304
headers = headers.append('Content-Type', 'text/uri-list');
292305
options.headers = headers;
293306

294307
const requestId = this.requestService.generateRequestId();
295-
const hrefObs = this.getMoveItemEndpoint(itemId, inheritPolicies);
308+
const hrefObs = this.getMoveItemEndpoint(itemId, inheritPolicies, keepEmbargoPolicies);
296309

297310
hrefObs.pipe(
298311
find((href: string) => hasValue(href)),

src/app/item-page/edit-item-page/item-move/item-move.component.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ <h1>{{'item.edit.move.head' | translate: {id: (itemRD$ | async)?.payload?.handle
3232
<p>
3333
{{'item.edit.move.inheritpolicies.description' | translate}}
3434
</p>
35+
<p *ngIf="inheritPolicies">
36+
<label for="keepEmbargoPoliciesCheckbox">
37+
<ng-template #keepEmbargoTooltipContent>
38+
{{ 'item.edit.move.keepembargopolicies.tooltip' | translate }}
39+
</ng-template>
40+
<input type="checkbox" name="keepEmbargo" [(ngModel)]="keepEmbargoPolicies" id="keepEmbargoPoliciesCheckbox" [ngbTooltip]="keepEmbargoTooltipContent"
41+
>
42+
{{'item.edit.move.keepembargopolicies.checkbox' | translate}}
43+
</label>
44+
</p>
45+
<p *ngIf="inheritPolicies">
46+
{{'item.edit.move.keepembargopolicies.description' | translate}}
47+
</p>
3548
</div>
3649
</div>
3750

src/app/item-page/edit-item-page/item-move/item-move.component.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,20 @@ describe('ItemMoveComponent', () => {
150150
comp.inheritPolicies = false;
151151
comp.moveToCollection();
152152

153-
expect(itemDataService.moveToCollection).toHaveBeenCalledWith('item-id', collection1, false);
153+
// keepEmbargoPolicies defaults to true; it is only sent on the request URL when inheriting
154+
expect(itemDataService.moveToCollection).toHaveBeenCalledWith('item-id', collection1, false, true);
155+
});
156+
it('should pass keepEmbargoPolicies through when inheriting policies', () => {
157+
comp.item = Object.assign(new Item(), {
158+
id: 'item-id',
159+
uuid: 'item-id',
160+
});
161+
comp.selectedCollection = collection1;
162+
comp.inheritPolicies = true;
163+
comp.keepEmbargoPolicies = false;
164+
comp.moveToCollection();
165+
166+
expect(itemDataService.moveToCollection).toHaveBeenCalledWith('item-id', collection1, true, false);
154167
});
155168
it('should call notificationsService success message on success', () => {
156169
comp.moveToCollection();

src/app/item-page/edit-item-page/item-move/item-move.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ export class ItemMoveComponent implements OnInit {
7272

7373
selectorType = DSpaceObjectType.COLLECTION;
7474

75-
inheritPolicies = false;
75+
inheritPolicies = true;
76+
77+
/** When inheriting, keep an existing embargo instead of letting the inherited default read lift it. */
78+
keepEmbargoPolicies = true;
7679
itemRD$: Observable<RemoteData<Item>>;
7780
originalCollection: Collection;
7881

@@ -145,8 +148,9 @@ export class ItemMoveComponent implements OnInit {
145148
*/
146149
moveToCollection() {
147150
this.processing = true;
148-
const move$ = this.itemDataService.moveToCollection(this.item.id, this.selectedCollection, this.inheritPolicies)
149-
.pipe(getFirstCompletedRemoteData());
151+
const move$ = this.itemDataService.moveToCollection(
152+
this.item.id, this.selectedCollection, this.inheritPolicies, this.keepEmbargoPolicies,
153+
).pipe(getFirstCompletedRemoteData());
150154

151155
move$.subscribe((response: RemoteData<any>) => {
152156
if (response.hasSucceeded) {

src/assets/i18n/en.json5

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,6 +2554,12 @@
25542554

25552555
"item.edit.move.inheritpolicies.tooltip": "Warning: When enabled, the read access policy for the item and any files associated with the item will be replaced by the default read access policy of the collection. This cannot be undone.",
25562556

2557+
"item.edit.move.keepembargopolicies.checkbox": "Keep this item's current embargo",
2558+
2559+
"item.edit.move.keepembargopolicies.description": "The item keeps the embargo it already has (its files stay embargoed until their original lift date). Everything else is inherited from the destination collection.",
2560+
2561+
"item.edit.move.keepembargopolicies.tooltip": "This is about the embargo already on this item, not the destination collection's. When enabled, the item's existing embargo (and its original lift date) is preserved and only the non-embargo access is inherited. When disabled, the destination collection's default read access replaces it and the embargo is lifted immediately.",
2562+
25572563
"item.edit.move.move": "Move",
25582564

25592565
"item.edit.move.processing": "Moving...",

0 commit comments

Comments
 (0)