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