Fix handling stack
parent: tbd commit: c53b026
1 | |
2 | |
3 | use ; |
4 | |
5 | use OperationError; |
6 | use Instance; |
7 | use |
8 | AnyObject, GiteratedObject, Object, ObjectRequest, ObjectRequestError, |
9 | ; |
10 | use ObjectBackend; |
11 | use GiteratedOperation; |
12 | use Repository; |
13 | use User; |
14 | use Debug; |
15 | use Mutex; |
16 | |
17 | use crate; |
18 | |
19 | use |
20 | repository_get_setting, repository_get_value, repository_info, repository_set_setting, |
21 | user_get_repositories, user_get_setting, user_get_value, user_set_setting, OperationHandlers, |
22 | ; |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | async |
30 | &self, |
31 | _object: O, |
32 | _operation: &str, |
33 | _payload: D, |
34 | |
35 | // We don't handle operations with this backend |
36 | Err |
37 | |
38 | |
39 | async |
40 | &self, |
41 | _object_str: &str, |
42 | |
43 | Err |
44 | |
45 | |
46 | |
47 | /// A backend implementation which attempts to resolve data from the instance's database. |
48 | |
49 | |
50 | pub(self) our_instance: Instance, |
51 | pub(self) user_backend: , |
52 | pub(self) repository_backend: , |
53 | |
54 | |
55 | |
56 | |
57 | instance: Instance, |
58 | user_backend: , |
59 | repository_backend: , |
60 | |
61 | Self |
62 | our_instance: instance, |
63 | user_backend, |
64 | repository_backend, |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | f.debug_struct .finish |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | async |
78 | &self, |
79 | object: O, |
80 | operation: &str, |
81 | payload: D, |
82 | |
83 | let serialized = |
84 | map_err?; | to_value .
85 | let object = object.to_string; |
86 | if let Ok = from_str |
87 | let mut handler = default; |
88 | |
89 | handler |
90 | .insert |
91 | .insert |
92 | .insert |
93 | .insert; |
94 | |
95 | match handler |
96 | .handle |
97 | &user, |
98 | operation, |
99 | unwrap, | from_value .
100 | self.clone, |
101 | |
102 | .await |
103 | |
104 | Ok => Ok |
105 | .map_err?, |
106 | Err => match err |
107 | => Err, | Internal
108 | => Err, | Unhandled
109 | => Err | Operation
110 | from_slice |
111 | .map_err?, |
112 | , |
113 | , |
114 | |
115 | else if let Ok = from_str |
116 | let mut handler = default; |
117 | |
118 | handler |
119 | .insert |
120 | .insert |
121 | .insert |
122 | .insert; |
123 | |
124 | match handler |
125 | .handle |
126 | &repository, |
127 | operation, |
128 | unwrap, | from_value .
129 | self.clone, |
130 | |
131 | .await |
132 | |
133 | Ok => Ok |
134 | .map_err?, |
135 | Err => match err |
136 | => Err, | Internal
137 | => Err, | Unhandled
138 | => Err | Operation
139 | from_slice |
140 | .map_err?, |
141 | , |
142 | , |
143 | |
144 | else if let Ok = from_str |
145 | if instance != self.our_instance |
146 | // We don't handle other objects currently |
147 | return Err; |
148 | |
149 | |
150 | if let Ok = |
151 | |
152 | let result = self. .await; |
153 | |
154 | let result = result |
155 | .map |
156 | .map_err |
157 | => | Operation
158 | Operation |
159 | |
160 | => Internal, | Internal
161 | => Unhandled, | Unhandled
162 | ; |
163 | |
164 | match result |
165 | Ok => Ok |
166 | .map_err?, |
167 | Err => match err |
168 | => | Internal
169 | Err |
170 | |
171 | => Err, | Unhandled
172 | => Err | Operation
173 | from_slice |
174 | .map_err?, |
175 | , |
176 | , |
177 | |
178 | else |
179 | Err |
180 | |
181 | else |
182 | Err |
183 | |
184 | |
185 | |
186 | async |
187 | &self, |
188 | object_str: &str, |
189 | |
190 | if let Ok = from_str |
191 | let mut user_backend = self.user_backend.lock .await; |
192 | |
193 | if user_backend |
194 | .exists |
195 | .await |
196 | .map_err? |
197 | |
198 | Ok |
199 | new_unchecked |
200 | from_object_str |
201 | .map_err?, |
202 | self.clone, |
203 | |
204 | |
205 | else |
206 | return Err; |
207 | |
208 | else if let Ok = from_str |
209 | let mut repository_backend = self.repository_backend.lock .await; |
210 | |
211 | if repository_backend |
212 | .exists |
213 | .await |
214 | .map_err? |
215 | |
216 | Ok |
217 | new_unchecked |
218 | from_object_str |
219 | .map_err?, |
220 | self.clone, |
221 | |
222 | |
223 | else |
224 | return Err; |
225 | |
226 | else if let Ok = from_str |
227 | if instance != self.our_instance |
228 | // We don't handle other objects currently |
229 | return Err; |
230 | |
231 | |
232 | return Err; |
233 | else |
234 | // Invalid object type |
235 | return Err; |
236 | |
237 | |
238 | |
239 | |
240 | // These tests verify that the essential handling of the database backend is |
241 | // functional and correct. |
242 | |
243 | |
244 | use ; |
245 | |
246 | use Error; |
247 | |
248 | use UserAuthenticationToken; |
249 | |
250 | use |
251 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, |
252 | ; |
253 | |
254 | use ObjectBackend; |
255 | |
256 | use |
257 | Description, Repository, RepositoryFileInspectRequest, RepositorySummary, |
258 | RepositoryTreeEntry, |
259 | ; |
260 | use AnySetting; |
261 | use ; |
262 | use ; |
263 | use Value; |
264 | use Mutex; |
265 | |
266 | use crate; |
267 | |
268 | use DatabaseBackend; |
269 | ; |
270 | |
271 | |
272 | |
273 | async |
274 | assert_eq!; |
275 | |
276 | Ok |
277 | & to_vec .unwrap, |
278 | |
279 | .unwrap |
280 | |
281 | async |
282 | Ok |
283 | & to_vec .unwrap, |
284 | |
285 | .unwrap |
286 | |
287 | async |
288 | &mut self, |
289 | _user: &User, |
290 | _name: &str, |
291 | _setting: &Value, |
292 | |
293 | Ok |
294 | |
295 | async |
296 | Ok |
297 | |
298 | async |
299 | &mut self, |
300 | requester: , |
301 | user: &User, |
302 | |
303 | todo! |
304 | |
305 | |
306 | |
307 | |
308 | |
309 | async |
310 | &mut self, |
311 | _request: RegisterAccountRequest, |
312 | |
313 | todo! |
314 | |
315 | |
316 | async |
317 | &mut self, |
318 | _source: &Instance, |
319 | _request: AuthenticationTokenRequest, |
320 | |
321 | todo! |
322 | |
323 | |
324 | |
325 | ; |
326 | |
327 | |
328 | |
329 | async |
330 | &mut self, |
331 | _user: &User, |
332 | _request: &RepositoryCreateRequest, |
333 | |
334 | todo! |
335 | |
336 | async |
337 | &mut self, |
338 | requester: , |
339 | repository: &Repository, |
340 | request: &RepositoryFileInspectRequest, |
341 | |
342 | todo! |
343 | |
344 | async |
345 | &mut self, |
346 | _repository: &Repository, |
347 | _name: &str, |
348 | |
349 | Ok |
350 | & to_vec .unwrap, |
351 | |
352 | .unwrap |
353 | |
354 | async |
355 | &mut self, |
356 | _repository: &Repository, |
357 | _name: &str, |
358 | |
359 | Ok |
360 | & to_vec .unwrap, |
361 | |
362 | .unwrap |
363 | |
364 | async |
365 | &mut self, |
366 | _repository: &Repository, |
367 | _name: &str, |
368 | _setting: &Value, |
369 | |
370 | Ok |
371 | |
372 | |
373 | async |
374 | // Ok(true) |
375 | Ok |
376 | == & from_str |
377 | "test_user:test.giterated.dev/[email protected]", |
378 | |
379 | .unwrap |
380 | |
381 | |
382 | |
383 | |
384 | DatabaseBackend |
385 | our_instance: from_str .unwrap, |
386 | user_backend: new as _, |
387 | repository_backend: new as _, |
388 | |
389 | |
390 | |
391 | |
392 | async |
393 | let backend = test_backend; |
394 | |
395 | let mut user = backend |
396 | . |
397 | .await |
398 | .expect; |
399 | |
400 | user. |
401 | .await |
402 | .expect; |
403 | |
404 | |
405 | |
406 | async |
407 | let backend = test_backend; |
408 | |
409 | let mut user = backend |
410 | . |
411 | .await |
412 | .expect; |
413 | |
414 | user. |
415 | .await |
416 | .expect; |
417 | |
418 | |
419 | |
420 | async |
421 | let backend = test_backend; |
422 | |
423 | let mut user = backend |
424 | . |
425 | .await |
426 | .expect; |
427 | |
428 | user. |
429 | .await |
430 | .expect; |
431 | |
432 | |
433 | |
434 | async |
435 | let backend = test_backend; |
436 | |
437 | let mut repository = backend |
438 | . |
439 | .await |
440 | .expect; |
441 | |
442 | repository |
443 | . |
444 | .await |
445 | .expect; |
446 | |
447 | |
448 | |
449 | async |
450 | let backend = test_backend; |
451 | |
452 | let mut repository = backend |
453 | . |
454 | .await |
455 | .expect; |
456 | |
457 | repository |
458 | . |
459 | .await |
460 | .expect; |
461 | |
462 | |
463 | |
464 | async |
465 | let backend = test_backend; |
466 | |
467 | let mut repository = backend |
468 | . |
469 | .await |
470 | .expect; |
471 | |
472 | repository |
473 | . |
474 | .await |
475 | .expect; |
476 | |
477 | |
478 |