Skip to content

Commit e41657f

Browse files
[DSC-2672] prevent custom url in admin pages
1 parent 6297173 commit e41657f

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/item-page/item-page.resolver.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { Item } from '../core/shared/item.model';
2727
import { getFirstCompletedRemoteData } from '../core/shared/operators';
2828
import {
2929
hasValue,
30-
isNotEmpty,
3130
} from '../shared/empty.util';
3231
import { getItemPageLinksToFollow } from './item.resolver';
3332
import { getItemPageRoute } from './item-page-routing-paths';
@@ -55,7 +54,6 @@ export const itemPageResolver: ResolveFn<RemoteData<Item>> = (
5554
platformId: any = inject(PLATFORM_ID),
5655
hardRedirectService: HardRedirectService = inject(HardRedirectService),
5756
): Observable<RemoteData<Item>> => {
58-
5957
const itemRD$ = itemService.findById(
6058
route.params.id,
6159
false,
@@ -73,23 +71,32 @@ export const itemPageResolver: ResolveFn<RemoteData<Item>> = (
7371

7472
return itemRD$.pipe(
7573
map((rd: RemoteData<Item>) => {
76-
store.dispatch(new ResolvedAction(state.url, rd.payload));
7774
if (rd.hasSucceeded && hasValue(rd.payload)) {
78-
const isItemEditPage = state.url.includes('/edit');
79-
const itemRoute = isItemEditPage ? state.url : router.parseUrl(getItemPageRoute(rd.payload)).toString();
80-
// Check if custom url not empty and if the current id parameter is different from the custom url redirect to custom url
81-
if (hasValue(rd.payload.metadata) && isNotEmpty(rd.payload.metadata['cris.customurl'])) {
82-
if (route.params.id !== rd.payload.metadata['cris.customurl'][0].value) {
83-
const newUrl = itemRoute.replace(route.params.id, rd.payload.metadata['cris.customurl'][0].value);
75+
let itemRoute;
76+
if (hasValue(rd.payload.metadata) && rd.payload.hasMetadata('cris.customurl')) {
77+
const customUrl = rd.payload.firstMetadataValue('cris.customurl');
78+
const isSubPath = !(state.url.endsWith(customUrl) || state.url.endsWith(rd.payload.id) || state.url.endsWith('/full'));
79+
itemRoute = isSubPath ? state.url : router.parseUrl(getItemPageRoute(rd.payload)).toString();
80+
let newUrl: string;
81+
if (route.params.id !== customUrl && !isSubPath) {
82+
newUrl = itemRoute.replace(route.params.id,rd.payload.firstMetadataValue('cris.customurl'));
83+
} else if (isSubPath && route.params.id === customUrl) {
84+
// In case of a sub path, we need to ensure we navigate to the edit page of the item ID, not the custom URL
85+
const itemId = rd.payload.uuid;
86+
newUrl = itemRoute.replace(rd.payload.firstMetadataValue('cris.customurl'), itemId);
87+
}
88+
89+
if (hasValue(newUrl)) {
8490
router.navigateByUrl(newUrl);
8591
}
86-
} else {
92+
} else {
8793
const thisRoute = state.url;
8894

8995
// Angular uses a custom function for encodeURIComponent, (e.g. it doesn't encode commas
9096
// or semicolons) and thisRoute has been encoded with that function. If we want to compare
9197
// it with itemRoute, we have to run itemRoute through Angular's version as well to ensure
9298
// the same characters are encoded the same way.
99+
itemRoute = router.parseUrl(getItemPageRoute(rd.payload)).toString();
93100

94101
if (!thisRoute.startsWith(itemRoute)) {
95102
const itemId = rd.payload.uuid;

0 commit comments

Comments
 (0)