Skip to content

Commit

Permalink
NAS-125468 / 24.04 / More improvements on audit page (#9287)
Browse files Browse the repository at this point in the history
* NAS-125468: More improvements on audit page

* NAS-125468: More improvements on audit page

* NAS-125468: More improvements on audit page
  • Loading branch information
AlexKarpov98 authored Dec 6, 2023
1 parent dbf9c55 commit ac679db
Show file tree
Hide file tree
Showing 98 changed files with 242 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/app/enums/audit-event.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum AuditEvent {
SetAttr = 'SET_ATTR',
SetQuota = 'SET_QUOTA',
Authentication = 'AUTHENTICATION',
MethodCall = 'METHOD_CALL',
}

export const auditEventLabels = new Map<AuditEvent, string>([
Expand All @@ -32,4 +33,5 @@ export const auditEventLabels = new Map<AuditEvent, string>([
[AuditEvent.SetAttr, T('Set Attribute')],
[AuditEvent.SetQuota, T('Set Quota')],
[AuditEvent.Authentication, T('Authentication')],
[AuditEvent.MethodCall, T('Method Call')],
]);
10 changes: 10 additions & 0 deletions src/app/helpers/get-log-important-data.helper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { TranslateService } from '@ngx-translate/core';
import { AuditEvent } from 'app/enums/audit-event.enum';
import { AuditEntry } from 'app/interfaces/audit.interface';
import { credentialTypeLabels } from 'app/interfaces/credential-type.interface';

export function getLogImportantData(log: AuditEntry, translateService: TranslateService): string {
switch (log.event) {
case AuditEvent.MethodCall:
return log.event_data?.description || log.event_data?.method;
case AuditEvent.Rename:
return `${log.event_data?.src_file?.path} -> ${log.event_data?.dst_file?.path}`;
case AuditEvent.Authentication:
if (log.event_data?.credentials) {
const credentialType = log.event_data?.credentials.credentials;
const credentialTypeKey = credentialTypeLabels.get(credentialType);
return translateService.instant('Credentials: {credentials}', {
credentials: credentialType ? translateService.instant(credentialTypeKey) : credentialType,
});
}
return translateService.instant('Account: {account}', { account: log.event_data?.clientAccount });
case AuditEvent.Connect:
case AuditEvent.Disconnect:
Expand Down
6 changes: 6 additions & 0 deletions src/app/interfaces/audit.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AuditEvent } from 'app/enums/audit-event.enum';
import { AuditService } from 'app/enums/audit.enum';
import { ApiTimestamp } from 'app/interfaces/api-date.interface';
import { CredentialType } from 'app/interfaces/credential-type.interface';

export interface BaseAuditEntry {
audit_id: string;
Expand All @@ -23,6 +24,11 @@ export interface AuditConfig {

interface EventData {
host?: string;
description?: string;
method?: string;
credentials?: {
credentials?: CredentialType;
};
clientAccount?: string;
file?: {
path?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { JobState } from 'app/enums/job-state.enum';
import { ApiJobMethod } from 'app/interfaces/api/api-job-directory.interface';
import { AuditEntry } from 'app/interfaces/audit.interface';
import { Job } from 'app/interfaces/job.interface';
import { ExportButtonComponent } from 'app/modules/export-button/components/export-button/export-button.component';
import { SortDirection } from 'app/modules/ix-table2/enums/sort-direction.enum';
import { ExportButtonComponent } from 'app/pages/audit/components/export-button/export-button.component';
import { StorageService } from 'app/services/storage.service';
import { WebSocketService } from 'app/services/ws.service';

Expand All @@ -34,7 +34,10 @@ describe('ExportButtonComponent', () => {

beforeEach(() => {
spectator = createComponent({
props: { method },
props: {
method,
defaultFilters: [['event', '~', '(?i)search query']],
},
});
loader = TestbedHarnessEnvironment.loader(spectator.fixture);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { WebSocketService } from 'app/services/ws.service';
export class ExportButtonComponent<T, M extends ApiJobMethod> {
@Input() method: M;
@Input() searchQuery: SearchQuery<T>;
@Input() defaultFilters: QueryFilters<T>;
@Input() sorting: TableSort<T>;
@Input() filename = 'data';

Expand Down Expand Up @@ -82,15 +83,10 @@ export class ExportButtonComponent<T, M extends ApiJobMethod> {
}

private getQueryFilters(searchQuery: SearchQuery<T>): QueryFilters<T> {
if (searchQuery && searchQuery.isBasicQuery) {
// TODO: Breaks encapsulation of the component.
// TODO: Rest of the component is generic and is not tied to specific filters.
return [['event', '~', `(?i)${searchQuery.query || ''}`]] as unknown as QueryFilters<T>;
if (searchQuery) {
return (searchQuery as AdvancedSearchQuery<T>)?.filters || this.defaultFilters;
}

if (searchQuery && !searchQuery.isBasicQuery) {
return (searchQuery as AdvancedSearchQuery<T>).filters;
}
return [];
}

Expand Down
18 changes: 18 additions & 0 deletions src/app/modules/export-button/export-button.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { TranslateModule } from '@ngx-translate/core';
import { ExportButtonComponent } from 'app/modules/export-button/components/export-button/export-button.component';

@NgModule({
declarations: [ExportButtonComponent],
imports: [
CommonModule,
TranslateModule,
MatButtonModule,
],
exports: [
ExportButtonComponent,
],
})
export class ExportButtonModule { }
6 changes: 3 additions & 3 deletions src/app/pages/audit/audit.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MatSelectModule } from '@angular/material/select';
import { MatTooltipModule } from '@angular/material/tooltip';
import { TranslateModule } from '@ngx-translate/core';
import { CoreComponents } from 'app/core/core-components.module';
import { ExportButtonModule } from 'app/modules/export-button/export-button.module';
import { IxFormsModule } from 'app/modules/ix-forms/ix-forms.module';
import { IxIconModule } from 'app/modules/ix-icon/ix-icon.module';
import { IxTable2Module } from 'app/modules/ix-table2/ix-table2.module';
Expand All @@ -15,7 +16,6 @@ import { AppLoaderModule } from 'app/modules/loader/app-loader.module';
import { SearchInputModule } from 'app/modules/search-input/search-input.module';
import { TestIdModule } from 'app/modules/test-id/test-id.module';
import { AuditComponent } from 'app/pages/audit/components/audit/audit.component';
import { ExportButtonComponent } from 'app/pages/audit/components/export-button/export-button.component';
import { routing } from './audit.routing';
import { EventDataDetailsCardComponent } from './components/event-data-details-card/event-data-details-card.component';
import { LogDetailsPanelComponent } from './components/log-details-panel/log-details-panel.component';
Expand All @@ -37,17 +37,17 @@ import { MetadataDetailsCardComponent } from './components/metadata-details-card
AppLoaderModule,
SearchInputModule,
CoreComponents,
routing,
CoreComponents,
MatTooltipModule,
ExportButtonModule,
routing,
],
exports: [],
declarations: [
AuditComponent,
LogDetailsPanelComponent,
MetadataDetailsCardComponent,
EventDataDetailsCardComponent,
ExportButtonComponent,
],
providers: [],
})
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/audit/components/audit/audit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
method="audit.export"
[searchQuery]="searchQuery"
[sorting]="this.dataProvider.sorting"
[defaultFilters]="basicQueryFilters"
></ix-export-button>
</div>
</mat-card>
Expand Down
22 changes: 18 additions & 4 deletions src/app/pages/audit/components/audit/audit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getLogImportantData } from 'app/helpers/get-log-important-data.helper';
import { ParamsBuilder } from 'app/helpers/params-builder/params-builder.class';
import { WINDOW } from 'app/helpers/window.helper';
import { AuditEntry, SmbAuditEntry } from 'app/interfaces/audit.interface';
import { QueryFilters } from 'app/interfaces/query-api.interface';
import { ApiDataProvider } from 'app/modules/ix-table2/classes/api-data-provider/api-data-provider';
import { PaginationServerSide } from 'app/modules/ix-table2/classes/api-data-provider/pagination-server-side.class';
import { SortingServerSide } from 'app/modules/ix-table2/classes/api-data-provider/sorting-server-side.class';
Expand Down Expand Up @@ -48,6 +49,10 @@ export class AuditComponent implements OnInit, AfterViewInit, OnDestroy {
searchQuery: SearchQuery<AuditEntry>;
pagination: TablePagination;

get basicQueryFilters(): QueryFilters<AuditEntry> {
return [['event', '~', `(?i)${(this.searchQuery as { query: string })?.query || ''}`]];
}

columns = createTable<AuditEntry>([
textColumn({
title: this.translate.instant('Service'),
Expand All @@ -64,7 +69,7 @@ export class AuditComponent implements OnInit, AfterViewInit, OnDestroy {
title: this.translate.instant('Event'),
getValue: (row) => (auditEventLabels.has(row.event)
? this.translate.instant(auditEventLabels.get(row.event))
: ''),
: row.event || '-'),
}),
textColumn({
title: this.translate.instant('Event Data'),
Expand Down Expand Up @@ -104,18 +109,27 @@ export class AuditComponent implements OnInit, AfterViewInit, OnDestroy {
textProperty(
'address',
this.translate.instant('Address'),
of(auditEntries.map((log) => ({ label: log.address, value: `"${log.address}"` }))),
of(auditEntries.map((log) => ({
label: log.address,
value: `"${log.address}"`,
}))),
),
textProperty(
'service',
this.translate.instant('Service'),
of(auditEntries.map((log) => ({ label: log.service, value: `"${log.service}"` }))),
of([
{ label: 'SMB', value: '"SMB"' },
{ label: this.translate.instant('Middleware'), value: '"MIDDLEWARE"' },
]),
),
textProperty(
'username',
this.translate.instant('Username'),
this.ws.call('user.query').pipe((
map((users) => users.map((user) => ({ label: user.username, value: `"${user.username}"` })))
map((users) => users.map((user) => ({
label: user.username,
value: `"${user.username}"`,
})))
)),
),
textProperty(
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/af.json
Original file line number Diff line number Diff line change
Expand Up @@ -2265,12 +2265,14 @@
"Metadata (Special) Small Block Size": "",
"Metadata VDEVs": "",
"Method": "",
"Method Call": "",
"Method of snapshot transfer:<ul> <li><i>SSH</i> is supported by most systems. It requires a previously created connection in <b>System > SSH Connections</b>.</li> <li><i>SSH+NETCAT</i> uses SSH to establish a connection to the destination system, then uses <a href=\"https://github.com/truenas/py-libzfs\" target=\"_blank\">py-libzfs</a> to send an unencrypted data stream for higher transfer speeds. This only works when replicating to a TrueNAS, or other system with <i>py-libzfs</i> installed.</li> <li><i>LOCAL</i> efficiently replicates snapshots to another dataset on the same system without using the network.</li> <li><i>LEGACY</i> uses the legacy replication engine from FreeNAS 11.2 and earlier.</li></ul>": "",
"Metrics": "",
"MiB. Units smaller than MiB are not allowed.": "",
"Microsoft Azure": "",
"Microsoft OneDrive": "",
"Microsoft Onedrive <a href=\"https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/authentication\" target=\"_blank\">Access Token</a>. Log in to the Microsoft account to add an access token.": "",
"Middleware": "",
"Migrate applications to the new pool": "",
"Min Poll": "",
"Minimum": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2265,12 +2265,14 @@
"Metadata (Special) Small Block Size": "",
"Metadata VDEVs": "",
"Method": "",
"Method Call": "",
"Method of snapshot transfer:<ul> <li><i>SSH</i> is supported by most systems. It requires a previously created connection in <b>System > SSH Connections</b>.</li> <li><i>SSH+NETCAT</i> uses SSH to establish a connection to the destination system, then uses <a href=\"https://github.com/truenas/py-libzfs\" target=\"_blank\">py-libzfs</a> to send an unencrypted data stream for higher transfer speeds. This only works when replicating to a TrueNAS, or other system with <i>py-libzfs</i> installed.</li> <li><i>LOCAL</i> efficiently replicates snapshots to another dataset on the same system without using the network.</li> <li><i>LEGACY</i> uses the legacy replication engine from FreeNAS 11.2 and earlier.</li></ul>": "",
"Metrics": "",
"MiB. Units smaller than MiB are not allowed.": "",
"Microsoft Azure": "",
"Microsoft OneDrive": "",
"Microsoft Onedrive <a href=\"https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/authentication\" target=\"_blank\">Access Token</a>. Log in to the Microsoft account to add an access token.": "",
"Middleware": "",
"Migrate applications to the new pool": "",
"Min Poll": "",
"Minimum": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -2265,12 +2265,14 @@
"Metadata (Special) Small Block Size": "",
"Metadata VDEVs": "",
"Method": "",
"Method Call": "",
"Method of snapshot transfer:<ul> <li><i>SSH</i> is supported by most systems. It requires a previously created connection in <b>System > SSH Connections</b>.</li> <li><i>SSH+NETCAT</i> uses SSH to establish a connection to the destination system, then uses <a href=\"https://github.com/truenas/py-libzfs\" target=\"_blank\">py-libzfs</a> to send an unencrypted data stream for higher transfer speeds. This only works when replicating to a TrueNAS, or other system with <i>py-libzfs</i> installed.</li> <li><i>LOCAL</i> efficiently replicates snapshots to another dataset on the same system without using the network.</li> <li><i>LEGACY</i> uses the legacy replication engine from FreeNAS 11.2 and earlier.</li></ul>": "",
"Metrics": "",
"MiB. Units smaller than MiB are not allowed.": "",
"Microsoft Azure": "",
"Microsoft OneDrive": "",
"Microsoft Onedrive <a href=\"https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/authentication\" target=\"_blank\">Access Token</a>. Log in to the Microsoft account to add an access token.": "",
"Middleware": "",
"Migrate applications to the new pool": "",
"Min Poll": "",
"Minimum": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/az.json
Original file line number Diff line number Diff line change
Expand Up @@ -2265,12 +2265,14 @@
"Metadata (Special) Small Block Size": "",
"Metadata VDEVs": "",
"Method": "",
"Method Call": "",
"Method of snapshot transfer:<ul> <li><i>SSH</i> is supported by most systems. It requires a previously created connection in <b>System > SSH Connections</b>.</li> <li><i>SSH+NETCAT</i> uses SSH to establish a connection to the destination system, then uses <a href=\"https://github.com/truenas/py-libzfs\" target=\"_blank\">py-libzfs</a> to send an unencrypted data stream for higher transfer speeds. This only works when replicating to a TrueNAS, or other system with <i>py-libzfs</i> installed.</li> <li><i>LOCAL</i> efficiently replicates snapshots to another dataset on the same system without using the network.</li> <li><i>LEGACY</i> uses the legacy replication engine from FreeNAS 11.2 and earlier.</li></ul>": "",
"Metrics": "",
"MiB. Units smaller than MiB are not allowed.": "",
"Microsoft Azure": "",
"Microsoft OneDrive": "",
"Microsoft Onedrive <a href=\"https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/authentication\" target=\"_blank\">Access Token</a>. Log in to the Microsoft account to add an access token.": "",
"Middleware": "",
"Migrate applications to the new pool": "",
"Min Poll": "",
"Minimum": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -2265,12 +2265,14 @@
"Metadata (Special) Small Block Size": "",
"Metadata VDEVs": "",
"Method": "",
"Method Call": "",
"Method of snapshot transfer:<ul> <li><i>SSH</i> is supported by most systems. It requires a previously created connection in <b>System > SSH Connections</b>.</li> <li><i>SSH+NETCAT</i> uses SSH to establish a connection to the destination system, then uses <a href=\"https://github.com/truenas/py-libzfs\" target=\"_blank\">py-libzfs</a> to send an unencrypted data stream for higher transfer speeds. This only works when replicating to a TrueNAS, or other system with <i>py-libzfs</i> installed.</li> <li><i>LOCAL</i> efficiently replicates snapshots to another dataset on the same system without using the network.</li> <li><i>LEGACY</i> uses the legacy replication engine from FreeNAS 11.2 and earlier.</li></ul>": "",
"Metrics": "",
"MiB. Units smaller than MiB are not allowed.": "",
"Microsoft Azure": "",
"Microsoft OneDrive": "",
"Microsoft Onedrive <a href=\"https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/authentication\" target=\"_blank\">Access Token</a>. Log in to the Microsoft account to add an access token.": "",
"Middleware": "",
"Migrate applications to the new pool": "",
"Min Poll": "",
"Minimum": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2265,12 +2265,14 @@
"Metadata (Special) Small Block Size": "",
"Metadata VDEVs": "",
"Method": "",
"Method Call": "",
"Method of snapshot transfer:<ul> <li><i>SSH</i> is supported by most systems. It requires a previously created connection in <b>System > SSH Connections</b>.</li> <li><i>SSH+NETCAT</i> uses SSH to establish a connection to the destination system, then uses <a href=\"https://github.com/truenas/py-libzfs\" target=\"_blank\">py-libzfs</a> to send an unencrypted data stream for higher transfer speeds. This only works when replicating to a TrueNAS, or other system with <i>py-libzfs</i> installed.</li> <li><i>LOCAL</i> efficiently replicates snapshots to another dataset on the same system without using the network.</li> <li><i>LEGACY</i> uses the legacy replication engine from FreeNAS 11.2 and earlier.</li></ul>": "",
"Metrics": "",
"MiB. Units smaller than MiB are not allowed.": "",
"Microsoft Azure": "",
"Microsoft OneDrive": "",
"Microsoft Onedrive <a href=\"https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/authentication\" target=\"_blank\">Access Token</a>. Log in to the Microsoft account to add an access token.": "",
"Middleware": "",
"Migrate applications to the new pool": "",
"Min Poll": "",
"Minimum": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -2265,12 +2265,14 @@
"Metadata (Special) Small Block Size": "",
"Metadata VDEVs": "",
"Method": "",
"Method Call": "",
"Method of snapshot transfer:<ul> <li><i>SSH</i> is supported by most systems. It requires a previously created connection in <b>System > SSH Connections</b>.</li> <li><i>SSH+NETCAT</i> uses SSH to establish a connection to the destination system, then uses <a href=\"https://github.com/truenas/py-libzfs\" target=\"_blank\">py-libzfs</a> to send an unencrypted data stream for higher transfer speeds. This only works when replicating to a TrueNAS, or other system with <i>py-libzfs</i> installed.</li> <li><i>LOCAL</i> efficiently replicates snapshots to another dataset on the same system without using the network.</li> <li><i>LEGACY</i> uses the legacy replication engine from FreeNAS 11.2 and earlier.</li></ul>": "",
"Metrics": "",
"MiB. Units smaller than MiB are not allowed.": "",
"Microsoft Azure": "",
"Microsoft OneDrive": "",
"Microsoft Onedrive <a href=\"https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/authentication\" target=\"_blank\">Access Token</a>. Log in to the Microsoft account to add an access token.": "",
"Middleware": "",
"Migrate applications to the new pool": "",
"Min Poll": "",
"Minimum": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/br.json
Original file line number Diff line number Diff line change
Expand Up @@ -2265,12 +2265,14 @@
"Metadata (Special) Small Block Size": "",
"Metadata VDEVs": "",
"Method": "",
"Method Call": "",
"Method of snapshot transfer:<ul> <li><i>SSH</i> is supported by most systems. It requires a previously created connection in <b>System > SSH Connections</b>.</li> <li><i>SSH+NETCAT</i> uses SSH to establish a connection to the destination system, then uses <a href=\"https://github.com/truenas/py-libzfs\" target=\"_blank\">py-libzfs</a> to send an unencrypted data stream for higher transfer speeds. This only works when replicating to a TrueNAS, or other system with <i>py-libzfs</i> installed.</li> <li><i>LOCAL</i> efficiently replicates snapshots to another dataset on the same system without using the network.</li> <li><i>LEGACY</i> uses the legacy replication engine from FreeNAS 11.2 and earlier.</li></ul>": "",
"Metrics": "",
"MiB. Units smaller than MiB are not allowed.": "",
"Microsoft Azure": "",
"Microsoft OneDrive": "",
"Microsoft Onedrive <a href=\"https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/authentication\" target=\"_blank\">Access Token</a>. Log in to the Microsoft account to add an access token.": "",
"Middleware": "",
"Migrate applications to the new pool": "",
"Min Poll": "",
"Minimum": "",
Expand Down
Loading

0 comments on commit ac679db

Please sign in to comment.