Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9550c2a
auth: use authlib, part 1
knuxify Aug 29, 2021
f6af000
auth: small fixes for authlib
knuxify Aug 30, 2021
b2b1510
db: move declarative_base to db module
knuxify Aug 31, 2021
e53d06d
Revert "db: move declarative_base to db module"
knuxify Aug 31, 2021
382cee3
auth: fix login with new model
knuxify Aug 31, 2021
7ec2731
auth: drop flask_login requirement from models
knuxify Aug 31, 2021
a2f61b5
commit my changes so far. this will be squashed eventually
knuxify Sep 7, 2021
8c937e7
auth: commit progress
knuxify Sep 13, 2021
d371279
auth: commit changes
knuxify Sep 14, 2021
9ba2b88
split settings into separate file and begin rewrite
knuxify Sep 16, 2021
0e7a15b
Merge branch 'develop' into authlib
knuxify Sep 18, 2021
e61c990
tests: fix database clearing, syntax error in psql commands
knuxify Sep 18, 2021
3512f35
progress
knuxify Sep 23, 2021
f74a406
fix linting issues and throw out old db functions\!\!\!... except the…
knuxify Sep 23, 2021
bf70841
update: there are tests now, and also some edit and remove functions …
knuxify Sep 29, 2021
ffdacd3
why did it commit boinc stuff
knuxify Sep 29, 2021
cebad81
finish basic tests, fix removing apps in the web interface; sadly edi…
knuxify Sep 30, 2021
aa6b4d3
tests: API tests rewrite
knuxify Oct 2, 2021
8862822
tests: test report API, report bugfixes
knuxify Oct 3, 2021
8266b40
fix client editing
knuxify Oct 3, 2021
86dd3cb
auth/objects: account username validation
knuxify Oct 4, 2021
f3a9a97
fix authorize endpoint
knuxify Oct 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions drywall/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from drywall import pings
from drywall import app
from drywall import config
from drywall import auth # noqa: F401
from drywall import auth # noqa: F401
from drywall import auth_oauth # noqa: F401
from drywall import web # noqa: F401

import simplejson as json
from flask import Response, request
Expand Down Expand Up @@ -118,18 +120,27 @@ def api_post_conference_child(conference_id, object_type, object_data):
"""
if not object_data:
return pings.response_from_error(2)

# Check if the conference exists before doing anything else
if not db.get_object_as_dict_by_id(conference_id):
return pings.response_from_error(4)

data = object_data.copy()
if object_data['object_type'] == "invite":
data['conference_id'] = conference_id
else:
data['parent_conference'] = conference_id
return api_post(object_data, object_type=object_type)
return api_post(data, object_type=object_type)

def api_get_patch_delete_conference_child(conference_id, object_type, object_id):
"""
Template for GET/PATCH/DELETE actions on conference members, invites, roles
etc.
"""
# Check if the conference exists before doing anything else
if not db.id_taken(conference_id):
return pings.response_from_error(4)

try:
object_get = api_get(object_id, object_type=object_type)
object_get_id = object_get['id']
Expand All @@ -149,12 +160,27 @@ def api_get_patch_delete_conference_child(conference_id, object_type, object_id)

def api_report(report_dict, object_id, object_type=None):
"""Template for /api/v1/<type>/<id>/report endpoints."""
api_get(object_id, object_type=object_type)
try:
object_get = api_get(object_id, object_type=object_type)
object_get_id = object_get['id']
except:
return object_get

new_report_dict = {"target": object_id}
if 'note' in report_dict:
new_report_dict = {
"object_type": "report", "target": object_get_id,
"submission_date": 'dummy' # this gets replaced when the object is created
}

if report_dict and 'note' in report_dict:
new_report_dict['note'] = report_dict['note']
report = objects.make_object_from_dict(new_report_dict)

try:
report = objects.make_object_from_dict(new_report_dict)
except TypeError as e:
return pings.response_from_error(10, error_message=e)
# TODO: differentiate between the possible typeerrors
except KeyError as e:
return pings.response_from_error(7, error_message=e)

db.add_object(report)
return Response(json.dumps(report.__dict__), status=201, mimetype='application/json')
Expand All @@ -163,6 +189,8 @@ def api_report_conference_child(conference_id, report_dict, object_id, object_ty
"""
Template for POST /api/v1/conference/<conference_id>/<object_type> APIs
"""
if not db.get_object_as_dict_by_id(conference_id):
return pings.response_from_error(4)
try:
object_get = api_get(object_id, object_type=object_type)
object_get['id']
Expand Down Expand Up @@ -231,9 +259,6 @@ def api_stash_request():

return stash

# TODO: Federation, authentication, clients
# Probably will be in separate files, but I'll note it down here for now

# Accounts

@app.route('/api/v1/accounts', methods=['POST'])
Expand Down
Loading