Skip to content

Commit

Permalink
Fix SetupEvent not sending websocket notifications (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
rstijerina authored Jun 28, 2023
1 parent 47a9619 commit 1291ab3
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions server/portal/apps/signals/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,23 @@ def index_project_on_save(sender, instance, created, **kwargs):


@receiver(post_save, sender=SetupEvent, dispatch_uid='setup_event')
def send_setup_event(sender, instance, created, **kwargs):
# Only send the event if it is being saved. (Creation also triggers post_save)
if created:
return

logger.debug("Sending setup event through websocket")
def send_setup_event(sender, instance, **kwargs):
logger.info("Sending setup event through websocket")
setup_event = instance

# All staff will receive websocket notifications so they can see
# setup event updates for users they are administering
receiving_users = get_user_model().objects.all().filter(is_staff=True)
receiving_users = [user for user in receiving_users]

# Add the setup_event's user to the notification list
receiving_users.append(setup_event.user)
try:
data = {
"event_type": "setup_event",
"setup_event": setup_event.to_dict()
}
for user in receiving_users:
for user in set(receiving_users):
async_to_sync(channel_layer.group_send)(
user.username,
{
Expand All @@ -100,15 +97,6 @@ def send_setup_event(sender, instance, created, **kwargs):
}
)

# Short expiry. Users viewing onboarding status changes should receive
# "live" messages. Users viewing the page after an event happens
# should be able to retrieve setup state without needing live
# notifications. This also prevents staff from accumulating messages
# for all users.

# TODO: translate this to channels?
# rp.publish_message(msg, expire=10)

except Exception:
logger.exception(
'Exception sending message to channel: portal_notification',
Expand Down

0 comments on commit 1291ab3

Please sign in to comment.