fix app author

This commit is contained in:
tonyrewin 2023-01-31 20:17:02 +03:00
parent f87139ea24
commit 5e1e363b7d

View File

@ -40,8 +40,9 @@ def get_shout_slug(entry):
def create_author_from_app(app):
user = None
userdata = None
with local_session() as session:
# check if email is used
if app['email']:
with local_session() as session:
user = session.query(User).where(User.email == app['email']).first()
if not user:
# print('[migration] app %r' % app)
@ -49,6 +50,7 @@ def create_author_from_app(app):
if name:
slug = translit(name, "ru", reversed=True).lower()
slug = re.sub('[^0-9a-zA-Z]+', '-', slug)
print('[migration] created slug %s' % slug)
# check if slug is used
if slug:
user = session.query(User).where(User.slug == slug).first()
@ -61,14 +63,6 @@ def create_author_from_app(app):
if user:
slug += '-author'
user = session.query(User).where(User.slug == slug).first()
else:
# print(f'[migration] author @{slug} is found by email')
pass
else:
# print(f'[migration] author @{slug} is found')
pass
# create user with application data
if not user:
@ -88,9 +82,10 @@ def create_author_from_app(app):
session.commit()
userdata['id'] = user.id
if not userdata:
userdata = user.dict()
return userdata
else:
raise Exception("app is not ok", app)
async def create_shout(shout_dict):
@ -115,17 +110,14 @@ async def get_user(entry, storage):
user_oid = None
if app:
userdata = create_author_from_app(app)
# print("[migration] from app")
if not userdata:
else:
user_oid = entry.get("createdBy")
if user_oid == "0":
userdata = discours
elif user_oid:
userdata = storage["users"]["by_oid"].get(user_oid)
# print("[migration] user from user_oid")
else:
# print("[migration] no app, no user_oid")
if not userdata:
print('no userdata by oid, anonymous')
userdata = anondict
print(app)
# cleanup slug
@ -141,7 +133,6 @@ async def get_user(entry, storage):
return user, user_oid
async def migrate(entry, storage):
author, user_oid = await get_user(entry, storage)
r = {