This commit is contained in:
shamoon
2024-04-13 23:59:39 -07:00
parent aeaa0d18e2
commit e25f361907
13 changed files with 34 additions and 33 deletions

View File

@@ -119,7 +119,7 @@ import { NgxFilesizeModule } from 'ngx-filesize'
import { RotateConfirmDialogComponent } from './components/common/confirm-dialog/rotate-confirm-dialog/rotate-confirm-dialog.component'
import { MergeConfirmDialogComponent } from './components/common/confirm-dialog/merge-confirm-dialog/merge-confirm-dialog.component'
import { SplitConfirmDialogComponent } from './components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component'
import { AuditLogComponent } from './components/audit-log/audit-log.component'
import { DocumentHistoryComponent } from './components/document-history/document-history.component'
import {
airplane,
archive,
@@ -473,7 +473,7 @@ function initializeApp(settings: SettingsService) {
RotateConfirmDialogComponent,
MergeConfirmDialogComponent,
SplitConfirmDialogComponent,
AuditLogComponent,
DocumentHistoryComponent,
],
imports: [
BrowserModule,

View File

@@ -285,12 +285,12 @@
</li>
}
@if (auditlogEnabled) {
@if (historyEnabled) {
<li [ngbNavItem]="DocumentDetailNavIDs.History">
<a ngbNavLink i18n>History</a>
<ng-template ngbNavContent>
<div class="mb-3">
<pngx-audit-log [documentId]="documentId"></pngx-audit-log>
<pngx-document-history [documentId]="documentId"></pngx-document-history>
</div>
</ng-template>
</li>

View File

@@ -903,12 +903,13 @@ export class DocumentDetailComponent
)
}
get auditlogEnabled(): boolean {
get historyEnabled(): boolean {
return (
this.settings.get(SETTINGS_KEYS.AUDITLOG_ENABLED) &&
this.userIsOwner &&
this.permissionsService.currentUserCan(
PermissionAction.View,
PermissionType.AuditLogEntry
PermissionType.History
)
)
}

View File

@@ -1,6 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { AuditLogComponent } from './audit-log.component'
import { DocumentHistoryComponent } from './document-history.component'
import { DocumentService } from 'src/app/services/rest/document.service'
import { of } from 'rxjs'
import { AuditLogAction } from 'src/app/data/auditlog-entry'
@@ -10,14 +10,14 @@ import { DatePipe } from '@angular/common'
import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
describe('AuditLogComponent', () => {
let component: AuditLogComponent
let fixture: ComponentFixture<AuditLogComponent>
describe('DocumentHistoryComponent', () => {
let component: DocumentHistoryComponent
let fixture: ComponentFixture<DocumentHistoryComponent>
let documentService: DocumentService
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AuditLogComponent, CustomDatePipe],
declarations: [DocumentHistoryComponent, CustomDatePipe],
providers: [DatePipe],
imports: [
HttpClientTestingModule,
@@ -26,14 +26,14 @@ describe('AuditLogComponent', () => {
],
}).compileComponents()
fixture = TestBed.createComponent(AuditLogComponent)
fixture = TestBed.createComponent(DocumentHistoryComponent)
documentService = TestBed.inject(DocumentService)
component = fixture.componentInstance
})
it('should get audit log entries on init', () => {
const getAuditLogSpy = jest.spyOn(documentService, 'getAuditLog')
getAuditLogSpy.mockReturnValue(
const getHistorySpy = jest.spyOn(documentService, 'getHistory')
getHistorySpy.mockReturnValue(
of([
{
id: 1,
@@ -52,6 +52,6 @@ describe('AuditLogComponent', () => {
)
component.documentId = 1
fixture.detectChanges()
expect(getAuditLogSpy).toHaveBeenCalledWith(1)
expect(getHistorySpy).toHaveBeenCalledWith(1)
})
})

View File

@@ -3,11 +3,11 @@ import { AuditLogAction, AuditLogEntry } from 'src/app/data/auditlog-entry'
import { DocumentService } from 'src/app/services/rest/document.service'
@Component({
selector: 'pngx-audit-log',
templateUrl: './audit-log.component.html',
styleUrl: './audit-log.component.scss',
selector: 'pngx-document-history',
templateUrl: './document-history.component.html',
styleUrl: './document-history.component.scss',
})
export class AuditLogComponent implements OnInit {
export class DocumentHistoryComponent implements OnInit {
public AuditLogAction = AuditLogAction
private _documentId: number
@@ -26,7 +26,7 @@ export class AuditLogComponent implements OnInit {
if (this._documentId) {
this.loading = true
this.documentService
.getAuditLog(this._documentId)
.getHistory(this._documentId)
.subscribe((auditLogEntries) => {
this.entries = auditLogEntries
this.loading = false

View File

@@ -19,7 +19,7 @@ export enum PermissionType {
PaperlessTask = '%s_paperlesstask',
AppConfig = '%s_applicationconfiguration',
UISettings = '%s_uisettings',
AuditLogEntry = '%s_logentry',
History = '%s_logentry',
Note = '%s_note',
MailAccount = '%s_mailaccount',
MailRule = '%s_mailrule',

View File

@@ -268,9 +268,9 @@ describe(`DocumentService`, () => {
})
it('should call appropriate api endpoint for getting audit log', () => {
subscription = service.getAuditLog(documents[0].id).subscribe()
subscription = service.getHistory(documents[0].id).subscribe()
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/${documents[0].id}/audit/`
`${environment.apiBaseUrl}${endpoint}/${documents[0].id}/history/`
)
})
})

View File

@@ -223,8 +223,8 @@ export class DocumentService extends AbstractPaperlessService<Document> {
)
}
getAuditLog(id: number): Observable<AuditLogEntry[]> {
return this.http.get<AuditLogEntry[]>(this.getResourceUrl(id, 'audit'))
getHistory(id: number): Observable<AuditLogEntry[]> {
return this.http.get<AuditLogEntry[]>(this.getResourceUrl(id, 'history'))
}
bulkDownload(