inventorymgr/transfer_requests.py
def accept_or_decline_transfer_request(request_id: int) -> Dict[str, bool]:
    """API endpoint to accept or decline a transfer request."""
    user = User.query.get(session["user_id"])
    transfer_request = TransferRequest.query.get(request_id)
    if transfer_request is None:
        raise APIError(reason="unknown_transfer_request", status_code=404)
    if user.id != transfer_request.target_user_id:
        raise APIError(reason="insufficient_permissions", status_code=403)
    if (
        transfer_request.borrowstate.borrowing_user_id
        != transfer_request.issuing_user_id
    ):
        db.session.delete(transfer_request)
        db.session.commit()
        raise APIError(reason="insufficient_permissions", status_code=403)
    if request.json["action"] == "accept":
        item = transfer_request.borrowstate.borrowed_item
        if not set(item.required_qualifications) <= set(user.qualifications):
            raise APIError(reason="missing_qualifications", status_code=403)
        db.session.add(
            LogEntry(
                action="transfer",
                timestamp=_utcnow(),
                subject=transfer_request.borrowstate.borrowing_user,
                secondary=user,
                items=[transfer_request.borrowstate.borrowed_item],
            )
        )
        transfer_request.borrowstate.borrowing_user = user
    elif request.json["action"] != "decline":
        raise APIError(reason="unknown_transfer_request_action", status_code=400)
    db.session.delete(transfer_request)
    db.session.commit()
    return {"success": True}
API endpoint to accept or decline a transfer request.
API endpoint to accept or decline a transfer request.
API endpoint to accept or decline a transfer request .
def accept_or_decline_transfer_request(request_id: int) -> Dict[str, bool]:
    user = User.query.get(session["user_id"])
    transfer_request = TransferRequest.query.get(request_id)
    if transfer_request is None:
        raise APIError(reason="unknown_transfer_request", status_code=404)
    if user.id != transfer_request.target_user_id:
        raise APIError(reason="insufficient_permissions", status_code=403)
    if (
        transfer_request.borrowstate.borrowing_user_id
        != transfer_request.issuing_user_id
    ):
        db.session.delete(transfer_request)
        db.session.commit()
        raise APIError(reason="insufficient_permissions", status_code=403)
    if request.json["action"] == "accept":
        item = transfer_request.borrowstate.borrowed_item
        if not set(item.required_qualifications) <= set(user.qualifications):
            raise APIError(reason="missing_qualifications", status_code=403)
        db.session.add(
            LogEntry(
                action="transfer",
                timestamp=_utcnow(),
                subject=transfer_request.borrowstate.borrowing_user,
                secondary=user,
                items=[transfer_request.borrowstate.borrowed_item],
            )
        )
        transfer_request.borrowstate.borrowing_user = user
    elif request.json["action"] != "decline":
        raise APIError(reason="unknown_transfer_request_action", status_code=400)
    db.session.delete(transfer_request)
    db.session.commit()
    return {"success": True}
def accept_or_decline_transfer_request ( request_id : int ) -> Dict [ str , bool ] : user = User . query . get ( session [ "user_id" ] ) transfer_request = TransferRequest . query . get ( request_id ) if transfer_request is None : raise APIError ( reason = "unknown_transfer_request" , status_code = 404 ) if user . id != transfer_request . target_user_id : raise APIError ( reason = "insufficient_permissions" , status_code = 403 ) if ( transfer_request . borrowstate . borrowing_user_id != transfer_request . issuing_user_id ) : db . session . delete ( transfer_request ) db . session . commit ( ) raise APIError ( reason = "insufficient_permissions" , status_code = 403 ) if request . json [ "action" ] == "accept" : item = transfer_request . borrowstate . borrowed_item if not set ( item . required_qualifications ) <= set ( user . qualifications ) : raise APIError ( reason = "missing_qualifications" , status_code = 403 ) db . session . add ( LogEntry ( action = "transfer" , timestamp = _utcnow ( ) , subject = transfer_request . borrowstate . borrowing_user , secondary = user , items = [ transfer_request . borrowstate . borrowed_item ] , ) ) transfer_request . borrowstate . borrowing_user = user elif request . json [ "action" ] != "decline" : raise APIError ( reason = "unknown_transfer_request_action" , status_code = 400 ) db . session . delete ( transfer_request ) db . session . commit ( ) return { "success" : True }
API endpoint to accept or decline a transfer request.
API endpoint to accept or decline a transfer request .
"""API endpoint to accept or decline a transfer request."""
request_id
int