Example #1
0
def update_and_cancel_user_identity(session: Session, user_ids: List[int],
                                    update_identity: USER_IDENTITY_LITERAL,
                                    cancel_identity: USER_IDENTITY_LITERAL):
    session.query(UserDB). \
        filter(or_many_condition([UserDB.id == i for i in user_ids])). \
        filter(UserDB.user_identity.op('&')(cancel_identity) == cancel_identity). \
        update({UserDB.user_identity: UserDB.user_identity - cancel_identity + update_identity}, synchronize_session=False)
Example #2
0
def get_role_under_user(session: Session, user: UserDB,
                        page_info: PageInfo) -> Pagination:
    if user.is_superuser:
        pagination = Pagination(session.query(RoleDB), page_info=page_info)
        return pagination

    query = session.query(RoleDB)
    condition_list = [RoleDB.id.in_(user.role_id_set)]
    for role_id in user.role_id_set:
        condition_list.append(RoleDB.grand_id.like(f'%|{role_id}|%'))

    query = query.filter(or_many_condition(condition_list))
    pagination = Pagination(query, page_info=page_info)
    return pagination
Example #3
0
def update_user_identity(session: Session, user_ids: List[int],
                         identity: USER_IDENTITY_LITERAL):
    session.query(UserDB). \
        filter(or_many_condition([UserDB.id == i for i in user_ids])). \
        update({UserDB.user_identity: UserDB.user_identity.op('|')(identity)}, synchronize_session=False)
Example #4
0
def get_user_role_id(session: Session, id_list: List[int]) -> List[Tuple[int, int]]:
    users = session.query(UserDB).filter(or_many_condition([UserDB.id == i for i in id_list])).all()
    role_ids = []
    for user in users:
        role_ids.append((user.id, user.role_id_set))
    return role_ids