diff --git a/tildes/alembic/versions/ec53997aff65_add_option_to_hide_scores.py b/tildes/alembic/versions/ec53997aff65_add_option_to_hide_scores.py new file mode 100644 index 0000000..691e208 --- /dev/null +++ b/tildes/alembic/versions/ec53997aff65_add_option_to_hide_scores.py @@ -0,0 +1,24 @@ +"""Add option to hide scores + +Revision ID: ec53997aff65 +Revises: +Create Date: 2018-07-18 17:28:08.273263 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'ec53997aff65' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column('users', sa.Column('hide_scores', sa.Boolean(), server_default='false', nullable=False)) + + +def downgrade(): + op.drop_column('users', 'hide_scores') diff --git a/tildes/tildes/models/user/user.py b/tildes/tildes/models/user/user.py index dd9dddc..659087b 100644 --- a/tildes/tildes/models/user/user.py +++ b/tildes/tildes/models/user/user.py @@ -82,6 +82,8 @@ class User(DatabaseModel): Boolean, nullable=False, server_default='false') auto_mark_notifications_read: bool = Column( Boolean, nullable=False, server_default='false') + hide_scores: bool = Column( + Boolean, nullable=False, server_default='false') is_banned: bool = Column(Boolean, nullable=False, server_default='false') is_admin: bool = Column(Boolean, nullable=False, server_default='false') home_default_order: Optional[TopicSortOption] = Column( diff --git a/tildes/tildes/templates/macros/comments.jinja2 b/tildes/tildes/templates/macros/comments.jinja2 index 5f7c3dc..18d6ad6 100644 --- a/tildes/tildes/templates/macros/comments.jinja2 +++ b/tildes/tildes/templates/macros/comments.jinja2 @@ -73,7 +73,7 @@ {% if request.has_permission('view', comment) %} {# Show votes at the top only if it's your own comment #} - {% if request.user == comment.user and comment.num_votes > 0 %} + {% if request.user == comment.user and comment.num_votes > 0 and not request.user.hide_scores %} {{ comment.num_votes }} votes {% endif %} @@ -115,7 +115,7 @@ data-ic-target="#comment-{{ comment.comment_id36 }} .comment-itself:first" >Vote {% endif %} - {% if comment.num_votes > 0 %} + {% if comment.num_votes > 0 and not request.user.hide_scores %} ({{ comment.num_votes }}) {% endif %} diff --git a/tildes/tildes/templates/macros/topics.jinja2 b/tildes/tildes/templates/macros/topics.jinja2 index 092ef4e..b5b7c56 100644 --- a/tildes/tildes/templates/macros/topics.jinja2 +++ b/tildes/tildes/templates/macros/topics.jinja2 @@ -106,7 +106,13 @@ {# Hide voting from the topic's author if it has zero votes #} {% if request.user != topic.user or topic.num_votes > 0 %} - {{ topic.num_votes }} + + {% if not request.user.hide_scores %} + {{ topic.num_votes }} + {% else %} + - + {% endif %} + {% trans num_votes=topic.num_votes %} vote diff --git a/tildes/tildes/templates/settings.jinja2 b/tildes/tildes/templates/settings.jinja2 index 0b6c85f..6897bd2 100644 --- a/tildes/tildes/templates/settings.jinja2 +++ b/tildes/tildes/templates/settings.jinja2 @@ -37,6 +37,26 @@ +
  • +
    +
    + +
    +
    +
  • Change your password
  • Set up account recovery diff --git a/tildes/tildes/views/api/web/user.py b/tildes/tildes/views/api/web/user.py index 06bb8e2..8e25322 100644 --- a/tildes/tildes/views/api/web/user.py +++ b/tildes/tildes/views/api/web/user.py @@ -104,6 +104,22 @@ def change_auto_mark_notifications(request: Request) -> Response: return IC_NOOP +@ic_view_config( + route_name='user', + request_method='PATCH', + request_param='ic-trigger-name=hide-scores', + permission='change_hide_scores_setting,' +) +def change_hide_scores(request: Request) -> Response: + """Change the user's "hide scores" setting.""" + user = request.context + + hide = bool(request.params.get('hide_scores')) + user.hide_scores = hide + + return IC_NOOP + + @ic_view_config( route_name='user', request_method='PATCH',