diff --git a/src/app/home-page/geoip-warning/geoip-warning.component.html b/src/app/home-page/geoip-warning/geoip-warning.component.html new file mode 100644 index 00000000000..dbae7311ae2 --- /dev/null +++ b/src/app/home-page/geoip-warning/geoip-warning.component.html @@ -0,0 +1,6 @@ +@if (showWarning$ | async) { + + +} diff --git a/src/app/home-page/geoip-warning/geoip-warning.component.ts b/src/app/home-page/geoip-warning/geoip-warning.component.ts new file mode 100644 index 00000000000..3904892ed90 --- /dev/null +++ b/src/app/home-page/geoip-warning/geoip-warning.component.ts @@ -0,0 +1,96 @@ +import { + AsyncPipe, + isPlatformBrowser, +} from '@angular/common'; +import { + Component, + Inject, + OnInit, + PLATFORM_ID, +} from '@angular/core'; +import { AuthorizationDataService } from '@dspace/core/data/feature-authorization/authorization-data.service'; +import { FeatureID } from '@dspace/core/data/feature-authorization/feature-id'; +import { + HealthResponse, + HealthStatus, +} from '@dspace/core/shared/health-component.model'; +import { TranslateModule } from '@ngx-translate/core'; +import { + Observable, + of, +} from 'rxjs'; +import { + catchError, + map, + switchMap, + take, +} from 'rxjs/operators'; + +import { HealthService } from '../../health-page/health.service'; +import { AlertComponent } from '../../shared/alert/alert.component'; +import { AlertType } from '../../shared/alert/alert-type'; + +const DISMISSED_KEY = 'geoip-warning-dismissed'; + +/** + * Component that displays a warning when the GeoLite database is not installed. + * Only visible to administrators. Once dismissed, stays hidden for the browser session. + */ +@Component({ + selector: 'ds-geoip-warning', + templateUrl: './geoip-warning.component.html', + imports: [ + AlertComponent, + AsyncPipe, + TranslateModule, + ], +}) +export class GeoIpWarningComponent implements OnInit { + + /** + * Whether to show the GeoIP warning. + */ + showWarning$: Observable; + + readonly AlertType = AlertType; + + constructor( + private authorizationService: AuthorizationDataService, + private healthService: HealthService, + @Inject(PLATFORM_ID) private platformId: object, + ) { + } + + ngOnInit(): void { + if (isPlatformBrowser(this.platformId) && sessionStorage.getItem(DISMISSED_KEY)) { + this.showWarning$ = of(false); + return; + } + + this.showWarning$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf).pipe( + switchMap((isAdmin: boolean) => { + if (!isAdmin) { + return of(false); + } + return this.healthService.getHealth().pipe( + take(1), + map((data: any) => { + const response: HealthResponse = data.payload; + return response?.components?.geoIp?.status === HealthStatus.UP_WITH_ISSUES; + }), + catchError(() => of(false)), + ); + }), + ); + } + + /** + * Dismiss the warning and remember it for the session. + */ + onDismiss(): void { + if (isPlatformBrowser(this.platformId)) { + sessionStorage.setItem(DISMISSED_KEY, 'true'); + } + } + +} diff --git a/src/app/home-page/home-page.component.html b/src/app/home-page/home-page.component.html index b53672768af..b9c8eac19cd 100644 --- a/src/app/home-page/home-page.component.html +++ b/src/app/home-page/home-page.component.html @@ -1,3 +1,4 @@ + @if (showDiscoverFilters) { diff --git a/src/app/home-page/home-page.component.ts b/src/app/home-page/home-page.component.ts index 54b76913c1c..f9397dbc152 100644 --- a/src/app/home-page/home-page.component.ts +++ b/src/app/home-page/home-page.component.ts @@ -17,6 +17,7 @@ import { map } from 'rxjs/operators'; import { SuggestionsPopupComponent } from '../notifications/suggestions/popup/suggestions-popup.component'; import { ThemedConfigurationSearchPageComponent } from '../search-page/themed-configuration-search-page.component'; import { ThemedSearchFormComponent } from '../shared/search-form/themed-search-form.component'; +import { GeoIpWarningComponent } from './geoip-warning/geoip-warning.component'; import { HomeCoarComponent } from './home-coar/home-coar.component'; import { ThemedHomeNewsComponent } from './home-news/themed-home-news.component'; import { RecentItemListComponent } from './recent-item-list/recent-item-list.component'; @@ -27,6 +28,7 @@ import { ThemedTopLevelCommunityListComponent } from './top-level-community-list styleUrls: ['./home-page.component.scss'], templateUrl: './home-page.component.html', imports: [ + GeoIpWarningComponent, HomeCoarComponent, NgTemplateOutlet, RecentItemListComponent, diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 1bd83d53467..f3a5f494a33 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -2273,6 +2273,8 @@ "home.breadcrumbs": "Home", + "home.geoip-warning": "The GeoLite database is not installed. Location-based statistics (countries, cities) are unavailable. See the DSpace installation instructions for details.", + "home.search-form.placeholder": "Search the repository ...", "home.title": "Home", diff --git a/src/themes/custom/app/home-page/home-page.component.ts b/src/themes/custom/app/home-page/home-page.component.ts index c717a0d53dd..c04f5666bef 100644 --- a/src/themes/custom/app/home-page/home-page.component.ts +++ b/src/themes/custom/app/home-page/home-page.component.ts @@ -2,6 +2,7 @@ import { NgTemplateOutlet } from '@angular/common'; import { Component } from '@angular/core'; import { TranslateModule } from '@ngx-translate/core'; +import { GeoIpWarningComponent } from '../../../../app/home-page/geoip-warning/geoip-warning.component'; import { HomeCoarComponent } from '../../../../app/home-page/home-coar/home-coar.component'; import { ThemedHomeNewsComponent } from '../../../../app/home-page/home-news/themed-home-news.component'; import { HomePageComponent as BaseComponent } from '../../../../app/home-page/home-page.component'; @@ -18,6 +19,7 @@ import { ThemedSearchFormComponent } from '../../../../app/shared/search-form/th // templateUrl: './home-page.component.html' templateUrl: '../../../../app/home-page/home-page.component.html', imports: [ + GeoIpWarningComponent, HomeCoarComponent, NgTemplateOutlet, RecentItemListComponent,