def _verify_post_against_community(cls, op, community_id, is_valid, is_muted): error = None if community_id and is_valid and not Community.is_post_valid( community_id, op): error = 'not authorized' #is_valid = False # TODO: reserved for future blacklist status? is_muted = True return error
def _build_post(cls, op, date, pid=None): """Validate and normalize a post operation. Post is muted if: - parent was muted - author unauthorized Post is invalid if: - parent is invalid - author unauthorized """ # TODO: non-nsfw post in nsfw community is `invalid` # if this is a top-level post: if not op['parent_author']: parent_id = None depth = 0 category = op['parent_permlink'] community_id = None if date > START_DATE: community_id = Community.validated_id(category) is_valid = True is_muted = False # this is a comment; inherit parent props. else: parent_id = cls.get_id(op['parent_author'], op['parent_permlink']) sql = """SELECT depth, category, community_id, is_valid, is_muted FROM hive_posts WHERE id = :id""" (parent_depth, category, community_id, is_valid, is_muted) = DB.query_row(sql, id=parent_id) depth = parent_depth + 1 if not is_valid: error = 'replying to invalid post' elif is_muted: error = 'replying to muted post' # check post validity in specified context error = None if community_id and is_valid and not Community.is_post_valid( community_id, op): error = 'not authorized' #is_valid = False # TODO: reserved for future blacklist status? is_muted = True return dict(author=op['author'], permlink=op['permlink'], id=pid, is_valid=is_valid, is_muted=is_muted, parent_id=parent_id, depth=depth, category=category, community_id=community_id, date=date, error=error)