-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Fix part of #19435: Migrate Email Dashboard #19627
Merged
DubeySandeep
merged 24 commits into
oppia:develop
from
sagar-subedi:email-dashboard-migration
Feb 12, 2024
Merged
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c5a1f4a
email dashboard page added among the pages registered with frontend
sagar-subedi 33bd7fc
handler for email dashboard removed from backend
sagar-subedi 5190e00
removed backend test for email dashbard page
sagar-subedi dc084b2
removed link with old handler
sagar-subedi ba494f9
redundant mainpage file deleted
sagar-subedi a42196b
added auth guard for email dashboard
sagar-subedi 9dc0e39
removed downgrading of email dashboard page
sagar-subedi 9988bd4
added root component for email dashboard
sagar-subedi 89416a4
updated module for email dashboard
sagar-subedi f0b82fa
added to the app routing module
sagar-subedi 2a14bb1
removed email dashboard module from webpack configuration
sagar-subedi 6482e88
fixed linter errors
sagar-subedi bff0e7d
linter checks fixed
sagar-subedi 006d21d
navbar added to the email dashboard page
sagar-subedi eab914f
test added for auth guard and root component of email dashboard
sagar-subedi 12f2f7b
removed redundant backend test case as the page is migrated to frontend
sagar-subedi ef1f1c9
added css to the root page component
sagar-subedi 1a37c71
style moved to the top to follow the existing standard
sagar-subedi 2054eae
updated 2023 to 2024 in copyright disclaimer
sagar-subedi 9eb7ba0
Merge branch 'develop' into email-dashboard-migration
sagar-subedi b545d40
Merge branch 'develop' into email-dashboard-migration
sagar-subedi e4ce9b1
updated test description
sagar-subedi efc23ef
Merge branch 'email-dashboard-migration' of https://github.com/sagar-…
sagar-subedi 60c0e02
Merge branch 'develop' into email-dashboard-migration
sagar-subedi 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
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 user 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 not redirect user to 401 page if 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.
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.
Please rename this test case to something around -- should access the email dashboard page if the user is super admin.
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.
Done.