1
0

Merge branch 'main' into w2p-121534_removed-metadata-export-search-request-for-non-admins-on-search_contribute-main

This commit is contained in:
Alan Orth
2024-12-03 12:13:19 +03:00
committed by GitHub
10 changed files with 254 additions and 142 deletions

125
package-lock.json generated
View File

@@ -109,7 +109,7 @@
"compression-webpack-plugin": "^9.2.0",
"copy-webpack-plugin": "^6.4.1",
"cross-env": "^7.0.3",
"cypress": "^13.15.1",
"cypress": "^13.16.0",
"cypress-axe": "^1.5.0",
"deep-freeze": "0.0.1",
"eslint": "^8.39.0",
@@ -4258,9 +4258,9 @@
}
},
"node_modules/@cypress/request": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/@cypress/request/-/request-3.0.4.tgz",
"integrity": "sha512-eqNHMsxEXuit0sRvvWoGG3/4+Q5qwqjKARWXKM/KoSsKvTNBwWt8pwspg5+TniP3POAZcPPx0O8CiEIQ4e6NWg==",
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/@cypress/request/-/request-3.0.6.tgz",
"integrity": "sha512-fi0eVdCOtKu5Ed6+E8mYxUF6ZTFJDZvHogCBelM0xVXmrDEkyM22gRArQzq1YcHPm1V47Vf/iAD+WgVdUlJCGg==",
"dev": true,
"dependencies": {
"aws-sign2": "~0.7.0",
@@ -4269,7 +4269,7 @@
"combined-stream": "~1.0.6",
"extend": "~3.0.2",
"forever-agent": "~0.6.1",
"form-data": "~2.5.0",
"form-data": "~4.0.0",
"http-signature": "~1.4.0",
"is-typedarray": "~1.0.0",
"isstream": "~0.1.2",
@@ -4278,7 +4278,7 @@
"performance-now": "^2.1.0",
"qs": "6.13.0",
"safe-buffer": "^5.1.2",
"tough-cookie": "^4.1.3",
"tough-cookie": "^5.0.0",
"tunnel-agent": "^0.6.0",
"uuid": "^8.3.2"
},
@@ -4286,20 +4286,6 @@
"node": ">= 6"
}
},
"node_modules/@cypress/request/node_modules/form-data": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
"integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
"dev": true,
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 0.12"
}
},
"node_modules/@cypress/schematic": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/@cypress/schematic/-/schematic-1.7.0.tgz",
@@ -9270,9 +9256,9 @@
}
},
"node_modules/ci-info": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz",
"integrity": "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==",
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.1.0.tgz",
"integrity": "sha512-HutrvTNsF48wnxkzERIXOe5/mlcfFcbfCmwcg6CJnizbSue78AbDt+1cgl26zwn61WFxhcPykPfZrbqjGmBb4A==",
"dev": true,
"funding": [
{
@@ -10285,13 +10271,13 @@
"dev": true
},
"node_modules/cypress": {
"version": "13.15.1",
"resolved": "https://registry.npmjs.org/cypress/-/cypress-13.15.1.tgz",
"integrity": "sha512-DwUFiKXo4lef9kA0M4iEhixFqoqp2hw8igr0lTqafRb9qtU3X0XGxKbkSYsUFdkrAkphc7MPDxoNPhk5pj9PVg==",
"version": "13.16.0",
"resolved": "https://registry.npmjs.org/cypress/-/cypress-13.16.0.tgz",
"integrity": "sha512-g6XcwqnvzXrqiBQR/5gN+QsyRmKRhls1y5E42fyOvsmU7JuY+wM6uHJWj4ZPttjabzbnRvxcik2WemR8+xT6FA==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
"@cypress/request": "^3.0.4",
"@cypress/request": "^3.0.6",
"@cypress/xvfb": "^1.2.4",
"@types/sinonjs__fake-timers": "8.1.1",
"@types/sizzle": "^2.3.2",
@@ -10302,6 +10288,7 @@
"cachedir": "^2.3.0",
"chalk": "^4.1.0",
"check-more-types": "^2.24.0",
"ci-info": "^4.0.0",
"cli-cursor": "^3.1.0",
"cli-table3": "~0.6.1",
"commander": "^6.2.1",
@@ -10316,7 +10303,6 @@
"figures": "^3.2.0",
"fs-extra": "^9.1.0",
"getos": "^3.2.1",
"is-ci": "^3.0.1",
"is-installed-globally": "~0.4.0",
"lazy-ass": "^1.6.0",
"listr2": "^3.8.3",
@@ -14122,18 +14108,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/is-ci": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.1.tgz",
"integrity": "sha512-ZYvCgrefwqoQ6yTyYUbQu64HsITZ3NfKX1lzaEYdkTDcfKzzCI/wthRRYKkdjHKFVgNiXKAKm65Zo1pk2as/QQ==",
"dev": true,
"dependencies": {
"ci-info": "^3.2.0"
},
"bin": {
"is-ci": "bin.js"
}
},
"node_modules/is-core-module": {
"version": "2.15.1",
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.1.tgz",
@@ -19273,12 +19247,6 @@
"dev": true,
"optional": true
},
"node_modules/psl": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
"integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==",
"dev": true
},
"node_modules/pstree.remy": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
@@ -19324,12 +19292,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/querystringify": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
"integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==",
"dev": true
},
"node_modules/queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
@@ -21937,6 +21899,24 @@
"resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz",
"integrity": "sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA=="
},
"node_modules/tldts": {
"version": "6.1.65",
"resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.65.tgz",
"integrity": "sha512-xU9gLTfAGsADQ2PcWee6Hg8RFAv0DnjMGVJmDnUmI8a9+nYmapMQix4afwrdaCtT+AqP4MaxEzu7cCrYmBPbzQ==",
"dev": true,
"dependencies": {
"tldts-core": "^6.1.65"
},
"bin": {
"tldts": "bin/cli.js"
}
},
"node_modules/tldts-core": {
"version": "6.1.65",
"resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.65.tgz",
"integrity": "sha512-Uq5t0N0Oj4nQSbU8wFN1YYENvMthvwU13MQrMJRspYCGLSAZjAfoBOJki5IQpnBM/WFskxxC/gIOTwaedmHaSg==",
"dev": true
},
"node_modules/tmp": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz",
@@ -21988,36 +21968,15 @@
}
},
"node_modules/tough-cookie": {
"version": "4.1.4",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.4.tgz",
"integrity": "sha512-Loo5UUvLD9ScZ6jh8beX1T6sO1w2/MpCRpEP7V280GKMVUQ0Jzar2U3UJPsrdbziLEMMhu3Ujnq//rhiFuIeag==",
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.0.0.tgz",
"integrity": "sha512-FRKsF7cz96xIIeMZ82ehjC3xW2E+O2+v11udrDYewUbszngYhsGa8z6YUMMzO9QJZzzyd0nGGXnML/TReX6W8Q==",
"dev": true,
"dependencies": {
"psl": "^1.1.33",
"punycode": "^2.1.1",
"universalify": "^0.2.0",
"url-parse": "^1.5.3"
"tldts": "^6.1.32"
},
"engines": {
"node": ">=6"
}
},
"node_modules/tough-cookie/node_modules/punycode": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/tough-cookie/node_modules/universalify": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz",
"integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==",
"dev": true,
"engines": {
"node": ">= 4.0.0"
"node": ">=16"
}
},
"node_modules/tr46": {
@@ -22512,16 +22471,6 @@
"node": ">=6"
}
},
"node_modules/url-parse": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz",
"integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==",
"dev": true,
"dependencies": {
"querystringify": "^2.1.1",
"requires-port": "^1.0.0"
}
},
"node_modules/use-memo-one": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/use-memo-one/-/use-memo-one-1.1.3.tgz",

View File

@@ -196,7 +196,7 @@
"compression-webpack-plugin": "^9.2.0",
"copy-webpack-plugin": "^6.4.1",
"cross-env": "^7.0.3",
"cypress": "^13.15.1",
"cypress": "^13.16.0",
"cypress-axe": "^1.5.0",
"deep-freeze": "0.0.1",
"eslint": "^8.39.0",

View File

@@ -19,6 +19,7 @@ import {
} from '@ngx-translate/core';
import {
BehaviorSubject,
catchError,
Observable,
} from 'rxjs';
import { map } from 'rxjs/operators';
@@ -34,6 +35,7 @@ import { Item } from '../../../core/shared/item.model';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { AlertComponent } from '../../../shared/alert/alert.component';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { createFailedRemoteDataObjectFromError$ } from '../../../shared/remote-data.utils';
@Component({
selector: 'ds-orcid-auth',
@@ -203,13 +205,14 @@ export class OrcidAuthComponent implements OnInit, OnChanges {
this.unlinkProcessing.next(true);
this.orcidAuthService.unlinkOrcidByItem(this.item).pipe(
getFirstCompletedRemoteData(),
catchError(createFailedRemoteDataObjectFromError$<ResearcherProfile>),
).subscribe((remoteData: RemoteData<ResearcherProfile>) => {
this.unlinkProcessing.next(false);
if (remoteData.isSuccess) {
if (remoteData.hasFailed) {
this.notificationsService.error(this.translateService.get('person.page.orcid.unlink.error'));
} else {
this.notificationsService.success(this.translateService.get('person.page.orcid.unlink.success'));
this.unlink.emit();
} else {
this.notificationsService.error(this.translateService.get('person.page.orcid.unlink.error'));
}
});
}

View File

@@ -20,6 +20,7 @@ import {
combineLatest,
} from 'rxjs';
import {
filter,
map,
take,
} from 'rxjs/operators';
@@ -187,8 +188,20 @@ export class OrcidPageComponent implements OnInit {
*/
private clearRouteParams(): void {
// update route removing the code from query params
const redirectUrl = this.router.url.split('?')[0];
this.router.navigate([redirectUrl]);
this.route.queryParamMap
.pipe(
filter((paramMap: ParamMap) => isNotEmpty(paramMap.keys)),
map(_ => Object.assign({})),
take(1),
).subscribe(queryParams =>
this.router.navigate(
[],
{
relativeTo: this.route,
queryParams,
},
),
);
}
}

View File

@@ -180,6 +180,7 @@ describe('OrcidSyncSettingsComponent test suite', () => {
scheduler = getTestScheduler();
fixture = TestBed.createComponent(OrcidSyncSettingsComponent);
comp = fixture.componentInstance;
researcherProfileService.findByRelatedItem.and.returnValue(createSuccessfulRemoteDataObject$(mockResearcherProfile));
comp.item = mockItemLinkedToOrcid;
fixture.detectChanges();
}));
@@ -216,7 +217,6 @@ describe('OrcidSyncSettingsComponent test suite', () => {
});
it('should call updateByOrcidOperations properly', () => {
researcherProfileService.findByRelatedItem.and.returnValue(createSuccessfulRemoteDataObject$(mockResearcherProfile));
researcherProfileService.patch.and.returnValue(createSuccessfulRemoteDataObject$(mockResearcherProfile));
const expectedOps: Operation[] = [
{
@@ -245,7 +245,6 @@ describe('OrcidSyncSettingsComponent test suite', () => {
});
it('should show notification on success', () => {
researcherProfileService.findByRelatedItem.and.returnValue(createSuccessfulRemoteDataObject$(mockResearcherProfile));
researcherProfileService.patch.and.returnValue(createSuccessfulRemoteDataObject$(mockResearcherProfile));
scheduler.schedule(() => comp.onSubmit(formGroup));
@@ -257,6 +256,8 @@ describe('OrcidSyncSettingsComponent test suite', () => {
it('should show notification on error', () => {
researcherProfileService.findByRelatedItem.and.returnValue(createFailedRemoteDataObject$());
comp.item = mockItemLinkedToOrcid;
fixture.detectChanges();
scheduler.schedule(() => comp.onSubmit(formGroup));
scheduler.flush();
@@ -266,7 +267,6 @@ describe('OrcidSyncSettingsComponent test suite', () => {
});
it('should show notification on error', () => {
researcherProfileService.findByRelatedItem.and.returnValue(createSuccessfulRemoteDataObject$(mockResearcherProfile));
researcherProfileService.patch.and.returnValue(createFailedRemoteDataObject$());
scheduler.schedule(() => comp.onSubmit(formGroup));

View File

@@ -3,6 +3,7 @@ import {
Component,
EventEmitter,
Input,
OnDestroy,
OnInit,
Output,
} from '@angular/core';
@@ -15,17 +16,32 @@ import {
TranslateService,
} from '@ngx-translate/core';
import { Operation } from 'fast-json-patch';
import { of } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import {
BehaviorSubject,
Observable,
} from 'rxjs';
import {
catchError,
filter,
map,
switchMap,
take,
takeUntil,
} from 'rxjs/operators';
import { RemoteData } from '../../../core/data/remote-data';
import { ResearcherProfile } from '../../../core/profile/model/researcher-profile.model';
import { ResearcherProfileDataService } from '../../../core/profile/researcher-profile-data.service';
import { Item } from '../../../core/shared/item.model';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import {
getFirstCompletedRemoteData,
getRemoteDataPayload,
} from '../../../core/shared/operators';
import { AlertComponent } from '../../../shared/alert/alert.component';
import { AlertType } from '../../../shared/alert/alert-type';
import { hasValue } from '../../../shared/empty.util';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { createFailedRemoteDataObjectFromError$ } from '../../../shared/remote-data.utils';
@Component({
selector: 'ds-orcid-sync-setting',
@@ -39,14 +55,9 @@ import { NotificationsService } from '../../../shared/notifications/notification
],
standalone: true,
})
export class OrcidSyncSettingsComponent implements OnInit {
export class OrcidSyncSettingsComponent implements OnInit, OnDestroy {
protected readonly AlertType = AlertType;
/**
* The item for which showing the orcid settings
*/
@Input() item: Item;
/**
* The prefix used for i18n keys
*/
@@ -91,12 +102,39 @@ export class OrcidSyncSettingsComponent implements OnInit {
* An event emitted when settings are updated
*/
@Output() settingsUpdated: EventEmitter<void> = new EventEmitter<void>();
/**
* Emitter that triggers onDestroy lifecycle
* @private
*/
readonly #destroy$ = new EventEmitter<void>();
/**
* {@link BehaviorSubject} that reflects {@link item} input changes
* @private
*/
readonly #item$ = new BehaviorSubject<Item>(null);
/**
* {@link Observable} that contains {@link ResearcherProfile} linked to the {@link #item$}
* @private
*/
#researcherProfile$: Observable<ResearcherProfile>;
constructor(private researcherProfileService: ResearcherProfileDataService,
private notificationsService: NotificationsService,
private translateService: TranslateService) {
}
/**
* The item for which showing the orcid settings
*/
@Input()
set item(item: Item) {
this.#item$.next(item);
}
ngOnDestroy(): void {
this.#destroy$.next();
}
/**
* Init orcid settings form
*/
@@ -128,20 +166,21 @@ export class OrcidSyncSettingsComponent implements OnInit {
};
});
const syncProfilePreferences = this.item.allMetadataValues('dspace.orcid.sync-profile');
this.updateSyncProfileOptions(this.#item$.asObservable());
this.updateSyncPreferences(this.#item$.asObservable());
this.syncProfileOptions = ['BIOGRAPHICAL', 'IDENTIFIERS']
.map((value) => {
return {
label: this.messagePrefix + '.sync-profile.' + value.toLowerCase(),
value: value,
checked: syncProfilePreferences.includes(value),
};
});
this.currentSyncMode = this.getCurrentPreference('dspace.orcid.sync-mode', ['BATCH', 'MANUAL'], 'MANUAL');
this.currentSyncPublications = this.getCurrentPreference('dspace.orcid.sync-publications', ['DISABLED', 'ALL'], 'DISABLED');
this.currentSyncFunding = this.getCurrentPreference('dspace.orcid.sync-fundings', ['DISABLED', 'ALL'], 'DISABLED');
this.#researcherProfile$ =
this.#item$.pipe(
switchMap(item =>
this.researcherProfileService.findByRelatedItem(item)
.pipe(
getFirstCompletedRemoteData(),
catchError(createFailedRemoteDataObjectFromError$<ResearcherProfile>),
getRemoteDataPayload(),
),
),
takeUntil(this.#destroy$),
);
}
/**
@@ -166,37 +205,84 @@ export class OrcidSyncSettingsComponent implements OnInit {
return;
}
this.researcherProfileService.findByRelatedItem(this.item).pipe(
this.#researcherProfile$
.pipe(
switchMap(researcherProfile => this.researcherProfileService.patch(researcherProfile, operations)),
getFirstCompletedRemoteData(),
switchMap((profileRD: RemoteData<ResearcherProfile>) => {
if (profileRD.hasSucceeded) {
return this.researcherProfileService.patch(profileRD.payload, operations).pipe(
getFirstCompletedRemoteData(),
);
catchError(createFailedRemoteDataObjectFromError$<ResearcherProfile>),
take(1),
)
.subscribe((remoteData: RemoteData<ResearcherProfile>) => {
if (remoteData.hasFailed) {
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.synchronization-settings-update.error'));
} else {
return of(profileRD);
}
}),
).subscribe((remoteData: RemoteData<ResearcherProfile>) => {
if (remoteData.isSuccess) {
this.notificationsService.success(this.translateService.get(this.messagePrefix + '.synchronization-settings-update.success'));
this.settingsUpdated.emit();
} else {
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.synchronization-settings-update.error'));
}
});
}
/**
*
* Handles subscriptions to populate sync preferences
*
* @param item observable that emits update on item changes
* @private
*/
private updateSyncPreferences(item: Observable<Item>) {
item.pipe(
filter(hasValue),
map(i => this.getCurrentPreference(i, 'dspace.orcid.sync-mode', ['BATCH', 'MANUAL'], 'MANUAL')),
takeUntil(this.#destroy$),
).subscribe(val => this.currentSyncMode = val);
item.pipe(
filter(hasValue),
map(i => this.getCurrentPreference(i, 'dspace.orcid.sync-publications', ['DISABLED', 'ALL'], 'DISABLED')),
takeUntil(this.#destroy$),
).subscribe(val => this.currentSyncPublications = val);
item.pipe(
filter(hasValue),
map(i => this.getCurrentPreference(i, 'dspace.orcid.sync-fundings', ['DISABLED', 'ALL'], 'DISABLED')),
takeUntil(this.#destroy$),
).subscribe(val => this.currentSyncFunding = val);
}
/**
* Handles subscription to populate the {@link syncProfileOptions} field
*
* @param item observable that emits update on item changes
* @private
*/
private updateSyncProfileOptions(item: Observable<Item>) {
item.pipe(
filter(hasValue),
map(i => i.allMetadataValues('dspace.orcid.sync-profile')),
map(metadata =>
['BIOGRAPHICAL', 'IDENTIFIERS']
.map((value) => {
return {
label: this.messagePrefix + '.sync-profile.' + value.toLowerCase(),
value: value,
checked: metadata.includes(value),
};
}),
),
takeUntil(this.#destroy$),
)
.subscribe(value => this.syncProfileOptions = value);
}
/**
* Retrieve setting saved in the item's metadata
*
* @param item The item from which retrieve settings
* @param metadataField The metadata name that contains setting
* @param allowedValues The allowed values
* @param defaultValue The default value
* @private
*/
private getCurrentPreference(metadataField: string, allowedValues: string[], defaultValue: string): string {
const currentPreference = this.item.firstMetadataValue(metadataField);
private getCurrentPreference(item: Item, metadataField: string, allowedValues: string[], defaultValue: string): string {
const currentPreference = item.firstMetadataValue(metadataField);
return (currentPreference && allowedValues.includes(currentPreference)) ? currentPreference : defaultValue;
}
@@ -216,3 +302,4 @@ export class OrcidSyncSettingsComponent implements OnInit {
}
}

View File

@@ -5,6 +5,7 @@
</button>
</div>
<div class="modal-body">
<div data-test="admin-div" *ngIf="(isAdmin$ | async)">
<button class="btn btn-outline-primary btn-lg btn-block" (click)="selectObject(undefined)">{{'dso-selector.create.community.top-level' | translate}}</button>
<div class="h3 position-relative py-1 my-3 font-weight-normal">
<hr>
@@ -12,7 +13,7 @@
<span class="px-4 bg-white">{{'dso-selector.create.community.or-divider' | translate}}</span>
</div>
</div>
</div>
<span class="h5 px-2">{{'dso-selector.create.community.sub-level' | translate}}</span>
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid" [types]="selectorTypes" [sort]="defaultSort" (onSelect)="selectObject($event)"></ds-dso-selector>
</div>

View File

@@ -7,13 +7,16 @@ import {
TestBed,
waitForAsync,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import {
ActivatedRoute,
Router,
} from '@angular/router';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
import { of as observableOf } from 'rxjs';
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
import { Community } from '../../../../core/shared/community.model';
import { MetadataValue } from '../../../../core/shared/metadata.models';
import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils';
@@ -38,7 +41,9 @@ describe('CreateCommunityParentSelectorComponent', () => {
const communityRD = createSuccessfulRemoteDataObject(community);
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
const createPath = '/communities/create';
const mockAuthorizationDataService = jasmine.createSpyObj('authorizationService', {
isAuthorized: observableOf(true),
});
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), CreateCommunityParentSelectorComponent],
@@ -59,6 +64,7 @@ describe('CreateCommunityParentSelectorComponent', () => {
{
provide: Router, useValue: router,
},
{ provide: AuthorizationDataService, useValue: mockAuthorizationDataService },
],
schemas: [NO_ERRORS_SCHEMA],
})
@@ -85,4 +91,20 @@ describe('CreateCommunityParentSelectorComponent', () => {
expect(router.navigate).toHaveBeenCalledWith([createPath], { queryParams: { parent: community.uuid } });
});
it('should show the div when user is an admin', (waitForAsync(() => {
component.isAdmin$ = observableOf(true);
fixture.detectChanges();
const divElement = fixture.debugElement.query(By.css('div[data-test="admin-div"]'));
expect(divElement).toBeTruthy();
})));
it('should hide the div when user is not an admin', (waitForAsync(() => {
component.isAdmin$ = observableOf(false);
fixture.detectChanges();
const divElement = fixture.debugElement.query(By.css('div[data-test="admin-div"]'));
expect(divElement).toBeFalsy();
})));
});

View File

@@ -1,3 +1,7 @@
import {
AsyncPipe,
NgIf,
} from '@angular/common';
import {
Component,
OnInit,
@@ -9,6 +13,7 @@ import {
} from '@angular/router';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { environment } from '../../../../../environments/environment';
import {
@@ -19,6 +24,8 @@ import {
SortDirection,
SortOptions,
} from '../../../../core/cache/models/sort-options.model';
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
import { DSpaceObjectType } from '../../../../core/shared/dspace-object-type.model';
import { hasValue } from '../../../empty.util';
@@ -40,18 +47,23 @@ import {
styleUrls: ['./create-community-parent-selector.component.scss'],
templateUrl: './create-community-parent-selector.component.html',
standalone: true,
imports: [DSOSelectorComponent, TranslateModule],
imports: [DSOSelectorComponent, TranslateModule, NgIf, AsyncPipe],
})
export class CreateCommunityParentSelectorComponent extends DSOSelectorModalWrapperComponent implements OnInit {
objectType = DSpaceObjectType.COMMUNITY;
selectorTypes = [DSpaceObjectType.COMMUNITY];
action = SelectorActionType.CREATE;
defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection);
isAdmin$: Observable<boolean>;
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router) {
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router, protected authorizationService: AuthorizationDataService) {
super(activeModal, route);
}
ngOnInit() {
this.isAdmin$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf);
}
/**
* Navigate to the community create page
*/

View File

@@ -1,3 +1,4 @@
import { HttpErrorResponse } from '@angular/common/http';
import {
Observable,
of as observableOf,
@@ -107,3 +108,27 @@ export function createNoContentRemoteDataObject<T>(timeCompleted?: number): Remo
export function createNoContentRemoteDataObject$<T>(timeCompleted?: number): Observable<RemoteData<T>> {
return createSuccessfulRemoteDataObject$(undefined, timeCompleted);
}
/**
* Method to create a remote data object that has failed starting from a given error
*
* @param error
*/
export function createFailedRemoteDataObjectFromError<T>(error: unknown): RemoteData<T> {
const remoteData = createFailedRemoteDataObject<T>();
if (error instanceof Error) {
remoteData.errorMessage = error.message;
}
if (error instanceof HttpErrorResponse) {
remoteData.statusCode = error.status;
}
return remoteData;
}
/**
* Method to create a remote data object that has failed starting from a given error
* @param error
*/
export function createFailedRemoteDataObjectFromError$<T>(error: unknown): Observable<RemoteData<T>> {
return observableOf(createFailedRemoteDataObjectFromError<T>(error));
}