def routine(user: User): # Retrieve post post = self.get_post(id) if post is None: # Post does not exist return responses.client_error(404, 'Post does not exist') if not user.admin and post.author != user.id: # Post cannot be deleted from requesting user return responses.client_error(401, 'User cannot delete this post') image = post.image is not None # If post has image thread = ThreadAPI.get_thread(post.thread) # Retrieve thread parent if thread is None: # Thread is None, IMPOSSIBLE raise AssertionError('Thread cannot be None') # Delete post from database and decrement replies uchan.delete_from_db(post, False) thread.decr_replies(image) uchan.commit() return '', 204
def routine(user: User, thread: Thread): if not user.admin and thread.author != user.id: return responses.client_error(401, 'User cannot delete this thread') for post in thread.posts: uchan.delete_from_db(post, False) uchan.delete_from_db(thread) return '', 204
def delete(self, token: str): """ DELETE method implementation for API Session resource entity. :param token: Requested token to delete (from URL) :return: JSON response (204 No Content, 404 Not Found) """ session = self.retrieve_session(token) if session is None: return responses.client_error(404, 'Token not found') uchan.delete_from_db(session) return '', 204
def deleting_routine(user: User, chatrequest: ChatRequest): # Delete ChatRequest uchan.delete_from_db(chatrequest) return '', 204