Browse Source

Prevent top-level comments in old scheduled topics

By default, new top-level comments will only be allowed in the latest
topic from a particular set of scheduled topics. Replies to existing
comments in old topics will still be allowed - this is just intended to
prevent the cases where an old scheduled topic gets bumped back up due
to a reply and people inadvertently start adding new top-level comments
to it instead of the latest one.

This should be the correct behavior for most scheduled topics, but it
can be disabled for a particular schedule if needed.
merge-requests/106/head
Deimos 4 years ago
parent
commit
c4af5c7d57
  1. 32
      tildes/alembic/versions/0435c46f64d8_topic_schedule_add_only_new_top_level_.py
  2. 10
      tildes/tildes/models/topic/topic.py
  3. 13
      tildes/tildes/models/topic/topic_schedule.py
  4. 7
      tildes/tildes/templates/topic.jinja2

32
tildes/alembic/versions/0435c46f64d8_topic_schedule_add_only_new_top_level_.py

@ -0,0 +1,32 @@
"""topic_schedule: add only_new_top_level_comments_in_latest
Revision ID: 0435c46f64d8
Revises: 468cf81f4a6b
Create Date: 2020-07-05 19:33:17.746617
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "0435c46f64d8"
down_revision = "468cf81f4a6b"
branch_labels = None
depends_on = None
def upgrade():
op.add_column(
"topic_schedule",
sa.Column(
"only_new_top_level_comments_in_latest",
sa.Boolean(),
server_default="true",
nullable=False,
),
)
def downgrade():
op.drop_column("topic_schedule", "only_new_top_level_comments_in_latest")

10
tildes/tildes/models/topic/topic.py

@ -315,6 +315,9 @@ class Topic(DatabaseModel):
# comment: # comment:
# - removed topics can only be commented on by users who can remove # - removed topics can only be commented on by users who can remove
# - locked topics can only be commented on by users who can lock # - locked topics can only be commented on by users who can lock
# - topics posted by the scheduler can only be commented in if they're the
# latest topic from that schedule, or only_new_top_level_comments_in_latest
# is False
# - otherwise, logged-in users can comment # - otherwise, logged-in users can comment
if self.is_removed: if self.is_removed:
acl.extend( acl.extend(
@ -336,6 +339,13 @@ class Topic(DatabaseModel):
) )
acl.append((Deny, Everyone, "comment")) acl.append((Deny, Everyone, "comment"))
if (
self.was_posted_by_scheduler
and self.schedule.only_new_top_level_comments_in_latest
and self.topic_id != self.schedule.latest_topic_id
):
acl.append((Deny, Everyone, "comment"))
acl.append((Allow, Authenticated, "comment")) acl.append((Allow, Authenticated, "comment"))
# edit: # edit:

13
tildes/tildes/models/topic/topic_schedule.py

@ -8,7 +8,15 @@ from typing import List, Optional
from dateutil.rrule import rrule from dateutil.rrule import rrule
from jinja2.sandbox import SandboxedEnvironment from jinja2.sandbox import SandboxedEnvironment
from sqlalchemy import CheckConstraint, Column, ForeignKey, Integer, Text, TIMESTAMP
from sqlalchemy import (
Boolean,
CheckConstraint,
Column,
ForeignKey,
Integer,
Text,
TIMESTAMP,
)
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.orm.session import Session from sqlalchemy.orm.session import Session
from sqlalchemy.sql.expression import text from sqlalchemy.sql.expression import text
@ -52,6 +60,9 @@ class TopicSchedule(DatabaseModel):
TIMESTAMP(timezone=True), nullable=True, index=True TIMESTAMP(timezone=True), nullable=True, index=True
) )
recurrence_rule: Optional[rrule] = Column(RecurrenceRule, nullable=True) recurrence_rule: Optional[rrule] = Column(RecurrenceRule, nullable=True)
only_new_top_level_comments_in_latest: bool = Column(
Boolean, nullable=False, server_default="true"
)
latest_topic_id: int = Column(Integer, ForeignKey("topics.topic_id"), nullable=True) latest_topic_id: int = Column(Integer, ForeignKey("topics.topic_id"), nullable=True)
group: Group = relationship("Group", innerjoin=True) group: Group = relationship("Group", innerjoin=True)

7
tildes/tildes/templates/topic.jinja2

@ -288,6 +288,13 @@
</div> </div>
</form> </form>
</section> </section>
{% elif topic.was_posted_by_scheduler
and topic.schedule.only_new_top_level_comments_in_latest
and topic != topic.schedule.latest_topic %}
<div class="divider"></div>
<p class="text-small">This is an older topic in a scheduled series, and is closed to new top-level comments.</p>
<p class="text-small">To respond, <a href="{{ topic.schedule.latest_topic.permalink }}">go to the most recent topic in the series</a> instead.</p>
{% endif %} {% endif %}
</article> </article>

Loading…
Cancel
Save