From e25f361907fc861a214d1ae8ff5b5756cbfb826e Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:59:39 -0700 Subject: [PATCH] Rename --- docs/api.md | 2 +- src-ui/src/app/app.module.ts | 4 ++-- .../document-detail.component.html | 4 ++-- .../document-detail.component.ts | 5 +++-- .../document-history.component.html} | 0 .../document-history.component.scss} | 0 .../document-history.component.spec.ts} | 18 +++++++++--------- .../document-history.component.ts} | 10 +++++----- src-ui/src/app/services/permissions.service.ts | 2 +- .../app/services/rest/document.service.spec.ts | 4 ++-- .../src/app/services/rest/document.service.ts | 4 ++-- src/documents/tests/test_api_documents.py | 12 ++++++------ src/documents/views.py | 2 +- 13 files changed, 34 insertions(+), 33 deletions(-) rename src-ui/src/app/components/{audit-log/audit-log.component.html => document-history/document-history.component.html} (100%) rename src-ui/src/app/components/{audit-log/audit-log.component.scss => document-history/document-history.component.scss} (100%) rename src-ui/src/app/components/{audit-log/audit-log.component.spec.ts => document-history/document-history.component.spec.ts} (73%) rename src-ui/src/app/components/{audit-log/audit-log.component.ts => document-history/document-history.component.ts} (76%) diff --git a/docs/api.md b/docs/api.md index 5d459cfb6..6a275be61 100644 --- a/docs/api.md +++ b/docs/api.md @@ -140,7 +140,7 @@ document. Paperless only reports PDF metadata at this point. - `/api/documents//notes/`: Retrieve notes for a document. - `/api/documents//share_links/`: Retrieve share links for a document. -- `/api/documents//audit/`: Retrieve history of changes for a document. +- `/api/documents//history/`: Retrieve history of changes for a document. ## Authorization diff --git a/src-ui/src/app/app.module.ts b/src-ui/src/app/app.module.ts index b3f8a0055..d7263de82 100644 --- a/src-ui/src/app/app.module.ts +++ b/src-ui/src/app/app.module.ts @@ -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, diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html index f4a5e44d3..6e2d47e2b 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.html +++ b/src-ui/src/app/components/document-detail/document-detail.component.html @@ -285,12 +285,12 @@ } - @if (auditlogEnabled) { + @if (historyEnabled) {
  • History
    - +
  • diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index 0f391683a..db0d16f5a 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -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 ) ) } diff --git a/src-ui/src/app/components/audit-log/audit-log.component.html b/src-ui/src/app/components/document-history/document-history.component.html similarity index 100% rename from src-ui/src/app/components/audit-log/audit-log.component.html rename to src-ui/src/app/components/document-history/document-history.component.html diff --git a/src-ui/src/app/components/audit-log/audit-log.component.scss b/src-ui/src/app/components/document-history/document-history.component.scss similarity index 100% rename from src-ui/src/app/components/audit-log/audit-log.component.scss rename to src-ui/src/app/components/document-history/document-history.component.scss diff --git a/src-ui/src/app/components/audit-log/audit-log.component.spec.ts b/src-ui/src/app/components/document-history/document-history.component.spec.ts similarity index 73% rename from src-ui/src/app/components/audit-log/audit-log.component.spec.ts rename to src-ui/src/app/components/document-history/document-history.component.spec.ts index 2478ecc4a..3a26c8a9b 100644 --- a/src-ui/src/app/components/audit-log/audit-log.component.spec.ts +++ b/src-ui/src/app/components/document-history/document-history.component.spec.ts @@ -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 +describe('DocumentHistoryComponent', () => { + let component: DocumentHistoryComponent + let fixture: ComponentFixture 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) }) }) diff --git a/src-ui/src/app/components/audit-log/audit-log.component.ts b/src-ui/src/app/components/document-history/document-history.component.ts similarity index 76% rename from src-ui/src/app/components/audit-log/audit-log.component.ts rename to src-ui/src/app/components/document-history/document-history.component.ts index eabeabdf4..7870c1714 100644 --- a/src-ui/src/app/components/audit-log/audit-log.component.ts +++ b/src-ui/src/app/components/document-history/document-history.component.ts @@ -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 diff --git a/src-ui/src/app/services/permissions.service.ts b/src-ui/src/app/services/permissions.service.ts index 56ed6fad8..c80bc763d 100644 --- a/src-ui/src/app/services/permissions.service.ts +++ b/src-ui/src/app/services/permissions.service.ts @@ -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', diff --git a/src-ui/src/app/services/rest/document.service.spec.ts b/src-ui/src/app/services/rest/document.service.spec.ts index c7c07d307..c379ba010 100644 --- a/src-ui/src/app/services/rest/document.service.spec.ts +++ b/src-ui/src/app/services/rest/document.service.spec.ts @@ -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/` ) }) }) diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index 0233a81f4..76e9124e0 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -223,8 +223,8 @@ export class DocumentService extends AbstractPaperlessService { ) } - getAuditLog(id: number): Observable { - return this.http.get(this.getResourceUrl(id, 'audit')) + getHistory(id: number): Observable { + return this.http.get(this.getResourceUrl(id, 'history')) } bulkDownload( diff --git a/src/documents/tests/test_api_documents.py b/src/documents/tests/test_api_documents.py index f0a682cfa..de95a71bf 100644 --- a/src/documents/tests/test_api_documents.py +++ b/src/documents/tests/test_api_documents.py @@ -316,7 +316,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase): response = self.client.get(f"/api/documents/{doc.pk}/thumb/") self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - def test_document_audit_action(self): + def test_document_history_action(self): """ GIVEN: - Document @@ -337,7 +337,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase): format="json", ) - response = self.client.get(f"/api/documents/{doc.pk}/audit/") + response = self.client.get(f"/api/documents/{doc.pk}/history/") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2) self.assertEqual(response.data[0]["actor"]["id"], self.user.id) @@ -347,7 +347,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase): {"title": ["First title", "New title"]}, ) - def test_document_audit_action_w_custom_fields(self): + def test_document_history_action_w_custom_fields(self): """ GIVEN: - Document with custom fields @@ -379,7 +379,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase): format="json", ) - response = self.client.get(f"/api/documents/{doc.pk}/audit/") + response = self.client.get(f"/api/documents/{doc.pk}/history/") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data[1]["actor"]["id"], self.user.id) self.assertEqual(response.data[1]["action"], "create") @@ -395,7 +395,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase): ) @override_settings(AUDIT_LOG_ENABLED=False) - def test_document_audit_action_disabled(self): + def test_document_history_action_disabled(self): """ GIVEN: - Audit log is disabled @@ -417,7 +417,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase): format="json", ) - response = self.client.get(f"/api/documents/{doc.pk}/audit/") + response = self.client.get(f"/api/documents/{doc.pk}/history/") self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) def test_document_filters(self): diff --git a/src/documents/views.py b/src/documents/views.py index 401dc2acc..1890d0479 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -732,7 +732,7 @@ class DocumentViewSet( return Response(links) @action(methods=["get"], detail=True, name="Audit Trail") - def audit(self, request, pk=None): + def history(self, request, pk=None): if not settings.AUDIT_LOG_ENABLED: return HttpResponseBadRequest("Audit log is disabled") try: