[api] remarks & drafts/collabs + migrations
This commit is contained in:
parent
6339a06b71
commit
b966ce6c24
|
@ -140,7 +140,7 @@ async def remarks_handle(storage):
|
||||||
print("[migration] comments")
|
print("[migration] comments")
|
||||||
c = 0
|
c = 0
|
||||||
for entry_remark in storage["remarks"]["data"]:
|
for entry_remark in storage["remarks"]["data"]:
|
||||||
remark = await migrateRemark(entry_remark)
|
remark = await migrateRemark(entry_remark, storage)
|
||||||
c += 1
|
c += 1
|
||||||
print("[migration] " + str(c) + " remarks migrated")
|
print("[migration] " + str(c) + " remarks migrated")
|
||||||
|
|
||||||
|
@ -179,9 +179,9 @@ async def all_handle(storage, args):
|
||||||
await users_handle(storage)
|
await users_handle(storage)
|
||||||
await topics_handle(storage)
|
await topics_handle(storage)
|
||||||
print("[migration] users and topics are migrated")
|
print("[migration] users and topics are migrated")
|
||||||
await remarks_handle(storage)
|
|
||||||
print("[migration] remarks are migrated")
|
|
||||||
await shouts_handle(storage, args)
|
await shouts_handle(storage, args)
|
||||||
|
print("[migration] remarks...")
|
||||||
|
await remarks_handle(storage)
|
||||||
print("[migration] migrating comments")
|
print("[migration] migrating comments")
|
||||||
await comments_handle(storage)
|
await comments_handle(storage)
|
||||||
# export_email_subscriptions()
|
# export_email_subscriptions()
|
||||||
|
@ -202,6 +202,7 @@ def data_load():
|
||||||
"cats": [],
|
"cats": [],
|
||||||
"tags": [],
|
"tags": [],
|
||||||
},
|
},
|
||||||
|
"remarks": {"data": []},
|
||||||
"users": {"by_oid": {}, "by_slug": {}, "data": []},
|
"users": {"by_oid": {}, "by_slug": {}, "data": []},
|
||||||
"replacements": json.loads(open("migration/tables/replacements.json").read()),
|
"replacements": json.loads(open("migration/tables/replacements.json").read()),
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,27 +4,28 @@ from migration.html2text import html2text
|
||||||
from orm.remark import Remark
|
from orm.remark import Remark
|
||||||
|
|
||||||
|
|
||||||
def migrate(entry):
|
def migrate(entry, storage):
|
||||||
|
post_oid = entry['contentItem']
|
||||||
|
print(post_oid)
|
||||||
|
shout_dict = storage['shouts']['by_oid'].get(post_oid)
|
||||||
remark = {
|
remark = {
|
||||||
"slug": entry["slug"],
|
"shout": shout_dict['id'],
|
||||||
"oid": entry["_id"],
|
"body": extract_md(
|
||||||
"body": extract_md(html2text(
|
html2text(entry['body']),
|
||||||
entry['body'] + entry['textAfter'] or '' + \
|
entry['_id']
|
||||||
|
),
|
||||||
|
"desc": extract_md(
|
||||||
|
html2text(
|
||||||
|
entry['textAfter'] or '' + \
|
||||||
entry['textBefore'] or '' + \
|
entry['textBefore'] or '' + \
|
||||||
entry['textSelected'] or ''
|
entry['textSelected'] or ''
|
||||||
), entry["_id"])
|
),
|
||||||
|
entry["_id"]
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
slug = remark["slug"]
|
rmrk = Remark.create(**remark)
|
||||||
rmrk = session.query(Remark).filter(Remark.slug == slug).first() or Remark.create(
|
|
||||||
**remark
|
|
||||||
)
|
|
||||||
if not rmrk:
|
|
||||||
raise Exception("no rmrk!")
|
|
||||||
if rmrk:
|
|
||||||
Remark.update(rmrk, remark)
|
|
||||||
session.commit()
|
session.commit()
|
||||||
rt = tt.__dict__.copy()
|
del rmrk["_sa_instance_state"]
|
||||||
del rt["_sa_instance_state"]
|
return rmrk
|
||||||
return rt
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ from base.orm import Base
|
||||||
|
|
||||||
class Remark(Base):
|
class Remark(Base):
|
||||||
|
|
||||||
tablename = "remark"
|
__tablename__ = "remark"
|
||||||
|
|
||||||
slug = Column(String, unique=True, nullable=False)
|
|
||||||
body = Column(String, nullable=False)
|
body = Column(String, nullable=False)
|
||||||
|
desc = Column(String, default='')
|
||||||
shout = Column(ForeignKey("shout.id"), nullable=True, index=True, comment="Shout")
|
shout = Column(ForeignKey("shout.id"), nullable=True, index=True, comment="Shout")
|
||||||
|
|
|
@ -72,7 +72,7 @@ async def update_draft(_, info, draft_input):
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
draft_input["updatedAt"] = datetime.now(tz=timezone.utc)
|
draft_input["updatedAt"] = datetime.now(tz=timezone.utc)
|
||||||
collab.update(**draft_input)
|
collab.update(draft_input)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
# TODO: email notify
|
# TODO: email notify
|
||||||
|
|
|
@ -162,16 +162,15 @@ async def update_profile(_, info, profile):
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).filter(User.id == user_id).one()
|
user = session.query(User).filter(User.id == user_id).one()
|
||||||
slugowner = session.query(User).where(User.slug == profile['slug']).one()
|
if not user:
|
||||||
if slugowner:
|
|
||||||
if slugowner.id != user_id:
|
|
||||||
return {
|
return {
|
||||||
"error": "slug is used by another user"
|
"error": "canoot find user"
|
||||||
}
|
}
|
||||||
user.update(profile)
|
user.update(profile)
|
||||||
session.commit()
|
session.commit()
|
||||||
return {
|
return {
|
||||||
"error": None
|
"error": None,
|
||||||
|
"author": user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -198,11 +198,10 @@ async def delete_reaction(_, info, reaction=None):
|
||||||
auth: AuthCredentials = info.context["request"].auth
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).where(User.id == auth.user_id).first()
|
|
||||||
r = session.query(Reaction).filter(Reaction.id == reaction).first()
|
r = session.query(Reaction).filter(Reaction.id == reaction).first()
|
||||||
if not r:
|
if not r:
|
||||||
return {"error": "invalid reaction id"}
|
return {"error": "invalid reaction id"}
|
||||||
if r.createdBy != user.id:
|
if r.createdBy != auth.user_id:
|
||||||
return {"error": "access denied"}
|
return {"error": "access denied"}
|
||||||
r.deletedAt = datetime.now(tz=timezone.utc)
|
r.deletedAt = datetime.now(tz=timezone.utc)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user