Exemplo n.º 1
0
async def delete_user(
        username: str,
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    await crud_delete_user(db, username)
Exemplo n.º 2
0
async def update_bucket(bucket_name: str,
                        bucket: BucketInUpdate = Body(...),
                        db: AsyncIOMotorClient = Depends(get_database),
                        current_user: User = Depends(get_current_user)):
    check_role_admin(current_user)

    response_bucket = await crud_update_bucket(db, bucket_name, bucket)

    return response_bucket
Exemplo n.º 3
0
async def create_new_bucket(
        bucket: BucketInCreate,
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    await check_free_bucket_name(db, bucket.name)

    new_bucket = await create_bucket(db, bucket, current_user)

    return new_bucket
Exemplo n.º 4
0
async def create_new_user(
        user: UserInCreate = Body(...),
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    await check_free_username_and_email(db, user.username, user.email)

    new_user = await create_user(db, user)

    return new_user
Exemplo n.º 5
0
async def update_user(
        username: str,
        user: UserInUpdate = Body(...),
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    await check_free_username_and_email(db, None, user.email)

    response_user = await crud_update_user(db, username, user)

    return response_user
Exemplo n.º 6
0
async def get_buckets(
        name: str = '',
        limit: int = Query(20),
        offset: int = Query(0),
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    filters = BucketFilterParams(name=name, limit=limit, offset=offset)

    buckets = await get_all_buckets(db, filters)
    return buckets
Exemplo n.º 7
0
async def get_user(
        username: str,
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    user = await crud_get_user_by_username(db, username)

    if not user:
        raise HTTPException(
            status_code=HTTP_404_NOT_FOUND,
            detail=f'Username {username} not found',
        )

    return user
Exemplo n.º 8
0
async def get_bucket(
        name: str,
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    bucket = await get_bucket_by_name(db, name)

    if not bucket:
        raise HTTPException(
            status_code=HTTP_404_NOT_FOUND,
            detail=f'Bucket {name} not found',
        )

    return bucket
Exemplo n.º 9
0
async def get_blob(
        path: str,
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    blob = await get_blob_by_path(db, path)

    if not blob:
        raise HTTPException(
            status_code=HTTP_404_NOT_FOUND,
            detail=f'Blob {path} not found',
        )

    return blob
Exemplo n.º 10
0
async def get_users(
        username: str = "",
        email: str = "",
        limit: int = Query(20),
        offset: int = Query(0),
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    filters = UserFilterParams(username=username,
                               email=email,
                               limit=limit,
                               offset=offset)

    users = await get_all_users(db, filters)
    return users
Exemplo n.º 11
0
async def get_all_blobs(
        path: str = '',
        bucket_name: str = '',
        limit: int = Query(20),
        offset: int = Query(0),
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    filters = BlobFilterParams(
        path=path,
        bucket_name=bucket_name,
        limit=limit,
        offset=offset
    )

    blobs = await crud_get_all_blobs(db, filters)
    return blobs
Exemplo n.º 12
0
async def create_user(
        user: UserInCreate = Body(...),
        db: AsyncIOMotorClient = Depends(get_database),
        current_user: User = Depends(get_current_user),
):
    check_role_admin(current_user)
    await check_free_username_and_email(db, user.username, user.email)

    new_user = await crud_create_user(db, user)

    # create bucket to new user
    try:
        await check_free_bucket_name(db, user.username)
        bucket = BucketInCreate(
            name=user.username,
            owner_username=user.username,
        )
        await crud_create_bucket(db, bucket, current_user)
    except:
        pass

    return new_user