-
-
Notifications
You must be signed in to change notification settings - Fork 663
add slack reaction based moderation alerts #5034
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a87ade4
Move Slack moderation logic into a seperate service+ update test +rea…
Mr-Rahul-Paul 93f0df1
Fix Slack workspace token placeholder
Mr-Rahul-Paul 9e941af
Add Slack moderation model help text
Mr-Rahul-Paul 4d68f86
Use admin-managed Slack reaction rules
Mr-Rahul-Paul cdc506d
Generalize Slack moderation models as reactions
Mr-Rahul-Paul 1f86707
Remove unnecessary local ngrok origin setting
Mr-Rahul-Paul 02acae1
check test fixes
Mr-Rahul-Paul 71aae42
Merge branch 'main' into pr/Mr-Rahul-Paul/5034
arkid15r baaa11b
Update code
arkid15r 2500f93
Update code
arkid15r 7e8146a
Address comments
arkid15r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| """Django admin screen for emitted Slack reaction alerts.""" | ||
|
|
||
| from django.contrib import admin | ||
|
|
||
| from apps.slack.models.reaction_alert import ReactionAlert | ||
|
|
||
|
|
||
| @admin.register(ReactionAlert) | ||
| class ReactionAlertAdmin(admin.ModelAdmin): | ||
| """Admin list/search controls for emitted reaction alerts.""" | ||
|
|
||
| list_display = ( | ||
| "conversation", | ||
| "message_ts", | ||
| "report_type", | ||
| "reaction_count", | ||
| "nest_created_at", | ||
| ) | ||
| search_fields = ("conversation__name", "message_ts", "report_type") | ||
| readonly_fields = ( | ||
| "conversation", | ||
| "message_ts", | ||
| "report_type", | ||
| "reaction_count", | ||
| "alert_message_ts", | ||
| ) | ||
|
|
||
| def has_add_permission(self, request): | ||
| """Disable manual alert creation in Django admin.""" | ||
| return False | ||
|
|
||
| def has_delete_permission(self, request, obj=None): | ||
| """Disable manual alert deletion in Django admin.""" | ||
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """Django admin screen for Slack reaction rules.""" | ||
|
|
||
| from django.contrib import admin | ||
|
|
||
| from apps.slack.models.reaction_rule import ReactionRule | ||
|
|
||
|
|
||
| @admin.register(ReactionRule) | ||
| class ReactionRuleAdmin(admin.ModelAdmin): | ||
| """Admin list/search controls for reaction rules.""" | ||
|
|
||
| list_display = ("conversation", "emoji_name", "report_type", "threshold", "is_enabled") | ||
| list_filter = ("is_enabled", "report_type") | ||
| search_fields = ("conversation__name", "emoji_name", "alert_channel_id") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """Handle Slack reaction_added events.""" | ||
|
|
||
| from apps.slack.events.event import EventBase | ||
| from apps.slack.services.reaction import process_reaction_added | ||
|
|
||
|
|
||
| class ReactionAdded(EventBase): | ||
| """Route reaction_added to the reaction service for processing.""" | ||
|
|
||
| event_type = "reaction_added" | ||
|
|
||
| def handle_event(self, event, client): | ||
| """Handle report reactions added to Slack messages.""" | ||
| process_reaction_added(event, client) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
backend/src/apps/slack/migrations/0023_reactionalert_reactionrule.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # Generated by Django 6.0.6 on 2026-06-22 20:33 | ||
|
|
||
| import django.core.validators | ||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("slack", "0022_workspace_invite_link_last_alert_message_ts_and_more"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="ReactionAlert", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.BigAutoField( | ||
| auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
| ), | ||
| ), | ||
| ("nest_created_at", models.DateTimeField(auto_now_add=True)), | ||
| ("nest_updated_at", models.DateTimeField(auto_now=True)), | ||
| ( | ||
| "message_ts", | ||
| models.CharField( | ||
| help_text="Slack timestamp of the message that triggered the alert.", | ||
| max_length=32, | ||
| ), | ||
| ), | ||
| ( | ||
| "report_type", | ||
| models.CharField( | ||
| help_text="Report category for the emitted reaction alert.", | ||
| max_length=64, | ||
| ), | ||
| ), | ||
| ("reaction_count", models.PositiveSmallIntegerField(default=0)), | ||
| ( | ||
| "alert_message_ts", | ||
| models.CharField( | ||
| blank=True, | ||
| default="", | ||
| help_text="Slack timestamp of the posted reaction alert message.", | ||
| max_length=32, | ||
| ), | ||
| ), | ||
| ( | ||
| "conversation", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, to="slack.conversation" | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "db_table": "slack_reaction_alerts", | ||
| "unique_together": {("conversation", "message_ts", "report_type")}, | ||
| }, | ||
| ), | ||
| migrations.CreateModel( | ||
| name="ReactionRule", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.BigAutoField( | ||
| auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
| ), | ||
| ), | ||
| ("nest_created_at", models.DateTimeField(auto_now_add=True)), | ||
| ("nest_updated_at", models.DateTimeField(auto_now=True)), | ||
| ( | ||
| "emoji_name", | ||
| models.CharField( | ||
| help_text="Slack emoji name that triggers this reaction rule.", | ||
| max_length=64, | ||
| ), | ||
| ), | ||
| ( | ||
| "report_type", | ||
| models.CharField( | ||
| help_text="Report category recorded when this reaction rule triggers.", | ||
| max_length=64, | ||
| ), | ||
| ), | ||
| ( | ||
| "threshold", | ||
| models.PositiveSmallIntegerField( | ||
| default=3, validators=[django.core.validators.MinValueValidator(1)] | ||
| ), | ||
| ), | ||
| ( | ||
| "alert_channel_id", | ||
| models.CharField( | ||
| help_text="Slack channel ID where reaction alerts are posted.", | ||
| max_length=50, | ||
| ), | ||
| ), | ||
| ("alert_user_ids", models.JSONField(blank=True, default=list)), | ||
| ("is_enabled", models.BooleanField(default=True)), | ||
| ( | ||
| "conversation", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, to="slack.conversation" | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "db_table": "slack_reaction_rules", | ||
| "unique_together": {("conversation", "emoji_name")}, | ||
| }, | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """Store emitted Slack reaction alerts.""" | ||
|
|
||
| from django.db import models | ||
|
|
||
| from apps.common.models import TimestampedModel | ||
| from apps.slack.models.conversation import Conversation | ||
|
|
||
|
|
||
| class ReactionAlert(TimestampedModel): | ||
| """Record that an alert was already sent for a reported message.""" | ||
|
|
||
| class Meta: | ||
| """Model options.""" | ||
|
|
||
| db_table = "slack_reaction_alerts" | ||
| unique_together = ("conversation", "message_ts", "report_type") | ||
|
|
||
| conversation = models.ForeignKey(Conversation, on_delete=models.CASCADE) | ||
| message_ts = models.CharField( | ||
| max_length=32, | ||
| help_text="Slack timestamp of the message that triggered the alert.", | ||
| ) | ||
| report_type = models.CharField( | ||
| max_length=64, | ||
| help_text="Report category for the emitted reaction alert.", | ||
| ) | ||
| reaction_count = models.PositiveSmallIntegerField(default=0) | ||
| alert_message_ts = models.CharField( | ||
| max_length=32, | ||
| blank=True, | ||
| default="", | ||
| help_text="Slack timestamp of the posted reaction alert message.", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| """Store channel-specific Slack reaction rules.""" | ||
|
|
||
| from typing import override | ||
|
|
||
| from django.core.validators import MinValueValidator | ||
| from django.db import models | ||
|
|
||
| from apps.common.models import TimestampedModel | ||
| from apps.slack.models.conversation import Conversation | ||
|
|
||
|
|
||
| class ReactionRule(TimestampedModel): | ||
| """Channel-specific emoji threshold and alert target.""" | ||
|
|
||
| class Meta: | ||
| """Model options.""" | ||
|
|
||
| db_table = "slack_reaction_rules" | ||
| unique_together = ("conversation", "emoji_name") | ||
|
|
||
| conversation = models.ForeignKey(Conversation, on_delete=models.CASCADE) | ||
| emoji_name = models.CharField( | ||
| max_length=64, | ||
| help_text="Slack emoji name that triggers this reaction rule.", | ||
| ) | ||
| report_type = models.CharField( | ||
| max_length=64, | ||
| help_text="Report category recorded when this reaction rule triggers.", | ||
| ) | ||
| threshold = models.PositiveSmallIntegerField(default=3, validators=[MinValueValidator(1)]) | ||
| alert_channel_id = models.CharField( | ||
| max_length=50, | ||
| help_text="Slack channel ID where reaction alerts are posted.", | ||
| ) | ||
| alert_user_ids = models.JSONField(blank=True, default=list) | ||
| is_enabled = models.BooleanField(default=True) | ||
|
|
||
| @override | ||
| def __str__(self): | ||
| return f"{self.conversation} :{self.emoji_name}" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.