-
-
Notifications
You must be signed in to change notification settings - Fork 658
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
fix: group cleanup #4334
fix: group cleanup #4334
Conversation
Sonatype Lift is retiringSonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
.returning(GROUP_COLUMNS); | ||
|
||
return rowToGroup(rows[0]); | ||
} catch (error) { |
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.
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.
If the role doesn't exist at all, it should fail, which I think this now does, thanks to this PR. If the role is not a root role then this will succeed but effectively be a no-op. Probably needs some love but I think this PR takes us forward
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.
Exactly, this PR prevent doesn't allow to pass nonexistent role ids and fails with 400 on those
.returning('*'); | ||
return rowToGroup(row[0]); | ||
} catch (error) { | ||
if ( |
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.
same as update
}); | ||
return await this.db.batchInsert(T.GROUP_USER, rows); | ||
} catch (error) { | ||
if ( |
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.
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.
Yeah agreed, I think it's fine living in this logical layer
import { AccountStore } from '../../db/account-store'; | ||
import EventStore from '../../db/event-store'; | ||
|
||
export const createGroupService = ( |
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.
needed for transaction support so that we new up a service per DB transaction
import { FromSchema } from 'json-schema-to-ts'; | ||
import { groupSchema } from './group-schema'; | ||
|
||
export const createGroupSchema = { |
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.
separate schema from the read schema we were sharing before
user: { | ||
type: 'object', | ||
description: 'A minimal user object', | ||
required: ['id'], |
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.
I was checking the UI and we don't send full users as the previous schema indicated but only the ids.
@@ -33,6 +33,11 @@ export interface IGroupModel extends IGroup { | |||
projects?: string[]; | |||
} | |||
|
|||
export interface ICreateGroupModel extends IGroup { |
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.
new TS model reflecting openapi schema change. Users are optional and each user is represented by id only
@@ -96,4 +96,5 @@ export interface IUnleashServices { | |||
transactionalFeatureToggleService: ( | |||
db: Knex.Transaction, | |||
) => FeatureToggleService; | |||
transactionalGroupService: (db: Knex.Transaction) => GroupService; |
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.
we'll use it in the enterprise controller
@@ -38,20 +38,20 @@ export interface IGroupStore extends Store<IGroup, number> { | |||
|
|||
updateGroupUsers( | |||
groupId: number, | |||
newUsers: IGroupUserModel[], | |||
newUsers: ICreateGroupUserModel[], |
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.
write/create model decoupled from the read model
@@ -124,3 +124,26 @@ test('adding a root role to a group with a project role should fail', async () = | |||
|
|||
expect.assertions(1); | |||
}); | |||
|
|||
test('adding a nonexistent role to a group should fail', async () => { |
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.
confirming the try/catch I added in the store works
created_by: userName, | ||
}; | ||
}); | ||
return (transaction || this.db).batchInsert(T.GROUP_USER, rows); |
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.
removing transactions from the store and moving them to the controller/around the group service in the enterprise repo
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.
LGTM
About the changes
Important files
Discussion points