Skip to content
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

Merged
merged 11 commits into from
Apr 18, 2024
Merged

Task/use audit info in events #6872

merged 11 commits into from
Apr 18, 2024

Conversation

chriswk
Copy link
Contributor

@chriswk chriswk commented Apr 16, 2024

So, this is the extension to the auditInfo middleware.

I've tried to use/add the audit info to all events I could see/find. This makes this PR necessarily huge, because we do store quite a few events here and there. I realise it might not be complete yet, but tests run green, and I think we now have a pattern to follow for other events. Merging this will probably break enterprise quite hard, so will prepare a PR on enterprise tomorrow which is linked against this.

@chriswk chriswk self-assigned this Apr 16, 2024
Copy link

vercel bot commented Apr 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Apr 18, 2024 2:27pm
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Visit Preview Apr 18, 2024 2:27pm

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 10 findings(s) 🚩
  • Improving Code Health: 54 findings(s) ✅
  • Affected Hotspots: 4 files(s) 🔥

View detailed results in CodeScene

Absence of Expected Change Pattern

  • unleash/src/test/e2e/api/admin/event.e2e.test.ts is usually changed with: unleash/src/test/e2e/health.e2e.test.ts

@@ -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';

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

@@ -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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No longer an issue: String Heavy Function Arguments
The ratio of strings in function arguments is no longer above the threshold

@@ -1,7 +1,6 @@
import {
CREATE_FEATURE_STRATEGY,
EnvironmentVariantEvent,
FEATURE_UPDATED,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Lines of Code in a Single File
The lines of code decreases from 1984 to 1941, improve code health by reducing it to 1000

@@ -1,7 +1,6 @@
import {
CREATE_FEATURE_STRATEGY,
EnvironmentVariantEvent,
FEATURE_UPDATED,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: String Heavy Function Arguments
The ratio of strings in function arguments decreases from 56.56% to 47.19%, threshold = 39.0%

@@ -1298,8 +1283,7 @@ class FeatureToggleService {
featureName: string,
projectId: string,
newFeatureName: string,
userName: string,
userId: number,
auditUser: IAuditUser,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Large Method
FeatureToggleService.cloneFeatureToggle decreases from 78 to 75 lines of code, threshold = 70

Comment on lines +475 to +482
const preHook = (
app,
config,
{
userService,
accessService,
}: Pick<IUnleashServices, 'userService' | 'accessService'>,
) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Getting worse: Large Method
'READ_FRONTEND_API_TOKEN should be able to see FRONTEND tokens' increases from 72 to 81 lines of code, threshold = 70

Suppress

Comment on lines +558 to +565
const preHook = (
app,
config,
{
userService,
accessService,
}: Pick<IUnleashServices, 'userService' | 'accessService'>,
) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Large Method
'READ_CLIENT_API_TOKEN should be able to see CLIENT tokens' has 78 lines, threshold = 70

Suppress

Comment on lines -306 to -307
userName,
userId,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No longer an issue: Large Method
'Roundtrip with strategies in multiple environments works' is no longer above the threshold for lines of code

IUnleashStores,
IUser,
IUserAccessOverview,
import {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ Getting worse: Lines of Code in a Single File
The lines of code increases from 1479 to 1505, improve code health by reducing it to 1000

Comment on lines +991 to +1000
await projectService.createProject(
projectForCreate,
editorUser,
TEST_AUDIT_USER,
);
await projectService.createProject(
projectForDelete,
editorUser,
TEST_AUDIT_USER,
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Getting worse: Large Method
'Should allow user to take multiple group roles and have expected permissions on each project' increases from 73 to 81 lines of code, threshold = 70

Suppress

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 20 findings(s) 🚩
  • Improving Code Health: 55 findings(s) ✅
  • Affected Hotspots: 4 files(s) 🔥

View detailed results in CodeScene

Absence of Expected Change Pattern

  • unleash/src/test/e2e/api/admin/event.e2e.test.ts is usually changed with: unleash/src/test/e2e/health.e2e.test.ts

Base automatically changed from task/addUserAuditInfo to main April 18, 2024 08:13
Copy link
Contributor

@gastonfournier gastonfournier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, just a minor comment, but no blocker

}

async deleteFeatureDependency(
dependency: FeatureDependencyId,
projectId: string,
user: IUser,
auditUser: IAuditUser,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future, we can consider merging auditUser with user as they should always represent the same, but user has permissions and auditUser don't, but for now, let's do this as a gradual improvement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment on lines 25 to 26
expect(audit!.id).toBe(-1);
expect(audit!.username).toBe('unknown');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: this comes from new NoAuthUser().id and new NoAuthUser().username which is injected by the noAuthentication function above

Comment on lines 10 to 12
if (!req.user) {
logger.info('Could not find user');
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to log everytime we don't find a user?

Suggested change
if (!req.user) {
logger.info('Could not find user');
} else {
if (req.user) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this middleware is only mounted on /api/admin not finding a user might actually be an error.

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 9 findings(s) 🚩
  • Improving Code Health: 54 findings(s) ✅
  • Affected Hotspots: 4 files(s) 🔥

View detailed results in CodeScene

Absence of Expected Change Pattern

  • unleash/src/test/e2e/api/admin/event.e2e.test.ts is usually changed with: unleash/src/test/e2e/health.e2e.test.ts

@@ -1,6 +1,6 @@
import { subDays } from 'date-fns';
import { ValidationError } from 'joi';
import type { IUser } from '../../types/user';
import type { IAuditUser, IUser } from '../../types/user';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Lines of Code in a Single File
The lines of code decreases from 1076 to 1054, improve code health by reducing it to 1000

@@ -1,6 +1,6 @@
import { subDays } from 'date-fns';
import { ValidationError } from 'joi';
import type { IUser } from '../../types/user';
import type { IAuditUser, IUser } from '../../types/user';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Primitive Obsession
The ratio of primitive types in function arguments decreases from 78.99% to 64.55%, threshold = 30.0%

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 9 findings(s) 🚩
  • Improving Code Health: 54 findings(s) ✅
  • Affected Hotspots: 4 files(s) 🔥

View detailed results in CodeScene

Absence of Expected Change Pattern

  • unleash/src/test/e2e/api/admin/event.e2e.test.ts is usually changed with: unleash/src/test/e2e/health.e2e.test.ts

@@ -18,14 +18,17 @@ import {
createProjectService,
} from '../index';
import {
type IAuditUser,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ Getting worse: Lines of Code in a Single File
The lines of code increases from 2138 to 2164, improve code health by reducing it to 1000

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 9 findings(s) 🚩
  • Improving Code Health: 54 findings(s) ✅
  • Affected Hotspots: 4 files(s) 🔥

View detailed results in CodeScene

Absence of Expected Change Pattern

  • unleash/src/test/e2e/api/admin/event.e2e.test.ts is usually changed with: unleash/src/test/e2e/health.e2e.test.ts

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 9 findings(s) 🚩
  • Improving Code Health: 54 findings(s) ✅
  • Affected Hotspots: 4 files(s) 🔥

View detailed results in CodeScene

Absence of Expected Change Pattern

  • unleash/src/test/e2e/api/admin/event.e2e.test.ts is usually changed with: unleash/src/test/e2e/health.e2e.test.ts

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 9 findings(s) 🚩
  • Improving Code Health: 54 findings(s) ✅
  • Affected Hotspots: 4 files(s) 🔥

View detailed results in CodeScene

Absence of Expected Change Pattern

  • unleash/src/test/e2e/api/admin/event.e2e.test.ts is usually changed with: unleash/src/test/e2e/health.e2e.test.ts

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 9 findings(s) 🚩
  • Improving Code Health: 54 findings(s) ✅
  • Affected Hotspots: 4 files(s) 🔥

View detailed results in CodeScene

Absence of Expected Change Pattern

  • unleash/src/test/e2e/api/admin/event.e2e.test.ts is usually changed with: unleash/src/test/e2e/health.e2e.test.ts

@chriswk chriswk merged commit cf2bd28 into main Apr 18, 2024
7 of 8 checks passed
@chriswk chriswk deleted the task/useAuditInfoInEvents branch April 18, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants