Browse Source

Log comment post events

merge-requests/34/head
Chad Birch 6 years ago
parent
commit
b4402d32e9
  1. 35
      tildes/alembic/versions/6a635773de8f_add_comment_post_to_logeventtype.py
  2. 2
      tildes/tildes/enums.py
  3. 7
      tildes/tildes/views/api/web/comment.py
  4. 8
      tildes/tildes/views/topic.py

35
tildes/alembic/versions/6a635773de8f_add_comment_post_to_logeventtype.py

@ -0,0 +1,35 @@
"""Add COMMENT_POST to logeventtype
Revision ID: 6a635773de8f
Revises: b3be50625592
Create Date: 2018-08-26 01:56:13.511360
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "6a635773de8f"
down_revision = "b3be50625592"
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 logeventtype ADD VALUE IF NOT EXISTS 'COMMENT_POST'")
# re-activate the transaction for any future migrations
if connection is not None:
connection.execution_options(isolation_level="READ_COMMITTED")
def downgrade():
# can't remove from enums, do nothing
pass

2
tildes/tildes/enums.py

@ -48,6 +48,8 @@ class LogEventType(enum.Enum):
USER_LOG_OUT = enum.auto() USER_LOG_OUT = enum.auto()
USER_REGISTER = enum.auto() USER_REGISTER = enum.auto()
COMMENT_POST = enum.auto()
TOPIC_LOCK = enum.auto() TOPIC_LOCK = enum.auto()
TOPIC_MOVE = enum.auto() TOPIC_MOVE = enum.auto()
TOPIC_POST = enum.auto() TOPIC_POST = enum.auto()

7
tildes/tildes/views/api/web/comment.py

@ -10,9 +10,10 @@ from sqlalchemy.orm.exc import FlushError
from webargs.pyramidparser import use_kwargs from webargs.pyramidparser import use_kwargs
from zope.sqlalchemy import mark_changed from zope.sqlalchemy import mark_changed
from tildes.enums import CommentNotificationType, CommentTagOption
from tildes.enums import CommentNotificationType, CommentTagOption, LogEventType
from tildes.lib.datetime import utc_now from tildes.lib.datetime import utc_now
from tildes.models.comment import Comment, CommentNotification, CommentTag, CommentVote from tildes.models.comment import Comment, CommentNotification, CommentTag, CommentVote
from tildes.models.log import LogComment
from tildes.models.topic import TopicVisit from tildes.models.topic import TopicVisit
from tildes.schemas.comment import CommentSchema, CommentTagSchema from tildes.schemas.comment import CommentSchema, CommentTagSchema
from tildes.views import IC_NOOP from tildes.views import IC_NOOP
@ -65,6 +66,8 @@ def post_toplevel_comment(request: Request, markdown: str) -> dict:
new_comment = Comment(topic=topic, author=request.user, markdown=markdown) new_comment = Comment(topic=topic, author=request.user, markdown=markdown)
request.db_session.add(new_comment) request.db_session.add(new_comment)
request.db_session.add(LogComment(LogEventType.COMMENT_POST, request, new_comment))
if topic.user != request.user and not topic.is_deleted: if topic.user != request.user and not topic.is_deleted:
notification = CommentNotification( notification = CommentNotification(
topic.user, new_comment, CommentNotificationType.TOPIC_REPLY topic.user, new_comment, CommentNotificationType.TOPIC_REPLY
@ -103,6 +106,8 @@ def post_comment_reply(request: Request, markdown: str) -> dict:
) )
request.db_session.add(new_comment) request.db_session.add(new_comment)
request.db_session.add(LogComment(LogEventType.COMMENT_POST, request, new_comment))
if parent_comment.user != request.user: if parent_comment.user != request.user:
notification = CommentNotification( notification = CommentNotification(
parent_comment.user, new_comment, CommentNotificationType.COMMENT_REPLY parent_comment.user, new_comment, CommentNotificationType.COMMENT_REPLY

8
tildes/tildes/views/topic.py

@ -23,7 +23,7 @@ from tildes.enums import (
from tildes.lib.datetime import SimpleHoursPeriod from tildes.lib.datetime import SimpleHoursPeriod
from tildes.models.comment import Comment, CommentNotification, CommentTree from tildes.models.comment import Comment, CommentNotification, CommentTree
from tildes.models.group import Group from tildes.models.group import Group
from tildes.models.log import LogTopic
from tildes.models.log import LogComment, LogTopic
from tildes.models.topic import Topic, TopicVisit from tildes.models.topic import Topic, TopicVisit
from tildes.models.user import UserGroupSettings from tildes.models.user import UserGroupSettings
from tildes.schemas.comment import CommentSchema from tildes.schemas.comment import CommentSchema
@ -55,6 +55,10 @@ def post_group_topics(
topic=new_topic, author=request.user, markdown=markdown topic=new_topic, author=request.user, markdown=markdown
) )
request.db_session.add(new_comment) request.db_session.add(new_comment)
request.db_session.add(
LogComment(LogEventType.COMMENT_POST, request, new_comment)
)
else: else:
new_topic = Topic.create_text_topic( new_topic = Topic.create_text_topic(
group=request.context, author=request.user, title=title, markdown=markdown group=request.context, author=request.user, title=title, markdown=markdown
@ -295,6 +299,8 @@ def post_comment_on_topic(request: Request, markdown: str) -> HTTPFound:
new_comment = Comment(topic=topic, author=request.user, markdown=markdown) new_comment = Comment(topic=topic, author=request.user, markdown=markdown)
request.db_session.add(new_comment) request.db_session.add(new_comment)
request.db_session.add(LogComment(LogEventType.COMMENT_POST, request, new_comment))
if topic.user != request.user and not topic.is_deleted: if topic.user != request.user and not topic.is_deleted:
notification = CommentNotification( notification = CommentNotification(
topic.user, new_comment, CommentNotificationType.TOPIC_REPLY topic.user, new_comment, CommentNotificationType.TOPIC_REPLY

Loading…
Cancel
Save