mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Merge pull request #3954 from DSpace/backport-3948-to-dspace-8_x
[Port dspace-8_x] Avoid retrieving user suggestions if Researcher profiles are disabled
This commit is contained in:
@@ -13,6 +13,10 @@ import {
|
|||||||
switchMap,
|
switchMap,
|
||||||
tap,
|
tap,
|
||||||
} from 'rxjs/operators';
|
} from 'rxjs/operators';
|
||||||
|
import { ConfigurationDataService } from 'src/app/core/data/configuration-data.service';
|
||||||
|
import { RemoteData } from 'src/app/core/data/remote-data';
|
||||||
|
import { ConfigurationProperty } from 'src/app/core/shared/configuration-property.model';
|
||||||
|
import { getFirstCompletedRemoteData } from 'src/app/core/shared/operators';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AuthActionTypes,
|
AuthActionTypes,
|
||||||
@@ -72,14 +76,23 @@ export class SuggestionTargetsEffects {
|
|||||||
), { dispatch: false });
|
), { dispatch: false });
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a notification on error.
|
* Retrieve the current user suggestions after retrieving the authenticated user
|
||||||
*/
|
*/
|
||||||
retrieveUserTargets$ = createEffect(() => this.actions$.pipe(
|
retrieveUserTargets$ = createEffect(() => this.actions$.pipe(
|
||||||
ofType(AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS),
|
ofType(AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS),
|
||||||
switchMap((action: RetrieveAuthenticatedEpersonSuccessAction) => {
|
switchMap((action: RetrieveAuthenticatedEpersonSuccessAction) => {
|
||||||
|
return this.configurationService.findByPropertyName('researcher-profile.entity-type').pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
switchMap((configRD: RemoteData<ConfigurationProperty> ) => {
|
||||||
|
if (configRD.hasSucceeded && configRD.payload.values.length > 0) {
|
||||||
return this.suggestionsService.retrieveCurrentUserSuggestions(action.payload).pipe(
|
return this.suggestionsService.retrieveCurrentUserSuggestions(action.payload).pipe(
|
||||||
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)),
|
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return of(new AddUserSuggestionsAction([]));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
));
|
||||||
})));
|
})));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,6 +104,13 @@ export class SuggestionTargetsEffects {
|
|||||||
return this.store$.select((state: any) => state.core.auth.userId)
|
return this.store$.select((state: any) => state.core.auth.userId)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap((userId: string) => {
|
switchMap((userId: string) => {
|
||||||
|
if (!userId) {
|
||||||
|
return of(new AddUserSuggestionsAction([]));
|
||||||
|
}
|
||||||
|
return this.configurationService.findByPropertyName('researcher-profile.entity-type').pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
switchMap((configRD: RemoteData<ConfigurationProperty> ) => {
|
||||||
|
if (configRD.hasSucceeded && configRD.payload.values.length > 0) {
|
||||||
return this.suggestionsService.retrieveCurrentUserSuggestions(userId)
|
return this.suggestionsService.retrieveCurrentUserSuggestions(userId)
|
||||||
.pipe(
|
.pipe(
|
||||||
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)),
|
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)),
|
||||||
@@ -101,6 +121,18 @@ export class SuggestionTargetsEffects {
|
|||||||
return of(new RefreshUserSuggestionsErrorAction());
|
return of(new RefreshUserSuggestionsErrorAction());
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return of(new AddUserSuggestionsAction([]));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
catchError((error: unknown) => {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
console.error(error.message);
|
||||||
|
}
|
||||||
|
return of(new RefreshUserSuggestionsErrorAction());
|
||||||
|
}),
|
||||||
|
);
|
||||||
}),
|
}),
|
||||||
catchError((error: unknown) => {
|
catchError((error: unknown) => {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
@@ -119,6 +151,7 @@ export class SuggestionTargetsEffects {
|
|||||||
* @param {TranslateService} translate
|
* @param {TranslateService} translate
|
||||||
* @param {NotificationsService} notificationsService
|
* @param {NotificationsService} notificationsService
|
||||||
* @param {SuggestionsService} suggestionsService
|
* @param {SuggestionsService} suggestionsService
|
||||||
|
* @param {ConfigurationDataService} configurationService
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
private actions$: Actions,
|
private actions$: Actions,
|
||||||
@@ -126,6 +159,7 @@ export class SuggestionTargetsEffects {
|
|||||||
private translate: TranslateService,
|
private translate: TranslateService,
|
||||||
private notificationsService: NotificationsService,
|
private notificationsService: NotificationsService,
|
||||||
private suggestionsService: SuggestionsService,
|
private suggestionsService: SuggestionsService,
|
||||||
|
private configurationService: ConfigurationDataService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user