-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(crons): honor alertsMemberWrite setting #104171
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
Changes from all commits
8b60ee2
ad98c86
acd0572
f6aea49
3eb84c4
765717d
1647065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,41 @@ | |
| from sentry.api.bases.project import ProjectAlertRulePermission, ProjectEndpoint | ||
| from sentry.api.exceptions import ResourceDoesNotExist | ||
| from sentry.incidents.models.alert_rule import AlertRule | ||
| from sentry.models.organization import Organization | ||
|
|
||
|
|
||
| class OrganizationAlertRuleBaseEndpoint(OrganizationEndpoint): | ||
| """ | ||
| Base endpoint for organization-scoped alert rule creation. | ||
| Provides permission checking for alert creation that handles both | ||
| org-level permissions and team admin project-scoped permissions. | ||
| """ | ||
|
|
||
| def check_can_create_alert(self, request: Request, organization: Organization) -> None: | ||
| """ | ||
| Determine if the requesting user has access to alert creation. If the request does not have the "alerts:write" | ||
| permission, then we must verify that the user is a team admin with "alerts:write" access to the project(s) | ||
| in their request. | ||
| """ | ||
|
|
||
| # if the requesting user has any of these org-level permissions, then they can create an alert | ||
| if ( | ||
| request.access.has_scope("alerts:write") | ||
| or request.access.has_scope("org:admin") | ||
| or request.access.has_scope("org:write") | ||
| ): | ||
| return | ||
|
|
||
| # team admins should be able to create alerts for the projects they have access to | ||
| projects = self.get_projects(request, organization) | ||
| # team admins will have alerts:write scoped to their projects, members will not | ||
| team_admin_has_access = all( | ||
| [request.access.has_project_scope(project, "alerts:write") for project in projects] | ||
| ) | ||
| # all() returns True for empty list, so include a check for it | ||
| if not team_admin_has_access or not projects: | ||
| raise PermissionDenied | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Permission check validates all projects, not the requested oneMedium Severity The Additional Locations (1) |
||
|
|
||
|
|
||
| class ProjectAlertRuleEndpoint(ProjectEndpoint): | ||
|
|
||
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.
Does this get all projects the user has access to, or just the projects in the current url params selection?
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.
Returns all project ids that the user can access within this organization:
https://github.com/getsentry/sentry/blob/master/src/sentry/api/bases/organization.py#L355-L369
Btw this is not the new code, it was moved from OrganizationAlertRuleIndexEndpoint.check_can_create_alert
https://github.com/getsentry/sentry/pull/104171/changes#diff-7ce0c5c5a5e204143274734b7e9a288cd70a869fa5d460e99eee830e44cda682L627-L628