Cancels a request if the request is in the created status and the caller is the requester.
(
&self,
request_id: &UUID,
reason: Option<String>,
ctx: &CallContext,
)
| 419 | |
| 420 | /// Cancels a request if the request is in the created status and the caller is the requester. |
| 421 | pub fn cancel_request( |
| 422 | &self, |
| 423 | request_id: &UUID, |
| 424 | reason: Option<String>, |
| 425 | ctx: &CallContext, |
| 426 | ) -> ServiceResult<Request> { |
| 427 | let caller = ctx.user().ok_or(RequestError::Unauthorized)?; |
| 428 | let request = self.get_request(request_id)?; |
| 429 | |
| 430 | if request.status != RequestStatus::Created { |
| 431 | Err(RequestError::CancellationNotAllowed { |
| 432 | reason: "Only requests in the created status can be cancelled.".to_string(), |
| 433 | })? |
| 434 | } |
| 435 | |
| 436 | if request.requested_by != caller.id { |
| 437 | Err(RequestError::CancellationNotAllowed { |
| 438 | reason: "Only the requester can cancel the request.".to_string(), |
| 439 | })? |
| 440 | } |
| 441 | |
| 442 | let request = self.request_repository.cancel_request( |
| 443 | request, |
| 444 | reason.unwrap_or("Request cancelled by requester.".to_string()), |
| 445 | next_time(), |
| 446 | ); |
| 447 | |
| 448 | Ok(request) |
| 449 | } |
| 450 | |
| 451 | pub async fn submit_request_approval( |
| 452 | &self, |
no test coverage detected