pull/6/head
Yax 3 years ago
parent 938fe0b4e9
commit bf1447a3a9

@ -7,10 +7,9 @@ import argparse
import logging import logging
from stacosys.conf.config import Config, ConfigParameter from stacosys.conf.config import Config, ConfigParameter
from stacosys.core import database from stacosys.db import database
from stacosys.core.rss import Rss from stacosys.core.rss import Rss
from stacosys.core.mailer import Mailer from stacosys.core.mailer import Mailer
from stacosys.core.mailer import SSLSMTPHandler
from stacosys.interface import app from stacosys.interface import app
from stacosys.interface import api from stacosys.interface import api
from stacosys.interface import form from stacosys.interface import form

@ -10,6 +10,7 @@ from stacosys.model.comment import Comment
from stacosys.model.email import Email from stacosys.model.email import Email
from stacosys.core.rss import Rss from stacosys.core.rss import Rss
from stacosys.core.mailer import Mailer from stacosys.core.mailer import Mailer
from stacosys.db import dao
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -29,40 +30,40 @@ def _reply_comment_email(lang, mailer: Mailer, rss: Rss, email: Email, site_toke
m = re.search(r"\[(\d+)\:(\w+)\]", email.subject) m = re.search(r"\[(\d+)\:(\w+)\]", email.subject)
if not m: if not m:
logger.warn("ignore corrupted email. No token %s" % email.subject) logger.warning("ignore corrupted email. No token %s" % email.subject)
return return
comment_id = int(m.group(1)) comment_id = int(m.group(1))
token = m.group(2) token = m.group(2)
if token != site_token: if token != site_token:
logger.warn("ignore corrupted email. Unknown token %d" % comment_id) logger.warning("ignore corrupted email. Unknown token %d" % comment_id)
return return
# retrieve site and comment rows # retrieve site and comment rows
comment = Comment.get_by_id(comment_id) comment = Comment
if not comment: if not comment:
logger.warn("unknown comment %d" % comment_id) logger.warning("unknown comment %d" % comment_id)
return True return True
if comment.published: if comment.published:
logger.warn("ignore already published email. token %d" % comment_id) logger.warning("ignore already published email. token %d" % comment_id)
return return
if not email.plain_text_content: if not email.plain_text_content:
logger.warn("ignore empty email") logger.warning("ignore empty email")
return return
# safe logic: no answer or unknown answer is a go for publishing # safe logic: no answer or unknown answer is a go for publishing
if email.plain_text_content[:2].upper() in ("NO"): if email.plain_text_content[:2].upper() == "NO":
logger.info("discard comment: %d" % comment_id) logger.info("discard comment: %d" % comment_id)
comment.delete_instance() comment.delete_instance()
new_email_body = templater.get_template(lang, Template.DROP_COMMENT).render( new_email_body = templater.get_template(lang, Template.DROP_COMMENT).render(
original=email.plain_text_content original=email.plain_text_content
) )
if not mailer.send(email.from_addr, "Re: " + email.subject, new_email_body): if not mailer.send(email.from_addr, "Re: " + email.subject, new_email_body):
logger.warn("minor failure. cannot send rejection mail " + email.subject) logger.warning("minor failure. cannot send rejection mail " + email.subject)
else: else:
# save publishing datetime # save publishing datetime
comment.publish() dao.publish(comment)
logger.info("commit comment: %d" % comment_id) logger.info("commit comment: %d" % comment_id)
# rebuild RSS # rebuild RSS
@ -73,7 +74,7 @@ def _reply_comment_email(lang, mailer: Mailer, rss: Rss, email: Email, site_toke
original=email.plain_text_content original=email.plain_text_content
) )
if not mailer.send(email.from_addr, "Re: " + email.subject, new_email_body): if not mailer.send(email.from_addr, "Re: " + email.subject, new_email_body):
logger.warn("minor failure. cannot send approval email " + email.subject) logger.warning("minor failure. cannot send approval email " + email.subject)
return True return True
@ -100,6 +101,6 @@ def submit_new_comment(lang, site_name, site_token, site_admin_email, mailer):
logger.debug("new comment processed ") logger.debug("new comment processed ")
# notify site admin and save notification datetime # notify site admin and save notification datetime
comment.notify_site_admin() dao.notify_site_admin(comment)
else: else:
logger.warn("rescheduled. send mail failure " + subject) logger.warning("rescheduled. send mail failure " + subject)

@ -0,0 +1,18 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from datetime import datetime
from stacosys.model.comment import Comment
def notify_site_admin(comment: Comment):
comment.notified = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
comment.save()
def publish(comment: Comment):
comment.published = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
comment.save()

@ -5,7 +5,7 @@ from peewee import CharField
from peewee import TextField from peewee import TextField
from peewee import DateTimeField from peewee import DateTimeField
from datetime import datetime from datetime import datetime
from stacosys.core.database import BaseModel from stacosys.db.database import BaseModel
class Comment(BaseModel): class Comment(BaseModel):
@ -17,11 +17,3 @@ class Comment(BaseModel):
author_site = CharField(default="") author_site = CharField(default="")
author_gravatar = CharField(default="") author_gravatar = CharField(default="")
content = TextField() content = TextField()
def notify_site_admin(self):
self.notified = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
self.save()
def publish(self):
self.published = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
self.save()

Loading…
Cancel
Save