Fixes
parent: tbd commit: b87f0a3
1 | |
2 | |
3 | use type_name; |
4 | use ; |
5 | |
6 | use OperationError; |
7 | use Instance; |
8 | use |
9 | AnyObject, GiteratedObject, Object, ObjectRequest, ObjectRequestError, ObjectResponse, |
10 | ; |
11 | use ObjectBackend; |
12 | use ; |
13 | use Repository; |
14 | use User; |
15 | use Debug; |
16 | use Mutex; |
17 | |
18 | use crate; |
19 | |
20 | use |
21 | repository_get_setting, repository_get_value, 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 | from_slice |
107 | .map_err?, |
108 | , |
109 | Err => match err |
110 | => Err, | Internal
111 | => Err, | Unhandled
112 | => Err | Operation
113 | from_slice |
114 | .map_err?, |
115 | , |
116 | , |
117 | |
118 | else if let Ok = from_str |
119 | let mut handler = default; |
120 | |
121 | handler |
122 | .insert |
123 | .insert |
124 | .insert; |
125 | |
126 | match handler |
127 | .handle |
128 | &repository, |
129 | operation, |
130 | unwrap, | from_value .
131 | self.clone, |
132 | |
133 | .await |
134 | |
135 | Ok => Ok |
136 | from_slice |
137 | .map_err?, |
138 | , |
139 | Err => match err |
140 | => Err, | Internal
141 | => Err, | Unhandled
142 | => Err | Operation
143 | from_slice |
144 | .map_err?, |
145 | , |
146 | , |
147 | |
148 | else if let Ok = from_str |
149 | if instance != self.our_instance |
150 | // We don't handle other objects currently |
151 | return Err; |
152 | |
153 | |
154 | if let Ok = |
155 | |
156 | let result = self. .await; |
157 | |
158 | let result = result |
159 | .map |
160 | .map_err |
161 | => | Operation
162 | Operation |
163 | |
164 | => Internal, | Internal
165 | => Unhandled, | Unhandled
166 | ; |
167 | |
168 | match result |
169 | Ok => Ok |
170 | from_slice |
171 | .map_err?, |
172 | , |
173 | Err => match err |
174 | => | Internal
175 | Err |
176 | |
177 | => Err, | Unhandled
178 | => Err | Operation
179 | from_slice |
180 | .map_err?, |
181 | , |
182 | , |
183 | |
184 | else |
185 | Err |
186 | |
187 | else |
188 | Err |
189 | |
190 | |
191 | |
192 | async |
193 | &self, |
194 | object_str: &str, |
195 | |
196 | if let Ok = from_str |
197 | let mut user_backend = self.user_backend.lock .await; |
198 | |
199 | if user_backend |
200 | .exists |
201 | .await |
202 | .map_err? |
203 | |
204 | Ok |
205 | new_unchecked |
206 | from_object_str |
207 | .map_err?, |
208 | self.clone, |
209 | |
210 | |
211 | else |
212 | return Err; |
213 | |
214 | else if let Ok = from_str |
215 | let mut repository_backend = self.repository_backend.lock .await; |
216 | |
217 | if repository_backend |
218 | .exists |
219 | .await |
220 | .map_err? |
221 | |
222 | Ok |
223 | new_unchecked |
224 | from_object_str |
225 | .map_err?, |
226 | self.clone, |
227 | |
228 | |
229 | else |
230 | return Err; |
231 | |
232 | else if let Ok = from_str |
233 | if instance != self.our_instance |
234 | // We don't handle other objects currently |
235 | return Err; |
236 | |
237 | |
238 | return Err; |
239 | else |
240 | // Invalid object type |
241 | return Err; |
242 | |
243 | |
244 | |
245 | |
246 | // These tests verify that the essential handling of the database backend is |
247 | // functional and correct. |
248 | |
249 | |
250 | use ; |
251 | |
252 | use Error; |
253 | |
254 | use UserAuthenticationToken; |
255 | |
256 | use |
257 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, |
258 | ; |
259 | |
260 | use ObjectBackend; |
261 | |
262 | use |
263 | Description, Repository, RepositoryFileInspectRequest, RepositorySummary, |
264 | RepositoryTreeEntry, |
265 | ; |
266 | use AnySetting; |
267 | use ; |
268 | use ; |
269 | use Value; |
270 | use Mutex; |
271 | |
272 | use crate; |
273 | |
274 | use DatabaseBackend; |
275 | ; |
276 | |
277 | |
278 | |
279 | async |
280 | assert_eq!; |
281 | |
282 | Ok |
283 | & to_vec .unwrap, |
284 | |
285 | .unwrap |
286 | |
287 | async |
288 | Ok |
289 | & to_vec .unwrap, |
290 | |
291 | .unwrap |
292 | |
293 | async |
294 | &mut self, |
295 | _user: &User, |
296 | _name: &str, |
297 | _setting: &Value, |
298 | |
299 | Ok |
300 | |
301 | async |
302 | Ok |
303 | |
304 | |
305 | |
306 | |
307 | |
308 | async |
309 | &mut self, |
310 | _request: RegisterAccountRequest, |
311 | |
312 | todo! |
313 | |
314 | |
315 | async |
316 | &mut self, |
317 | _source: &Instance, |
318 | _request: AuthenticationTokenRequest, |
319 | |
320 | todo! |
321 | |
322 | |
323 | |
324 | ; |
325 | |
326 | |
327 | |
328 | async |
329 | &mut self, |
330 | _user: &User, |
331 | _request: &RepositoryCreateRequest, |
332 | |
333 | todo! |
334 | |
335 | async |
336 | &mut self, |
337 | _requester: , |
338 | _request: &RepositoryFileInspectRequest, |
339 | |
340 | todo! |
341 | |
342 | async |
343 | &mut self, |
344 | _requester: , |
345 | _user: &User, |
346 | |
347 | todo! |
348 | |
349 | |
350 | async |
351 | &mut self, |
352 | _repository: &Repository, |
353 | _name: &str, |
354 | |
355 | Ok |
356 | & to_vec .unwrap, |
357 | |
358 | .unwrap |
359 | |
360 | async |
361 | &mut self, |
362 | _repository: &Repository, |
363 | _name: &str, |
364 | |
365 | Ok |
366 | & to_vec .unwrap, |
367 | |
368 | .unwrap |
369 | |
370 | async |
371 | &mut self, |
372 | _repository: &Repository, |
373 | _name: &str, |
374 | _setting: &Value, |
375 | |
376 | Ok |
377 | |
378 | |
379 | async |
380 | // Ok(true) |
381 | Ok |
382 | == & from_str |
383 | "test_user:test.giterated.dev/[email protected]", |
384 | |
385 | .unwrap |
386 | |
387 | |
388 | |
389 | |
390 | DatabaseBackend |
391 | our_instance: from_str .unwrap, |
392 | user_backend: new as _, |
393 | repository_backend: new as _, |
394 | |
395 | |
396 | |
397 | |
398 | async |
399 | let backend = test_backend; |
400 | |
401 | let mut user = backend |
402 | . |
403 | .await |
404 | .expect; |
405 | |
406 | user. |
407 | .await |
408 | .expect; |
409 | |
410 | |
411 | |
412 | async |
413 | let backend = test_backend; |
414 | |
415 | let mut user = backend |
416 | . |
417 | .await |
418 | .expect; |
419 | |
420 | user. |
421 | .await |
422 | .expect; |
423 | |
424 | |
425 | |
426 | async |
427 | let backend = test_backend; |
428 | |
429 | let mut user = backend |
430 | . |
431 | .await |
432 | .expect; |
433 | |
434 | user. |
435 | .await |
436 | .expect; |
437 | |
438 | |
439 | |
440 | async |
441 | let backend = test_backend; |
442 | |
443 | let mut repository = backend |
444 | . |
445 | .await |
446 | .expect; |
447 | |
448 | repository |
449 | . |
450 | .await |
451 | .expect; |
452 | |
453 | |
454 | |
455 | async |
456 | let backend = test_backend; |
457 | |
458 | let mut repository = backend |
459 | . |
460 | .await |
461 | .expect; |
462 | |
463 | repository |
464 | . |
465 | .await |
466 | .expect; |
467 | |
468 | |
469 | |
470 | async |
471 | let backend = test_backend; |
472 | |
473 | let mut repository = backend |
474 | . |
475 | .await |
476 | .expect; |
477 | |
478 | repository |
479 | . |
480 | .await |
481 | .expect; |
482 | |
483 | |
484 |