Author: Manos Pitsidianakis [manos@pitsidianak.is]
Hash: b221283e4f5ca3198dd8c4b6a3df8daf3952a7ec
Timestamp: Fri, 15 Sep 2023 12:25:21 +0000 (1 year ago)

+83 -69 +/-4 browse
web: update axum-login (not working)
1diff --git a/Cargo.lock b/Cargo.lock
2index d9c0270..a929a06 100644
3--- a/Cargo.lock
4+++ b/Cargo.lock
5 @@ -257,7 +257,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
6 dependencies = [
7 "proc-macro2",
8 "quote",
9- "syn 2.0.15",
10+ "syn 2.0.33",
11 ]
12
13 [[package]]
14 @@ -274,7 +274,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
15 dependencies = [
16 "proc-macro2",
17 "quote",
18- "syn 2.0.15",
19+ "syn 2.0.33",
20 ]
21
22 [[package]]
23 @@ -379,24 +379,24 @@ dependencies = [
24
25 [[package]]
26 name = "axum-login"
27- version = "0.5.0"
28+ version = "0.6.0"
29 source = "registry+https://github.com/rust-lang/crates.io-index"
30- checksum = "2160b4bfd1db39feb3e689c287519d4b9234a5bcbdf89e975027b04d25c4bc32"
31+ checksum = "e53380c8fe0c99b72463662d8a245e7706a40554bf9a08954f3e4c4249635a02"
32 dependencies = [
33 "async-trait",
34 "axum",
35 "axum-sessions",
36 "base64 0.13.1",
37 "dyn-clone",
38- "eyre",
39 "futures",
40+ "percent-encoding",
41 "ring",
42 "secrecy",
43 "serde",
44 "serde_json",
45 "tokio",
46 "tower",
47- "tower-http 0.3.5",
48+ "tower-http 0.4.0",
49 "tracing",
50 ]
51
52 @@ -409,7 +409,7 @@ dependencies = [
53 "heck",
54 "proc-macro2",
55 "quote",
56- "syn 2.0.15",
57+ "syn 2.0.33",
58 ]
59
60 [[package]]
61 @@ -436,6 +436,12 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
62
63 [[package]]
64 name = "base64"
65+ version = "0.20.0"
66+ source = "registry+https://github.com/rust-lang/crates.io-index"
67+ checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5"
68+
69+ [[package]]
70+ name = "base64"
71 version = "0.21.0"
72 source = "registry+https://github.com/rust-lang/crates.io-index"
73 checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
74 @@ -650,7 +656,7 @@ dependencies = [
75 "proc-macro2",
76 "quote",
77 "serde_json",
78- "syn 2.0.15",
79+ "syn 2.0.33",
80 "xz2",
81 ]
82
83 @@ -793,7 +799,7 @@ dependencies = [
84 "heck",
85 "proc-macro2",
86 "quote",
87- "syn 2.0.15",
88+ "syn 2.0.33",
89 ]
90
91 [[package]]
92 @@ -976,7 +982,7 @@ dependencies = [
93 "proc-macro2",
94 "quote",
95 "scratch",
96- "syn 2.0.15",
97+ "syn 2.0.33",
98 ]
99
100 [[package]]
101 @@ -993,7 +999,7 @@ checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"
102 dependencies = [
103 "proc-macro2",
104 "quote",
105- "syn 2.0.15",
106+ "syn 2.0.33",
107 ]
108
109 [[package]]
110 @@ -1166,15 +1172,6 @@ dependencies = [
111 ]
112
113 [[package]]
114- name = "error-chain"
115- version = "0.12.4"
116- source = "registry+https://github.com/rust-lang/crates.io-index"
117- checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc"
118- dependencies = [
119- "version_check",
120- ]
121-
122- [[package]]
123 name = "event-listener"
124 version = "2.5.3"
125 source = "registry+https://github.com/rust-lang/crates.io-index"
126 @@ -1388,7 +1385,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
127 dependencies = [
128 "proc-macro2",
129 "quote",
130- "syn 2.0.15",
131+ "syn 2.0.33",
132 ]
133
134 [[package]]
135 @@ -2014,7 +2011,6 @@ version = "0.1.1"
136 dependencies = [
137 "anyhow",
138 "chrono",
139- "error-chain",
140 "jsonschema",
141 "log",
142 "mailpot-tests",
143 @@ -2027,6 +2023,7 @@ dependencies = [
144 "serde_json",
145 "stderrlog",
146 "tempfile",
147+ "thiserror",
148 "toml",
149 "xdg",
150 ]
151 @@ -2476,7 +2473,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
152 dependencies = [
153 "proc-macro2",
154 "quote",
155- "syn 2.0.15",
156+ "syn 2.0.33",
157 ]
158
159 [[package]]
160 @@ -2587,7 +2584,7 @@ dependencies = [
161 "pest_meta",
162 "proc-macro2",
163 "quote",
164- "syn 2.0.15",
165+ "syn 2.0.33",
166 ]
167
168 [[package]]
169 @@ -2730,18 +2727,18 @@ dependencies = [
170
171 [[package]]
172 name = "proc-macro2"
173- version = "1.0.56"
174+ version = "1.0.67"
175 source = "registry+https://github.com/rust-lang/crates.io-index"
176- checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
177+ checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328"
178 dependencies = [
179 "unicode-ident",
180 ]
181
182 [[package]]
183 name = "quote"
184- version = "1.0.27"
185+ version = "1.0.33"
186 source = "registry+https://github.com/rust-lang/crates.io-index"
187- checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500"
188+ checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
189 dependencies = [
190 "proc-macro2",
191 ]
192 @@ -3078,7 +3075,7 @@ checksum = "a2a0814352fd64b58489904a44ea8d90cb1a91dcb6b4f5ebabc32c8318e93cb6"
193 dependencies = [
194 "proc-macro2",
195 "quote",
196- "syn 2.0.15",
197+ "syn 2.0.33",
198 ]
199
200 [[package]]
201 @@ -3275,9 +3272,9 @@ dependencies = [
202
203 [[package]]
204 name = "syn"
205- version = "2.0.15"
206+ version = "2.0.33"
207 source = "registry+https://github.com/rust-lang/crates.io-index"
208- checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
209+ checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668"
210 dependencies = [
211 "proc-macro2",
212 "quote",
213 @@ -3336,22 +3333,22 @@ checksum = "9d4ae32d0a4605a89c28534371b056919c12e7a070ee07505af75130ff030111"
214
215 [[package]]
216 name = "thiserror"
217- version = "1.0.40"
218+ version = "1.0.48"
219 source = "registry+https://github.com/rust-lang/crates.io-index"
220- checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
221+ checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7"
222 dependencies = [
223 "thiserror-impl",
224 ]
225
226 [[package]]
227 name = "thiserror-impl"
228- version = "1.0.40"
229+ version = "1.0.48"
230 source = "registry+https://github.com/rust-lang/crates.io-index"
231- checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
232+ checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35"
233 dependencies = [
234 "proc-macro2",
235 "quote",
236- "syn 2.0.15",
237+ "syn 2.0.33",
238 ]
239
240 [[package]]
241 @@ -3444,7 +3441,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
242 dependencies = [
243 "proc-macro2",
244 "quote",
245- "syn 2.0.15",
246+ "syn 2.0.33",
247 ]
248
249 [[package]]
250 @@ -3522,6 +3519,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
251 checksum = "5d1d42a9b3f3ec46ba828e8d376aec14592ea199f70a06a548587ecd1c4ab658"
252 dependencies = [
253 "async-compression",
254+ "base64 0.20.0",
255 "bitflags",
256 "bytes",
257 "futures-core",
258 @@ -3529,6 +3527,7 @@ dependencies = [
259 "http",
260 "http-body",
261 "http-range-header",
262+ "mime",
263 "pin-project-lite",
264 "tokio",
265 "tokio-util",
266 @@ -3570,7 +3569,7 @@ checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74"
267 dependencies = [
268 "proc-macro2",
269 "quote",
270- "syn 2.0.15",
271+ "syn 2.0.33",
272 ]
273
274 [[package]]
275 diff --git a/web/Cargo.toml b/web/Cargo.toml
276index 39e8d99..e46e88b 100644
277--- a/web/Cargo.toml
278+++ b/web/Cargo.toml
279 @@ -18,7 +18,7 @@ doc-scrape-examples = true
280 [dependencies]
281 axum = { version = "^0.6" }
282 axum-extra = { version = "^0.7", features = ["typed-routing"] }
283- axum-login = { version = "^0.5" }
284+ axum-login = { version = "^0.6" }
285 axum-sessions = { version = "^0.5" }
286 build-info = { version = "0.0.31" }
287 cfg-if = { version = "1" }
288 @@ -38,7 +38,7 @@ serde_json = "^1"
289 stderrlog = "^0.5"
290 tempfile = { version = "^3.5" }
291 tokio = { version = "1", features = ["full"] }
292- tower-http = { version = "^0.3" }
293+ tower-http = { version = "^0.3", features = ["auth"] }
294 tower-service = { version = "^0.3" }
295 zstd = { version = "0.12", default-features = false }
296
297 diff --git a/web/src/lib.rs b/web/src/lib.rs
298index 869e5d7..cd73d4a 100644
299--- a/web/src/lib.rs
300+++ b/web/src/lib.rs
301 @@ -103,7 +103,7 @@ pub use utils::*;
302
303 #[derive(Debug)]
304 pub struct ResponseError {
305- pub inner: Box<dyn std::error::Error>,
306+ pub inner: Box<dyn std::error::Error + Send + Sync>,
307 pub status: StatusCode,
308 }
309
310 @@ -113,6 +113,8 @@ impl std::fmt::Display for ResponseError {
311 }
312 }
313
314+ impl std::error::Error for ResponseError {}
315+
316 impl ResponseError {
317 pub fn new(msg: String, status: StatusCode) -> Self {
318 Self {
319 @@ -120,23 +122,8 @@ impl ResponseError {
320 status,
321 }
322 }
323- }
324-
325- impl<E: Into<Box<dyn std::error::Error>>> From<E> for ResponseError {
326- fn from(err: E) -> Self {
327- Self {
328- inner: err.into(),
329- status: StatusCode::INTERNAL_SERVER_ERROR,
330- }
331- }
332- }
333
334- pub trait IntoResponseError {
335- fn with_status(self, status: StatusCode) -> ResponseError;
336- }
337-
338- impl<E: Into<Box<dyn std::error::Error>>> IntoResponseError for E {
339- fn with_status(self, status: StatusCode) -> ResponseError {
340+ pub fn with_status(self, status: StatusCode) -> ResponseError {
341 ResponseError {
342 status,
343 ..ResponseError::from(self)
344 @@ -144,6 +131,25 @@ impl<E: Into<Box<dyn std::error::Error>>> IntoResponseError for E {
345 }
346 }
347
348+ macro_rules! impl_from {
349+ ($t:ty) => {
350+ impl From<$t> for ResponseError {
351+ fn from(err: $t) -> Self {
352+ Self {
353+ inner: err.into(),
354+ status: StatusCode::INTERNAL_SERVER_ERROR,
355+ }
356+ }
357+ }
358+ };
359+ }
360+
361+ impl_from! { mailpot::Error }
362+ impl_from! { minijinja::Error }
363+ impl_from! { mailpot::rusqlite::Error }
364+ impl_from! { mailpot::serde_json::Error }
365+ impl_from! { mailpot::melib::Error }
366+
367 impl IntoResponse for ResponseError {
368 fn into_response(self) -> axum::response::Response {
369 let Self { inner, status } = self;
370 @@ -157,10 +163,10 @@ pub trait IntoResponseErrorResult<R> {
371
372 impl<R, E> IntoResponseErrorResult<R> for std::result::Result<R, E>
373 where
374- E: IntoResponseError,
375+ E: Into<ResponseError>
376 {
377 fn with_status(self, status: StatusCode) -> std::result::Result<R, ResponseError> {
378- self.map_err(|err| err.with_status(status))
379+ self.map_err(|err| E::into(err).with_status(status))
380 }
381 }
382
383 @@ -193,11 +199,12 @@ mod auth_impls {
384 User: axum_login::AuthUser<UserId, Role>,
385 {
386 type User = User;
387+ type Error = ResponseError;
388
389 async fn load_user(
390 &self,
391 user_id: &UserId,
392- ) -> std::result::Result<Option<Self::User>, eyre::Report> {
393+ ) -> std::result::Result<Option<Self::User>, Self::Error> {
394 Ok(self.user_store.read().await.get(user_id).cloned())
395 }
396 }
397 diff --git a/web/src/typed_paths.rs b/web/src/typed_paths.rs
398index 9429756..c21656d 100644
399--- a/web/src/typed_paths.rs
400+++ b/web/src/typed_paths.rs
401 @@ -171,29 +171,37 @@ list_id_impl!(list_candidates_path, ListEditCandidatesPath);
402
403 macro_rules! list_post_impl {
404 ($ident:ident, $ty:tt) => {
405- pub fn $ident(state: &minijinja::State, id: Value, msg_id: Value) -> std::result::Result<Value, Error> {
406+ pub fn $ident(
407+ state: &minijinja::State,
408+ id: Value,
409+ msg_id: Value,
410+ ) -> std::result::Result<Value, Error> {
411 urlize(state, {
412- let Some(msg_id) = msg_id.as_str().map(|s| if s.starts_with('<') && s.ends_with('>') { s.to_string() } else {
413- format!("<{s}>")
414+ let Some(msg_id) = msg_id.as_str().map(|s| {
415+ if s.starts_with('<') && s.ends_with('>') {
416+ s.to_string()
417+ } else {
418+ format!("<{s}>")
419+ }
420 }) else {
421 return Err(Error::new(
422- minijinja::ErrorKind::UnknownMethod,
423- "Second argument of list_post_path must be a string."
424+ minijinja::ErrorKind::UnknownMethod,
425+ "Second argument of list_post_path must be a string.",
426 ));
427 };
428
429 if let Some(id) = id.as_str() {
430 Value::from(
431 $ty(ListPathIdentifier::Id(id.to_string()), msg_id)
432- .to_crumb()
433- .to_string(),
434+ .to_crumb()
435+ .to_string(),
436 )
437 } else {
438 let pk = id.try_into()?;
439 Value::from(
440 $ty(ListPathIdentifier::Pk(pk), msg_id)
441- .to_crumb()
442- .to_string(),
443+ .to_crumb()
444+ .to_string(),
445 )
446 }
447 })