Add authentication back into the operation states
parent: tbd commit: 97a26fd
1 | use Error; |
2 | |
3 | use ; |
4 | use |
5 | , | UserAuthenticationToken
6 | , |
7 | |
8 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, |
9 | , |
10 | , | ObjectBackend
11 | |
12 | Commit, DefaultBranch, Description, LatestCommit, Repository, |
13 | RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffPatchRequest, |
14 | RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, |
15 | RepositoryFileFromPathRequest, RepositoryFileInspectRequest, RepositoryInfoRequest, |
16 | RepositorySummary, RepositoryView, Visibility, |
17 | , |
18 | , |
19 | , |
20 | , |
21 | ; |
22 | use ; |
23 | |
24 | use DatabaseBackend; |
25 | |
26 | |
27 | object: &User, |
28 | _operation: UserRepositoriesRequest, |
29 | state: DatabaseBackend, |
30 | |
31 | let object = object.clone; |
32 | |
33 | async move |
34 | let mut user_backend = state.user_backend.lock .await; |
35 | let repositories = user_backend |
36 | .repositories_for_user |
37 | .await |
38 | .map_err?; |
39 | |
40 | Ok |
41 | |
42 | .boxed |
43 | |
44 | |
45 | |
46 | object: &User, |
47 | operation: , |
48 | state: DatabaseBackend, |
49 | |
50 | let object = object.clone; |
51 | |
52 | async move |
53 | let mut user_backend = state.user_backend.lock .await; |
54 | let value = user_backend |
55 | .get_value |
56 | .await |
57 | .map_err?; |
58 | |
59 | Ok |
60 | |
61 | .boxed |
62 | |
63 | |
64 | |
65 | object: &User, |
66 | operation: , |
67 | state: DatabaseBackend, |
68 | |
69 | let object = object.clone; |
70 | |
71 | async move |
72 | let mut user_backend = state.user_backend.lock .await; |
73 | let value = user_backend |
74 | .get_setting |
75 | .await |
76 | .map_err?; |
77 | |
78 | Ok |
79 | |
80 | .boxed |
81 | |
82 | |
83 | |
84 | object: &User, |
85 | operation: , |
86 | state: DatabaseBackend, |
87 | |
88 | let object = object.clone; |
89 | |
90 | async move |
91 | let mut user_backend = state.user_backend.lock .await; |
92 | let value = user_backend |
93 | .write_setting |
94 | .await |
95 | .map_err?; |
96 | |
97 | Ok |
98 | |
99 | .boxed |
100 | |
101 | |
102 | |
103 | object: &Repository, |
104 | operation: RepositoryInfoRequest, |
105 | state: DatabaseBackend, |
106 | operation_state: StackOperationState, |
107 | backend: BackendWrapper, |
108 | |
109 | let object = object.clone; |
110 | |
111 | async move |
112 | let mut object = backend |
113 | . |
114 | .await |
115 | .unwrap; |
116 | |
117 | let mut repository_backend = state.repository_backend.lock .await; |
118 | let tree = repository_backend |
119 | .repository_file_inspect |
120 | None, |
121 | object.object, |
122 | &RepositoryFileInspectRequest |
123 | extra_metadata: operation.extra_metadata, |
124 | path: operation.path, |
125 | rev: operation.rev.clone, |
126 | , |
127 | |
128 | .await |
129 | .map_err?; |
130 | drop; |
131 | |
132 | let info = RepositoryView |
133 | name: object.object .name.clone, |
134 | owner: object.object .owner.clone, |
135 | description: object. .await.ok, |
136 | visibility: object |
137 | . |
138 | .await |
139 | .map_err?, |
140 | default_branch: object |
141 | . |
142 | .await |
143 | .map_err?, |
144 | // TODO: Can't be a simple get function, this needs to be returned alongside the tree as this differs depending on the rev and path. |
145 | latest_commit: object. .await.ok, |
146 | tree_rev: operation.rev, |
147 | tree, |
148 | ; |
149 | |
150 | Ok |
151 | |
152 | .boxed |
153 | |
154 | |
155 | |
156 | object: &Repository, |
157 | operation: RepositoryFileFromIdRequest, |
158 | state: DatabaseBackend, |
159 | operation_state: StackOperationState, |
160 | backend: BackendWrapper, |
161 | |
162 | let object = object.clone; |
163 | |
164 | async move |
165 | let object = backend |
166 | . |
167 | .await |
168 | .unwrap; |
169 | |
170 | let mut repository_backend = state.repository_backend.lock .await; |
171 | let file = repository_backend |
172 | .repository_file_from_id |
173 | None, |
174 | object.object, |
175 | &RepositoryFileFromIdRequest, |
176 | |
177 | .await |
178 | .map_err?; |
179 | drop; |
180 | |
181 | Ok |
182 | |
183 | .boxed |
184 | |
185 | |
186 | |
187 | object: &Repository, |
188 | operation: RepositoryFileFromPathRequest, |
189 | state: DatabaseBackend, |
190 | operation_state: StackOperationState, |
191 | backend: BackendWrapper, |
192 | |
193 | let object = object.clone; |
194 | |
195 | async move |
196 | let object = backend |
197 | . |
198 | .await |
199 | .unwrap; |
200 | |
201 | let mut repository_backend = state.repository_backend.lock .await; |
202 | let file = repository_backend |
203 | .repository_file_from_path |
204 | None, |
205 | object.object, |
206 | &RepositoryFileFromPathRequest |
207 | rev: operation.rev, |
208 | path: operation.path, |
209 | , |
210 | |
211 | .await |
212 | .map_err?; |
213 | drop; |
214 | |
215 | Ok |
216 | |
217 | .boxed |
218 | |
219 | |
220 | |
221 | object: &Repository, |
222 | operation: RepositoryDiffRequest, |
223 | state: DatabaseBackend, |
224 | operation_state: StackOperationState, |
225 | backend: BackendWrapper, |
226 | |
227 | let object = object.clone; |
228 | |
229 | async move |
230 | let object = backend |
231 | . |
232 | .await |
233 | .unwrap; |
234 | |
235 | let mut repository_backend = state.repository_backend.lock .await; |
236 | let diff = repository_backend |
237 | .repository_diff |
238 | .await |
239 | .map_err?; |
240 | drop; |
241 | |
242 | Ok |
243 | |
244 | .boxed |
245 | |
246 | |
247 | |
248 | object: &Repository, |
249 | operation: RepositoryDiffPatchRequest, |
250 | state: DatabaseBackend, |
251 | operation_state: StackOperationState, |
252 | backend: BackendWrapper, |
253 | |
254 | let object = object.clone; |
255 | |
256 | async move |
257 | let object = backend |
258 | . |
259 | .await |
260 | .unwrap; |
261 | |
262 | let mut repository_backend = state.repository_backend.lock .await; |
263 | let patch = repository_backend |
264 | .repository_diff_patch |
265 | .await |
266 | .map_err?; |
267 | drop; |
268 | |
269 | Ok |
270 | |
271 | .boxed |
272 | |
273 | |
274 | |
275 | object: &Repository, |
276 | operation: RepositoryCommitBeforeRequest, |
277 | state: DatabaseBackend, |
278 | operation_state: StackOperationState, |
279 | backend: BackendWrapper, |
280 | |
281 | let object = object.clone; |
282 | |
283 | async move |
284 | let object = backend |
285 | . |
286 | .await |
287 | .unwrap; |
288 | |
289 | let mut repository_backend = state.repository_backend.lock .await; |
290 | let file = repository_backend |
291 | .repository_commit_before |
292 | .await |
293 | .map_err?; |
294 | drop; |
295 | |
296 | Ok |
297 | |
298 | .boxed |
299 | |
300 | |
301 | |
302 | object: &Repository, |
303 | operation: , |
304 | state: DatabaseBackend, |
305 | |
306 | let object = object.clone; |
307 | |
308 | async move |
309 | let mut repository_backend = state.repository_backend.lock .await; |
310 | let value = repository_backend |
311 | .get_value |
312 | .await |
313 | .map_err |
314 | Internal |
315 | ?; |
316 | |
317 | Ok |
318 | |
319 | .boxed |
320 | |
321 | |
322 | |
323 | object: &Repository, |
324 | operation: , |
325 | state: DatabaseBackend, |
326 | |
327 | let object = object.clone; |
328 | |
329 | async move |
330 | let mut repository_backend = state.repository_backend.lock .await; |
331 | let value = repository_backend |
332 | .get_setting |
333 | .await |
334 | .map_err?; |
335 | |
336 | Ok |
337 | |
338 | .boxed |
339 | |
340 | |
341 | |
342 | object: &Repository, |
343 | operation: , |
344 | state: DatabaseBackend, |
345 | |
346 | let object = object.clone; |
347 | |
348 | async move |
349 | let mut repository_backend = state.repository_backend.lock .await; |
350 | let value = repository_backend |
351 | .write_setting |
352 | .await |
353 | .map_err?; |
354 | |
355 | Ok |
356 | |
357 | .boxed |
358 | |
359 | |
360 | |
361 | object: &Instance, |
362 | operation: AuthenticationTokenRequest, |
363 | state: DatabaseBackend, |
364 | |
365 | let object = object.clone; |
366 | async move |
367 | let mut backend = state.user_backend.lock .await; |
368 | |
369 | backend |
370 | .login |
371 | .await |
372 | .map_err |
373 | |
374 | .boxed |
375 | |
376 | |
377 | |
378 | _object: &Instance, |
379 | operation: RegisterAccountRequest, |
380 | state: DatabaseBackend, |
381 | |
382 | async move |
383 | let mut backend = state.user_backend.lock .await; |
384 | |
385 | backend |
386 | .register |
387 | .await |
388 | .map_err |
389 | |
390 | .boxed |
391 | |
392 | |
393 | |
394 | _object: &Instance, |
395 | operation: RepositoryCreateRequest, |
396 | state: DatabaseBackend, |
397 | |
398 | async move |
399 | let mut backend = state.repository_backend.lock .await; |
400 | |
401 | backend |
402 | .create_repository |
403 | .await |
404 | .map_err |
405 | |
406 | .boxed |
407 | |
408 |