@@ -5,8 +5,9 @@ import { map, switchMap } from 'rxjs/operators';
55import { inject } from '@angular/core' ;
66import { CanMatchFn , Route , Router , UrlSegment } from '@angular/router' ;
77
8- import { CurrentResourceType } from '../../shared/enums' ;
9- import { CurrentResourceSelectors , GetResource } from '../../shared/stores' ;
8+ import { UserSelectors } from '@core/store/user' ;
9+ import { CurrentResourceType } from '@shared/enums' ;
10+ import { CurrentResourceSelectors , GetResource } from '@shared/stores' ;
1011
1112export const isRegistryGuard : CanMatchFn = ( route : Route , segments : UrlSegment [ ] ) => {
1213 const store = inject ( Store ) ;
@@ -19,8 +20,9 @@ export const isRegistryGuard: CanMatchFn = (route: Route, segments: UrlSegment[]
1920 }
2021
2122 const currentResource = store . selectSnapshot ( CurrentResourceSelectors . getCurrentResource ) ;
23+ const currentUser = store . selectSnapshot ( UserSelectors . getCurrentUser ) ;
2224
23- if ( currentResource && currentResource . id === id ) {
25+ if ( currentResource && ! id . startsWith ( currentResource . id ) ) {
2426 if ( currentResource . type === CurrentResourceType . Registrations && currentResource . parentId ) {
2527 router . navigate ( [ '/' , currentResource . parentId , 'files' , id ] ) ;
2628 return true ;
@@ -32,7 +34,11 @@ export const isRegistryGuard: CanMatchFn = (route: Route, segments: UrlSegment[]
3234 }
3335
3436 if ( currentResource . type === CurrentResourceType . Users ) {
35- router . navigate ( [ '/user' , id ] ) ;
37+ if ( currentUser && currentUser . id === currentResource . id ) {
38+ router . navigate ( [ '/profile' ] ) ;
39+ } else {
40+ router . navigate ( [ '/user' , id ] ) ;
41+ }
3642 return false ;
3743 }
3844
@@ -42,7 +48,7 @@ export const isRegistryGuard: CanMatchFn = (route: Route, segments: UrlSegment[]
4248 return store . dispatch ( new GetResource ( id ) ) . pipe (
4349 switchMap ( ( ) => store . select ( CurrentResourceSelectors . getCurrentResource ) ) ,
4450 map ( ( resource ) => {
45- if ( ! resource || resource . id !== id ) {
51+ if ( ! resource || ! id . startsWith ( resource . id ) ) {
4652 return false ;
4753 }
4854
@@ -57,7 +63,11 @@ export const isRegistryGuard: CanMatchFn = (route: Route, segments: UrlSegment[]
5763 }
5864
5965 if ( resource . type === CurrentResourceType . Users ) {
60- router . navigate ( [ '/profile' , id ] ) ;
66+ if ( currentUser && currentUser . id === resource . id ) {
67+ router . navigate ( [ '/profile' ] ) ;
68+ } else {
69+ router . navigate ( [ '/user' , id ] ) ;
70+ }
6171 return false ;
6272 }
6373
0 commit comments