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

Add group_names qs method for Acknowledgement list #838

Merged
merged 5 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/838.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added method to check whether incident is acknowledged by a specific user group.
3 changes: 3 additions & 0 deletions src/argus/incident/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ def acked(self):

return self.events.filter((acks_query & acks_not_expired_query) | ack_is_just_being_created).exists()

def is_acked_by(self, group: str) -> bool:
return Acknowledgement.objects.filter(event__incident=self, event__actor__groups__name=group).exists()

Copy link
Contributor

Choose a reason for hiding this comment

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

You need to check if it has expired...

Do that and return False early if it has.

Also, you could probably reuse the property "acks", like so:

return self.acks.filter(event__actor__groups__name=group).exists()

(Both "acks" and "acked" need a refactor, frankly. Needs its own issue.)

Copy link
Contributor

Choose a reason for hiding this comment

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

You could also just rename it to "has_been_acked_by" and ignore expiration.

Copy link
Contributor

Choose a reason for hiding this comment

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

(The best solution is denormalizing, having whether this is a current ack on the incident itself, but that doesn't help in this specific case. we should not have a database field on incident for every not-expired ack per group...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will stick to is_acked_by and check if ack has expired

def create_first_event(self):
"""Create the correct type of first event for an incident

Expand Down
Loading