From 95cfa9ae52b4e09e6a623e5135b10bc2fb0fa085 Mon Sep 17 00:00:00 2001 From: Choom Date: Mon, 9 Jan 2023 23:29:31 -0300 Subject: Arreglando borrado --- cgi/api.py | 3 +- cgi/post.py | 71 ++++++++++++++++++++++++++++++---- cgi/templates/mobile/base_top.html | 2 +- cgi/templates/txt_board.en.html | 8 ++-- cgi/templates/txt_board.html | 6 +-- cgi/templates/txt_thread.html | 4 +- cgi/weabot.py | 78 ++++---------------------------------- 7 files changed, 81 insertions(+), 91 deletions(-) (limited to 'cgi') diff --git a/cgi/api.py b/cgi/api.py index 7b8b6bd..871e88f 100644 --- a/cgi/api.py +++ b/cgi/api.py @@ -6,7 +6,6 @@ from framework import * from database import * from post import * - def api(self, path_split): if len(path_split) > 2: try: @@ -356,7 +355,7 @@ def api_process(self, path_split): if data_imageonly and data_imageonly == 1: imageonly = True - deletePost(postid, data_password, board['recyclebin'], imageonly) + deletePosts(board['dir'], postid, imageonly, data_password) elif method == 'post': boarddir = formdata.get('board') diff --git a/cgi/post.py b/cgi/post.py index b7efef1..c53e8a1 100644 --- a/cgi/post.py +++ b/cgi/post.py @@ -56,7 +56,7 @@ class Post(object): return self.post def insert(self): - logging.info("Insertando Post") + logging.info("Insertando post") post_keys = [] post_templates = [] post_values = [] @@ -694,7 +694,63 @@ def regenerateBoard(everything=False): for post in op_posts: regenerateThreadPage(post["id"]) -def deletePost(postid, password, deltype=0, imageonly=False, quick=False): +def deletePosts(boarddir, postid, imageonly, password): + board = setBoard(boarddir) + + # validate posts + if not postid: + raise UserError("Selecciona uno o más mensajes a eliminar.") + + to_delete = [] + if isinstance(postid, list): + to_delete = [int(n.value) for n in postid] + else: + to_delete = [int(postid)] + + if not password: + raise UserError(_("Please enter a password.")) + + # delete posts + if board['board_type'] == 1 and len(to_delete) == 1: + # only delete a single post on textboards + # check if it's the last post and delete permanently if so + deltype = 0 + + post = FetchOne("SELECT id, timestamp, parentid FROM posts WHERE boardid = %s AND id = %s LIMIT 1", (board["id"], to_delete[0]) ) + if not post: + raise UserError(_("There isn't a post with this ID. It was probably deleted.")) + + if post['parentid']: + op = get_parent_post(post['parentid'], board['id']) + if op['last'] != post['timestamp']: + deltype = 1 + + deletePost(to_delete[0], password, deltype, imageonly) + regenerateHome() + else: + # delete all checked posts on imageboards + deleted = 0 + errors = 0 + msgs = [] + + for pid in to_delete: + try: + deletePost(pid, password, board['recyclebin'], imageonly) + deleted += 1 + msgs.append('No.%d: Eliminado' % pid) + except UserError as message: + errors += 1 + msgs.append('No.%d: %s' % (pid, message)) + + # regenerate home + if deleted: + regenerateHome() + + # show errors, if any + if errors: + raise UserError('No se pudieron eliminar todos los posts.
' + '
'.join(msgs)) + +def deletePost(postid, password, deltype=0, imageonly=False): """ Remove post from database and unlink file (if present), along with all replies if supplied post is a thread @@ -705,7 +761,7 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False): postid = int(postid) # get post - post = FetchOne("SELECT `id`, `timestamp`, `parentid`, `file`, `thumb`, `password`, `length` FROM `posts` WHERE `boardid` = %s AND `id` = %s LIMIT 1", (board["id"], postid)) + post = FetchOne("SELECT `id`, `timestamp`, `parentid`, `file`, `thumb`, `password`, `length` FROM `posts` WHERE `boardid` = %s AND `id` = %s LIMIT 1", (board["id"], postid) ) # abort if the post doesn't exist if not post: @@ -713,13 +769,12 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False): if password: if password != post['password']: - raise UserError("No tienes permiso para eliminar este mensaje.") + raise UserError("No tienes permiso para eliminar este post.") elif not post["parentid"] and post["length"] >= Settings.DELETE_FORBID_LENGTH: raise UserError("No puedes eliminar un hilo con tantas respuestas.") elif (int(time.time()) - post["timestamp"]) > 86400: raise UserError("No puedes eliminar un post tan viejo.") - # just update the DB if deleting only the image, otherwise delete whole post if imageonly: if post["file"]: deleteFile(post) @@ -729,14 +784,14 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False): if not post["parentid"]: deleteReplies(post) - logging.info("Deleting post %d - parentid: %d" % (post["id"], post["parentid"])) + logging.debug("Deleting post %d - parentid: %d" % (post["id"], post["parentid"])) if deltype != 0 and post["parentid"]: # Soft delete (recycle bin) - logging.info("Soft delete") + logging.debug("Soft delete") UpdateDb("UPDATE `posts` SET `IS_DELETED` = %s WHERE `boardid` = %s AND `id` = %s LIMIT 1", (deltype, board["id"], post["id"])) else: # Hard delete - logging.info("Hard delete") + logging.debug("Hard delete") if post["file"]: deleteFile(post) diff --git a/cgi/templates/mobile/base_top.html b/cgi/templates/mobile/base_top.html index aa016a4..bc4e680 100644 --- a/cgi/templates/mobile/base_top.html +++ b/cgi/templates/mobile/base_top.html @@ -10,5 +10,5 @@ - + diff --git a/cgi/templates/txt_board.en.html b/cgi/templates/txt_board.en.html index 9327c77..ff101b5 100644 --- a/cgi/templates/txt_board.en.html +++ b/cgi/templates/txt_board.en.html @@ -86,10 +86,10 @@
- Name: E-mail: + Name: E-mail:
- +
Thread has been closed. You cannot reply anymore.
@@ -131,7 +131,7 @@ E-mail: - + @@ -139,7 +139,7 @@ Body: - + diff --git a/cgi/templates/txt_board.html b/cgi/templates/txt_board.html index a6899bf..817f8d6 100644 --- a/cgi/templates/txt_board.html +++ b/cgi/templates/txt_board.html @@ -86,10 +86,10 @@
No tocar:
- Nombre:  E-mail:  + Nombre:  E-mail: 
- +
El hilo ha sido cerrado. Ya no se puede postear en él.
@@ -139,7 +139,7 @@ Mensaje: - + diff --git a/cgi/templates/txt_thread.html b/cgi/templates/txt_thread.html index 77237ab..611cf82 100644 --- a/cgi/templates/txt_thread.html +++ b/cgi/templates/txt_thread.html @@ -90,10 +90,10 @@
No tocar:
- Nombre:  E-mail:  + Nombre:  E-mail: 
- +
diff --git a/cgi/weabot.py b/cgi/weabot.py index 4a5cfcd..48f19f5 100755 --- a/cgi/weabot.py +++ b/cgi/weabot.py @@ -173,8 +173,8 @@ class weabot(object): self.output += repr(self.environ) elif path_split[1] == "delete": - # Deleting a post caught = True + OpenDb() boarddir = self.formdata.get('board') postid = self.formdata.get('delete') @@ -183,7 +183,12 @@ class weabot(object): mobile = self.formdata.get('mobile') # call delete function - self.delete_post(boarddir, postid, imageonly, password, mobile) + deletePosts(boarddir, postid, imageonly, password) + + self.output += '

%s

' % ( + ("/cgi/mobile/" if mobile else Settings.BOARDS_URL) + boarddir, + ("Archivo" if imageonly else "Post") + " eliminado con éxito." + ) elif path_split[1] == "anarkia": import anarkia caught = True @@ -854,75 +859,6 @@ class weabot(object): return (post_url, ttaken, postid) - def delete_post(self, boarddir, postid, imageonly, password, mobile=False): - OpenDb() - - # set the board - board = setBoard(boarddir) - - if board["dir"] == '0': - raise UserError("No se pueden eliminar mensajes en esta sección.") - - # check if we have a post id and check it's numeric - if not postid: - raise UserError("Selecciona uno o más mensajes a eliminar.") - - # make sure we have a password - if not password: - raise UserError(_("Please enter a password.")) - - to_delete = [] - if isinstance(postid, list): - to_delete = [int(n.value) for n in postid] - else: - to_delete = [int(postid)] - - # delete posts - if board['board_type'] == 1 and len(to_delete) == 1: - # we should be deleting only one (textboard) - # check if it's the last post and delete permanently if so - deltype = 0 - post = FetchOne("SELECT `id`, `timestamp`, `parentid` FROM `posts` WHERE `boardid` = %s AND `id` = %s LIMIT 1", ( - board["id"], to_delete[0])) - if post['parentid']: - op = get_parent_post(post['parentid'], board['id']) - if op['last'] != post['timestamp']: - deltype = 1 - - deletePost(to_delete[0], password, deltype, imageonly) - regenerateHome() - else: - # delete all checked posts (IB) - deleted = 0 - errors = 0 - msgs = [] - - for pid in to_delete: - try: - deletePost(pid, password, board['recyclebin'], imageonly) - deleted += 1 - msgs.append('No.%d: Eliminado' % pid) - except UserError as message: - errors += 1 - msgs.append('No.%d: %s' % (pid, message)) - - # regenerate home - if deleted: - regenerateHome() - - # show errors, if any - if errors: - raise UserError('No todos los mensajes pudieron ser eliminados.
' + \ - '
'.join(msgs)) - - # redirect - if imageonly: - self.output += '

%s

' % ( - ("/cgi/mobile/" if mobile else Settings.BOARDS_URL) + board["dir"], _("File deleted successfully.")) - else: - self.output += '

%s

' % ( - ("/cgi/mobile/" if mobile else Settings.BOARDS_URL) + board["dir"], _("Post deleted successfully.")) - def report(self, ip, boarddir, postid, reason, txt, postshow): # don't allow if the report system is off if not Settings.REPORTS_ENABLE: -- cgit v1.2.1-18-gbd029