Skip to content

Commit

Permalink
Merge pull request #3948 from toniprieto/avoid-retrieve-suggestions-i…
Browse files Browse the repository at this point in the history
…f-disabled

Avoid retrieving user suggestions if Researcher profiles are disabled
  • Loading branch information
tdonohue authored Feb 4, 2025
2 parents 073cd07 + 72919cd commit 0649342
Showing 1 changed file with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
switchMap,
tap,
} 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 {
AuthActionTypes,
Expand Down Expand Up @@ -72,14 +76,23 @@ export class SuggestionTargetsEffects {
), { dispatch: false });

/**
* Show a notification on error.
* Retrieve the current user suggestions after retrieving the authenticated user
*/
retrieveUserTargets$ = createEffect(() => this.actions$.pipe(
ofType(AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS),
switchMap((action: RetrieveAuthenticatedEpersonSuccessAction) => {
return this.suggestionsService.retrieveCurrentUserSuggestions(action.payload).pipe(
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)),
);
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(
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)),
);
} else {
return of(new AddUserSuggestionsAction([]));
}
},
));
})));

/**
Expand All @@ -91,16 +104,35 @@ export class SuggestionTargetsEffects {
return this.store$.select((state: any) => state.core.auth.userId)
.pipe(
switchMap((userId: string) => {
return this.suggestionsService.retrieveCurrentUserSuggestions(userId)
.pipe(
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)),
catchError((error: unknown) => {
if (error instanceof Error) {
console.error(error.message);
}
return of(new RefreshUserSuggestionsErrorAction());
}),
);
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)
.pipe(
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)),
catchError((error: unknown) => {
if (error instanceof Error) {
console.error(error.message);
}
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) => {
if (error instanceof Error) {
Expand All @@ -119,13 +151,15 @@ export class SuggestionTargetsEffects {
* @param {TranslateService} translate
* @param {NotificationsService} notificationsService
* @param {SuggestionsService} suggestionsService
* @param {ConfigurationDataService} configurationService
*/
constructor(
private actions$: Actions,
private store$: Store<any>,
private translate: TranslateService,
private notificationsService: NotificationsService,
private suggestionsService: SuggestionsService,
private configurationService: ConfigurationDataService,
) {
}
}

0 comments on commit 0649342

Please sign in to comment.