give an error message when theres no prev mass content removal to revert

master
Aevann 2024-11-14 17:37:25 +02:00
parent fbf783f84a
commit ecf72de5a3
1 changed files with 18 additions and 27 deletions

View File

@ -1793,39 +1793,30 @@ def admin_nunuke_user(v):
user = get_user(request.values.get("user")) user = get_user(request.values.get("user"))
for post in g.db.query(Post).filter_by(author_id=user.id): objs = g.db.query(Post).filter(
if not post.is_banned: Post.author_id == user.id,
continue Post.is_banned == True,
Post.ban_reason.like('%(Mass Removal)'),
).all() + \
g.db.query(Comment).filter(
Comment.author_id == user.id,
Comment.is_banned == True,
Comment.ban_reason.like('%(Mass Removal)'),
).all()
if not post.ban_reason.endswith('(Mass Removal)'): if not objs:
continue stop(400, "There is no previous mass content removal to revert!")
post.is_banned = False for obj in objs:
obj.is_banned = False
for media_usage in post.media_usages: for media_usage in obj.media_usages:
media_usage.removed_utc = None media_usage.removed_utc = None
g.db.add(media_usage) g.db.add(media_usage)
post.ban_reason = None obj.ban_reason = None
post.is_approved = v.id obj.is_approved = v.id
g.db.add(post) g.db.add(obj)
for comment in g.db.query(Comment).filter_by(author_id=user.id):
if not comment.is_banned:
continue
if not comment.ban_reason.endswith('(Mass Removal)'):
continue
comment.is_banned = False
for media_usage in comment.media_usages:
media_usage.removed_utc = None
g.db.add(media_usage)
comment.ban_reason = None
comment.is_approved = v.id
g.db.add(comment)
ma = ModAction( ma = ModAction(
kind="unnuke_user", kind="unnuke_user",