From c56824fc6eb2683020f3b5d47367d829a447fcc9 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Thu, 2 Jul 2026 13:56:15 +1200 Subject: [PATCH 1/2] Avoid calling QA, notify or correctiontypes endpoints for anonymous users on item pages - This should reduce the number of 401 responses written to the console and backend logs. Sponsored-by: Auckland University of Technology, New Zealand --- .../submission/correctiontype-data.service.ts | 24 +++++++++++++++---- .../full/full-item-page.component.html | 10 +++++--- .../full/full-item-page.component.ts | 12 +++++++++- .../item-page/simple/item-page.component.html | 17 +++++++------ .../item-page/simple/item-page.component.ts | 10 ++++++++ 5 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/app/core/submission/correctiontype-data.service.ts b/src/app/core/submission/correctiontype-data.service.ts index 6096cfddd8d..325ef4cd544 100644 --- a/src/app/core/submission/correctiontype-data.service.ts +++ b/src/app/core/submission/correctiontype-data.service.ts @@ -2,8 +2,14 @@ import { Injectable } from '@angular/core'; import { map, Observable, + of, } from 'rxjs'; +import { + switchMap, +} from 'rxjs/operators'; + +import { NotificationsService } from '../../shared/notifications/notifications.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RequestParam } from '../cache/models/request-param.model'; import { ObjectCacheService } from '../cache/object-cache.service'; @@ -21,6 +27,8 @@ import { } from '../shared/operators'; import { CorrectionType } from './models/correctiontype.model'; +import { AuthService } from '../../core/auth/auth.service'; + /** * A service that provides methods to make REST requests with correctiontypes endpoint. */ @@ -37,6 +45,7 @@ export class CorrectionTypeDataService extends IdentifiableDataService>> { - const options = new FindListOptions(); - options.searchParams = [new RequestParam('uuid', itemUuid)]; - return this.searchData.searchBy(this.searchFindByItem, options, useCachedVersionIfAvailable); + findByItem(itemUuid: string, useCachedVersionIfAvailable): Observable>> { + return this.authService.isAuthenticated().pipe( + switchMap(auth => { + if (!auth) { + return of ([]); + } + const options = new FindListOptions(); + options.searchParams = [new RequestParam('uuid', itemUuid)]; + return this.searchData.searchBy(this.searchFindByItem, options, useCachedVersionIfAvailable); + }) + ); } /** diff --git a/src/app/item-page/full/full-item-page.component.html b/src/app/item-page/full/full-item-page.component.html index 43ecae9f170..cf00a59445c 100644 --- a/src/app/item-page/full/full-item-page.component.html +++ b/src/app/item-page/full/full-item-page.component.html @@ -3,8 +3,10 @@
@if (itemRD?.payload; as item) {
- - + @if ((isLoggedIn$|async)) { + + + } @if (!item.isWithdrawn || (isAdmin$|async)) {
@@ -35,7 +37,9 @@
- + @if ((isLoggedIn$|async)) { + + } @if (fromSubmissionObject) {
diff --git a/src/app/item-page/full/full-item-page.component.ts b/src/app/item-page/full/full-item-page.component.ts index ace0f9a91f4..38faad55283 100644 --- a/src/app/item-page/full/full-item-page.component.ts +++ b/src/app/item-page/full/full-item-page.component.ts @@ -50,6 +50,8 @@ import { ItemVersionsComponent } from '../versions/item-versions.component'; import { ItemVersionsNoticeComponent } from '../versions/notice/item-versions-notice.component'; import { ThemedFullFileSectionComponent } from './field-components/file-section/themed-full-file-section.component'; +import { AuthService } from '../../core/auth/auth.service'; + /** * This component renders a full item page. * The route parameter 'id' is used to request the item it represents. @@ -84,6 +86,11 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit, metadata$: Observable; + /** + * Whether the current user is logged in + */ + isLoggedIn$: Observable; + /** * True when the itemRD has been originated from its workspaceite/workflowitem, false otherwise. */ @@ -101,9 +108,10 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit, protected signpostingDataService: SignpostingDataService, protected linkHeadService: LinkHeadService, protected notifyInfoService: NotifyInfoService, + protected auth: AuthService, @Inject(PLATFORM_ID) protected platformId: string, ) { - super(route, router, items, authorizationService, responseService, signpostingDataService, linkHeadService, notifyInfoService, platformId); + super(route, router, items, authorizationService, responseService, signpostingDataService, linkHeadService, notifyInfoService, auth, platformId); } /*** AoT inheritance fix, will hopefully be resolved in the near future **/ @@ -118,6 +126,8 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit, this.fromSubmissionObject = hasValue(data.wfi) || hasValue(data.wsi); }), ); + + this.isLoggedIn$ = this.auth.isAuthenticated(); } /** diff --git a/src/app/item-page/simple/item-page.component.html b/src/app/item-page/simple/item-page.component.html index 4de3dd56b1c..33b3522106e 100644 --- a/src/app/item-page/simple/item-page.component.html +++ b/src/app/item-page/simple/item-page.component.html @@ -3,16 +3,19 @@
@if (itemRD?.payload; as item) {
- - - - - - + @if ((isLoggedIn$|async)) { + + + + + + } @if (!item.isWithdrawn || (isAdmin$|async)) { } - + @if ((isLoggedIn$|async)) { + + }
}
diff --git a/src/app/item-page/simple/item-page.component.ts b/src/app/item-page/simple/item-page.component.ts index 0e1bf923f7f..3cdf7f6997e 100644 --- a/src/app/item-page/simple/item-page.component.ts +++ b/src/app/item-page/simple/item-page.component.ts @@ -61,6 +61,8 @@ import { CustomUrlConflictErrorComponent } from './custom-url-conflict-error/cus import { NotifyRequestsStatusComponent } from './notify-requests-status/notify-requests-status-component/notify-requests-status.component'; import { QaEventNotificationComponent } from './qa-event-notification/qa-event-notification.component'; +import { AuthService } from '../../core/auth/auth.service'; + /** * This component renders a simple item page. * The route parameter 'id' is used to request the item it represents. @@ -121,6 +123,11 @@ export class ItemPageComponent implements OnInit, OnDestroy { */ isAdmin$: Observable; + /** + * Whether the current user is logged in + */ + isLoggedIn$: Observable; + itemUrl: string; /** @@ -152,6 +159,7 @@ export class ItemPageComponent implements OnInit, OnDestroy { protected signpostingDataService: SignpostingDataService, protected linkHeadService: LinkHeadService, protected notifyInfoService: NotifyInfoService, + protected auth: AuthService, @Inject(PLATFORM_ID) protected platformId: string, ) { this.initPageLinks(); @@ -182,6 +190,8 @@ export class ItemPageComponent implements OnInit, OnDestroy { return null; }), ); + + this.isLoggedIn$ = this.auth.isAuthenticated(); } /** From cc4f192bbad7181f2aa241ba9692347cf5d87488 Mon Sep 17 00:00:00 2001 From: Alex Buckley <37675958+alexklbuckley@users.noreply.github.com> Date: Fri, 3 Jul 2026 15:47:38 +1200 Subject: [PATCH 2/2] Fix redundant import in correctiontype-data.service.ts --- src/app/core/submission/correctiontype-data.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/core/submission/correctiontype-data.service.ts b/src/app/core/submission/correctiontype-data.service.ts index 325ef4cd544..b3323b199fa 100644 --- a/src/app/core/submission/correctiontype-data.service.ts +++ b/src/app/core/submission/correctiontype-data.service.ts @@ -9,7 +9,6 @@ import { switchMap, } from 'rxjs/operators'; -import { NotificationsService } from '../../shared/notifications/notifications.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RequestParam } from '../cache/models/request-param.model'; import { ObjectCacheService } from '../cache/object-cache.service';