From 60ce4ec3f1073fee0515d867b591c3d3d6c59c28 Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Mon, 26 Mar 2018 02:03:49 +0200 Subject: [PATCH] Implement comment locking (#439) * Implement comment locking This adds a new flags to torrents, which is only editable by moderators and admins. If checked, it does not allow unprivileged users to post, edit or delete comments on that torrent. * Rename "locked" to "comment_locked". * Shorter button and additional words on alt text * Admin log: Change comment locking message dude I love bikeshedding xd * Bikeshedding over admin log messages * >& Also some bikeshedding --- nyaa/backend.py | 4 ++++ nyaa/forms.py | 2 ++ nyaa/models.py | 2 ++ nyaa/templates/edit.html | 8 ++++++++ nyaa/templates/help.html | 2 +- nyaa/templates/view.html | 12 ++++++++++-- nyaa/views/torrents.py | 23 +++++++++++++++++++++-- 7 files changed, 48 insertions(+), 5 deletions(-) diff --git a/nyaa/backend.py b/nyaa/backend.py index c3f6212..8ed7cde 100644 --- a/nyaa/backend.py +++ b/nyaa/backend.py @@ -218,6 +218,10 @@ def handle_torrent_upload(upload_form, uploading_user=None, fromAPI=False): # To do, automatically mark trusted if user is trusted unless user specifies otherwise torrent.trusted = upload_form.is_trusted.data if can_mark_trusted else False + # Only allow mods to upload locked torrents + can_mark_locked = uploading_user and uploading_user.is_moderator + torrent.comment_locked = upload_form.is_comment_locked.data if can_mark_locked else False + # Set category ids torrent.main_category_id, torrent.sub_category_id = \ upload_form.category.parsed_data.get_category_ids() diff --git a/nyaa/forms.py b/nyaa/forms.py index 5f62d03..68ec1ad 100644 --- a/nyaa/forms.py +++ b/nyaa/forms.py @@ -263,6 +263,7 @@ class EditForm(FlaskForm): is_anonymous = BooleanField('Anonymous') is_complete = BooleanField('Complete') is_trusted = BooleanField('Trusted') + is_comment_locked = BooleanField('Lock Comments') information = StringField('Information', [ Length(max=255, message='Information must be at most %(max)d characters long.') @@ -338,6 +339,7 @@ class UploadForm(FlaskForm): is_anonymous = BooleanField('Anonymous') is_complete = BooleanField('Complete') is_trusted = BooleanField('Trusted') + is_comment_locked = BooleanField('Lock Comments') information = StringField('Information', [ Length(max=255, message='Information must be at most %(max)d characters long.') diff --git a/nyaa/models.py b/nyaa/models.py index a11f656..5e846d9 100644 --- a/nyaa/models.py +++ b/nyaa/models.py @@ -100,6 +100,7 @@ class TorrentFlags(IntEnum): COMPLETE = 16 DELETED = 32 BANNED = 64 + COMMENT_LOCKED = 128 class TorrentBase(DeclarativeHelperBase): @@ -259,6 +260,7 @@ class TorrentBase(DeclarativeHelperBase): trusted = FlagProperty(TorrentFlags.TRUSTED) remake = FlagProperty(TorrentFlags.REMAKE) complete = FlagProperty(TorrentFlags.COMPLETE) + comment_locked = FlagProperty(TorrentFlags.COMMENT_LOCKED) # Class methods diff --git a/nyaa/templates/edit.html b/nyaa/templates/edit.html index 065df0e..b6d55ef 100644 --- a/nyaa/templates/edit.html +++ b/nyaa/templates/edit.html @@ -68,6 +68,14 @@ Trusted {% endif %} + {% if g.user.is_moderator %} + + {% endif %} diff --git a/nyaa/templates/help.html b/nyaa/templates/help.html index 012ccfd..7854feb 100644 --- a/nyaa/templates/help.html +++ b/nyaa/templates/help.html @@ -105,7 +105,7 @@ {{ linkable_header("IRC Help Channel Policies", "irchelp") }}

Our IRC help channel is at Rizon #nyaa-help. A webchat link - pre-filled with our channel is available right here.

+ pre-filled with our channel is available right here.

Read this to avoid getting banned: