Skip to content

Commit

Permalink
Resolvendo conflitos de merge
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielRoger07 committed Aug 26, 2024
2 parents 6f252b6 + 5a9ef97 commit 6e22bdd
Show file tree
Hide file tree
Showing 28 changed files with 2,274 additions and 322 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/continous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ jobs:

- name: Test 📋
run: npm run test:prod

- name: Generate JUnit report
run: |
cp test-report-example.xml test-report.xml
- name: Test Printing Test Report
run: cat test-report.xml

- name: Remove src/app/app.constant.ts from lcov.info
run: |
grep -v "SF:src/app/app.constant.ts" coverage/unb-tv-frontend/lcov.info > coverage/unb-tv-frontend/lcov_temp.info
mv coverage/unb-tv-frontend/lcov_temp.info coverage/unb-tv-frontend/lcov.info

- name: Executa SonarCloud Scan
if: ${{ always() }}
Expand Down
33 changes: 22 additions & 11 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ import { PrivacyPolicyComponent } from './pages/privacy-policy/privacy-policy.co

import { HomeAdminComponent } from './pages/home-admin/home-admin.component';
import { AdminActivateComponent } from './pages/admin-activate/admin-activate.component';
import { SuperAdminActivateComponent } from './pages/super-admin-activate/super-admin-activate.component';
import { CategoryTableComponent } from './pages/category-table/category-table.component';
import { VideoViewsComponent } from './pages/video-views/video-views.component';
import { RecordComponent } from './pages/record/record.component';
import { DashboardCategoryComponent } from './pages/dashboard-category/dashboard-category.component';
import { ControleSuperAdminComponent } from './pages/controle-super-admin/controle-super-admin.component';

import { WithTokenGuard } from './guard/with-token.guard';
import { TokenAdminGuard } from './guard/admin.guard';

import { TokenSuperAdminGuard } from './guard/super-admin.guard';

const routes: Routes = [
{ path: '', component: LoginComponent, canActivate: [WithTokenGuard] },
Expand Down Expand Up @@ -93,22 +95,26 @@ const routes: Routes = [
canActivate: [AdminGuard],
},
{ path: 'privacy', component: PrivacyPolicyComponent },

{ path: 'homeAdmin',
{
path: 'homeAdmin',
component: HomeAdminComponent,
canActivate: [TokenAdminGuard],
},
{
path: 'adminActivate',
component: AdminActivateComponent
component: AdminActivateComponent,
},
{
path: 'superAdminActivate',
component: SuperAdminActivateComponent,
},
{
{
path: 'category-views',
component: CategoryTableComponent,
canActivate: [TokenAdminGuard],
},
{
path: 'video-views',
{
path: 'video-views',
component: VideoViewsComponent,
canActivate: [TokenAdminGuard],
},
Expand All @@ -118,14 +124,19 @@ const routes: Routes = [
canActivate: [TokenAdminGuard],
},
{
path: 'record',
component: RecordComponent,
canActivate: [AuthGuard]
path: 'record',
component: RecordComponent,
canActivate: [AuthGuard],
},
{
path: 'controleSuperAdmin',
component: ControleSuperAdminComponent,
canActivate: [TokenSuperAdminGuard],
},
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule { }
export class AppRoutingModule {}
5 changes: 5 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { SocialLoginModule, SocialAuthServiceConfig, GoogleLoginProvider, Facebo

// Declaration
import { NgModule, isDevMode } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AppComponent } from './app.component';
import { LoginComponent } from './pages/login/login.component';
import { RegisterComponent } from './pages/register/register.component';
Expand Down Expand Up @@ -46,6 +47,8 @@ import { PrivacyPolicyComponent } from './pages/privacy-policy/privacy-policy.co
import { ServiceWorkerModule } from '@angular/service-worker';
import { NgChartsModule } from 'ng2-charts';
import { HomeAdminComponent } from './pages/home-admin/home-admin.component';
import {ControleSuperAdminComponent} from './pages/controle-super-admin/controle-super-admin.component'


import { CategoryTableComponent } from './pages/category-table/category-table.component';
import { VideoViewsComponent } from './pages/video-views/video-views.component';
Expand Down Expand Up @@ -79,6 +82,7 @@ import { RecordComponent } from './pages/record/record.component';
registrationStrategy: 'registerWhenStable:30000'
}),
NgChartsModule,
CommonModule,
],

declarations: [
Expand Down Expand Up @@ -108,6 +112,7 @@ import { RecordComponent } from './pages/record/record.component';
VideoViewsComponent,
DashboardCategoryComponent,
RecordComponent,
ControleSuperAdminComponent,
],

providers: [
Expand Down
2 changes: 1 addition & 1 deletion src/app/guard/admin.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class TokenAdminGuard implements CanActivate {
if (this.authService.isAuthenticated()) {
const userRole = this.userService.getRoles();

if (userRole === 'ADMIN') {
if (userRole === 'ADMIN' || userRole === 'COADMIN') {
return true;
} else {
this.router.navigate(['/loginsocial']);
Expand Down
70 changes: 70 additions & 0 deletions src/app/guard/super-admin.guard.spec.ts
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' } });
});
});

35 changes: 35 additions & 0 deletions src/app/guard/super-admin.guard.ts
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;
}
}
}
1 change: 1 addition & 0 deletions src/app/pages/category-table/category-table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<li><a href="/video-views">Dados - Vídeos</a></li>
<li><a href="/category-views" class="linkSelecionado">Dados - Categorias</a></li>
<li><a href="/dashboard">Dashboard - Categorias</a></li>
<li><a href="/controleSuperAdmin">Administração de Usuários</a></li>
</ul>
</nav>
</aside>
Expand Down
123 changes: 123 additions & 0 deletions src/app/pages/controle-super-admin/controle-super-admin.component.css
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;
}
Loading

0 comments on commit 6e22bdd

Please sign in to comment.