Browse Source

Convert "flame" and "troll" tags to "malice"

No functionality impact yet, but changes these two tags into a single
one. The alembic migration is a bit tricky to deal with the potential
constraint violation if a user had tagged a comment with both "flame"
and "troll".
merge-requests/40/head
Deimos 6 years ago
parent
commit
b7962c5f65
  1. 51
      tildes/alembic/versions/1996feae620d_change_troll_and_flame_comment_tags_to_.py
  2. 3
      tildes/scss/_themes.scss
  3. 3
      tildes/scss/_variables.scss
  4. 8
      tildes/scss/modules/_btn.scss
  5. 3
      tildes/tildes/enums.py

51
tildes/alembic/versions/1996feae620d_change_troll_and_flame_comment_tags_to_.py

@ -0,0 +1,51 @@
"""Change Troll and Flame comment tags to Malice
Revision ID: 1996feae620d
Revises: b825165870d9
Create Date: 2018-09-18 00:42:30.213639
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "1996feae620d"
down_revision = "b825165870d9"
branch_labels = None
depends_on = None
def upgrade():
# ALTER TYPE doesn't work from inside a transaction, disable it
connection = None
if not op.get_context().as_sql:
connection = op.get_bind()
connection.execution_options(isolation_level="AUTOCOMMIT")
op.execute("ALTER TYPE commenttagoption ADD VALUE IF NOT EXISTS 'MALICE'")
# re-activate the transaction for any future migrations
if connection is not None:
connection.execution_options(isolation_level="READ_COMMITTED")
# delete all "flame" tags where the user also tagged the same comment as "troll"
# (so that we don't violate constraint when converting both to "malice")
op.execute(
"""
DELETE FROM comment_tags AS flame_tag
WHERE tag = 'FLAME' AND
EXISTS (SELECT * FROM comment_tags
WHERE user_id = flame_tag.user_id
AND comment_id = flame_tag.comment_id
AND tag = 'TROLL');
"""
)
# convert all the old "troll" and "flame" tags to "malice" ones
op.execute("UPDATE comment_tags SET tag = 'MALICE' WHERE tag IN ('FLAME', 'TROLL')")
def downgrade():
# not a proper revert, changing Malice back to Flame is about all we can do
op.execute("UPDATE comment_tags SET tag = 'FLAME' WHERE tag = 'MALICE'")

3
tildes/scss/_themes.scss

@ -121,8 +121,7 @@
.label-comment-tag-joke { @include specialtag($comment-tag-joke-color, $is-light); }
.label-comment-tag-noise { @include specialtag($comment-tag-noise-color, $is-light); }
.label-comment-tag-offtopic { @include specialtag($comment-tag-offtopic-color, $is-light); }
.label-comment-tag-troll { @include specialtag($comment-tag-troll-color, $is-light); }
.label-comment-tag-flame { @include specialtag($comment-tag-flame-color, $is-light); }
.label-comment-tag-malice { @include specialtag($comment-tag-malice-color, $is-light); }
}
%collapsed-theme {

3
tildes/scss/_variables.scss

@ -39,8 +39,7 @@ $topic-tag-spoiler-color: $yellow;
$comment-tag-joke-color: $cyan;
$comment-tag-noise-color: $yellow;
$comment-tag-offtopic-color: $orange;
$comment-tag-troll-color: $green;
$comment-tag-flame-color: $red;
$comment-tag-malice-color: $red;
$sidebar-width: 300px;

8
tildes/scss/modules/_btn.scss

@ -113,10 +113,6 @@
@include tagbutton($comment-tag-offtopic-color);
}
.btn-comment-tag-troll {
@include tagbutton($comment-tag-troll-color);
}
.btn-comment-tag-flame {
@include tagbutton($comment-tag-flame-color);
.btn-comment-tag-malice {
@include tagbutton($comment-tag-malice-color);
}

3
tildes/tildes/enums.py

@ -41,8 +41,7 @@ class CommentTagOption(enum.Enum):
JOKE = enum.auto()
NOISE = enum.auto()
OFFTOPIC = enum.auto()
TROLL = enum.auto()
FLAME = enum.auto()
MALICE = enum.auto()
class LogEventType(enum.Enum):

Loading…
Cancel
Save