add private mode

pull/6/head
Yax 7 years ago
parent 7718776ae8
commit 34f10baae2

@ -7,7 +7,6 @@ from flask import request, jsonify, abort
from app import app from app import app
from app.models.site import Site from app.models.site import Site
from app.models.comment import Comment from app.models.comment import Comment
from app.helpers.hashing import md5
from app.services import processor from app.services import processor
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -31,8 +30,7 @@ def query_comments():
d['content'] = comment.content d['content'] = comment.content
if comment.author_site: if comment.author_site:
d['site'] = comment.author_site d['site'] = comment.author_site
if comment.author_email: d['avatar'] = comment.author_gravatar
d['avatar'] = md5(comment.author_email.strip().lower())
d['date'] = comment.published.strftime("%Y-%m-%d %H:%M:%S") d['date'] = comment.published.strftime("%Y-%m-%d %H:%M:%S")
logger.debug(d) logger.debug(d)
comments.append(d) comments.append(d)

@ -17,6 +17,7 @@ class Comment(Model):
author_name = CharField() author_name = CharField()
author_email = CharField(default='') author_email = CharField(default='')
author_site = CharField(default='') author_site = CharField(default='')
author_gravatar = CharField(default='')
content = TextField() content = TextField()
site = ForeignKeyField(Site, related_name='site') site = ForeignKeyField(Site, related_name='site')

@ -4,7 +4,6 @@
import os import os
import sys import sys
import logging import logging
from werkzeug.contrib.fixers import ProxyFix
from flask.ext.cors import CORS from flask.ext.cors import CORS
# add current path and parent path to syspath # add current path and parent path to syspath
@ -23,7 +22,6 @@ from app.controllers import api
from app.controllers import form from app.controllers import form
from app.controllers import report from app.controllers import report
from app.controllers import mail from app.controllers import mail
from app.controllers import reader
from app import app from app import app
@ -49,26 +47,36 @@ logger = logging.getLogger(__name__)
# initialize database # initialize database
database.setup() database.setup()
#from app.helpers.hashing import md5
#from app.models.comment import Comment
#for comment in Comment.select():
# email = comment.author_email.strip().lower()
# if email:
# comment.author_gravatar = md5(email)
# comment.author_email = ''
# comment.save()
# routes # routes
logger.debug('imported: %s ' % api.__name__) logger.debug('imported: %s ' % api.__name__)
logger.debug('imported: %s ' % mail.__name__) logger.debug('imported: %s ' % mail.__name__)
logger.debug('imported: %s ' % reader.__name__)
# start processor # start processor
template_path = os.path.abspath(os.path.join(current_path, 'templates')) template_path = os.path.abspath(os.path.join(current_path, 'templates'))
processor.start(template_path) processor.start(template_path)
logger.info("Start Stacosys application") # less feature in private mode
if not config.PRIVATE:
# enable CORS # enable CORS
cors = CORS(app, resources={r"/comments/*": {"origins": "*"}}) cors = CORS(app, resources={r"/comments/*": {"origins": "*"}})
from app.controllers import reader
logger.debug('imported: %s ' % reader.__name__)
# tune logging level # tune logging level
if not config.DEBUG: if not config.DEBUG:
logging.getLogger('app.cors').level = logging.WARNING logging.getLogger('app.cors').level = logging.WARNING
logging.getLogger('werkzeug').level = logging.WARNING logging.getLogger('werkzeug').level = logging.WARNING
app.wsgi_app = ProxyFix(app.wsgi_app) logger.info("Start Stacosys application")
if __name__ == '__main__': if __name__ == '__main__':

@ -10,9 +10,9 @@ from queue import Queue
from jinja2 import Environment from jinja2 import Environment
from jinja2 import FileSystemLoader from jinja2 import FileSystemLoader
from app.models.site import Site from app.models.site import Site
from app.models.comment import Comment
from app.models.reader import Reader from app.models.reader import Reader
from app.models.report import Report from app.models.report import Report
from app.helpers.hashing import md5
import requests import requests
import json import json
import config import config
@ -68,6 +68,13 @@ def new_comment(data):
message = data.get('message', '') message = data.get('message', '')
subscribe = data.get('subscribe', '') subscribe = data.get('subscribe', '')
# private mode: email contains gravar md5 hash
if config.PRIVATE:
author_gravatar = author_email
author_email = ''
else:
author_gravatar = md5(author_email.lower())
# create a new comment row # create a new comment row
site = Site.select().where(Site.token == token).get() site = Site.select().where(Site.token == token).get()
@ -79,6 +86,7 @@ def new_comment(data):
# add a row to Comment table # add a row to Comment table
comment = Comment(site=site, url=url, author_name=author_name, comment = Comment(site=site, url=url, author_name=author_name,
author_site=author_site, author_email=author_email, author_site=author_site, author_email=author_email,
author_gravatar=author_gravatar,
content=message, created=created, published=None) content=message, created=created, published=None)
comment.save() comment.save()
@ -104,7 +112,7 @@ def new_comment(data):
mail(site.admin_email, subject, email_body) mail(site.admin_email, subject, email_body)
# Reader subscribes to further comments # Reader subscribes to further comments
if subscribe and author_email: if not config.PRIVATE and subscribe and author_email:
subscribe_reader(author_email, token, url) subscribe_reader(author_email, token, url)
logger.debug("new comment processed ") logger.debug("new comment processed ")
@ -163,14 +171,15 @@ def reply_comment_email(data):
mail(from_email, 'Re: ' + subject, email_body) mail(from_email, 'Re: ' + subject, email_body)
# notify reader once comment is published # notify reader once comment is published
reader_email = get_email_metadata(message) if not config.PRIVATE:
if reader_email: reader_email = get_email_metadata(message)
notify_reader(from_email, reader_email, comment.site.token, if reader_email:
comment.site.url, comment.url) notify_reader(from_email, reader_email, comment.site.token,
comment.site.url, comment.url)
# notify subscribers every time a new comment is published
notify_subscribed_readers( # notify subscribers every time a new comment is published
comment.site.token, comment.site.url, comment.url) notify_subscribed_readers(
comment.site.token, comment.site.url, comment.url)
def late_reject_comment(id): def late_reject_comment(id):

@ -12,7 +12,6 @@ MAIL_URL = "http://localhost:8025/mbox"
HTTP_ADDRESS = "127.0.0.1" HTTP_ADDRESS = "127.0.0.1"
HTTP_PORT = 8100 HTTP_PORT = 8100
HTTP_WORKERS = 1 HTTP_WORKERS = 1
CORS_ORIGIN = "*"
SALT = "BRRJRqXgGpXWrgTidBPcixIThHpDuKc0" SALT = "BRRJRqXgGpXWrgTidBPcixIThHpDuKc0"
@ -22,3 +21,5 @@ ROOT_URL = 'http://localhost:8100'
RSS_URL_PROTO = 'http' RSS_URL_PROTO = 'http'
RSS_FILE = 'comments.xml' RSS_FILE = 'comments.xml'
PRIVATE = True
Loading…
Cancel
Save