roundabout,
created on Saturday, 14 September 2024, 13:34:12 (1726320852),
received on Saturday, 14 September 2024, 13:34:14 (1726320854)
Author identity: vlad <vlad.muntoiu@gmail.com>
f6761660d8605d7e52d484f411ac90f5f1ca3ef0
app.py
@@ -1740,3 +1740,63 @@ def api_gallery_remove_picture(id):
return flask.jsonify({"message": "Picture removed from gallery"}) @app.route("/api/gallery/<int:id>/users/add", methods=["POST"]) def api_gallery_add_user(id): gallery = db.session.get(Gallery, id) if gallery is None: flask.abort(404) current_user = db.session.get(User, flask.session.get("username")) if current_user is None: flask.abort(401) if current_user != gallery.owner and not current_user.admin: flask.abort(403) username = flask.request.json.get("username") if username == gallery.owner_name: return flask.jsonify({"error": "The owner cannot be added to trusted users"}), 400 user = db.session.get(User, username) if user is None: return flask.jsonify({"error": "User not found"}), 404 if UserInGallery.query.filter_by(user=user, gallery=gallery).first(): return flask.jsonify({"error": "User is already in the gallery"}), 400 db.session.add(UserInGallery(user, gallery)) db.session.commit() return flask.jsonify({"message": "User added to gallery"}) @app.route("/api/gallery/<int:id>/users/remove", methods=["POST"]) def api_gallery_remove_user(id): gallery = db.session.get(Gallery, id) if gallery is None: flask.abort(404) current_user = db.session.get(User, flask.session.get("username")) if current_user is None: flask.abort(401) if current_user != gallery.owner and not current_user.admin: flask.abort(403) username = flask.request.json.get("username") user = db.session.get(User, username) if user is None: return flask.jsonify({"error": "User not found"}), 404 user_in_gallery = UserInGallery.query.filter_by(user=user, gallery=gallery).first() if user_in_gallery is None: return flask.jsonify({"error": "User is not in the gallery"}), 400 db.session.delete(user_in_gallery) db.session.commit() return flask.jsonify({"message": "User removed from gallery"})