add private mode
This commit is contained in:
parent
3e15b83d2a
commit
f05bfb8383
5 changed files with 38 additions and 21 deletions
|
@ -7,7 +7,6 @@ from flask import request, jsonify, abort
|
|||
from app import app
|
||||
from app.models.site import Site
|
||||
from app.models.comment import Comment
|
||||
from app.helpers.hashing import md5
|
||||
from app.services import processor
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -31,8 +30,7 @@ def query_comments():
|
|||
d['content'] = comment.content
|
||||
if comment.author_site:
|
||||
d['site'] = comment.author_site
|
||||
if comment.author_email:
|
||||
d['avatar'] = md5(comment.author_email.strip().lower())
|
||||
d['avatar'] = comment.author_gravatar
|
||||
d['date'] = comment.published.strftime("%Y-%m-%d %H:%M:%S")
|
||||
logger.debug(d)
|
||||
comments.append(d)
|
||||
|
|
|
@ -17,6 +17,7 @@ class Comment(Model):
|
|||
author_name = CharField()
|
||||
author_email = CharField(default='')
|
||||
author_site = CharField(default='')
|
||||
author_gravatar = CharField(default='')
|
||||
content = TextField()
|
||||
site = ForeignKeyField(Site, related_name='site')
|
||||
|
||||
|
|
24
app/run.py
24
app/run.py
|
@ -4,7 +4,6 @@
|
|||
import os
|
||||
import sys
|
||||
import logging
|
||||
from werkzeug.contrib.fixers import ProxyFix
|
||||
from flask.ext.cors import CORS
|
||||
|
||||
# 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 report
|
||||
from app.controllers import mail
|
||||
from app.controllers import reader
|
||||
from app import app
|
||||
|
||||
|
||||
|
@ -49,26 +47,36 @@ logger = logging.getLogger(__name__)
|
|||
# initialize database
|
||||
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
|
||||
logger.debug('imported: %s ' % api.__name__)
|
||||
logger.debug('imported: %s ' % mail.__name__)
|
||||
logger.debug('imported: %s ' % reader.__name__)
|
||||
|
||||
# start processor
|
||||
template_path = os.path.abspath(os.path.join(current_path, 'templates'))
|
||||
processor.start(template_path)
|
||||
|
||||
logger.info("Start Stacosys application")
|
||||
|
||||
# enable CORS
|
||||
cors = CORS(app, resources={r"/comments/*": {"origins": "*"}})
|
||||
# less feature in private mode
|
||||
if not config.PRIVATE:
|
||||
# enable CORS
|
||||
cors = CORS(app, resources={r"/comments/*": {"origins": "*"}})
|
||||
from app.controllers import reader
|
||||
logger.debug('imported: %s ' % reader.__name__)
|
||||
|
||||
# tune logging level
|
||||
if not config.DEBUG:
|
||||
logging.getLogger('app.cors').level = logging.WARNING
|
||||
logging.getLogger('werkzeug').level = logging.WARNING
|
||||
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app)
|
||||
logger.info("Start Stacosys application")
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
|
|
|
@ -10,9 +10,9 @@ from queue import Queue
|
|||
from jinja2 import Environment
|
||||
from jinja2 import FileSystemLoader
|
||||
from app.models.site import Site
|
||||
from app.models.comment import Comment
|
||||
from app.models.reader import Reader
|
||||
from app.models.report import Report
|
||||
from app.helpers.hashing import md5
|
||||
import requests
|
||||
import json
|
||||
import config
|
||||
|
@ -68,6 +68,13 @@ def new_comment(data):
|
|||
message = data.get('message', '')
|
||||
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
|
||||
site = Site.select().where(Site.token == token).get()
|
||||
|
||||
|
@ -79,6 +86,7 @@ def new_comment(data):
|
|||
# add a row to Comment table
|
||||
comment = Comment(site=site, url=url, author_name=author_name,
|
||||
author_site=author_site, author_email=author_email,
|
||||
author_gravatar=author_gravatar,
|
||||
content=message, created=created, published=None)
|
||||
comment.save()
|
||||
|
||||
|
@ -104,7 +112,7 @@ def new_comment(data):
|
|||
mail(site.admin_email, subject, email_body)
|
||||
|
||||
# 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)
|
||||
|
||||
logger.debug("new comment processed ")
|
||||
|
@ -163,14 +171,15 @@ def reply_comment_email(data):
|
|||
mail(from_email, 'Re: ' + subject, email_body)
|
||||
|
||||
# notify reader once comment is published
|
||||
reader_email = get_email_metadata(message)
|
||||
if reader_email:
|
||||
notify_reader(from_email, reader_email, comment.site.token,
|
||||
comment.site.url, comment.url)
|
||||
if not config.PRIVATE:
|
||||
reader_email = get_email_metadata(message)
|
||||
if reader_email:
|
||||
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(
|
||||
comment.site.token, comment.site.url, comment.url)
|
||||
# notify subscribers every time a new comment is published
|
||||
notify_subscribed_readers(
|
||||
comment.site.token, comment.site.url, comment.url)
|
||||
|
||||
|
||||
def late_reject_comment(id):
|
||||
|
|
|
@ -12,7 +12,6 @@ MAIL_URL = "http://localhost:8025/mbox"
|
|||
HTTP_ADDRESS = "127.0.0.1"
|
||||
HTTP_PORT = 8100
|
||||
HTTP_WORKERS = 1
|
||||
CORS_ORIGIN = "*"
|
||||
|
||||
SALT = "BRRJRqXgGpXWrgTidBPcixIThHpDuKc0"
|
||||
|
||||
|
@ -22,3 +21,5 @@ ROOT_URL = 'http://localhost:8100'
|
|||
|
||||
RSS_URL_PROTO = 'http'
|
||||
RSS_FILE = 'comments.xml'
|
||||
|
||||
PRIVATE = True
|
Loading…
Add table
Reference in a new issue