فهرست منبع

make sure to set File.user_id

Son NK 5 سال پیش
والد
کامیت
abd2278c24
4فایلهای تغییر یافته به همراه10 افزوده شده و 8 حذف شده
  1. 3 2
      app/auth/views/facebook.py
  2. 5 4
      app/auth/views/google.py
  3. 1 1
      app/dashboard/views/setting.py
  4. 1 1
      app/developer/views/client_detail.py

+ 3 - 2
app/auth/views/facebook.py

@@ -102,7 +102,7 @@ def facebook_callback():
     if user:
         if picture_url and not user.profile_picture_id:
             LOG.d("set user profile picture to %s", picture_url)
-            file = create_file_from_url(picture_url)
+            file = create_file_from_url(user, picture_url)
             user.profile_picture_id = file.id
             db.session.commit()
 
@@ -120,10 +120,11 @@ def facebook_callback():
         user = User.create(
             email=email.lower(), name=facebook_user_data["name"], activated=True
         )
+        db.session.flush()
 
         if picture_url:
             LOG.d("set user profile picture to %s", picture_url)
-            file = create_file_from_url(picture_url)
+            file = create_file_from_url(user, picture_url)
             user.profile_picture_id = file.id
 
         db.session.commit()

+ 5 - 4
app/auth/views/google.py

@@ -88,7 +88,7 @@ def google_callback():
     if user:
         if picture_url and not user.profile_picture_id:
             LOG.d("set user profile picture to %s", picture_url)
-            file = create_file_from_url(picture_url)
+            file = create_file_from_url(user, picture_url)
             user.profile_picture_id = file.id
             db.session.commit()
     # create user
@@ -105,10 +105,11 @@ def google_callback():
         user = User.create(
             email=email.lower(), name=google_user_data["name"], activated=True
         )
+        db.session.flush()
 
         if picture_url:
             LOG.d("set user profile picture to %s", picture_url)
-            file = create_file_from_url(picture_url)
+            file = create_file_from_url(user, picture_url)
             user.profile_picture_id = file.id
 
         db.session.commit()
@@ -133,9 +134,9 @@ def google_callback():
     return after_login(user, next_url)
 
 
-def create_file_from_url(url) -> File:
+def create_file_from_url(user, url) -> File:
     file_path = random_string(30)
-    file = File.create(path=file_path)
+    file = File.create(path=file_path, user_id=user.id)
 
     s3.upload_from_url(url, file_path)
 

+ 1 - 1
app/dashboard/views/setting.py

@@ -106,7 +106,7 @@ def setting():
 
                 if form.profile_picture.data:
                     file_path = random_string(30)
-                    file = File.create(path=file_path)
+                    file = File.create(user_id=current_user.id, path=file_path)
 
                     s3.upload_from_bytesio(
                         file_path, BytesIO(form.profile_picture.data.read())

+ 1 - 1
app/developer/views/client_detail.py

@@ -45,7 +45,7 @@ def client_detail(client_id):
             # todo: remove current icon if any
             # todo: handle remove icon
             file_path = random_string(30)
-            file = File.create(path=file_path)
+            file = File.create(path=file_path, user_id=client.user_id)
 
             s3.upload_from_bytesio(file_path, BytesIO(form.icon.data.read()))