mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: on project delete with tokens put token deleted in audit log (#7675)
Use service with audit tracking instead of store directly.
This commit is contained in:
parent
5bec8ea508
commit
1f2d47bd91
@ -5,6 +5,7 @@ import { AccountStore } from '../../db/account-store';
|
||||
import EnvironmentStore from '../project-environments/environment-store';
|
||||
import {
|
||||
type AccessService,
|
||||
ApiTokenService,
|
||||
EventService,
|
||||
FavoritesService,
|
||||
GroupService,
|
||||
@ -39,8 +40,6 @@ import {
|
||||
createPrivateProjectChecker,
|
||||
} from '../private-project/createPrivateProjectChecker';
|
||||
import FakeFeatureTagStore from '../../../test/fixtures/fake-feature-tag-store';
|
||||
import FeatureTypeStore from '../../db/feature-type-store';
|
||||
import FakeFeatureTypeStore from '../../../test/fixtures/fake-feature-type-store';
|
||||
import { ProjectOwnersReadModel } from './project-owners-read-model';
|
||||
import { FakeProjectOwnersReadModel } from './fake-project-owners-read-model';
|
||||
import { FakeProjectFlagCreatorsReadModel } from './fake-project-flag-creators-read-model';
|
||||
@ -76,7 +75,6 @@ export const createProjectService = (
|
||||
eventBus,
|
||||
getLogger,
|
||||
);
|
||||
const featureTypeStore = new FeatureTypeStore(db, getLogger);
|
||||
const projectStatsStore = new ProjectStatsStore(db, eventBus, getLogger);
|
||||
const accessService: AccessService = createAccessService(db, config);
|
||||
const featureToggleService = createFeatureToggleService(db, config);
|
||||
@ -120,6 +118,12 @@ export const createProjectService = (
|
||||
|
||||
const privateProjectChecker = createPrivateProjectChecker(db, config);
|
||||
|
||||
const apiTokenService = new ApiTokenService(
|
||||
{ apiTokenStore, environmentStore },
|
||||
config,
|
||||
eventService,
|
||||
);
|
||||
|
||||
return new ProjectService(
|
||||
{
|
||||
projectStore,
|
||||
@ -127,12 +131,10 @@ export const createProjectService = (
|
||||
featureToggleStore,
|
||||
environmentStore,
|
||||
featureEnvironmentStore,
|
||||
featureTypeStore,
|
||||
accountStore,
|
||||
projectStatsStore,
|
||||
projectOwnersReadModel,
|
||||
projectFlagCreatorsReadModel,
|
||||
apiTokenStore,
|
||||
},
|
||||
config,
|
||||
accessService,
|
||||
@ -141,6 +143,7 @@ export const createProjectService = (
|
||||
favoriteService,
|
||||
eventService,
|
||||
privateProjectChecker,
|
||||
apiTokenService,
|
||||
);
|
||||
};
|
||||
|
||||
@ -157,7 +160,6 @@ export const createFakeProjectService = (
|
||||
const accountStore = new FakeAccountStore();
|
||||
const environmentStore = new FakeEnvironmentStore();
|
||||
const featureEnvironmentStore = new FakeFeatureEnvironmentStore();
|
||||
const featureTypeStore = new FakeFeatureTypeStore();
|
||||
const projectStatsStore = new FakeProjectStatsStore();
|
||||
const { accessService } = createFakeAccessService(config);
|
||||
const { featureToggleService } = createFakeFeatureToggleService(config);
|
||||
@ -187,6 +189,12 @@ export const createFakeProjectService = (
|
||||
|
||||
const privateProjectChecker = createFakePrivateProjectChecker();
|
||||
|
||||
const apiTokenService = new ApiTokenService(
|
||||
{ apiTokenStore, environmentStore },
|
||||
config,
|
||||
eventService,
|
||||
);
|
||||
|
||||
return new ProjectService(
|
||||
{
|
||||
projectStore,
|
||||
@ -196,10 +204,8 @@ export const createFakeProjectService = (
|
||||
featureToggleStore,
|
||||
environmentStore,
|
||||
featureEnvironmentStore,
|
||||
featureTypeStore,
|
||||
accountStore,
|
||||
projectStatsStore,
|
||||
apiTokenStore,
|
||||
},
|
||||
config,
|
||||
accessService,
|
||||
@ -208,5 +214,6 @@ export const createFakeProjectService = (
|
||||
favoriteService,
|
||||
eventService,
|
||||
privateProjectChecker,
|
||||
apiTokenService,
|
||||
);
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { IAuditUser, IFlagResolver, IUnleashConfig } from '../../types';
|
||||
import getLogger from '../../../test/fixtures/no-logger';
|
||||
import { createFakeProjectService } from './createProjectService';
|
||||
import type { IUser } from '../../types';
|
||||
import { createTestConfig } from '../../../test/config/test-config';
|
||||
|
||||
const alwaysOnFlagResolver = {
|
||||
isEnabled() {
|
||||
@ -12,7 +12,7 @@ const alwaysOnFlagResolver = {
|
||||
test('Should not allow to exceed project limit', async () => {
|
||||
const LIMIT = 1;
|
||||
const projectService = createFakeProjectService({
|
||||
getLogger,
|
||||
...createTestConfig(),
|
||||
flagResolver: alwaysOnFlagResolver,
|
||||
resourceLimits: {
|
||||
projects: LIMIT,
|
||||
|
@ -22,7 +22,6 @@ import {
|
||||
type IFeatureEnvironmentStore,
|
||||
type IFeatureNaming,
|
||||
type IFeatureToggleStore,
|
||||
type IFeatureTypeStore,
|
||||
type IFlagResolver,
|
||||
type IProject,
|
||||
type IProjectApplications,
|
||||
@ -53,7 +52,6 @@ import {
|
||||
type ProjectCreated,
|
||||
type IProjectOwnersReadModel,
|
||||
ADMIN,
|
||||
type IApiTokenStore,
|
||||
} from '../../types';
|
||||
import type {
|
||||
IProjectAccessModel,
|
||||
@ -86,6 +84,7 @@ import type {
|
||||
import type { IProjectFlagCreatorsReadModel } from './project-flag-creators-read-model.type';
|
||||
import { throwExceedsLimitError } from '../../error/exceeds-limit-error';
|
||||
import type EventEmitter from 'events';
|
||||
import type { ApiTokenService } from '../../services/api-token-service';
|
||||
|
||||
type Days = number;
|
||||
type Count = number;
|
||||
@ -132,8 +131,6 @@ export default class ProjectService {
|
||||
|
||||
private featureEnvironmentStore: IFeatureEnvironmentStore;
|
||||
|
||||
private featureTypeStore: IFeatureTypeStore;
|
||||
|
||||
private environmentStore: IEnvironmentStore;
|
||||
|
||||
private groupService: GroupService;
|
||||
@ -146,7 +143,7 @@ export default class ProjectService {
|
||||
|
||||
private accountStore: IAccountStore;
|
||||
|
||||
private apiTokenStore: IApiTokenStore;
|
||||
private apiTokenService: ApiTokenService;
|
||||
|
||||
private favoritesService: FavoritesService;
|
||||
|
||||
@ -171,10 +168,8 @@ export default class ProjectService {
|
||||
featureToggleStore,
|
||||
environmentStore,
|
||||
featureEnvironmentStore,
|
||||
featureTypeStore,
|
||||
accountStore,
|
||||
projectStatsStore,
|
||||
apiTokenStore,
|
||||
}: Pick<
|
||||
IUnleashStores,
|
||||
| 'projectStore'
|
||||
@ -186,8 +181,6 @@ export default class ProjectService {
|
||||
| 'featureEnvironmentStore'
|
||||
| 'accountStore'
|
||||
| 'projectStatsStore'
|
||||
| 'featureTypeStore'
|
||||
| 'apiTokenStore'
|
||||
>,
|
||||
config: IUnleashConfig,
|
||||
accessService: AccessService,
|
||||
@ -196,6 +189,7 @@ export default class ProjectService {
|
||||
favoriteService: FavoritesService,
|
||||
eventService: EventService,
|
||||
privateProjectChecker: IPrivateProjectChecker,
|
||||
apiTokenService: ApiTokenService,
|
||||
) {
|
||||
this.projectStore = projectStore;
|
||||
this.projectOwnersReadModel = projectOwnersReadModel;
|
||||
@ -205,8 +199,7 @@ export default class ProjectService {
|
||||
this.accessService = accessService;
|
||||
this.eventStore = eventStore;
|
||||
this.featureToggleStore = featureToggleStore;
|
||||
this.featureTypeStore = featureTypeStore;
|
||||
this.apiTokenStore = apiTokenStore;
|
||||
this.apiTokenService = apiTokenService;
|
||||
this.featureToggleService = featureToggleService;
|
||||
this.favoritesService = favoriteService;
|
||||
this.privateProjectChecker = privateProjectChecker;
|
||||
@ -565,14 +558,14 @@ export default class ProjectService {
|
||||
archived: true,
|
||||
});
|
||||
|
||||
this.featureToggleService.deleteFeatures(
|
||||
await this.featureToggleService.deleteFeatures(
|
||||
archivedFlags.map((flag) => flag.name),
|
||||
id,
|
||||
auditUser,
|
||||
);
|
||||
|
||||
if (this.flagResolver.isEnabled('cleanApiTokenWhenOrphaned')) {
|
||||
const allTokens = await this.apiTokenStore.getAll();
|
||||
const allTokens = await this.apiTokenService.getAllTokens();
|
||||
const projectTokens = allTokens.filter(
|
||||
(token) =>
|
||||
(token.projects &&
|
||||
@ -585,7 +578,7 @@ export default class ProjectService {
|
||||
|
||||
await Promise.all(
|
||||
projectTokens.map((token) =>
|
||||
this.apiTokenStore.delete(token.secret),
|
||||
this.apiTokenService.delete(token.secret, auditUser),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user