-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* email dashboard page added among the pages registered with frontend * handler for email dashboard removed from backend * removed backend test for email dashbard page * removed link with old handler * redundant mainpage file deleted * added auth guard for email dashboard * removed downgrading of email dashboard page * added root component for email dashboard * updated module for email dashboard * added to the app routing module * removed email dashboard module from webpack configuration * fixed linter errors * linter checks fixed * navbar added to the email dashboard page * test added for auth guard and root component of email dashboard * removed redundant backend test case as the page is migrated to frontend * added css to the root page component * style moved to the top to follow the existing standard * updated 2023 to 2024 in copyright disclaimer * updated test description
- Loading branch information
1 parent
2eb298f
commit fe15ab8
Showing
15 changed files
with
296 additions
and
162 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
86 changes: 86 additions & 0 deletions
86
core/templates/pages/email-dashboard-pages/email-dashboard-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,86 @@ | ||
// Copyright 2024 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Tests for EmailDashboardAuthGuard | ||
*/ | ||
|
||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot, NavigationExtras } from '@angular/router'; | ||
|
||
import { AppConstants } from '../../app.constants'; | ||
import { UserInfo } from '../../domain/user/user-info.model'; | ||
import { UserService } from '../../services/user.service'; | ||
import { EmailDashboardAuthGuard } from './email-dashboard-auth.guard'; | ||
|
||
|
||
class MockRouter { | ||
navigate(commands: string[], extras?: NavigationExtras): Promise<boolean> { | ||
return Promise.resolve(true); | ||
} | ||
} | ||
|
||
describe('EmailDashboardAuthGuard', () => { | ||
let userService: UserService; | ||
let router: Router; | ||
let guard: EmailDashboardAuthGuard; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [UserService, { provide: Router, useClass: MockRouter }], | ||
}).compileComponents(); | ||
|
||
guard = TestBed.inject(EmailDashboardAuthGuard); | ||
userService = TestBed.inject(UserService); | ||
router = TestBed.inject(Router); | ||
}); | ||
|
||
it('should redirect to 401 page if user is not super admin', (done) => { | ||
const getUserInfoAsyncSpy = spyOn( | ||
userService, 'getUserInfoAsync').and.returnValue( | ||
Promise.resolve(UserInfo.createDefault()) | ||
); | ||
const navigateSpy = spyOn(router, 'navigate').and.callThrough(); | ||
|
||
guard.canActivate( | ||
new ActivatedRouteSnapshot(), {} as RouterStateSnapshot).then( | ||
(canActivate) => { | ||
expect(canActivate).toBeFalse(); | ||
expect(getUserInfoAsyncSpy).toHaveBeenCalledTimes(1); | ||
expect(navigateSpy).toHaveBeenCalledWith([ | ||
`${AppConstants.PAGES_REGISTERED_WITH_FRONTEND.ERROR.ROUTE}/401`]); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should access the email dashboard if the user is super admin', (done) => { | ||
const getUserInfoAsyncSpy = spyOn( | ||
userService, 'getUserInfoAsync').and.returnValue( | ||
Promise.resolve(new UserInfo( | ||
[], false, false, true, false, false, '', '', '', true)) | ||
); | ||
const navigateSpy = spyOn(router, 'navigate').and.callThrough(); | ||
|
||
guard.canActivate( | ||
new ActivatedRouteSnapshot(), {} as RouterStateSnapshot).then( | ||
(canActivate) => { | ||
expect(canActivate).toBeTrue(); | ||
expect(getUserInfoAsyncSpy).toHaveBeenCalledTimes(1); | ||
expect(navigateSpy).not.toHaveBeenCalled(); | ||
done(); | ||
}); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
core/templates/pages/email-dashboard-pages/email-dashboard-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,58 @@ | ||
// Copyright 2024 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Guard that redirects user to 401 error page | ||
* if the user is not a super admin. | ||
*/ | ||
|
||
import { Location } from '@angular/common'; | ||
import { Injectable } from '@angular/core'; | ||
import { | ||
ActivatedRouteSnapshot, | ||
CanActivate, | ||
Router, | ||
RouterStateSnapshot, | ||
} from '@angular/router'; | ||
|
||
import { AppConstants } from 'app.constants'; | ||
import { UserService } from 'services/user.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class EmailDashboardAuthGuard implements CanActivate { | ||
constructor( | ||
private userService: UserService, | ||
private router: Router, | ||
private location: Location | ||
) {} | ||
|
||
async canActivate( | ||
route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot | ||
): Promise<boolean> { | ||
const userInfo = await this.userService.getUserInfoAsync(); | ||
if (userInfo.isSuperAdmin()) { | ||
return true; | ||
} | ||
|
||
this.router.navigate( | ||
[`${AppConstants.PAGES_REGISTERED_WITH_FRONTEND | ||
.ERROR.ROUTE}/401`]).then(() => { | ||
this.location.replaceState(state.url); | ||
}); | ||
return false; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
core/templates/pages/email-dashboard-pages/email-dashboard-page-root.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,25 @@ | ||
<style> | ||
.success { | ||
color: #00f; | ||
} | ||
|
||
.oppia-query-form { | ||
text-align: center; | ||
} | ||
</style> | ||
<oppia-angular-root> | ||
<oppia-base-content> | ||
<navbar-breadcrumb> | ||
<ul class="nav navbar-nav oppia-navbar-breadcrumb"> | ||
<li> | ||
<span class="oppia-navbar-breadcrumb-separator"></span> | ||
Email Dashboard | ||
</li> | ||
</ul> | ||
</navbar-breadcrumb> | ||
<content> | ||
<oppia-email-dashboard-page></oppia-email-dashboard-page> | ||
</content> | ||
<page-footer></page-footer> | ||
</oppia-base-content> | ||
</oppia-angular-root> |
50 changes: 50 additions & 0 deletions
50
core/templates/pages/email-dashboard-pages/email-dashboard-page-root.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,50 @@ | ||
// Copyright 2024 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Unit tests for Email Dashboard Page Root component. | ||
*/ | ||
|
||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
|
||
import { AppConstants } from '../../app.constants'; | ||
import { PageHeadService } from '../../services/page-head.service'; | ||
import { EmailDashboardPageRootComponent } from './email-dashboard-page-root.component'; | ||
|
||
describe('EmailDashboardPageRootComponent', () => { | ||
let fixture: ComponentFixture<EmailDashboardPageRootComponent>; | ||
let component: EmailDashboardPageRootComponent; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot(), HttpClientTestingModule], | ||
declarations: [EmailDashboardPageRootComponent], | ||
providers: [PageHeadService], | ||
schemas: [CUSTOM_ELEMENTS_SCHEMA], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(EmailDashboardPageRootComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should have the title and meta tags set', () => { | ||
expect(component.title).toEqual( | ||
AppConstants.PAGES_REGISTERED_WITH_FRONTEND.EMAIL_DASHBOARD.TITLE); | ||
expect(component.meta).toEqual( | ||
AppConstants.PAGES_REGISTERED_WITH_FRONTEND.EMAIL_DASHBOARD.META); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
core/templates/pages/email-dashboard-pages/email-dashboard-page-root.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,34 @@ | ||
// Copyright 2024 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Email Dashboard page root component. | ||
*/ | ||
|
||
import { Component } from '@angular/core'; | ||
import { AppConstants } from 'app.constants'; | ||
import { BaseRootComponent, MetaTagData } from 'pages/base-root.component'; | ||
|
||
@Component({ | ||
selector: 'oppia-email-dashboard-page-root', | ||
templateUrl: './email-dashboard-page-root.component.html', | ||
}) | ||
export class EmailDashboardPageRootComponent extends BaseRootComponent { | ||
title: string = | ||
AppConstants.PAGES_REGISTERED_WITH_FRONTEND.EMAIL_DASHBOARD.TITLE; | ||
|
||
meta: MetaTagData[] = | ||
AppConstants.PAGES_REGISTERED_WITH_FRONTEND.EMAIL_DASHBOARD.META as | ||
unknown as Readonly<MetaTagData>[]; | ||
} |
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
38 changes: 0 additions & 38 deletions
38
core/templates/pages/email-dashboard-pages/email-dashboard-page.mainpage.html
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.