From 7db48800a262c5ccf0a8158bb8007524db020e6c Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 3 Jun 2018 11:41:18 +0200 Subject: [PATCH] Tweak the UI (make it use the new user API) and bugfixes --- activitypub.py | 2 +- app.py | 51 ++++++++++++------------------------------ docker-compose-dev.yml | 4 ++-- tasks.py | 1 - templates/new.html | 4 +++- 5 files changed, 20 insertions(+), 42 deletions(-) diff --git a/activitypub.py b/activitypub.py index 316d620..d9764f2 100644 --- a/activitypub.py +++ b/activitypub.py @@ -182,7 +182,7 @@ class BaseActivity(object): valid_kwargs = {} for k, v in kwargs.items(): if v is None: - break + continue valid_kwargs[k] = v self._data.update(**valid_kwargs) diff --git a/app.py b/app.py index de08979..a9751ad 100644 --- a/app.py +++ b/app.py @@ -75,13 +75,15 @@ app.config.update( ) csrf = CSRFProtect(app) +logging.basicConfig(level=logging.DEBUG) + logger = logging.getLogger(__name__) # Hook up Flask logging with gunicorn -gunicorn_logger = logging.getLogger('gunicorn.error') -root_logger = logging.getLogger() -root_logger.handlers = gunicorn_logger.handlers -root_logger.setLevel(gunicorn_logger.level) +# gunicorn_logger = logging.getLogger('gunicorn.error') +# root_logger = logging.getLogger() +# root_logger.handlers = gunicorn_logger.handlers +# root_logger.setLevel(gunicorn_logger.level) SIG_AUTH = HTTPSigAuth(ID+'#main-key', KEY.privkey) @@ -460,6 +462,7 @@ def nodeinfo(): 'usage': {'users': {'total': 1}, 'localPosts': DB.outbox.count()}, 'metadata': { 'sourceCode': 'https://github.com/tsileo/microblog.pub', + 'nodeName': f'@{USERNAME}@{DOMAIN}', }, }), ) @@ -482,16 +485,16 @@ def wellknown_nodeinfo(): def wellknown_webfinger(): """Enable WebFinger support, required for Mastodon interopability.""" resource = request.args.get('resource') - if resource not in ["acct:"+USERNAME+"@"+DOMAIN, ID]: + if resource not in [f'acct:{USERNAME}@{DOMAIN}', ID]: abort(404) out = { - "subject": "acct:"+USERNAME+"@"+DOMAIN, + "subject": f'acct:{USERNAME}@{DOMAIN}', "aliases": [ID], "links": [ {"rel": "http://webfinger.net/rel/profile-page", "type": "text/html", "href": BASE_URL}, {"rel": "self", "type": "application/activity+json", "href": ID}, - {"rel":"http://ostatus.org/schema/1.0/subscribe","template": BASE_URL+"/authorize_follow?profile={uri}"}, + {"rel":"http://ostatus.org/schema/1.0/subscribe", "template": BASE_URL+"/authorize_follow?profile={uri}"}, ], } @@ -690,36 +693,9 @@ def admin(): ) -@app.route('/new', methods=['GET', 'POST']) +@app.route('/new', methods=['GET']) @login_required def new(): - if request.method == 'POST': - reply = None - if request.form.get('reply'): - reply = activitypub.parse_activity(OBJECT_SERVICE.get(request.form.get('reply'))) - source = request.form.get('content') - content, tags = parse_markdown(source) - to = request.form.get('to') - cc = [ID+'/followers'] - if reply: - cc.append(reply.attributedTo) - for tag in tags: - if tag['type'] == 'Mention': - cc.append(tag['href']) - - note = activitypub.Note( - cc=cc, - to=[to if to else config.AS_PUBLIC], - content=content, # TODO(tsileo): handle markdown - tag=tags, - source={'mediaType': 'text/markdown', 'content': source}, - inReplyTo=reply.id if reply else None - ) - - create = note.build_create() - print(create.to_dict()) - create.post_to_outbox() - reply_id = None content = '' if request.args.get('reply'): @@ -804,8 +780,9 @@ def _user_api_get_note(from_outbox: bool = False): def _user_api_response(**kwargs): - if request.args.get('redirect'): - return redirect(request.args.get('redirect')) + _redirect = _user_api_arg('redirect') + if _redirect: + return redirect(_redirect) resp = flask_jsonify(**kwargs) resp.status_code = 201 diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 980264e..b487dc9 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3' services: celery: image: microblogpub:latest @@ -7,7 +7,7 @@ services: - rabbitmq command: 'celery worker -l info -A tasks' environment: - - MICROBLOGPUB_AMQP_BORKER=pyamqp://guest@rabbitmq// + - MICROBLOGPUB_AMQP_BROKER=pyamqp://guest@rabbitmq// - MICROBLOGPUB_MONGODB_HOST=mongo:27017 mongo: image: "mongo:latest" diff --git a/tasks.py b/tasks.py index c9ce2b0..a30854a 100644 --- a/tasks.py +++ b/tasks.py @@ -19,7 +19,6 @@ from utils.linked_data_sig import generate_signature log = logging.getLogger(__name__) app = Celery('tasks', broker=os.getenv('MICROBLOGPUB_AMQP_BROKER', 'pyamqp://guest@localhost//')) -# app = Celery('tasks', broker='pyamqp://guest@rabbitmq//') SigAuth = HTTPSigAuth(ID+'#main-key', KEY.privkey) diff --git a/templates/new.html b/templates/new.html index 572eb61..7e76445 100644 --- a/templates/new.html +++ b/templates/new.html @@ -5,7 +5,9 @@
{% include "header.html" %}
-
+ + + {% if reply %}{% endif %}