Exemplo n.º 1
0
def verify_user_permissions_to_update_event(user, event_id, database):
    """
    :param user: User Object, intended as logged in user
    :param event_id: Event Id
    :param database: database session
    """
    is_at_least_role(Roles.MODERATOR, user)
    db_event = get_event_by_id(database, event_id)
    if db_event.user_id != user.id and user.role != Roles.ADMIN:
        raise HTTPException(status_code=403, detail=USER_FORBIDDEN)

    return db_event
Exemplo n.º 2
0
async def update_application(
    application_id: int,
    data: ApplicationUpdate,
    database: Session = Depends(get_db),
    current_user: UserInDB = Depends(get_current_user)):
    """Approve/Reject Application"""
    approved_state_map = {
        True: ApplicationStates.APPROVED,
        False: ApplicationStates.REJECTED
    }
    if is_at_least_role(current_user=current_user, role=min_update_role):
        application_from_db = crud.get_application(database, application_id)
        if not application_from_db.status == ApplicationStates.PENDING:
            raise HTTPException(status_code=400,
                                detail="The application must be pending")

        updated_application = crud.change_state_of_application(
            database=database,
            application_id=application_id,
            new_state=approved_state_map[data.approved])
        if updated_application:
            if data.approved:
                await create_user_from_application(
                    database=database, application=updated_application)
            else:
                await send_fail_mail(updated_application)
            return updated_application
        raise HTTPException(status_code=404, detail="Application not found")
Exemplo n.º 3
0
def view_application(application_id: int,
                     database: Session = Depends(get_db),
                     current_user: UserInDB = Depends(get_current_user)):
    """View an application"""
    if is_at_least_role(current_user=current_user, role=min_view_role):
        return crud.get_application(database=database,
                                    application_id=application_id)
Exemplo n.º 4
0
def view_all_pending_applications(
        database: Session = Depends(get_db),
        current_user: UserInDB = Depends(get_current_user)):
    """View all pending applications"""
    if is_at_least_role(current_user=current_user, role=min_view_role):
        return crud.get_pending_applications(database)
Exemplo n.º 5
0
def create_event(event: EventBaseSerializer, user=Depends(get_current_user),
                 database: Session = Depends(get_db)):
    """Create event"""
    is_at_least_role(Roles.MODERATOR, user)
    return crud.create_event(database, event, user)
Exemplo n.º 6
0
async def get_feedback_by_id(feedback_id: int, database: Session = Depends(get_db),
                             current_user: UserInDB = Depends(get_current_user)):
    """Get feedback by id"""
    is_at_least_role(Roles.MODERATOR, current_user)
    return crud.get_feedback_by_id(database, feedback_id)
Exemplo n.º 7
0
async def get_all_feedback(database: Session = Depends(get_db),
                           current_user: UserInDB = Depends(get_current_user)):
    """List all feedback data"""
    is_at_least_role(Roles.MODERATOR, current_user)
    return crud.get_all_feedback(database)