Skip to content

Commit

Permalink
chore: stop using deprecated method (#6764)
Browse files Browse the repository at this point in the history
`storeUserEvent` from event-service was deprecated. We stop using it and
remove the method completely
  • Loading branch information
gastonfournier committed Apr 3, 2024
1 parent 994bc5b commit 0a0f5a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 64 deletions.
20 changes: 0 additions & 20 deletions src/lib/features/events/event-service.test.ts

This file was deleted.

41 changes: 1 addition & 40 deletions src/lib/features/events/event-service.ts
Expand Up @@ -2,15 +2,11 @@ import type { IUnleashConfig } from '../../types/option';
import type { IFeatureTagStore, IUnleashStores } from '../../types/stores';
import type { Logger } from '../../logger';
import type { IEventStore } from '../../types/stores/event-store';
import type { IBaseEvent, IEventList, IUserEvent } from '../../types/events';
import type { IBaseEvent, IEventList } from '../../types/events';
import type { SearchEventsSchema } from '../../openapi/spec/search-events-schema';
import type EventEmitter from 'events';
import type { IApiUser, ITag, IUser } from '../../types';
import { ApiTokenType } from '../../types/models/api-token';
import {
extractUserIdFromUser,
extractUsernameFromUser,
} from '../../util/extract-user';
import { EVENTS_CREATED_BY_PROCESSED } from '../../metric-events';

export default class EventService {
Expand Down Expand Up @@ -94,16 +90,6 @@ export default class EventService {
return (user as IApiUser)?.type === ApiTokenType.ADMIN;
}

getUserDetails(user: IUser | IApiUser): {
createdBy: string;
createdByUserId: number;
} {
return {
createdBy: extractUsernameFromUser(user),
createdByUserId: extractUserIdFromUser(user),
};
}

async storeEvent(event: IBaseEvent): Promise<void> {
return this.storeEvents([event]);
}
Expand All @@ -116,31 +102,6 @@ export default class EventService {
return this.eventStore.batchStore(enhancedEvents);
}

/**
* @deprecated this is tech debt, we should migrate to storeEvents and send the right
* userId and username parameters in IBaseEvent
*/
async storeUserEvent(event: IUserEvent): Promise<void> {
return this.storeUserEvents([event]);
}

/**
* @deprecated this is tech debt, we should migrate to storeEvents and send the right
* userId and username parameters in IBaseEvent
*/
async storeUserEvents(events: IUserEvent[]): Promise<void> {
let enhancedEvents = events.map(({ byUser, ...event }) => {
return {
...event,
...this.getUserDetails(byUser),
};
});
for (const enhancer of [this.enhanceEventsWithTags.bind(this)]) {
enhancedEvents = await enhancer(enhancedEvents);
}
return this.eventStore.batchStore(enhancedEvents);
}

async setEventCreatedByUserId(): Promise<void> {
const updated = await this.eventStore.setCreatedByUserId(100);
if (updated !== undefined) {
Expand Down
11 changes: 7 additions & 4 deletions src/lib/services/pat-service.ts
Expand Up @@ -10,6 +10,7 @@ import { OperationDeniedError } from '../error/operation-denied-error';
import { PAT_LIMIT } from '../util/constants';
import type EventService from '../features/events/event-service';
import type { CreatePatSchema, PatSchema } from '../openapi';
import { extractUserIdFromUser, extractUsernameFromUser } from '../util';

export default class PatService {
private config: IUnleashConfig;
Expand Down Expand Up @@ -41,9 +42,10 @@ export default class PatService {
const secret = this.generateSecretKey();
const newPat = await this.patStore.create(pat, secret, forUserId);

await this.eventService.storeUserEvent({
await this.eventService.storeEvent({
type: PAT_CREATED,
byUser,
createdBy: extractUsernameFromUser(byUser),
createdByUserId: extractUserIdFromUser(byUser),
data: { ...pat, secret: '***' },
});

Expand All @@ -61,9 +63,10 @@ export default class PatService {
): Promise<void> {
const pat = await this.patStore.get(id);

await this.eventService.storeUserEvent({
await this.eventService.storeEvent({
type: PAT_DELETED,
byUser,
createdBy: extractUsernameFromUser(byUser),
createdByUserId: extractUserIdFromUser(byUser),
data: { ...pat, secret: '***' },
});

Expand Down

0 comments on commit 0a0f5a7

Please sign in to comment.