-
-
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
* Make blog-admin backend migration changes * Create blog admin route guard and remove redundant file * Create blog-admin-page root component and remove downgrading * Update blog-admin-page module * Update blog-admin module components * Update app routing and webpack configuration * Fix linting issues * Fix linting issues * Fix incorrect file overview * Remove BLOG_ADMIN_PAGE_URL from feconf * Fix blog admin page not having navbar
- Loading branch information
Showing
18 changed files
with
276 additions
and
150 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
85 changes: 85 additions & 0 deletions
85
core/templates/pages/blog-admin-page/blog-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,85 @@ | ||
// 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 BlogAdminAuthGuard | ||
*/ | ||
|
||
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 { BlogAdminAuthGuard } from './blog-admin-auth.guard'; | ||
|
||
class MockRouter { | ||
navigate(commands: string[], extras?: NavigationExtras): Promise<boolean> { | ||
return Promise.resolve(true); | ||
} | ||
} | ||
|
||
describe('BlogAdminAuthGuard', () => { | ||
let userService: UserService; | ||
let router: Router; | ||
let guard: BlogAdminAuthGuard; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [UserService, { provide: Router, useClass: MockRouter }], | ||
}).compileComponents(); | ||
|
||
guard = TestBed.inject(BlogAdminAuthGuard); | ||
userService = TestBed.inject(UserService); | ||
router = TestBed.inject(Router); | ||
}); | ||
|
||
it('should redirect user to 401 page if user is not blog 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 blog admin', (done) => { | ||
const getUserInfoAsyncSpy = spyOn( | ||
userService, 'getUserInfoAsync').and.returnValue( | ||
Promise.resolve(new UserInfo( | ||
['BLOG_ADMIN'], false, false, false, 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/blog-admin-page/blog-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,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 blog 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 BlogAdminAuthGuard 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.isBlogAdmin()) { | ||
return true; | ||
} | ||
|
||
this.router.navigate( | ||
[`${AppConstants.PAGES_REGISTERED_WITH_FRONTEND | ||
.ERROR.ROUTE}/401`]).then(() => { | ||
this.location.replaceState(state.url); | ||
}); | ||
return false; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
core/templates/pages/blog-admin-page/blog-admin-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,4 @@ | ||
<oppia-angular-root> | ||
<oppia-blog-admin-navbar></oppia-blog-admin-navbar> | ||
<oppia-blog-admin-page></oppia-blog-admin-page> | ||
</oppia-angular-root> |
50 changes: 50 additions & 0 deletions
50
core/templates/pages/blog-admin-page/blog-admin-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 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 blog admin 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 { BlogAdminPageRootComponent } from './blog-admin-page-root.component'; | ||
|
||
describe('BlogAdminPageRootComponent', () => { | ||
let fixture: ComponentFixture<BlogAdminPageRootComponent>; | ||
let component: BlogAdminPageRootComponent; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot(), HttpClientTestingModule], | ||
declarations: [BlogAdminPageRootComponent], | ||
providers: [PageHeadService], | ||
schemas: [CUSTOM_ELEMENTS_SCHEMA], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(BlogAdminPageRootComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should have the title and meta tags set', () => { | ||
expect(component.title).toEqual( | ||
AppConstants.PAGES_REGISTERED_WITH_FRONTEND.BLOG_ADMIN.TITLE); | ||
expect(component.meta).toEqual( | ||
AppConstants.PAGES_REGISTERED_WITH_FRONTEND.BLOG_ADMIN.META); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
core/templates/pages/blog-admin-page/blog-admin-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,32 @@ | ||
// 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 Blog admin page root component. | ||
*/ | ||
|
||
import { Component } from '@angular/core'; | ||
import { AppConstants } from 'app.constants'; | ||
import { BaseRootComponent, MetaTagData } from 'pages/base-root.component'; | ||
|
||
@Component({ | ||
selector: 'oppia-blog-admin-page-root', | ||
templateUrl: './blog-admin-page-root.component.html', | ||
}) | ||
export class BlogAdminPageRootComponent extends BaseRootComponent { | ||
title: string = AppConstants.PAGES_REGISTERED_WITH_FRONTEND.BLOG_ADMIN.TITLE; | ||
meta: MetaTagData[] = | ||
AppConstants.PAGES_REGISTERED_WITH_FRONTEND.BLOG_ADMIN.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
18 changes: 0 additions & 18 deletions
18
core/templates/pages/blog-admin-page/blog-admin-page.mainpage.html
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.