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

Move addComments to permissionClass #2263

Merged
merged 6 commits into from Mar 26, 2024
Merged

Move addComments to permissionClass #2263

merged 6 commits into from Mar 26, 2024

Conversation

mknowlton89
Copy link
Collaborator

@mknowlton89 mknowlton89 commented Mar 22, 2024

Features and Changes

This PR moves the addComments permission check to the new permissionClass. This is the first READ_ONLY type permission that we've migrated, so there are updates to the checkProjectFilterPermissions method.

If the resource is in "All Projects", we'll add the user's project-specific roles to the projects array, as the user only needs to have the permission globally, or in at least 1 project in order to have the permission.

@@ -38,6 +39,10 @@ export class Permissions {
return this.checkProjectFilterPermission(metric, "createMetrics");
};

public canAddComment = (projects: string[]): boolean => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

open to suggestions on how to type the arguments here - we check for this permission across metrics (with have projects, along with ideas, experiments, and features, which only have a project property.

It'd be nice to standardize so the engineer doesn't have to have much context when calling canAddComment.

Currently, it still seems like a step in the right direction, as before it could be a string, or undefined, or string[], so this at least simplifies it a bit.

Copy link
Member

Choose a reason for hiding this comment

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

One option is to type the argument like this:

type ObjWithProject = {project?: string; projects?: string[]};

That way, you could call it directly with the thing you want to comment on:

canAddComment(feature);
canAddComment(metric);

Another option is to make separate canCommentOnFeature, canCommentOnMetric, etc. methods. They could all check the same addComments permission for now, but it leaves the door open for us to make this finer grained in the future.

Copy link
Member

Choose a reason for hiding this comment

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

I'm also fine with how you have it

@mknowlton89 mknowlton89 requested a review from jdorn March 25, 2024 19:44
@mknowlton89 mknowlton89 self-assigned this Mar 25, 2024
@mknowlton89 mknowlton89 marked this pull request as ready for review March 25, 2024 19:44
Copy link

github-actions bot commented Mar 25, 2024

Your preview environment pr-2263-bttf has been deployed.

Preview environment endpoints are available at:

@mknowlton89 mknowlton89 merged commit 1e64af1 into main Mar 26, 2024
3 checks passed
@mknowlton89 mknowlton89 deleted the mk/add-comments branch March 26, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants