diff --git a/app/blueprints/main/routes.py b/app/blueprints/main/routes.py index e34e6f58..82673c91 100644 --- a/app/blueprints/main/routes.py +++ b/app/blueprints/main/routes.py @@ -56,7 +56,7 @@ def news(): ) -@bp.route('/privacy_policy') +@bp.route('/privacy-policy') def privacy_policy(): return render_template( 'main/privacy_policy.html.j2', @@ -64,11 +64,11 @@ def privacy_policy(): ) -@bp.route('/terms_of_use') +@bp.route('/terms-of-use') def terms_of_use(): return render_template( 'main/terms_of_use.html.j2', - title='Terms of Use' + title='Terms of use' ) diff --git a/app/blueprints/users/events.py b/app/blueprints/users/events.py index fcbe18bd..0a778228 100644 --- a/app/blueprints/users/events.py +++ b/app/blueprints/users/events.py @@ -9,50 +9,83 @@ from app.models import User @socketio_login_required def subscribe(user_hashid: str) -> dict: if not isinstance(user_hashid, str): - return {'status': 400, 'statusText': 'Bad Request'} + return { + 'code': 400, + 'name': 'Bad Request', + 'description': 'Invalid User ID.' + } user_id = hashids.decode(user_hashid) if not isinstance(user_id, int): - return {'status': 400, 'statusText': 'Bad Request'} + return { + 'code': 400, + 'name': 'Bad Request', + 'description': 'Invalid User ID.' + } user = User.query.get(user_id) if user is None: - return {'status': 404, 'statusText': 'Not Found'} + return { + 'code': 404, + 'name': 'Not Found', + 'description': 'User not found.' + } if not ( user == current_user or current_user.is_administrator ): - return {'status': 403, 'statusText': 'Forbidden'} + return { + 'code': 403, + 'name': 'Forbidden', + 'description': 'Not allowed to subscribe to this user.' + } join_room(f'/users/{user.hashid}') - return {'status': 200, 'statusText': 'OK'} + return {'code': 204, 'name': 'No Content'} + @socketio.on('UNSUBSCRIBE User') @socketio_login_required def unsubscribe(user_hashid: str) -> dict: if not isinstance(user_hashid, str): - return {'status': 400, 'statusText': 'Bad Request'} + return { + 'code': 400, + 'name': 'Bad Request', + 'description': 'Invalid User ID.' + } user_id = hashids.decode(user_hashid) if not isinstance(user_id, int): - return {'status': 400, 'statusText': 'Bad Request'} + return { + 'code': 400, + 'name': 'Bad Request', + 'description': 'Invalid User ID.' + } user = User.query.get(user_id) if user is None: - return {'status': 404, 'statusText': 'Not Found'} + return { + 'code': 404, + 'name': 'Not Found', + 'description': 'User not found.' + } if not ( user == current_user or current_user.is_administrator ): - return {'status': 403, 'statusText': 'Forbidden'} + return { + 'code': 403, + 'name': 'Forbidden', + 'description': 'Not allowed to unsubscribe from this user.' + } leave_room(f'/users/{user.hashid}') - return {'status': 200, 'statusText': 'OK'} + return {'code': 204, 'name': 'No Content'} diff --git a/app/static/js/app/endpoints/users.js b/app/static/js/app/endpoints/users.js index e7d4496f..cb0f231c 100644 --- a/app/static/js/app/endpoints/users.js +++ b/app/static/js/app/endpoints/users.js @@ -21,16 +21,16 @@ nopaque.app.endpoints.Users = class Users { async subscribe(userId) { const response = await this.app.socket.emitWithAck('SUBSCRIBE User', userId); - if (response.status != 200) { - throw new Error(`[${response.status}] ${response.statusText}`); + if (response.code != 204) { + throw new Error(`${response.name}: ${response.description}`); } } async unsubscribe(userId) { const response = await this.app.socket.emitWithAck('UNSUBSCRIBE User', userId); - if (response.status != 200) { - throw new Error(`[${response.status}] ${response.statusText}`); + if (response.status != 204) { + throw new Error(`${response.name}: ${response.description}`); } } diff --git a/app/templates/_base/modals.html.j2 b/app/templates/_base/modals.html.j2 index a00efa3a..11559d59 100644 --- a/app/templates/_base/modals.html.j2 +++ b/app/templates/_base/modals.html.j2 @@ -1,34 +1,30 @@ -{% if current_user.is_authenticated and not current_user.terms_of_use_accepted %} -