예제 #1
0
def comment_created(sender, **kwargs):
    comment = kwargs["instance"]
    state = kwargs["state"]
    text, exist_in_past, text_version = get_past_and_text(comment)
    if exist_in_past:
        return

    alerts = EmailAlert.objects.get_alerts(text)
    for alert in alerts:
        user = alert.user

        # permission & activate check
        allowed_states = comment_states_with_perm_for_text("can_view_comment_local_text", user, text_version.id)
        if user.is_active and state in allowed_states:
            send_comment_created_email(comment, alert, user)
예제 #2
0
def state_changed(sender, **kwargs):
    comment = kwargs["instance"]
    old_state = kwargs["old_state"]
    old_workflow = kwargs["old_workflow"]
    state = kwargs["state"]
    text, exist_in_past, text_version = get_past_and_text(comment)
    if exist_in_past:
        return
    alerts = EmailAlert.objects.get_alerts(text)
    for alert in alerts:
        user = alert.user

        allowed_states = comment_states_with_perm_for_text("can_view_comment_local_text", user, text_version.id)
        if old_workflow:
            old_allowed_states = comment_states_with_perm_for_workflow(
                "can_view_comment_local_text", user, old_workflow, text.id
            )
        else:
            old_allowed_states = allowed_states
        # permission check
        # check that the state update makes the comment visible
        if user.is_active and state in allowed_states and old_state not in old_allowed_states:
            send_comment_created_email(comment, alert, user)