From 6e763b845395da4ad9f1f1a1cddbe7fd3c2acf57 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 15 Dec 2020 22:00:46 +0000 Subject: [PATCH] Add notification type for bot messages --- app/models/packages.py | 2 ++ app/models/users.py | 13 ++++++++--- app/utils.py | 2 +- migrations/versions/f565dde93553_.py | 33 ++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/f565dde93553_.py diff --git a/app/models/packages.py b/app/models/packages.py index 260f9e2b..2afb6112 100644 --- a/app/models/packages.py +++ b/app/models/packages.py @@ -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) diff --git a/app/models/users.py b/app/models/users.py index 63f5e523..a199715a 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -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 diff --git a/app/utils.py b/app/utils.py index d8d58741..d81b34ec 100644 --- a/app/utils.py +++ b/app/utils.py @@ -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) diff --git a/migrations/versions/f565dde93553_.py b/migrations/versions/f565dde93553_.py new file mode 100644 index 00000000..1bc7e9b5 --- /dev/null +++ b/migrations/versions/f565dde93553_.py @@ -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')