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