-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(aci): prevent deletion of system-created monitors in API #103843
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
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 |
|---|---|---|
|
|
@@ -69,6 +69,31 @@ def can_edit_detector(detector: Detector, request: Request) -> bool: | |
| return can_edit_user_created_detectors(request, detector.project) | ||
|
|
||
|
|
||
| def can_delete_detectors(detectors: QuerySet[Detector], request: Request) -> bool: | ||
| """ | ||
| Determine if the requesting user has access to delete the given detectors. | ||
| Only user-created detectors can be deleted, and require "alerts:write" permission. | ||
| """ | ||
| if any(is_system_created_detector(detector) for detector in detectors): | ||
| return False | ||
|
|
||
| projects = Project.objects.filter( | ||
| id__in=detectors.values_list("project_id", flat=True).distinct() | ||
| ) | ||
| return all(can_edit_user_created_detectors(request, project) for project in projects) | ||
|
|
||
|
|
||
| def can_delete_detector(detector: Detector, request: Request) -> bool: | ||
| """ | ||
| Determine if the requesting user has access to delete the given detector. | ||
| Only user-created detectors can be deleted, and require "alerts:write" permission. | ||
| """ | ||
| if is_system_created_detector(detector): | ||
| return False | ||
|
|
||
| return can_edit_user_created_detectors(request, detector.project) | ||
|
Comment on lines
+86
to
+94
Member
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. Instead of having 2 functions that do the same thing, you could pass a single detector to
Member
Author
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. the single detector function is nice because it saves us a lookup from the Project table |
||
|
|
||
|
|
||
| def can_edit_detector_workflow_connections(detector: Detector, request: Request) -> bool: | ||
| """ | ||
| Anyone with alert write access to the project can connect/disconnect detectors of any type, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.