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