1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::api::rcos::meetings::authorization_for::{AuthorizationFor, UserMeetingAuthorization};
use crate::api::rcos::meetings::delete::DeleteMeeting;
use crate::error::TelescopeError;
use crate::web::services::auth::identity::AuthenticationCookie;
use actix_web::http::header::LOCATION;
use actix_web::web::{Path, ServiceConfig};
use actix_web::HttpResponse;
pub fn register(config: &mut ServiceConfig) {
config.service(delete_meeting);
}
#[post("/meeting/{meeting_id}/delete")]
async fn delete_meeting(
auth: AuthenticationCookie,
Path(meeting_id): Path<i64>,
) -> Result<HttpResponse, TelescopeError> {
let user_id = auth.get_user_id_or_error().await?;
let auth: UserMeetingAuthorization = AuthorizationFor::get(Some(user_id)).await?;
if !auth.can_delete_meetings() {
return Err(TelescopeError::Forbidden);
}
let api_response = DeleteMeeting::execute(meeting_id).await?;
if api_response.delete_meetings_by_pk.is_none() {
return Err(TelescopeError::ise(
"Meeting Deletion did not return meeting ID.",
));
}
Ok(HttpResponse::Found().header(LOCATION, "/meetings").finish())
}