From ba19809c52e81b81e390fd426c8caf18345f0135 Mon Sep 17 00:00:00 2001 From: Deimos Date: Fri, 8 Mar 2019 16:20:08 -0700 Subject: [PATCH] Allow groups to always show user as topic source This will allow individual groups to always show the username on topics, overriding the usual behavior of only showing username when it's a text topic. On Tildes itself, this will be useful for groups like ~creative. --- ...144_group_add_is_user_treated_as_topic_.py | 36 +++++++++++++++++++ tildes/tildes/models/group/group.py | 3 ++ tildes/tildes/models/topic/topic.py | 3 ++ 3 files changed, 42 insertions(+) create mode 100644 tildes/alembic/versions/7ac1aad64144_group_add_is_user_treated_as_topic_.py diff --git a/tildes/alembic/versions/7ac1aad64144_group_add_is_user_treated_as_topic_.py b/tildes/alembic/versions/7ac1aad64144_group_add_is_user_treated_as_topic_.py new file mode 100644 index 0000000..914d72e --- /dev/null +++ b/tildes/alembic/versions/7ac1aad64144_group_add_is_user_treated_as_topic_.py @@ -0,0 +1,36 @@ +"""Group: add is_user_treated_as_topic_source + +Revision ID: 7ac1aad64144 +Revises: 61f43e57679a +Create Date: 2019-03-08 23:02:33.848382 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "7ac1aad64144" +down_revision = "61f43e57679a" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "groups", + sa.Column( + "is_user_treated_as_topic_source", + sa.Boolean(), + server_default="false", + nullable=False, + ), + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("groups", "is_user_treated_as_topic_source") + # ### end Alembic commands ### diff --git a/tildes/tildes/models/group/group.py b/tildes/tildes/models/group/group.py index 09cd025..a592b7e 100644 --- a/tildes/tildes/models/group/group.py +++ b/tildes/tildes/models/group/group.py @@ -47,6 +47,9 @@ class Group(DatabaseModel): is_admin_posting_only: bool = Column( Boolean, nullable=False, server_default="false" ) + is_user_treated_as_topic_source: bool = Column( + Boolean, nullable=False, server_default="false" + ) # Create a GiST index on path as well as the btree one that will be created by the # index=True/unique=True keyword args to Column above. The GiST index supports diff --git a/tildes/tildes/models/topic/topic.py b/tildes/tildes/models/topic/topic.py index 2ba8154..9cc8809 100644 --- a/tildes/tildes/models/topic/topic.py +++ b/tildes/tildes/models/topic/topic.py @@ -452,4 +452,7 @@ class Topic(DatabaseModel): @property def is_user_treated_as_source(self) -> bool: """Return whether the user that posted the topic is its "source".""" + if self.group.is_user_treated_as_topic_source: + return True + return self.is_text_type