def patch(schema: ApplicationFeatureRequestSchema,
          name: str,
          dbcontext: DbContext = Depends(get_dbcontext),
          current_user: User = Depends(get_current_user)):
    try:
        data = schema.__dict__
        service = ApplicationService(dbcontext)
        application: Application = None
        if "all" in data.keys() and data["all"]:
            application = service.add_feature_all_environments(
                name, data, current_user)
        else:
            application = service.add_feature(name, data, current_user)
        features: List[ApplicationFeatureResponseSchema] = [
            ApplicationFeatureResponseSchema(
                environment_id=feature.environment_id,
                environment=feature.environment.name,
                name=feature.name,
                enable=feature.enable) for feature in application.features
        ]

        return features
    except IntegrityError:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail=f"The feature({schema.name}) already exists this environment"
        )
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_204_NO_CONTENT,
                            detail=str(e))
def delete(feature_name: str,
           name: str,
           environment_id: Optional[int] = 0,
           dbcontext: DbContext = Depends(get_dbcontext),
           current_user: User = Depends(get_current_user)):
    try:
        service = ApplicationService(dbcontext)
        application: Application = None
        if environment_id > 0:
            application = service.remove_feature(name, feature_name,
                                                 environment_id, current_user)
        else:
            application = service.remove_feature_all_environments(
                name, feature_name, current_user)
        features: List[ApplicationFeatureResponseSchema] = [
            ApplicationFeatureResponseSchema(
                environment_id=feature.environment_id,
                environment=feature.environment.name,
                name=feature.name,
                enable=feature.enable) for feature in application.features
        ]

        return features
    except IntegrityError as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST,
                            detail=str(e))
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_204_NO_CONTENT,
                            detail=str(e))
Exemplo n.º 3
0
def get(
    dbcontext: DbContext = Depends(get_dbcontext),
    current_user: User = Depends(get_current_user)
):
    applications = ApplicationService(dbcontext).get_all_by_user(current_user)

    return [ApplicationResponseSchema.from_orm(application) for application in applications]
Exemplo n.º 4
0
def get_application_service(database: Database = Depends(get_database),
                            user_service: UserService = Depends(
                                get_user_service),
                            environment_service: EnvironmentService = Depends(
                                get_environment_service)) -> Generator:
    service = ApplicationService(database, user_service, environment_service)

    yield service
Exemplo n.º 5
0
def get_by_name(
    name: str,
    dbcontext: DbContext = Depends(get_dbcontext),
    current_user: User = Depends(get_current_user)
):
    try:
        application = ApplicationService(dbcontext).get_by_name(name, current_user)

        return ApplicationResponseSchema.from_orm(application)
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_204_NO_CONTENT, detail=str(e))
Exemplo n.º 6
0
def get(name: str,
        dbcontext: DbContext = Depends(get_dbcontext),
        current_user: User = Depends(get_current_user)):
    try:
        application = ApplicationService(dbcontext).get_by_name(
            name, current_user)
        users: List[str] = [str(user.user.email) for user in application.users]

        return users
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_204_NO_CONTENT,
                            detail=str(e))
Exemplo n.º 7
0
def put(
    name: str,
    schema: ApplicationRequestSchema,
    dbcontex: DbContext = Depends(get_dbcontext),
    current_user: User = Depends(get_current_user)
):
    try:
        application = ApplicationService(dbcontex).update(schema.__dict__, name, current_user)

        return ApplicationResponseSchema.from_orm(application)
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
    except IntegrityError as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
Exemplo n.º 8
0
def inactive(
    name: str,
    dbcontex: DbContext = Depends(get_dbcontext),
    current_user: User = Depends(get_current_user)
):
    try:
        application = ApplicationService(dbcontex).inactive(name, current_user)

        return {
            "id": application.id,
            "name": application.name,
            "active": application.active
        }
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
Exemplo n.º 9
0
def delete(dbcontext: DbContext = Depends(get_dbcontext),
           current_user: User = Depends(get_current_user),
           user_id: int = None,
           name: str = None):
    try:
        application = ApplicationService(dbcontext).remove_user(
            name, user_id, current_user)
        users: List[str] = [str(user.user.email) for user in application.users]

        return users
    except IntegrityError as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST,
                            detail=str(e))
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_204_NO_CONTENT,
                            detail=str(e))
Exemplo n.º 10
0
def post(
    schema: ApplicationRequestSchema,
    dbcontex: DbContext = Depends(get_dbcontext),
    current_user: User = Depends(get_current_user)
):
    try:
        application = ApplicationService(dbcontex).create(schema.__dict__, current_user)

        return {
            "id": application.id,
            "name": application.name,
            "active": application.active
        }
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
    except IntegrityError as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
def get(name: str,
        dbcontext: DbContext = Depends(get_dbcontext),
        current_user: User = Depends(get_current_user)):
    try:
        application = ApplicationService(dbcontext).get_by_name(
            name, current_user)
        features: List[ApplicationFeatureResponseSchema] = [
            ApplicationFeatureResponseSchema(
                environment_id=feature.environment_id,
                environment=feature.environment.name,
                name=feature.name,
                enable=feature.enable) for feature in application.features
        ]

        return features
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_204_NO_CONTENT,
                            detail=str(e))
Exemplo n.º 12
0
def patch(name: str,
          schema: ApplicationUserRequestSchema,
          dbcontext: DbContext = Depends(get_dbcontext),
          current_user: User = Depends(get_current_user)):
    try:
        application = ApplicationService(dbcontext).add_user(
            name, schema.user_id, current_user)
        users: List[str] = [str(user.user.email) for user in application.users]

        return users
    except IntegrityError:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail=
            f"The user({schema.user_id}) cannot possible to add in application {name}"
        )
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_204_NO_CONTENT,
                            detail=str(e))