forked from fga-eps-mds/2023.2-UnB-TV-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
2,274 additions
and
322 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { Router } from '@angular/router'; | ||
import { TokenSuperAdminGuard } from './super-admin.guard'; | ||
import { AuthService } from '../services/auth.service'; | ||
import { UserService } from '../services/user.service'; | ||
import { AlertService } from '../services/alert.service'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
describe('TokenSuperAdminGuard', () => { | ||
let guard: TokenSuperAdminGuard; | ||
let authService: jasmine.SpyObj<AuthService>; | ||
let userService: jasmine.SpyObj<UserService>; | ||
let alertService: jasmine.SpyObj<AlertService>; | ||
let router: jasmine.SpyObj<Router>; | ||
|
||
beforeEach(() => { | ||
const authServiceSpy = jasmine.createSpyObj('AuthService', ['isAuthenticated']); | ||
const userServiceSpy = jasmine.createSpyObj('UserService', ['getRoles']); | ||
const alertServiceSpy = jasmine.createSpyObj('AlertService', ['showMessage']); | ||
const routerSpy = jasmine.createSpyObj('Router', ['navigate']); | ||
|
||
TestBed.configureTestingModule({ | ||
imports: [RouterTestingModule], | ||
providers: [ | ||
TokenSuperAdminGuard, | ||
{ provide: AuthService, useValue: authServiceSpy }, | ||
{ provide: UserService, useValue: userServiceSpy }, | ||
{ provide: AlertService, useValue: alertServiceSpy }, | ||
{ provide: Router, useValue: routerSpy } | ||
], | ||
}); | ||
|
||
guard = TestBed.inject(TokenSuperAdminGuard); | ||
authService = TestBed.inject(AuthService) as jasmine.SpyObj<AuthService>; | ||
userService = TestBed.inject(UserService) as jasmine.SpyObj<UserService>; | ||
alertService = TestBed.inject(AlertService) as jasmine.SpyObj<AlertService>; | ||
router = TestBed.inject(Router) as jasmine.SpyObj<Router>; | ||
}); | ||
|
||
it('should allow access if user is authenticated and role is ADMIN', () => { | ||
authService.isAuthenticated.and.returnValue(true); | ||
userService.getRoles.and.returnValue('ADMIN'); | ||
|
||
const result = guard.canActivate({} as any, {} as any); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should deny access and navigate to /homeAdmin if user is not ADMIN', () => { | ||
authService.isAuthenticated.and.returnValue(true); | ||
userService.getRoles.and.returnValue('USER'); | ||
|
||
const result = guard.canActivate({} as any, {} as any); | ||
|
||
expect(result).toBe(false); | ||
expect(alertService.showMessage).toHaveBeenCalledWith('error', 'Erro', 'Você não possui acesso!'); | ||
expect(router.navigate).toHaveBeenCalledWith(['/homeAdmin']); | ||
}); | ||
|
||
it('should deny access and navigate to /loginsocial if user is not authenticated', () => { | ||
authService.isAuthenticated.and.returnValue(false); | ||
|
||
const result = guard.canActivate({} as any, { url: '/someUrl' } as any); | ||
|
||
expect(result).toBe(false); | ||
expect(alertService.showMessage).toHaveBeenCalledWith('error', 'Erro', 'Você não está logado!'); | ||
expect(router.navigate).toHaveBeenCalledWith(['/loginsocial'], { queryParams: { returnUrl: '/someUrl' } }); | ||
}); | ||
}); | ||
|
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,35 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; | ||
import { AuthService } from '../services/auth.service'; | ||
import { UserService } from '../services/user.service'; | ||
import { AlertService } from '../services/alert.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class TokenSuperAdminGuard implements CanActivate { | ||
constructor( | ||
private authService: AuthService, | ||
private userService: UserService, | ||
private router: Router, | ||
private alertService: AlertService | ||
) {} | ||
|
||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { | ||
if (this.authService.isAuthenticated()) { | ||
const userRole = this.userService.getRoles(); | ||
|
||
if (userRole === 'ADMIN') { | ||
return true; | ||
} else { | ||
this.alertService.showMessage('error', 'Erro', 'Você não possui acesso!') | ||
this.router.navigate(['/homeAdmin']); | ||
return false; | ||
} | ||
} else { | ||
this.alertService.showMessage('error', 'Erro', 'Você não está logado!') | ||
this.router.navigate(['/loginsocial'], { queryParams: { returnUrl: state.url } }); | ||
return false; | ||
} | ||
} | ||
} |
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
123 changes: 123 additions & 0 deletions
123
src/app/pages/controle-super-admin/controle-super-admin.component.css
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,123 @@ | ||
/* Estilos gerais */ | ||
.home-container { | ||
display: flex; | ||
} | ||
|
||
aside { | ||
width: 13.2em; | ||
background-color: white; | ||
padding: 1em 0.75em; | ||
box-shadow: 0.125em 0 0.3125em rgba(0, 0, 0, 0.1); | ||
text-align: left; | ||
position: fixed; | ||
height: 100%; | ||
margin: 0; | ||
} | ||
|
||
.user-info p { | ||
margin: 0; | ||
font-size: 1.2em; | ||
} | ||
|
||
.linksBarraLateral { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin: 0.75em 0; | ||
} | ||
|
||
.linkLogout, | ||
.linkVoltar { | ||
color: #0087c8; | ||
text-decoration: none; | ||
} | ||
|
||
.linkLogout:hover, | ||
.linkVoltar:hover { | ||
text-decoration: underline; | ||
color: #0056b3; | ||
cursor: pointer; | ||
} | ||
|
||
hr.solid { | ||
border-top: 0.0625em solid #bbb; | ||
} | ||
|
||
nav ul { | ||
list-style: none; | ||
padding: 0; | ||
} | ||
|
||
nav ul li { | ||
margin: 0.9375em 0; | ||
} | ||
|
||
nav ul li a { | ||
text-decoration: none; | ||
color: #1d1d1d; | ||
font-size: 1.1em; | ||
} | ||
|
||
nav ul li a:hover, | ||
nav ul li a.linkSelecionado { | ||
color: #00a550; | ||
} | ||
|
||
main { | ||
flex: 1; | ||
padding: 1em; | ||
margin-left: 14.2em; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
header h1 { | ||
font-size: 2.4em; | ||
color: #00a550; | ||
margin-top: 1em; | ||
} | ||
|
||
hr.solid2 { | ||
border-top: 0.125em solid #bbb; | ||
} | ||
|
||
/* Estilos da tabela */ | ||
table { | ||
width: 100%; | ||
border-collapse: collapse; | ||
margin-top: 1em; | ||
} | ||
|
||
thead { | ||
background-color: #00a550; | ||
color: white; | ||
} | ||
|
||
th, | ||
td { | ||
padding: 0.75em; | ||
text-align: left; | ||
border: 1px solid #ddd; | ||
} | ||
|
||
tbody tr:nth-child(even) { | ||
background-color: #f9f9f9; | ||
} | ||
|
||
button { | ||
background-color: #ff4c4c; | ||
color: white; | ||
border: none; | ||
padding: 0.5em 1em; | ||
cursor: pointer; | ||
border-radius: 5px; | ||
margin-right: 0.5em; | ||
} | ||
|
||
.btn-setRole { | ||
background-color: #0087c8; | ||
} | ||
|
||
button:hover { | ||
background-color: #7ad0eb; | ||
} |
Oops, something went wrong.