-
-
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
Changes from 15 commits
c5a1f4a
33bd7fc
5190e00
dc084b2
ba494f9
a42196b
9dc0e39
9988bd4
89416a4
f0b82fa
2a14bb1
6482e88
bff0e7d
006d21d
eab914f
12f2f7b
ef1f1c9
1a37c71
2054eae
9eb7ba0
b545d40
e4ce9b1
efc23ef
60c0e02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2023 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) => { | ||
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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. 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(); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2023 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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2023 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); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2023 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 was deleted.
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.
Copyright 2024..
Please update this to 2024 and ditto elsewhere
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