def update_post_safety(post: model.Post, safety: str) -> None: assert post safety = util.flip(SAFETY_MAP).get(safety, None) if not safety: raise InvalidPostSafetyError('Safety can be either of %r.' % list(SAFETY_MAP.values())) post.safety = safety
def update_post_safety(post: model.Post, safety: str) -> None: assert post safety = util.flip(SAFETY_MAP).get(safety, None) if not safety: raise InvalidPostSafetyError('위험도는 다음중 하나여야 합니다: %r' % list(SAFETY_MAP.values())) post.safety = safety
def update_post_safety(post, safety): assert post safety = util.flip(SAFETY_MAP).get(safety, None) if not safety: raise InvalidPostSafetyError( 'Safety can be either of %r.' % list(SAFETY_MAP.values())) post.safety = safety
def has_privilege(user, privilege_name): all_ranks = list(RANK_MAP.keys()) assert privilege_name in config.config['privileges'] assert user.rank in all_ranks minimal_rank = util.flip(RANK_MAP)[ config.config['privileges'][privilege_name]] good_ranks = all_ranks[all_ranks.index(minimal_rank):] return user.rank in good_ranks
def update_post_flags(post, flags): target_flags = [] for flag in flags: flag = util.flip(FLAG_MAP).get(flag, None) if not flag: raise InvalidPostFlagError( 'Flag must be one of %r.' % list(FLAG_MAP.values())) target_flags.append(flag) post.flags = target_flags
def has_privilege(user: model.User, privilege_name: str) -> bool: assert user all_ranks = list(RANK_MAP.keys()) assert privilege_name in config.config["privileges"] assert user.rank in all_ranks minimal_rank = util.flip(RANK_MAP)[config.config["privileges"] [privilege_name]] good_ranks = all_ranks[all_ranks.index(minimal_rank):] return user.rank in good_ranks
def update_post_flags(post: model.Post, flags: List[str]) -> None: assert post target_flags = [] for flag in flags: flag = util.flip(FLAG_MAP).get(flag, None) if not flag: raise InvalidPostFlagError( 'Flag must be one of %r.' % list(FLAG_MAP.values())) target_flags.append(flag) post.flags = ','.join(target_flags)
def update_post_flags(post: model.Post, flags: List[str]) -> None: assert post target_flags = [] for flag in flags: flag = util.flip(FLAG_MAP).get(flag, None) if not flag: raise InvalidPostFlagError('플래그는 다음중 하나여야 합니다: %r' % list(FLAG_MAP.values())) target_flags.append(flag) post.flags = target_flags
def create_user(name, password, email): user = db.User() update_user_name(user, name) update_user_password(user, password) update_user_email(user, email) if get_user_count() > 0: user.rank = util.flip(auth.RANK_MAP)[config.config['default_rank']] else: user.rank = db.User.RANK_ADMINISTRATOR user.creation_time = datetime.datetime.now() user.avatar_style = db.User.AVATAR_GRAVATAR return user
def create_user(name: str, password: str, email: str) -> model.User: user = model.User() update_user_name(user, name) update_user_password(user, password) update_user_email(user, email) if get_user_count() > 0: user.rank = util.flip(auth.RANK_MAP)[config.config['default_rank']] else: user.rank = model.User.RANK_ADMINISTRATOR user.creation_time = datetime.utcnow() user.avatar_style = model.User.AVATAR_GRAVATAR return user
def update_user_rank(user, rank, authenticated_user): if not rank: raise InvalidRankError('Rank cannot be empty.') rank = util.flip(auth.RANK_MAP).get(rank.strip(), None) all_ranks = list(auth.RANK_MAP.values()) if not rank: raise InvalidRankError('Rank can be either of %r.' % all_ranks) if rank in (db.User.RANK_ANONYMOUS, db.User.RANK_NOBODY): raise InvalidRankError('Rank %r cannot be used.' % auth.RANK_MAP[rank]) if all_ranks.index(authenticated_user.rank) \ < all_ranks.index(rank) and get_user_count() > 0: raise errors.AuthError('Trying to set higher rank than your own.') user.rank = rank
def update_user_rank(user, rank, authenticated_user): if not rank: raise InvalidRankError('Rank cannot be empty.') rank = util.flip(auth.RANK_MAP).get(rank.strip(), None) all_ranks = list(auth.RANK_MAP.values()) if not rank: raise InvalidRankError( 'Rank can be either of %r.' % all_ranks) if rank in (db.User.RANK_ANONYMOUS, db.User.RANK_NOBODY): raise InvalidRankError('Rank %r cannot be used.' % auth.RANK_MAP[rank]) if all_ranks.index(authenticated_user.rank) \ < all_ranks.index(rank) and get_user_count() > 0: raise errors.AuthError('Trying to set higher rank than your own.') user.rank = rank
def update_user_rank(user: model.User, rank: str, auth_user: model.User) -> None: assert user if not rank: raise InvalidRankError('등급은 빈 값일 수 없습니다.') rank = util.flip(auth.RANK_MAP).get(rank.strip(), None) all_ranks = list(auth.RANK_MAP.values()) if not rank: raise InvalidRankError('등급은 다음중 하나여야 합니다: %r' % all_ranks) if rank in (model.User.RANK_ANONYMOUS, model.User.RANK_NOBODY): raise InvalidRankError('등급 %r 은(는) 사용할 수 없습니다.' % auth.RANK_MAP[rank]) if all_ranks.index(auth_user.rank) \ < all_ranks.index(rank) and get_user_count() > 0: raise errors.AuthError('당신보다 높은 등급을 지정할 수 없습니다.') user.rank = rank
def update_user_rank(user: model.User, rank: str, auth_user: model.User) -> None: assert user if not rank: raise InvalidRankError("Rank cannot be empty.") rank = util.flip(auth.RANK_MAP).get(rank.strip(), None) all_ranks = list(auth.RANK_MAP.values()) if not rank: raise InvalidRankError("Rank can be either of %r." % all_ranks) if rank in (model.User.RANK_ANONYMOUS, model.User.RANK_NOBODY): raise InvalidRankError("Rank %r cannot be used." % auth.RANK_MAP[rank]) if (all_ranks.index(auth_user.rank) < all_ranks.index(rank) and get_user_count() > 0): raise errors.AuthError("Trying to set higher rank than your own.") user.rank = rank