add deleting, promoting/demoting, guesting (soft banning) users

This commit is contained in:
2025-05-19 18:34:21 +03:00
parent 349f4d38ef
commit a5a7175365
14 changed files with 234 additions and 37 deletions

View File

@ -14,6 +14,9 @@ util.TransientUser = {
is_admin = function (self)
return false
end,
is_mod = function (self)
return false
end,
is_guest = function (self)
return true
end,
@ -116,7 +119,6 @@ function util.create_post(thread_id, user_id, content)
local revision = PostHistory:create({
post_id = post.id,
user_id = user_id,
content = bb_content,
is_initial_revision = true,
})
@ -127,4 +129,16 @@ function util.create_post(thread_id, user_id, content)
return post
end
return util
function util.transfer_and_delete_user(user)
local deleted_user = Users:find({
username = "DeletedUser",
})
-- this needs to be atomic
db.query("BEGIN")
db.query('UPDATE "threads" SET "user_id" = ? WHERE "user_id" = ?', deleted_user.id, user.id)
db.query('UPDATE "posts" SET "user_id" = ? WHERE "user_id" = ?', deleted_user.id, user.id)
user:delete() -- uncomment later
db.query("COMMIT")
end
return util