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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use crate::api::rcos::meetings::authorization_for::{AuthorizationFor, UserMeetingAuthorization};
use crate::api::rcos::meetings::get_by_id::{meeting::MeetingMeeting, Meeting};
use crate::error::TelescopeError;
use crate::templates::page::Page;
use crate::templates::tags::Tags;
use crate::templates::Template;
use crate::web::services::auth::identity::Identity;
use actix_web::web::Path;
use actix_web::HttpRequest;
use chrono::{Local, TimeZone};
const TEMPLATE_PATH: &'static str = "meetings/page";
#[get("/meeting/{meeting_id}")]
pub async fn meeting(
req: HttpRequest,
Path(meeting_id): Path<i64>,
identity: Identity,
) -> Result<Page, TelescopeError> {
let viewer: Option<_> = identity.get_user_id().await?;
let authorization: UserMeetingAuthorization = AuthorizationFor::get(viewer).await?;
let meeting: Option<MeetingMeeting> = Meeting::get(meeting_id).await?;
if meeting.is_none() {
return Err(TelescopeError::resource_not_found(
"Meeting Not Found",
"Could not find a meeting for this ID.",
));
}
let meeting: MeetingMeeting = meeting.unwrap();
let meeting_host: Option<_> = meeting.host.as_ref().map(|host| host.id);
let can_edit: bool = authorization.can_edit(meeting_host);
if !can_edit && meeting.is_draft && !authorization.can_view_drafts() {
return Err(TelescopeError::BadRequest {
header: "Meeting Not Visible".into(),
message: "This meeting is currently marked as a draft and is only visible to \
coordinators and faculty advisors. If you believe this is in error, please \
contact a coordinator."
.into(),
show_status_code: false,
});
}
if !authorization.can_view(meeting.type_) {
return Err(TelescopeError::BadRequest {
header: "Meeting Access Restricted".into(),
message: "Access to this meeting is restricted to mentors or coordinators. If you \
think this is in error, please contact a coordinator."
.into(),
show_status_code: false,
});
}
let mut tags = Tags::default();
tags.title = meeting.title();
tags.url = req.uri().to_string();
let mut description = String::new();
let start = Local.from_utc_datetime(&meeting.start_date_time.naive_utc());
let end = Local.from_utc_datetime(&meeting.end_date_time.naive_utc());
if start.date() == end.date() {
description.push_str(
format!(
"{} {} - {}",
start.format("%B %-d, %Y"),
start.format("%-I:%M %P"),
end.format("%-I:%M %P")
)
.as_str(),
);
} else {
description.push_str(
format!(
"{} at {} - {} at {}",
start.format("%B %-d, %Y"),
start.format("%-I:%M %P"),
end.format("%B %-d, %Y"),
end.format("%-I:%M %P")
)
.as_str(),
);
}
if meeting.location.is_some() {
let location = meeting.location.as_ref().unwrap();
if location != "" {
description.push_str(format!(" @ {}", location).as_str());
}
} else if meeting.is_remote {
description.push_str(" @ Remote");
}
description.push_str("\n");
description.push_str(format!("{}", meeting.type_).as_str());
if meeting.host.is_some() {
let host = meeting.host.as_ref().unwrap();
description
.push_str(format!(" hosted by: {} {}", host.first_name, host.last_name).as_str());
}
description.push_str("\n");
description.push_str(meeting.description.as_str());
tags.description = description;
let mut template = Template::new(TEMPLATE_PATH);
template.fields = json!({
"meeting": &meeting,
"auth": authorization
});
let mut page = template.in_page(&req, meeting.title()).await?;
page.ogp_tags = tags;
return Ok(page);
}