limiting log data returned for unauthenticated users
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
"@nestjs/passport": "^10.0.3",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@noahspan/azure-database": "^3.1.2",
|
||||
"@noahspan/noahspan-modules": "^1.0.0",
|
||||
"@noahspan/noahspan-modules": "^1.1.5",
|
||||
"@schematics/angular": "^17.3.7",
|
||||
"dotenv": "^16.4.7",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
|
||||
@@ -44,11 +44,11 @@ import configuration from './config/configuration';
|
||||
provide: APP_FILTER,
|
||||
useClass: HttpExceptionFilter
|
||||
},
|
||||
{
|
||||
provide: APP_GUARD,
|
||||
useClass: AuthGuard
|
||||
},
|
||||
Reflector
|
||||
// {
|
||||
// provide: APP_GUARD,
|
||||
// useClass: AuthGuard
|
||||
// },
|
||||
// Reflector
|
||||
]
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
39
api/src/log/interceptors/log.interceptor.ts
Normal file
39
api/src/log/interceptors/log.interceptor.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
||||
import { Observable, map } from 'rxjs';
|
||||
|
||||
export class LogInterceptor implements NestInterceptor {
|
||||
intercept(context: ExecutionContext, handler: CallHandler): Observable<any> {
|
||||
const req = context.switchToHttp().getRequest();
|
||||
const authHeader = req.headers.authorization;
|
||||
const token = authHeader && authHeader.split(' ')[1];
|
||||
|
||||
if (!token) {
|
||||
return handler.handle().pipe(
|
||||
map((data) => {
|
||||
if (data.length) {
|
||||
const logs = data.map((log) => {
|
||||
return {
|
||||
partitionKey: log.partitionKey,
|
||||
rowKey: log.rowKey,
|
||||
pilotId: log.pilotId,
|
||||
pilotName: log.pilotName,
|
||||
date: log.date,
|
||||
aircraftMakeModel: log.aircraftMakeModel,
|
||||
routeFrom: log.routeFrom,
|
||||
routeTo: log.routeTo,
|
||||
durationOfFlight: log.durationOfFlight,
|
||||
notes: log.notes
|
||||
};
|
||||
});
|
||||
|
||||
return logs;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return handler.handle().pipe(map((data) => data));
|
||||
}
|
||||
}
|
||||
@@ -7,20 +7,22 @@ import {
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards
|
||||
UseGuards,
|
||||
UseInterceptors
|
||||
} from '@nestjs/common';
|
||||
import { LogDto } from './log.dto';
|
||||
import { Log } from './log.entity';
|
||||
import { LogService } from './log.service';
|
||||
import { CustomError } from '../error/customError';
|
||||
import { Public } from '@noahspan/noahspan-modules';
|
||||
import { AuthGuard } from '@noahspan/noahspan-modules';
|
||||
import { LogInterceptor } from './interceptors/log.interceptor';
|
||||
|
||||
|
||||
@Controller('logs')
|
||||
@UseInterceptors(new LogInterceptor())
|
||||
export class LogController {
|
||||
constructor(private readonly logService: LogService) {}
|
||||
|
||||
@Public()
|
||||
@Get(':partitionKey/:rowKey')
|
||||
async find(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@@ -35,7 +37,6 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Get()
|
||||
async findAll(): Promise<Log[]> {
|
||||
try {
|
||||
@@ -47,6 +48,7 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Post()
|
||||
async create(@Body() logDto: LogDto): Promise<Log> {
|
||||
try {
|
||||
@@ -62,6 +64,7 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Put(':partitionKey/:rowKey')
|
||||
async update(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@@ -81,6 +84,7 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Delete(':partitionKey/:rowKey')
|
||||
async delete(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
|
||||
@@ -19,7 +19,7 @@ export class PilotInterceptor implements NestInterceptor {
|
||||
name: pilot.name
|
||||
};
|
||||
});
|
||||
console.log(pilots)
|
||||
|
||||
return pilots;
|
||||
} else {
|
||||
return data;
|
||||
|
||||
@@ -7,13 +7,14 @@ import {
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common';
|
||||
import { PilotDto } from './pilot.dto';
|
||||
import { Pilot } from './pilot.entity';
|
||||
import { PilotService } from './pilot.service';
|
||||
import { CustomError } from '../error/customError';
|
||||
import { Public } from '@noahspan/noahspan-modules'
|
||||
import { AuthGuard } from '@noahspan/noahspan-modules'
|
||||
import { PilotInterceptor } from './interceptors/pilot.interceptor';
|
||||
|
||||
@Controller('pilots')
|
||||
@@ -21,7 +22,6 @@ import { PilotInterceptor } from './interceptors/pilot.interceptor';
|
||||
export class PilotController {
|
||||
constructor(private readonly pilotService: PilotService) {}
|
||||
|
||||
@Public()
|
||||
@Get(':partitionKey/:rowKey')
|
||||
async find(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@@ -36,7 +36,6 @@ export class PilotController {
|
||||
}
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Get()
|
||||
async findAll() {
|
||||
try {
|
||||
@@ -48,6 +47,7 @@ export class PilotController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Post()
|
||||
async create(@Body() pilotDto: PilotDto) {
|
||||
try {
|
||||
@@ -78,6 +78,7 @@ export class PilotController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Put(':partitionKey/:rowKey')
|
||||
async update(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@@ -112,6 +113,7 @@ export class PilotController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Delete(':partitionKey/:rowKey')
|
||||
async delete(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
|
||||
@@ -129,10 +129,56 @@ const Logbook: React.FC<unknown> = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const columns: ColumnDef<ILogbookEntry>[] = [
|
||||
const unauthColumns: ColumnDef<ILogbookEntry>[] = [
|
||||
{
|
||||
accessorKey: 'pilotName',
|
||||
header: 'Pilot'
|
||||
header: 'Pilot',
|
||||
},
|
||||
{
|
||||
accessorKey: 'date',
|
||||
header: 'Date'
|
||||
},
|
||||
{
|
||||
accessorKey: 'aircraftMakeModel',
|
||||
header: 'Aircraft Make & Model'
|
||||
},
|
||||
{
|
||||
id: 'route',
|
||||
header: 'Route of Flight',
|
||||
meta: {
|
||||
headerAlign: 'center'
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
accessorKey: 'routeFrom',
|
||||
header: 'From'
|
||||
},
|
||||
{
|
||||
accessorKey: 'routeTo',
|
||||
header: 'To'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
accessorKey: 'durationOfFlight',
|
||||
header: 'Duration Of Flight',
|
||||
meta: {
|
||||
align: 'right',
|
||||
headerAlign: 'right'
|
||||
},
|
||||
cell: (info: any) =>
|
||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||
},
|
||||
{
|
||||
accessorKey: 'notes',
|
||||
header: 'Notes'
|
||||
},
|
||||
]
|
||||
|
||||
const authColumns: ColumnDef<ILogbookEntry>[] = [
|
||||
{
|
||||
accessorKey: 'pilotName',
|
||||
header: 'Pilot',
|
||||
},
|
||||
{
|
||||
accessorKey: 'date',
|
||||
@@ -144,7 +190,7 @@ const Logbook: React.FC<unknown> = () => {
|
||||
},
|
||||
{
|
||||
accessorKey: 'aircraftIdentity',
|
||||
header: 'Aircraft Identity'
|
||||
header: 'Aircraft Identity',
|
||||
},
|
||||
{
|
||||
id: 'route',
|
||||
@@ -390,7 +436,7 @@ const Logbook: React.FC<unknown> = () => {
|
||||
{!state.isLoading && (
|
||||
<Grid size={12}>
|
||||
{state.entries.length > 0 && (
|
||||
<Table columns={columns} data={state.entries} />
|
||||
<Table columns={isAuthenticated ? authColumns : unauthColumns} data={state.entries} />
|
||||
)}
|
||||
</Grid>
|
||||
)}
|
||||
|
||||
@@ -2,7 +2,7 @@ version: '3.8'
|
||||
|
||||
services:
|
||||
azurite:
|
||||
container_name: azurite
|
||||
container_name: azurite-flying
|
||||
image: mcr.microsoft.com/azure-storage/azurite
|
||||
ports:
|
||||
- '10000:10000'
|
||||
|
||||
593
pnpm-lock.yaml
generated
593
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user