-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SF-2574 Create Serval Administration Panel
- Loading branch information
1 parent
411d241
commit 4ce3934
Showing
29 changed files
with
940 additions
and
18 deletions.
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
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
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
56 changes: 56 additions & 0 deletions
56
....XForge.Scripture/ClientApp/src/app/serval-administration/serval-admin-auth.guard.spec.ts
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,56 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; | ||
import { SystemRole } from 'realtime-server/lib/esm/common/models/system-role'; | ||
import { of } from 'rxjs'; | ||
import { anything, mock, when } from 'ts-mockito'; | ||
import { AuthGuard } from 'xforge-common/auth.guard'; | ||
import { AuthService } from 'xforge-common/auth.service'; | ||
import { configureTestingModule } from 'xforge-common/test-utils'; | ||
import { ServalAdminAuthGuard } from './serval-admin-auth.guard'; | ||
|
||
const mockedAuthGuard = mock(AuthGuard); | ||
const mockedAuthService = mock(AuthService); | ||
|
||
describe('ServalAdminAuthGuard', () => { | ||
configureTestingModule(() => ({ | ||
providers: [ | ||
{ provide: AuthGuard, useMock: mockedAuthGuard }, | ||
{ provide: AuthService, useMock: mockedAuthService } | ||
] | ||
})); | ||
|
||
it('can activate if user is logged in and has ServalAdmin role', () => { | ||
const env = new TestEnvironment(true, SystemRole.ServalAdmin); | ||
|
||
env.service.canActivate({} as ActivatedRouteSnapshot, {} as RouterStateSnapshot).subscribe(result => { | ||
expect(result).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it('cannot activate if user is not logged in', () => { | ||
const env = new TestEnvironment(false, SystemRole.None); | ||
|
||
env.service.canActivate({} as ActivatedRouteSnapshot, {} as RouterStateSnapshot).subscribe(result => { | ||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
it('cannot activate if user is logged in but does not have ServalAdmin role', () => { | ||
const env = new TestEnvironment(true, SystemRole.SystemAdmin); | ||
|
||
env.service.canActivate({} as ActivatedRouteSnapshot, {} as RouterStateSnapshot).subscribe(result => { | ||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
class TestEnvironment { | ||
readonly service: ServalAdminAuthGuard; | ||
|
||
constructor(isLoggedIn: boolean, role: SystemRole) { | ||
this.service = TestBed.inject(ServalAdminAuthGuard); | ||
when(mockedAuthGuard.canActivate(anything(), anything())).thenReturn(of(isLoggedIn)); | ||
when(mockedAuthGuard.allowTransition()).thenReturn(of(isLoggedIn)); | ||
when(mockedAuthService.currentUserRoles).thenReturn([role]); | ||
} | ||
} | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/SIL.XForge.Scripture/ClientApp/src/app/serval-administration/serval-admin-auth.guard.ts
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,29 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; | ||
import { SystemRole } from 'realtime-server/lib/esm/common/models/system-role'; | ||
import { Observable } from 'rxjs'; | ||
import { map, switchMap } from 'rxjs/operators'; | ||
import { AuthGuard } from 'xforge-common/auth.guard'; | ||
import { AuthService } from 'xforge-common/auth.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ServalAdminAuthGuard { | ||
constructor(private readonly authGuard: AuthGuard, private readonly authService: AuthService) {} | ||
|
||
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { | ||
return this.authGuard.canActivate(next, state).pipe(switchMap(() => this.allowTransition())); | ||
} | ||
|
||
allowTransition(): Observable<boolean> { | ||
return this.authGuard.allowTransition().pipe( | ||
map(isLoggedIn => { | ||
if (isLoggedIn) { | ||
return this.authService.currentUserRoles.includes(SystemRole.ServalAdmin); | ||
} | ||
return false; | ||
}) | ||
); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ge.Scripture/ClientApp/src/app/serval-administration/serval-administration.component.html
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,5 @@ | ||
<div fxLayout="column" fxLayoutAlign="center start" class="body-content"> | ||
<h1>Serval Administration</h1> | ||
</div> | ||
|
||
<app-serval-projects></app-serval-projects> |
Empty file.
37 changes: 37 additions & 0 deletions
37
...Scripture/ClientApp/src/app/serval-administration/serval-administration.component.spec.ts
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,37 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { TestRealtimeModule } from 'xforge-common/test-realtime.module'; | ||
import { configureTestingModule, TestTranslocoModule } from 'xforge-common/test-utils'; | ||
import { SF_TYPE_REGISTRY } from '../core/models/sf-type-registry'; | ||
import { ServalAdministrationComponent } from './serval-administration.component'; | ||
import { ServalProjectsComponent } from './serval-projects.component'; | ||
|
||
describe('ServalAdministrationComponent', () => { | ||
configureTestingModule(() => ({ | ||
imports: [ | ||
ServalAdministrationComponent, | ||
ServalProjectsComponent, | ||
NoopAnimationsModule, | ||
TestTranslocoModule, | ||
TestRealtimeModule.forRoot(SF_TYPE_REGISTRY), | ||
HttpClientTestingModule | ||
] | ||
})); | ||
|
||
it('should be created', () => { | ||
const env = new TestEnvironment(); | ||
expect(env.component).toBeTruthy(); | ||
}); | ||
|
||
class TestEnvironment { | ||
readonly component: ServalAdministrationComponent; | ||
readonly fixture: ComponentFixture<ServalAdministrationComponent>; | ||
|
||
constructor() { | ||
this.fixture = TestBed.createComponent(ServalAdministrationComponent); | ||
this.component = this.fixture.componentInstance; | ||
this.fixture.detectChanges(); | ||
} | ||
} | ||
}); |
11 changes: 11 additions & 0 deletions
11
...orge.Scripture/ClientApp/src/app/serval-administration/serval-administration.component.ts
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,11 @@ | ||
import { Component } from '@angular/core'; | ||
import { ServalProjectsComponent } from './serval-projects.component'; | ||
|
||
@Component({ | ||
selector: 'app-serval-administration', | ||
templateUrl: './serval-administration.component.html', | ||
styleUrls: ['./serval-administration.component.scss'], | ||
standalone: true, | ||
imports: [ServalProjectsComponent] | ||
}) | ||
export class ServalAdministrationComponent {} |
34 changes: 34 additions & 0 deletions
34
...e.Scripture/ClientApp/src/app/serval-administration/serval-administration.service.spec.ts
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,34 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { mock } from 'ts-mockito'; | ||
import { CommandService } from 'xforge-common/command.service'; | ||
import { RealtimeService } from 'xforge-common/realtime.service'; | ||
import { RetryingRequestService } from 'xforge-common/retrying-request.service'; | ||
import { configureTestingModule } from 'xforge-common/test-utils'; | ||
import { ServalAdministrationService } from './serval-administration.service'; | ||
|
||
const mockedCommandService = mock(CommandService); | ||
const mockedRealtimeService = mock(RealtimeService); | ||
const mockedRetryingRequestService = mock(RetryingRequestService); | ||
|
||
describe('ServalAdministrationService', () => { | ||
configureTestingModule(() => ({ | ||
providers: [ | ||
{ provide: CommandService, useMock: mockedCommandService }, | ||
{ provide: RealtimeService, useMock: mockedRealtimeService }, | ||
{ provide: RetryingRequestService, useMock: mockedRetryingRequestService } | ||
] | ||
})); | ||
|
||
it('should be created', () => { | ||
const env = new TestEnvironment(); | ||
expect(env.service).toBeTruthy(); | ||
}); | ||
|
||
class TestEnvironment { | ||
readonly service: ServalAdministrationService; | ||
|
||
constructor() { | ||
this.service = TestBed.inject(ServalAdministrationService); | ||
} | ||
} | ||
}); |
Oops, something went wrong.