-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
Task/use audit info in events #6872
Changes from all commits
2621fff
36adada
460c466
89f2c67
7be1aee
61b6ceb
880cc37
3b1947f
bcc0235
8a3b714
bfed1fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import { | |
} from '../../../../test/e2e/helpers/test-helper'; | ||
import getLogger from '../../../../test/fixtures/no-logger'; | ||
import { DEFAULT_ENV } from '../../../util/constants'; | ||
import type { IUserWithRootRole } from '../../../types'; | ||
import { type IUserWithRootRole, TEST_AUDIT_USER } from '../../../types'; | ||
|
||
let app: IUnleashTest; | ||
let db: ITestDb; | ||
|
@@ -73,11 +73,14 @@ beforeAll(async () => { | |
db.rawDatabase, | ||
); | ||
|
||
dummyAdmin = await app.services.userService.createUser({ | ||
name: 'Some Name', | ||
email: '[email protected]', | ||
rootRole: RoleName.ADMIN, | ||
}); | ||
dummyAdmin = await app.services.userService.createUser( | ||
{ | ||
name: 'Some Name', | ||
email: '[email protected]', | ||
rootRole: RoleName.ADMIN, | ||
}, | ||
TEST_AUDIT_USER, | ||
); | ||
}); | ||
|
||
afterEach(async () => { | ||
|
@@ -137,10 +140,12 @@ test('should support filtering on project', async () => { | |
await app.services.projectService.createProject( | ||
{ name: 'projectA', id: 'projecta' }, | ||
dummyAdmin, | ||
TEST_AUDIT_USER, | ||
); | ||
await app.services.projectService.createProject( | ||
{ name: 'projectB', id: 'projectb' }, | ||
dummyAdmin, | ||
TEST_AUDIT_USER, | ||
); | ||
await app.createFeature('ab_test1', 'projecta'); | ||
await app.createFeature('bd_test2', 'projectb'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,14 @@ import type { | |
} from './dependent-features'; | ||
import type { IDependentFeaturesReadModel } from './dependent-features-read-model-type'; | ||
import type { EventService } from '../../services'; | ||
import type { IUser } from '../../server-impl'; | ||
import { SKIP_CHANGE_REQUEST } from '../../types'; | ||
import type { IAuditUser, IUser } from '../../server-impl'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ No longer an issue: String Heavy Function Arguments |
||
import { | ||
FeatureDependenciesRemovedEvent, | ||
FeatureDependencyAddedEvent, | ||
FeatureDependencyRemovedEvent, | ||
SKIP_CHANGE_REQUEST, | ||
} from '../../types'; | ||
import type { IChangeRequestAccessReadModel } from '../change-request-access-service/change-request-access-read-model'; | ||
import { extractUsernameFromUser } from '../../util'; | ||
import type { IFeaturesReadModel } from '../feature-toggle/types/features-read-model-type'; | ||
|
||
interface IDependentFeaturesServiceDeps { | ||
|
@@ -52,8 +56,7 @@ export class DependentFeaturesService { | |
newFeatureName, | ||
projectId, | ||
}: { featureName: string; newFeatureName: string; projectId: string }, | ||
user: string, | ||
userId: number, | ||
auditUser: IAuditUser, | ||
) { | ||
const parents = | ||
await this.dependentFeaturesReadModel.getParents(featureName); | ||
|
@@ -66,8 +69,7 @@ export class DependentFeaturesService { | |
enabled: parent.enabled, | ||
variants: parent.variants, | ||
}, | ||
user, | ||
userId, | ||
auditUser, | ||
), | ||
), | ||
); | ||
|
@@ -77,22 +79,21 @@ export class DependentFeaturesService { | |
{ child, projectId }: { child: string; projectId: string }, | ||
dependentFeature: CreateDependentFeatureSchema, | ||
user: IUser, | ||
auditUser: IAuditUser, | ||
): Promise<void> { | ||
await this.stopWhenChangeRequestsEnabled(projectId, user); | ||
|
||
return this.unprotectedUpsertFeatureDependency( | ||
{ child, projectId }, | ||
dependentFeature, | ||
extractUsernameFromUser(user), | ||
user.id, | ||
auditUser, | ||
); | ||
} | ||
|
||
async unprotectedUpsertFeatureDependency( | ||
{ child, projectId }: { child: string; projectId: string }, | ||
dependentFeature: CreateDependentFeatureSchema, | ||
user: string, | ||
userId: number, | ||
auditUser: IAuditUser, | ||
): Promise<void> { | ||
const { enabled, feature: parent, variants } = dependentFeature; | ||
|
||
|
@@ -148,82 +149,81 @@ export class DependentFeaturesService { | |
variants, | ||
}; | ||
await this.dependentFeaturesStore.upsert(featureDependency); | ||
await this.eventService.storeEvent({ | ||
type: 'feature-dependency-added', | ||
project: projectId, | ||
featureName: child, | ||
createdBy: user, | ||
createdByUserId: userId, | ||
data: { | ||
feature: parent, | ||
enabled: featureDependency.enabled, | ||
...(variants !== undefined && { variants }), | ||
}, | ||
}); | ||
await this.eventService.storeEvent( | ||
new FeatureDependencyAddedEvent({ | ||
project: projectId, | ||
featureName: child, | ||
auditUser, | ||
data: { | ||
feature: parent, | ||
enabled: featureDependency.enabled, | ||
...(variants !== undefined && { variants }), | ||
}, | ||
}), | ||
); | ||
} | ||
|
||
async deleteFeatureDependency( | ||
dependency: FeatureDependencyId, | ||
projectId: string, | ||
user: IUser, | ||
auditUser: IAuditUser, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the future, we can consider merging There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, agreed, the thing missing was having some way from audit user to UserWithPermission. so the one thing audituser has that most other user implementations do not have is the ip. |
||
): Promise<void> { | ||
await this.stopWhenChangeRequestsEnabled(projectId, user); | ||
|
||
return this.unprotectedDeleteFeatureDependency( | ||
dependency, | ||
projectId, | ||
extractUsernameFromUser(user), | ||
user.id, | ||
auditUser, | ||
); | ||
} | ||
|
||
async unprotectedDeleteFeatureDependency( | ||
dependency: FeatureDependencyId, | ||
projectId: string, | ||
user: string, | ||
userId: number, | ||
auditUser: IAuditUser, | ||
): Promise<void> { | ||
await this.dependentFeaturesStore.delete(dependency); | ||
await this.eventService.storeEvent({ | ||
type: 'feature-dependency-removed', | ||
project: projectId, | ||
featureName: dependency.child, | ||
createdBy: user, | ||
createdByUserId: userId, | ||
data: { feature: dependency.parent }, | ||
}); | ||
await this.eventService.storeEvent( | ||
new FeatureDependencyRemovedEvent({ | ||
project: projectId, | ||
featureName: dependency.child, | ||
auditUser, | ||
data: { feature: dependency.parent }, | ||
}), | ||
); | ||
} | ||
|
||
async deleteFeaturesDependencies( | ||
features: string[], | ||
projectId: string, | ||
user: IUser, | ||
auditUser: IAuditUser, | ||
): Promise<void> { | ||
await this.stopWhenChangeRequestsEnabled(projectId, user); | ||
|
||
return this.unprotectedDeleteFeaturesDependencies( | ||
features, | ||
projectId, | ||
extractUsernameFromUser(user), | ||
user.id, | ||
auditUser, | ||
); | ||
} | ||
|
||
async unprotectedDeleteFeaturesDependencies( | ||
features: string[], | ||
projectId: string, | ||
user: string, | ||
userId: number, | ||
auditUser: IAuditUser, | ||
): Promise<void> { | ||
await this.dependentFeaturesStore.deleteAll(features); | ||
await this.eventService.storeEvents( | ||
features.map((feature) => ({ | ||
type: 'feature-dependencies-removed', | ||
project: projectId, | ||
featureName: feature, | ||
createdBy: user, | ||
createdByUserId: userId, | ||
})), | ||
features.map( | ||
(feature) => | ||
new FeatureDependenciesRemovedEvent({ | ||
project: projectId, | ||
featureName: feature, | ||
auditUser, | ||
}), | ||
), | ||
); | ||
} | ||
|
||
|
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.
✅ No longer an issue: Primitive Obsession
The ratio of primivite types in function arguments is no longer above the threshold