Skip to content

Commit 19bb933

Browse files
authored
update for deprecated Query.get() (#2960)
* update for deprecated Query.get() * fix call of send_from_directory
1 parent 27a2fb1 commit 19bb933

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

mslib/mscolab/file_manager.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def save_user_profile_image(self, user_id, image_file):
329329
"""
330330
relative_file_path = self.upload_file(image_file, subfolder='profile', identifier=user_id)
331331

332-
user = User.query.get(user_id)
332+
user = db.session.get(User, user_id)
333333
if user:
334334
if user.profile_image_path:
335335
# Delete the previous image
@@ -340,6 +340,18 @@ def save_user_profile_image(self, user_id, image_file):
340340
else:
341341
return False, "User not found"
342342

343+
def get_user_profile_image(self, user_id):
344+
"""
345+
Retrieve the user's profile image from the database.
346+
"""
347+
user = db.session.get(User, user_id)
348+
if user:
349+
if user.profile_image_path:
350+
return True, user.profile_image_path
351+
return False, "Profile image not found"
352+
else:
353+
return False, "User not found"
354+
343355
def update_operation(self, op_id, attribute, value, user):
344356
"""
345357
op_id: operation id

mslib/mscolab/server.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
See the License for the specific language governing permissions and
2525
limitations under the License.
2626
"""
27-
from pathlib import Path
2827
import sys
2928
import functools
3029
import json
@@ -35,6 +34,7 @@
3534
import sqlalchemy.exc
3635
import werkzeug
3736
import flask_migrate
37+
from pathlib import Path
3838

3939
from itsdangerous import URLSafeTimedSerializer, BadSignature
4040
from flask import g, jsonify, request, render_template, flash
@@ -472,13 +472,12 @@ def upload_profile_image():
472472
@verify_user
473473
def fetch_profile_image():
474474
user_id = request.form['user_id']
475-
user = User.query.get(user_id)
476-
if user and user.profile_image_path:
475+
success, filename = fm.get_user_profile_image(user_id)
476+
if success:
477477
base_path = mscolab_settings.UPLOAD_FOLDER
478-
filename = user.profile_image_path
479478
return send_from_directory(Path(base_path), filename)
480479
else:
481-
abort(404)
480+
return jsonify({'message': 'User or profile image not found'}), 404
482481

483482

484483
@APP.route("/delete_own_account", methods=["POST"])

0 commit comments

Comments
 (0)