-
Notifications
You must be signed in to change notification settings - Fork 497
Angular: Audit Trail feature #4576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FrancescoMolinaro
wants to merge
24
commits into
DSpace:main
Choose a base branch
from
4Science:task/main/DURACOM-317
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a9d269c
[DURACOM-317] first part implementation Audit feature
steph-ieffam 78de62b
[DURACOM-317] fix menu, eperson resolution, add config for overview, …
FrancescoMolinaro 8d970a1
[DURACOM-317] refactor to flow control, remove observables call from …
FrancescoMolinaro 687edb1
[DURACOM-317] add missing breadcrumbs, fix tests, add missing labels
FrancescoMolinaro 54c396c
[DURACOM-317] fix accessibility issues, clean up, add e2e test for ov…
FrancescoMolinaro bfc6de5
[DURACOM-317] clean up, add expandable section, refactor to presentat…
FrancescoMolinaro 6c2c2d6
[DURACOM-317] clean up, add tests
FrancescoMolinaro 65b1dfa
Merge remote-tracking branch 'gitHub/main' into task/main/DURACOM-317
FrancescoMolinaro 4bb3b85
[DURACOM-317] fix lint
FrancescoMolinaro 16b47c2
[DURACOM-317] fix expected timestamp
FrancescoMolinaro 93623f7
Merge remote-tracking branch 'gitHub/main' into task/main/DURACOM-317
FrancescoMolinaro 9f72031
[DURACOM-317] fix tests
FrancescoMolinaro c6745bd
[DURACOM-317] correct text fix
FrancescoMolinaro a7b8519
[DURACOM-317] fix/improve audit view
steph-ieffam fe25c55
[DURACOM-317] audit view improvement
steph-ieffam a1b602e
[DURACOM-317] refactor, fix other object reference
FrancescoMolinaro 15e3316
Merge remote-tracking branch 'gitHub/main' into task/main/DURACOM-317
FrancescoMolinaro 63ed343
[DURACOM-317] fix conflicts, adapt paths
FrancescoMolinaro 851c63e
Merge remote-tracking branch 'gitHub/main' into task/main/DURACOM-317
FrancescoMolinaro 8c5bb1d
[DURACOM-317] refactor, improve e2e, adapt route structure
FrancescoMolinaro 39f8864
[DURACOM-317] fix comm/coll routes for audit
FrancescoMolinaro b20a4d6
[DURACOM-317] fix mock
FrancescoMolinaro 48f4662
[DURACOM-317] fix table links, fix tests
FrancescoMolinaro f919f1d
[DURACOM-317] add description, adapt table header, fix menu visibility
FrancescoMolinaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { testA11y } from 'cypress/support/utils'; | ||
|
|
||
| describe('Audit Overview Page', () => { | ||
| beforeEach(() => { | ||
| // Must login as an Admin to see the page | ||
| cy.visit('/auditlogs'); | ||
| cy.loginViaForm(Cypress.env('DSPACE_TEST_ADMIN_USER'), Cypress.env('DSPACE_TEST_ADMIN_PASSWORD')); | ||
| }); | ||
|
|
||
| it('page structure should be correct and should pass accessibility tests', () => { | ||
| // Page must first be visible | ||
| cy.get('ds-audit-overview').should('be.visible'); | ||
| // Check for presence of main container and title | ||
| cy.get('.container').should('exist'); | ||
| cy.get('[data-test="audit-title"]').should('be.visible'); | ||
| cy.get('body').then($body => { | ||
| const hasTable = $body.find('[data-test="audit-table"]').length > 0; | ||
| const hasEmpty = $body.find('[data-test="audit-empty"]').length > 0; | ||
| // At least one present and not both | ||
| expect(hasTable || hasEmpty).to.equal(true); | ||
| expect(!(hasTable && hasEmpty)).to.equal(true); | ||
| }); | ||
| // Analyze <ds-audit-overview> for accessibility issues | ||
| testA11y('ds-audit-overview'); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { Route } from '@angular/router'; | ||
|
|
||
| import { authenticatedGuard } from '../core/auth/authenticated.guard'; | ||
| import { i18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver'; | ||
| import { AuditOverviewComponent } from './overview/audit-overview.component'; | ||
|
|
||
| export const ROUTES: Route[] = [ | ||
| { | ||
| path: '', | ||
| canActivate: [authenticatedGuard], | ||
| children: [ | ||
| { | ||
| path: '', | ||
| component: AuditOverviewComponent, | ||
| data: { title: 'audit.overview.title', breadcrumbKey: 'audit.overview' }, | ||
| resolve: { breadcrumb: i18nBreadcrumbResolver }, | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| ]; |
157 changes: 157 additions & 0 deletions
157
src/app/audit-page/audit-table/audit-table.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| @if (audits.totalElements === 0) { | ||
| <div>{{ 'audit.data.not-found' | translate }}</div> | ||
| } @else { | ||
| <ds-pagination | ||
| [paginationOptions]="pageConfig" | ||
| [collectionSize]="audits?.totalElements" | ||
| [hideGear]="true" | ||
| [hidePagerWhenSinglePage]="true"> | ||
| <div class="table-responsive"> | ||
| <table class="table table-striped table-hover"> | ||
| <thead> | ||
| <tr> | ||
| <th>{{ 'audit.overview.table.entityType' | translate }}</th> | ||
| <th>{{ 'audit.overview.table.eperson' | translate }}</th> | ||
| <th>{{ 'audit.overview.table.timestamp' | translate }}</th> | ||
| @if (isOverviewPage) { | ||
| <th>{{ 'audit.overview.table.subjectUUID' | translate }}</th> | ||
| <th>{{ 'audit.overview.table.subjectType' | translate }}</th> | ||
| <th>{{ 'audit.overview.table.objectUUID' | translate }}</th> | ||
| <th>{{ 'audit.overview.table.objectType' | translate }}</th> | ||
| } @else { | ||
| <th>{{ 'audit.overview.table.other' | translate }}</th> | ||
| } | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| @for (audit of audits?.page; track audit) { | ||
| <tr> | ||
| <td> | ||
| @if (audit.hasDetails) { | ||
| <div role="button" class="d-flex align-items-center" (click)="toggleCollapse(audit)"> | ||
| <div class="btn btn-link p-1 mr-1"> | ||
| @if (audit.isCollapsed) { | ||
| <i class="fas fa-caret-right"></i> | ||
| } @else { | ||
| <i class="fas fa-caret-down"></i> | ||
| } | ||
| </div> | ||
| <div> | ||
| {{ audit.eventType }} | ||
| </div> | ||
| </div> | ||
| } @else { | ||
| <div class="ml-4"> | ||
| {{ audit.eventType }} | ||
| </div> | ||
| } | ||
| </td> | ||
| <td>{{ audit.epersonName }}</td> | ||
| <td>{{ audit.timeStamp | date:dateFormat:'UTC' }}</td> | ||
| @if (isOverviewPage) { | ||
| <td> | ||
| @if (audit.objectUUID) { | ||
| <ng-container *ngVar="(getObjectRoute$(audit.objectUUID) | async) as objectRoute"> | ||
| @if (objectRoute !== ('/' + auditPath)) { | ||
| <a [routerLink]="[objectRoute]">{{audit.objectUUID}}</a> | ||
| } @else { | ||
| <span>{{audit.objectUUID}}</span> | ||
| } | ||
| </ng-container> | ||
| } | ||
| </td> | ||
| <td>{{ audit.objectType }}</td> | ||
| <td> | ||
| @if (audit.subjectUUID) { | ||
| <ng-container *ngVar="(getObjectRoute$(audit.subjectUUID) | async) as subjectRoute"> | ||
| @if (subjectRoute !== ('/' + auditPath)) { | ||
| <a [routerLink]="[subjectRoute]">{{audit.subjectUUID}}</a> | ||
| } @else { | ||
| <span>{{audit.subjectUUID}}</span> | ||
| } | ||
| </ng-container> | ||
| } | ||
| </td> | ||
| <td>{{ audit.subjectType }}</td> | ||
| } @else { | ||
| <td> | ||
| <span> | ||
| @if (audit.otherAuditObject; as dso) { | ||
| {{ getDsoName(dso) }} <em>({{ dso.type }})</em> | ||
| } @else { | ||
| {{ dataNotAvailable }} | ||
| } | ||
| </span> | ||
| </td> | ||
| } | ||
| </tr> | ||
| @if (audit.hasDetails) { | ||
| <tr [(ngbCollapse)]="audit.isCollapsed" [id]="audit.id" [ngClass]="{'border-top-0': !audit.isCollapsed}" class="w-100 nested-row"> | ||
| @if (isOverviewPage) { | ||
| <td colspan="7" class="border-top-0"> | ||
| <ng-container *ngTemplateOutlet="auditInto; context: { audit }"></ng-container> | ||
| </td> | ||
| } @else { | ||
| <td colspan="4" class="border-top-0"> | ||
| <ng-container *ngTemplateOutlet="auditInto; context: { audit }"></ng-container> | ||
| </td> | ||
| } | ||
| </tr> | ||
| } | ||
| } | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| </ds-pagination> | ||
| } | ||
|
|
||
| <ng-template #auditInto let-audit=audit> | ||
| <div class="w-100"> | ||
| <div class="d-flex flex-column mw-100 w-100"> | ||
| @if (audit.metadataField) { | ||
| <div class="d-flex mb-1"> | ||
| <small class="font-weight-bold me-2" >{{"audit.detail.metadata.field" | translate}}</small> | ||
| <small>{{ audit.metadataField | dsStringReplace: "_":"." }}</small> | ||
| </div> | ||
| } | ||
| @if (audit.value) { | ||
| <div class="d-flex mb-1"> | ||
| <small class="font-weight-bold me-2">{{"audit.detail.metadata.value" | translate}}</small> | ||
| <small class="content dont-break-out preserve-line-breaks"> | ||
| {{ audit.value }} | ||
| </small> | ||
| </div> | ||
| } | ||
| @if (audit.authority) { | ||
| <div class="d-flex mb-1"> | ||
| <small class="font-weight-bold me-2">{{"audit.detail.metadata.authority" | translate}}</small> | ||
| <small>{{ audit.authority }}</small> | ||
| </div> | ||
| } | ||
| @if (audit.confidence !== null) { | ||
| <div class="d-flex mb-1"> | ||
| <small class="font-weight-bold me-2">{{"audit.detail.metadata.confidence" | translate}}</small> | ||
| <small>{{ audit.confidence }}</small> | ||
| </div> | ||
| } | ||
| @if (audit.place !== null) { | ||
| <div class="d-flex mb-1"> | ||
| <small class="font-weight-bold me-2">{{"audit.detail.metadata.place" | translate}}</small> | ||
| <small>{{ audit.place }}</small> | ||
| </div> | ||
| } | ||
| @if (audit.action) { | ||
| <div class="d-flex mb-1"> | ||
| <small class="font-weight-bold me-2">{{"audit.detail.metadata.action" | translate}}</small> | ||
| <small>{{ audit.action }}</small> | ||
| </div> | ||
| } | ||
| @if (audit.checksum) { | ||
| <div class="d-flex"> | ||
| <small class="font-weight-bold me-2">{{"audit.detail.metadata.checksum" | translate}}</small> | ||
| <small>{{ audit.checksum }}</small> | ||
| </div> | ||
| } | ||
| </div> | ||
| </div> | ||
| </ng-template> |
103 changes: 103 additions & 0 deletions
103
src/app/audit-page/audit-table/audit-table.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import { NO_ERRORS_SCHEMA } from '@angular/core'; | ||
| import { | ||
| ComponentFixture, | ||
| TestBed, | ||
| waitForAsync, | ||
| } from '@angular/core/testing'; | ||
| import { By } from '@angular/platform-browser'; | ||
| import { RouterTestingModule } from '@angular/router/testing'; | ||
| import { Audit } from '@dspace/core/audit/model/audit.model'; | ||
| import { DSONameService } from '@dspace/core/breadcrumbs/dso-name.service'; | ||
| import { DSpaceObjectDataService } from '@dspace/core/data/dspace-object-data.service'; | ||
| import { PaginatedList } from '@dspace/core/data/paginated-list.model'; | ||
| import { DSpaceObject } from '@dspace/core/shared/dspace-object.model'; | ||
| import { AuditMock } from '@dspace/core/testing/audit.mock'; | ||
| import { DSONameServiceMock } from '@dspace/core/testing/dso-name.service.mock'; | ||
| import { createSuccessfulRemoteDataObject$ } from '@dspace/core/utilities/remote-data.utils'; | ||
| import { TranslateModule } from '@ngx-translate/core'; | ||
| import { PaginationComponent } from 'src/app/shared/pagination/pagination.component'; | ||
|
|
||
| import { AuditTableComponent } from './audit-table.component'; | ||
|
|
||
| describe('AuditTableComponent', () => { | ||
| let component: AuditTableComponent; | ||
| let fixture: ComponentFixture<AuditTableComponent>; | ||
|
|
||
| let audits = new PaginatedList() as PaginatedList<Audit>; | ||
| const dSpaceObjectDataService = jasmine.createSpyObj('DSpaceObjectDataService', { findById: createSuccessfulRemoteDataObject$(new DSpaceObject()) }); | ||
|
|
||
|
|
||
| beforeEach(waitForAsync(() => { | ||
| audits.page = [ AuditMock ]; | ||
| TestBed.configureTestingModule({ | ||
| imports: [ | ||
| TranslateModule.forRoot(), | ||
| RouterTestingModule.withRoutes([]), | ||
| AuditTableComponent, | ||
| PaginationComponent, | ||
| ], | ||
| providers: [ | ||
| { provide: DSONameService, useValue: new DSONameServiceMock() }, | ||
| { provide: DSpaceObjectDataService, useValue: dSpaceObjectDataService }, | ||
| ], | ||
| schemas: [NO_ERRORS_SCHEMA], | ||
| }) | ||
| .overrideComponent(AuditTableComponent, { | ||
| remove: { imports: [PaginationComponent] }, | ||
| }) | ||
| .compileComponents(); | ||
| })); | ||
|
|
||
| beforeEach(() => { | ||
| fixture = TestBed.createComponent(AuditTableComponent); | ||
| component = fixture.componentInstance; | ||
| component.audits = audits; | ||
| component.isOverviewPage = true; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| describe('table structure', () => { | ||
|
|
||
| it('should display the entityType in the first column', () => { | ||
| const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); | ||
| const el = rowElements[0].query(By.css('td:nth-child(1)')).nativeElement; | ||
| expect(el.textContent).toContain(audits.page[0].eventType); | ||
| }); | ||
|
|
||
| it('should display the eperson in the second column', () => { | ||
| const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); | ||
| const el = rowElements[0].query(By.css('td:nth-child(2)')).nativeElement; | ||
| expect(el.textContent).toContain(audits.page[0].epersonName); | ||
| }); | ||
|
|
||
| it('should display the timestamp in the third column', () => { | ||
| const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); | ||
| const el = rowElements[0].query(By.css('td:nth-child(3)')).nativeElement; | ||
| expect(el.textContent).toContain('2020-11-13 10:41:06'); | ||
| }); | ||
|
|
||
| it('should display the objectUUID in the fourth column', () => { | ||
| const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); | ||
| const el = rowElements[0].query(By.css('td:nth-child(4)')).nativeElement; | ||
| expect(el.textContent).toContain(audits.page[0].objectUUID); | ||
| }); | ||
|
|
||
| it('should display the objectType in the fifth column', () => { | ||
| const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); | ||
| const el = rowElements[0].query(By.css('td:nth-child(5)')).nativeElement; | ||
| expect(el.textContent).toContain(audits.page[0].objectType); | ||
| }); | ||
|
|
||
| it('should display the subjectUUID in the sixth column', () => { | ||
| const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); | ||
| const el = rowElements[0].query(By.css('td:nth-child(6)')).nativeElement; | ||
| expect(el.textContent).toContain(audits.page[0].subjectUUID); | ||
| }); | ||
|
|
||
| it('should display the subjectType in the seventh column', () => { | ||
| const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); | ||
| const el = rowElements[0].query(By.css('td:nth-child(7)')).nativeElement; | ||
| expect(el.textContent).toContain(audits.page[0].subjectType); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would appreciate it if we could add some more basic e2e tests for this page... even just check that the basic page structure exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still would be good to add more basic e2e tests here, testing that the basic page structure exists.