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