-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metadata Editor: redirect to login URL if accessing the editor as anonymous user #1006
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import { Route } from '@angular/router' | ||
import { DashboardPageComponent } from './dashboard/dashboard-page.component' | ||
import { SignInPageComponent } from './sign-in/sign-in-page.component' | ||
import { EditPageComponent } from './edit/edit-page.component' | ||
import { EditRecordResolver } from './edit-record.resolver' | ||
import { MyDraftComponent } from './records/my-draft/my-draft.component' | ||
|
@@ -10,100 +9,110 @@ import { NewRecordResolver } from './new-record.resolver' | |
import { DuplicateRecordResolver } from './duplicate-record.resolver' | ||
import { AllRecordsComponent } from './records/all-records/all-records.component' | ||
import { MyRecordsStateWrapperComponent } from './records/my-records/my-records-state-wrapper.component' | ||
import { AuthGuardService } from './auth-guard.service' | ||
|
||
export const appRoutes: Route[] = [ | ||
{ path: '', redirectTo: 'catalog/search', pathMatch: 'prefix' }, | ||
{ | ||
path: 'catalog', | ||
component: DashboardPageComponent, | ||
outlet: 'primary', | ||
path: '', | ||
canActivate: [AuthGuardService], | ||
children: [ | ||
{ | ||
path: '', | ||
redirectTo: 'search', | ||
redirectTo: 'catalog/search', | ||
pathMatch: 'prefix', | ||
}, | ||
{ | ||
path: 'discussion', | ||
component: AllRecordsComponent, | ||
pathMatch: 'prefix', | ||
path: 'catalog', | ||
component: DashboardPageComponent, | ||
outlet: 'primary', | ||
children: [ | ||
{ | ||
path: '', | ||
redirectTo: 'search', | ||
pathMatch: 'prefix', | ||
}, | ||
{ | ||
path: 'discussion', | ||
component: AllRecordsComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
{ | ||
path: 'calendar', | ||
component: AllRecordsComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
{ | ||
path: 'contacts', | ||
component: AllRecordsComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
{ | ||
path: 'thesaurus', | ||
component: AllRecordsComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
{ | ||
path: 'search', | ||
title: 'Search Records', | ||
component: AllRecordsComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
], | ||
}, | ||
{ | ||
path: 'calendar', | ||
component: AllRecordsComponent, | ||
pathMatch: 'prefix', | ||
path: 'my-space', | ||
component: DashboardPageComponent, | ||
outlet: 'primary', | ||
title: 'My space', | ||
children: [ | ||
{ | ||
path: 'my-records', | ||
title: 'My Records', | ||
component: MyRecordsStateWrapperComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
{ | ||
path: 'my-draft', | ||
title: 'My Draft', | ||
component: MyDraftComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
{ | ||
path: 'templates', | ||
title: 'Templates', | ||
component: TemplatesComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
], | ||
}, | ||
{ | ||
path: 'contacts', | ||
component: AllRecordsComponent, | ||
pathMatch: 'prefix', | ||
path: 'users', | ||
component: DashboardPageComponent, | ||
outlet: 'primary', | ||
title: 'Users', | ||
children: [ | ||
{ | ||
path: 'my-org', | ||
component: MyOrgUsersComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
], | ||
}, | ||
{ | ||
path: 'thesaurus', | ||
component: AllRecordsComponent, | ||
pathMatch: 'prefix', | ||
path: 'create', | ||
component: EditPageComponent, | ||
resolve: { record: NewRecordResolver }, | ||
}, | ||
{ | ||
path: 'search', | ||
title: 'Search Records', | ||
component: AllRecordsComponent, | ||
pathMatch: 'prefix', | ||
path: 'duplicate/:uuid', | ||
component: EditPageComponent, | ||
resolve: { record: DuplicateRecordResolver }, | ||
}, | ||
], | ||
}, | ||
{ | ||
path: 'my-space', | ||
component: DashboardPageComponent, | ||
outlet: 'primary', | ||
title: 'My space', | ||
children: [ | ||
{ | ||
path: 'my-records', | ||
title: 'My Records', | ||
component: MyRecordsStateWrapperComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
{ | ||
path: 'my-draft', | ||
title: 'My Draft', | ||
component: MyDraftComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
{ | ||
path: 'templates', | ||
title: 'Templates', | ||
component: TemplatesComponent, | ||
pathMatch: 'prefix', | ||
}, | ||
], | ||
}, | ||
{ | ||
path: 'users', | ||
component: DashboardPageComponent, | ||
outlet: 'primary', | ||
title: 'Users', | ||
children: [ | ||
{ | ||
path: 'my-org', | ||
component: MyOrgUsersComponent, | ||
pathMatch: 'prefix', | ||
path: 'edit/:uuid', | ||
component: EditPageComponent, | ||
resolve: { record: EditRecordResolver }, | ||
}, | ||
], | ||
}, | ||
{ path: 'sign-in', component: SignInPageComponent }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this route was removed as it was obviously not needed anyway |
||
{ | ||
path: 'create', | ||
component: EditPageComponent, | ||
resolve: { record: NewRecordResolver }, | ||
}, | ||
{ | ||
path: 'duplicate/:uuid', | ||
component: EditPageComponent, | ||
resolve: { record: DuplicateRecordResolver }, | ||
}, | ||
{ | ||
path: 'edit/:uuid', | ||
component: EditPageComponent, | ||
resolve: { record: EditRecordResolver }, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { AuthGuardService } from './auth-guard.service' | ||
import { MockBuilder, MockProvider } from 'ng-mocks' | ||
import { AuthService } from '@geonetwork-ui/api/repository' | ||
import { TestBed } from '@angular/core/testing' | ||
import { of } from 'rxjs' | ||
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface' | ||
|
||
Object.defineProperty(window, 'location', { | ||
value: new URL('http://localhost'), | ||
}) | ||
|
||
describe('AuthGuardService', () => { | ||
let service: AuthGuardService | ||
beforeEach(() => { | ||
return MockBuilder(AuthGuardService) | ||
}) | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
MockProvider(AuthService, { | ||
loginUrl: 'http://login.com/bla?', | ||
}), | ||
MockProvider(PlatformServiceInterface, { | ||
isAnonymous: () => of(true), | ||
}), | ||
], | ||
}) | ||
window.location.href = 'http://original.path' | ||
service = TestBed.inject(AuthGuardService) | ||
}) | ||
|
||
it('returns true if the user is logged in', async () => { | ||
jest | ||
.spyOn(TestBed.inject(PlatformServiceInterface), 'isAnonymous') | ||
.mockReturnValue(of(false)) | ||
expect(await service.canActivate()).toBe(true) | ||
expect(window.location.href).toBe('http://original.path/') | ||
}) | ||
it('redirects the user to the login page if the user is not logged in', async () => { | ||
expect(await service.canActivate()).toBe(false) | ||
expect(window.location.href).toBe('http://login.com/bla?') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Injectable } from '@angular/core' | ||
import { AuthService } from '@geonetwork-ui/api/repository' | ||
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface' | ||
import { firstValueFrom } from 'rxjs' | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class AuthGuardService { | ||
constructor( | ||
private platformService: PlatformServiceInterface, | ||
private authService: AuthService | ||
) {} | ||
|
||
// this will redirect the user to the authentication form if required | ||
async canActivate(): Promise<boolean> { | ||
const notLoggedIn = await firstValueFrom(this.platformService.isAnonymous()) | ||
if (notLoggedIn) { | ||
window.location.href = this.authService.loginUrl | ||
return false | ||
} | ||
return true | ||
} | ||
} |
Empty file.
1 change: 0 additions & 1 deletion
1
apps/metadata-editor/src/app/sign-in/sign-in-page.component.html
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
apps/metadata-editor/src/app/sign-in/sign-in-page.component.spec.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
apps/metadata-editor/src/app/sign-in/sign-in-page.component.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a root route ( 🤔 ) makes it easier to apply the same guard to all routes