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

feat: protect segment operations for change requests #4417

Merged
merged 2 commits into from
Aug 4, 2023

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Aug 4, 2023

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?

@sonatype-lift
Copy link

sonatype-lift bot commented Aug 4, 2023

Sonatype Lift is retiring

Sonatype 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.
We are extremely grateful and thank you for your support over the years.

📖 Read about the impacts and timeline

@vercel
Copy link

vercel bot commented Aug 4, 2023

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

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 4, 2023 10:09am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Aug 4, 2023 10:09am

@@ -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> {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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',
Copy link
Contributor Author

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')) {
Copy link
Contributor Author

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

Copy link
Contributor

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(
Copy link
Contributor Author

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

Copy link
Contributor

@thomasheartman thomasheartman left a 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);
Copy link
Contributor

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.

Copy link
Contributor Author

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')) {
Copy link
Contributor

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

@gastonfournier
Copy link
Contributor

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?

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)

@kwasniew kwasniew merged commit e20e7df into main Aug 4, 2023
15 checks passed
@kwasniew kwasniew deleted the protect-segment-operations-for-cr branch August 4, 2023 10:23
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

3 participants