Skip to content

Commit

Permalink
verification check on user is already in an incident
Browse files Browse the repository at this point in the history
  • Loading branch information
jennafauconnier committed Nov 8, 2024
1 parent c78d24f commit 2f7389a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/firefighter/slack/views/modals/critical.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from slack_sdk.models.views import View

from firefighter.incidents.forms.create_incident import CreateIncidentForm
from firefighter.incidents.models.incident_membership import IncidentMembership
from firefighter.slack.slack_app import SlackApp
from firefighter.slack.utils import respond
from firefighter.slack.views.modals.base_modal.base import ModalForm

if TYPE_CHECKING:
Expand Down Expand Up @@ -91,6 +93,11 @@ def build_modal_fn(self, **kwargs: Any) -> View:
def handle_modal_fn( # type: ignore
self, ack: Ack, body: dict[str, Any], user: User
) -> None :
if not self.is_user_member_of_incident(user):
ack()
respond(body, text=":x: You must be linked to an incident to use this command.")
return

slack_form = self.handle_form_errors(
ack, body, forms_kwargs={},
)
Expand All @@ -116,5 +123,8 @@ def handle_modal_fn( # type: ignore
logger.warning("Form is empty, no data captured.")
return

def is_user_member_of_incident(self, user: User) -> bool:
return IncidentMembership.objects.filter(user=user).exists()


modal_critical = CriticalModal()

0 comments on commit 2f7389a

Please sign in to comment.