diff options
| author | Tom Harley | 2021-07-10 21:41:09 +0000 |
|---|---|---|
| committer | Tom Harley | 2021-07-11 14:23:35 +0000 |
| commit | c4e848c21c028ca7c52846ea1abd7f3a38aff7d6 (patch) | |
| tree | fb886b06dcdd4d9ae4cc54ee9ea9f481ec124166 /sw/users.py | |
| parent | Add basic inbox/outbox functionality (diff) | |
| download | swap-c4e848c21c028ca7c52846ea1abd7f3a38aff7d6.tar.gz swap-c4e848c21c028ca7c52846ea1abd7f3a38aff7d6.zip | |
Still not even total coverage!
Need to:
- write more tests for outbox manipulation
- look into and implement receiving content from other servers (+ write tests)
off the top of my head.
Diffstat (limited to 'sw/users.py')
| -rw-r--r-- | sw/users.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/sw/users.py b/sw/users.py index 08302b3..71258c1 100644 --- a/sw/users.py +++ b/sw/users.py @@ -1,4 +1,4 @@ -from flask import Blueprint, jsonify, url_for, request, abort +from flask import Blueprint, jsonify, url_for, request, abort, g, Response import json @@ -45,8 +45,10 @@ def get_user_inbox(username): "select inbox_size from users where username=?", (username,) ).fetchone()[0] - if inbox_size is None: - abort(404, "User not found") + # since a logged-in user is required to access this endpoint, there + # is no way that a non-existant user can be queried (in other + # words, the user will not have the clearance to see an unreal + # user's inbox) return jsonify( { @@ -139,12 +141,12 @@ def post_user_inbox_item(username): db = get_db() time = now() - res = db.exec( - "insert into inbox (recipient, received, content) values (?,?,?) ;", - (username, time, data), + res = db.execute( + "insert into inbox (recipient, received, ap_content) values (?,?,?) ;", + (username, time, str(data)), ) - db.exec( + db.execute( "update users set inbox_size = inbox_size + 1 where id = ? ;", (g.user["id"],), ) @@ -235,7 +237,7 @@ def post_user_outbox_item(username): item_id = None if "id" not in data: res = db.exec( - "insert into items (created, updated, content) " + "insert into items (created, updated, ap_content) " "output Inserted.id " "values (?,?,?) " ";", @@ -254,7 +256,7 @@ def post_user_outbox_item(username): if not is_ap_activity(data): activity = create_wrapper(item_id) res = db.exec( - "insert into items (created, updated, content) " + "insert into items (created, updated, ap_content) " "output Inserted.id " "values (?,?,?) " ";", |
