-
-
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
feat: protect segment operations for change requests #4417
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 ↗︎
1 Ignored Deployment
|
@@ -177,7 +177,7 @@ export default class FakeProjectStore implements IProjectStore { | |||
projectId: string, | |||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |||
environment: string, | |||
): Promise<CreateFeatureStrategySchema | undefined> { | |||
): Promise<CreateFeatureStrategySchema | null> { |
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.
TS error fix
@@ -248,4 +283,16 @@ export class SegmentService implements ISegmentService { | |||
); | |||
} | |||
} | |||
|
|||
private async stopWhenChangeRequestsEnabled(project?: string, user?: User) { |
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.
this is the most important method
@@ -108,13 +130,26 @@ export class SegmentService implements ISegmentService { | |||
|
|||
await this.eventStore.store({ | |||
type: SEGMENT_UPDATED, | |||
createdBy: user.email || user.username, | |||
createdBy: user.email || user.username || 'unknown', |
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.
TS error fix
data: segment, | ||
}); | ||
|
||
return segment; | ||
} | ||
|
||
async update( | ||
async update(id: number, data: unknown, user: User): Promise<void> { | ||
if (this.flagResolver.isEnabled('segmentChangeRequests')) { |
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 have to be careful not to enable it before the UI is ready
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.
Fair. It's currently enabled in dev, but we can turn that off
@@ -35,6 +35,23 @@ export class ChangeRequestAccessReadModel | |||
return !(changeRequestEnabled && !canSkipChangeRequest); | |||
} | |||
|
|||
public async canBypassChangeRequestForProject( |
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 check for environment. If a user can skip change requests in any env we're good for now. We can tweak this logic later. For now need something cheap to experiment
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.
Nice! My only comment is the double negation. It'd be nice if we could express that a bit clearer, but I'll leave it up to you.
: Promise.resolve(false), | ||
this.isChangeRequestsEnabledForProject(project), | ||
]); | ||
return !(changeRequestEnabled && !canSkipChangeRequest); |
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.
Could we express this without the double negation? I'm struggling to parse what we're saying here.
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.
great catch, changing it to return canSkipChangeRequest || !changeRequestEnabled;
data: segment, | ||
}); | ||
|
||
return segment; | ||
} | ||
|
||
async update( | ||
async update(id: number, data: unknown, user: User): Promise<void> { | ||
if (this.flagResolver.isEnabled('segmentChangeRequests')) { |
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.
Fair. It's currently enabled in dev, but we can turn that off
Looking at #3315 I think the plan was to use the interface to establish the contract as enterprise and OSS had different implementations. I don't remember the context but we were moving things that were on OSS to the enterprise repo and this was probably in the expansion phase of the migration and it just stayed... If it doesn't make more sense and you want to remove it, I vote we follow our conventions (and this is out of our code conventions) |
About the changes
Update segment and delete segment now have protected mode which means that with CR enabled you can't change them willy-nilly. You either need skip permission for any project environment or go through a change request.
There's a corresponding enterprise change where I have tests and fix breaking changes.
Important files
Discussion points
I noticed that we have interface for the segment service. Since this is the only service with an interface it looks odd. I'm tempted to remove it since there's only one impl of the interface and TS is structurally typed. @gastonfournier since you added the interface WDYT?