Implement `FromOperationState` for `AuthenticatedUser` and `AuthenticatedInstance`
Use `AuthenticatedUser` on repository requests so we can filter by privacy. Woohoo! Attempt to filter `UserRepositoriesRequest` responses by visibility to the requester.
parent: tbd commit: 75dcac3
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 | operation_state: StackOperationState, |
31 | requester: , |
32 | |
33 | let object = object.clone; |
34 | |
35 | async move |
36 | let mut user_backend = state.user_backend.lock .await; |
37 | let repositories_response = user_backend |
38 | .repositories_for_user |
39 | .await |
40 | .map_err?; |
41 | |
42 | let mut repositories = vec!; |
43 | |
44 | for repository in repositories_response |
45 | if operation_state |
46 | .giterated_backend |
47 | . |
48 | .await |
49 | .is_ok |
50 | |
51 | repositories.push; |
52 | |
53 | |
54 | |
55 | Ok |
56 | |
57 | .boxed |
58 | |
59 | |
60 | |
61 | object: &User, |
62 | operation: , |
63 | state: DatabaseBackend, |
64 | |
65 | let object = object.clone; |
66 | |
67 | async move |
68 | let mut user_backend = state.user_backend.lock .await; |
69 | let value = user_backend |
70 | .get_value |
71 | .await |
72 | .map_err?; |
73 | |
74 | Ok |
75 | |
76 | .boxed |
77 | |
78 | |
79 | |
80 | object: &User, |
81 | operation: , |
82 | state: DatabaseBackend, |
83 | |
84 | let object = object.clone; |
85 | |
86 | async move |
87 | let mut user_backend = state.user_backend.lock .await; |
88 | let value = user_backend |
89 | .get_setting |
90 | .await |
91 | .map_err?; |
92 | |
93 | Ok |
94 | |
95 | .boxed |
96 | |
97 | |
98 | |
99 | object: &User, |
100 | operation: , |
101 | state: DatabaseBackend, |
102 | |
103 | let object = object.clone; |
104 | |
105 | async move |
106 | let mut user_backend = state.user_backend.lock .await; |
107 | let value = user_backend |
108 | .write_setting |
109 | .await |
110 | .map_err?; |
111 | |
112 | Ok |
113 | |
114 | .boxed |
115 | |
116 | |
117 | |
118 | object: &Repository, |
119 | operation: RepositoryInfoRequest, |
120 | state: DatabaseBackend, |
121 | operation_state: StackOperationState, |
122 | backend: BackendWrapper, |
123 | requester: , |
124 | |
125 | let object = object.clone; |
126 | |
127 | async move |
128 | let mut object = backend |
129 | . |
130 | .await |
131 | .unwrap; |
132 | |
133 | let mut repository_backend = state.repository_backend.lock .await; |
134 | let tree = repository_backend |
135 | .repository_file_inspect |
136 | &requester, |
137 | object.object, |
138 | &RepositoryFileInspectRequest |
139 | extra_metadata: operation.extra_metadata, |
140 | path: operation.path, |
141 | rev: operation.rev.clone, |
142 | , |
143 | |
144 | .await |
145 | .map_err?; |
146 | drop; |
147 | |
148 | let info = RepositoryView |
149 | name: object.object .name.clone, |
150 | owner: object.object .owner.clone, |
151 | description: object. .await.ok, |
152 | visibility: object |
153 | . |
154 | .await |
155 | .map_err?, |
156 | default_branch: object |
157 | . |
158 | .await |
159 | .map_err?, |
160 | // 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. |
161 | latest_commit: object. .await.ok, |
162 | tree_rev: operation.rev, |
163 | tree, |
164 | ; |
165 | |
166 | Ok |
167 | |
168 | .boxed |
169 | |
170 | |
171 | |
172 | object: &Repository, |
173 | operation: RepositoryFileFromIdRequest, |
174 | state: DatabaseBackend, |
175 | operation_state: StackOperationState, |
176 | backend: BackendWrapper, |
177 | requester: , |
178 | |
179 | let object = object.clone; |
180 | |
181 | async move |
182 | let object = backend |
183 | . |
184 | .await |
185 | .unwrap; |
186 | |
187 | let mut repository_backend = state.repository_backend.lock .await; |
188 | let file = repository_backend |
189 | .repository_file_from_id |
190 | &requester, |
191 | object.object, |
192 | &RepositoryFileFromIdRequest, |
193 | |
194 | .await |
195 | .map_err?; |
196 | drop; |
197 | |
198 | Ok |
199 | |
200 | .boxed |
201 | |
202 | |
203 | |
204 | object: &Repository, |
205 | operation: RepositoryFileFromPathRequest, |
206 | state: DatabaseBackend, |
207 | operation_state: StackOperationState, |
208 | backend: BackendWrapper, |
209 | requester: , |
210 | |
211 | let object = object.clone; |
212 | |
213 | async move |
214 | let object = backend |
215 | . |
216 | .await |
217 | .unwrap; |
218 | |
219 | let mut repository_backend = state.repository_backend.lock .await; |
220 | let file = repository_backend |
221 | .repository_file_from_path |
222 | &requester, |
223 | object.object, |
224 | &RepositoryFileFromPathRequest |
225 | rev: operation.rev, |
226 | path: operation.path, |
227 | , |
228 | |
229 | .await |
230 | .map_err?; |
231 | drop; |
232 | |
233 | Ok |
234 | |
235 | .boxed |
236 | |
237 | |
238 | |
239 | object: &Repository, |
240 | operation: RepositoryDiffRequest, |
241 | state: DatabaseBackend, |
242 | operation_state: StackOperationState, |
243 | backend: BackendWrapper, |
244 | requester: , |
245 | |
246 | let object = object.clone; |
247 | |
248 | async move |
249 | let object = backend |
250 | . |
251 | .await |
252 | .unwrap; |
253 | |
254 | let mut repository_backend = state.repository_backend.lock .await; |
255 | let diff = repository_backend |
256 | .repository_diff |
257 | .await |
258 | .map_err?; |
259 | drop; |
260 | |
261 | Ok |
262 | |
263 | .boxed |
264 | |
265 | |
266 | |
267 | object: &Repository, |
268 | operation: RepositoryDiffPatchRequest, |
269 | state: DatabaseBackend, |
270 | operation_state: StackOperationState, |
271 | backend: BackendWrapper, |
272 | requester: , |
273 | |
274 | let object = object.clone; |
275 | |
276 | async move |
277 | let object = backend |
278 | . |
279 | .await |
280 | .unwrap; |
281 | |
282 | let mut repository_backend = state.repository_backend.lock .await; |
283 | let patch = repository_backend |
284 | .repository_diff_patch |
285 | .await |
286 | .map_err?; |
287 | drop; |
288 | |
289 | Ok |
290 | |
291 | .boxed |
292 | |
293 | |
294 | |
295 | object: &Repository, |
296 | operation: RepositoryCommitBeforeRequest, |
297 | state: DatabaseBackend, |
298 | operation_state: StackOperationState, |
299 | backend: BackendWrapper, |
300 | requester: , |
301 | |
302 | let object = object.clone; |
303 | |
304 | async move |
305 | let object = backend |
306 | . |
307 | .await |
308 | .unwrap; |
309 | |
310 | let mut repository_backend = state.repository_backend.lock .await; |
311 | let file = repository_backend |
312 | .repository_commit_before |
313 | .await |
314 | .map_err?; |
315 | drop; |
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_value |
333 | .await |
334 | .map_err |
335 | Internal |
336 | ?; |
337 | |
338 | Ok |
339 | |
340 | .boxed |
341 | |
342 | |
343 | |
344 | object: &Repository, |
345 | operation: , |
346 | state: DatabaseBackend, |
347 | |
348 | let object = object.clone; |
349 | |
350 | async move |
351 | let mut repository_backend = state.repository_backend.lock .await; |
352 | let value = repository_backend |
353 | .get_setting |
354 | .await |
355 | .map_err?; |
356 | |
357 | Ok |
358 | |
359 | .boxed |
360 | |
361 | |
362 | |
363 | object: &Repository, |
364 | operation: , |
365 | state: DatabaseBackend, |
366 | |
367 | let object = object.clone; |
368 | |
369 | async move |
370 | let mut repository_backend = state.repository_backend.lock .await; |
371 | let value = repository_backend |
372 | .write_setting |
373 | .await |
374 | .map_err?; |
375 | |
376 | Ok |
377 | |
378 | .boxed |
379 | |
380 | |
381 | |
382 | object: &Instance, |
383 | operation: AuthenticationTokenRequest, |
384 | state: DatabaseBackend, |
385 | |
386 | let object = object.clone; |
387 | async move |
388 | let mut backend = state.user_backend.lock .await; |
389 | |
390 | backend |
391 | .login |
392 | .await |
393 | .map_err |
394 | |
395 | .boxed |
396 | |
397 | |
398 | |
399 | _object: &Instance, |
400 | operation: RegisterAccountRequest, |
401 | state: DatabaseBackend, |
402 | |
403 | async move |
404 | let mut backend = state.user_backend.lock .await; |
405 | |
406 | backend |
407 | .register |
408 | .await |
409 | .map_err |
410 | |
411 | .boxed |
412 | |
413 | |
414 | |
415 | _object: &Instance, |
416 | operation: RepositoryCreateRequest, |
417 | state: DatabaseBackend, |
418 | requester: AuthenticatedUser, |
419 | |
420 | async move |
421 | let mut backend = state.repository_backend.lock .await; |
422 | |
423 | backend |
424 | .create_repository |
425 | .await |
426 | .map_err |
427 | |
428 | .boxed |
429 | |
430 |