mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-04 23:45:07 +00:00
fix: ignore 0 retention on event search (#5614)
* fix: filter all search events if retention * test(e2e): test event api filter
This commit is contained in:
parent
5c8748d769
commit
29c0adb650
@ -5,6 +5,7 @@
|
||||
(click)="showFilter = !showFilter"
|
||||
class="cnsl-action-button"
|
||||
#triggereventfilter="cdkOverlayOrigin"
|
||||
data-e2e="open-filter-button"
|
||||
>
|
||||
<i class="las la-filter no-margin"></i>
|
||||
<span>{{ 'ACTIONS.FILTER' | translate }}</span>
|
||||
@ -29,7 +30,7 @@
|
||||
<div class="filter-events-top">
|
||||
<button mat-stroked-button type="button" (click)="reset()">{{ 'ACTIONS.RESET' | translate }}</button>
|
||||
<span class="filter-middle">{{ 'FILTER.TITLE' | translate }}</span>
|
||||
<button mat-raised-button color="primary" type="button" (click)="finish()">
|
||||
<button mat-raised-button color="primary" type="button" (click)="finish()" data-e2e="filter-finish-button">
|
||||
{{ 'ACTIONS.FINISH' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
@ -96,6 +97,7 @@
|
||||
name="eventTypesFilterSet"
|
||||
class="cb"
|
||||
formControlName="eventTypesFilterSet"
|
||||
data-e2e="event-type-filter-checkbox"
|
||||
>{{ 'IAM.EVENTS.FILTERS.TYPE.CHECKBOX' | translate }}
|
||||
</mat-checkbox>
|
||||
</div>
|
||||
|
@ -91,7 +91,7 @@
|
||||
|
||||
<ng-container matColumnDef="type">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ 'IAM.EVENTS.TYPE' | translate }}</th>
|
||||
<td mat-cell *matCellDef="let event">
|
||||
<td mat-cell *matCellDef="let event" data-e2e="event-type-cell">
|
||||
<ng-container *ngIf="event | toobject as event">
|
||||
<span *ngIf="event.type?.localized?.localizedMessage">{{ event.type.localized.localizedMessage }}</span>
|
||||
</ng-container>
|
||||
|
18
e2e/cypress/e2e/events/events.cy.ts
Normal file
18
e2e/cypress/e2e/events/events.cy.ts
Normal file
@ -0,0 +1,18 @@
|
||||
describe('events', () => {
|
||||
beforeEach(() => {
|
||||
cy.context().as('ctx');
|
||||
});
|
||||
|
||||
it('events can be filtered', () => {
|
||||
const eventTypeEnglish = 'Instance added';
|
||||
cy.visit('/events');
|
||||
cy.get('[data-e2e="event-type-cell"]').should('have.length', 20);
|
||||
cy.get('[data-e2e="open-filter-button"]').click();
|
||||
cy.get('[data-e2e="event-type-filter-checkbox"]').click();
|
||||
cy.get('#mat-select-value-1').click();
|
||||
cy.contains('mat-option', eventTypeEnglish).click();
|
||||
cy.get('body').click();
|
||||
cy.get('[data-e2e="filter-finish-button"]').click();
|
||||
cy.contains('[data-e2e="event-type-cell"]', eventTypeEnglish).should('have.length.at.least', 1);
|
||||
});
|
||||
});
|
@ -34,18 +34,25 @@ func (q *Queries) SearchEvents(ctx context.Context, query *eventstore.SearchQuer
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if auditLogRetention != 0 {
|
||||
events = filterAuditLogRetention(ctx, events, auditLogRetention)
|
||||
}
|
||||
|
||||
return q.convertEvents(ctx, events), nil
|
||||
}
|
||||
|
||||
func filterAuditLogRetention(ctx context.Context, events []eventstore.Event, auditLogRetention time.Duration) []eventstore.Event {
|
||||
callTime := call.FromContext(ctx)
|
||||
if callTime.IsZero() {
|
||||
callTime = time.Now()
|
||||
}
|
||||
for i, event := range events {
|
||||
if event.CreationDate().Before(callTime.Add(-auditLogRetention)) {
|
||||
events = events[:i]
|
||||
break
|
||||
filteredEvents := make([]eventstore.Event, 0, len(events))
|
||||
for _, event := range events {
|
||||
if event.CreationDate().After(callTime.Add(-auditLogRetention)) {
|
||||
filteredEvents = append(filteredEvents, event)
|
||||
}
|
||||
}
|
||||
|
||||
return q.convertEvents(ctx, events, auditLogRetention), nil
|
||||
return filteredEvents
|
||||
}
|
||||
|
||||
func (q *Queries) SearchEventTypes(ctx context.Context) []string {
|
||||
@ -56,7 +63,7 @@ func (q *Queries) SearchAggregateTypes(ctx context.Context) []string {
|
||||
return q.eventstore.AggregateTypes()
|
||||
}
|
||||
|
||||
func (q *Queries) convertEvents(ctx context.Context, events []eventstore.Event, auditLogRetention time.Duration) []*Event {
|
||||
func (q *Queries) convertEvents(ctx context.Context, events []eventstore.Event) []*Event {
|
||||
result := make([]*Event, len(events))
|
||||
users := make(map[string]*EventEditor)
|
||||
for i, event := range events {
|
||||
|
Loading…
Reference in New Issue
Block a user