Add notification type for bot messages

This commit is contained in:
rubenwardy 2020-12-15 22:00:46 +00:00
parent 09a9219fcd
commit 6e763b8453
4 changed files with 46 additions and 4 deletions

@ -956,4 +956,6 @@ class PackageUpdateConfig(db.Model):
outdated = db.Column(db.Boolean, nullable=False, default=False)
trigger = db.Column(db.Enum(PackageUpdateTrigger), nullable=False, default=PackageUpdateTrigger.COMMIT)
ref = db.Column(db.String(41), nullable=True, default=None)
make_release = db.Column(db.Boolean, nullable=False, default=False)

@ -313,14 +313,17 @@ class NotificationType(enum.Enum):
# Posted reply to subscribed thread
THREAD_REPLY = 5
# A bot notification
BOT = 6
# Added / removed as maintainer
MAINTAINER = 6
MAINTAINER = 7
# Editor misc
EDITOR_ALERT = 7
EDITOR_ALERT = 8
# Editor misc
EDITOR_MISC = 8
EDITOR_MISC = 9
# Any other
OTHER = 0
@ -343,6 +346,8 @@ class NotificationType(enum.Enum):
return "When a user posts a review on your package."
elif self == NotificationType.THREAD_REPLY:
return "When someone replies to a thread you're watching."
elif self == NotificationType.BOT:
return "From a bot - for example, update notifications."
elif self == NotificationType.MAINTAINER:
return "When your package's maintainers change."
elif self == NotificationType.EDITOR_ALERT:
@ -424,6 +429,7 @@ class UserNotificationPreferences(db.Model):
pref_new_thread = db.Column(db.Integer, nullable=False)
pref_new_review = db.Column(db.Integer, nullable=False)
pref_thread_reply = db.Column(db.Integer, nullable=False)
pref_bot = db.Column(db.Integer, nullable=False)
pref_maintainer = db.Column(db.Integer, nullable=False)
pref_editor_alert = db.Column(db.Integer, nullable=False)
pref_editor_misc = db.Column(db.Integer, nullable=False)
@ -436,6 +442,7 @@ class UserNotificationPreferences(db.Model):
self.pref_new_thread = 1
self.pref_new_review = 1
self.pref_thread_reply = 2
self.pref_bot = 1
self.pref_maintainer = 1
self.pref_editor_alert = 1
self.pref_editor_misc = 0

@ -276,7 +276,7 @@ def post_system_thread(package: Package, title: str, message: str):
reply.comment = "# {}\n\n{}".format(title, message)
db.session.add(reply)
addNotification(thread.watchers, system_user, NotificationType.THREAD_REPLY,
addNotification(thread.watchers, system_user, NotificationType.BOT,
title, thread.getViewURL(), thread.package)
thread.replies.append(reply)

@ -0,0 +1,33 @@
"""empty message
Revision ID: f565dde93553
Revises: 4585ce5147b8
Create Date: 2020-12-15 21:49:19.190893
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = 'f565dde93553'
down_revision = '4585ce5147b8'
branch_labels = None
depends_on = None
def upgrade():
op.add_column('package_update_config', sa.Column('ref', sa.String(length=41), nullable=True))
op.add_column('user_notification_preferences', sa.Column('pref_bot', sa.Integer(), nullable=True, server_default=None))
op.execute("""UPDATE user_notification_preferences SET pref_bot=pref_new_thread""")
op.alter_column('user_notification_preferences', 'pref_bot',
existing_type=sa.INTEGER(),
nullable=False)
op.execute("COMMIT")
op.execute("ALTER TYPE notificationtype ADD VALUE 'BOT'")
def downgrade():
op.drop_column('user_notification_preferences', 'pref_bot')
op.drop_column('package_update_config', 'ref')