Fix networked setting request
parent: tbd commit: 4b5330d
Showing 3 changed files with 21 insertions and 22 deletions
giterated-daemon/src/database_backend/handler.rs
@@ -16,11 +16,12 @@ use giterated_models::{ | ||
16 | 16 | RepositoryInfoRequest, RepositoryLastCommitOfFileRequest, RepositoryStatistics, |
17 | 17 | RepositoryStatisticsRequest, RepositorySummary, RepositoryView, Visibility, |
18 | 18 | }, |
19 | settings::{AnySetting, GetSetting, GetSettingError}, | |
19 | settings::{GetSetting, GetSettingError}, | |
20 | 20 | user::{Bio, DisplayName, User, UserRepositoriesRequest}, |
21 | 21 | value::{AnyValue, GetValueTyped}, |
22 | 22 | }; |
23 | 23 | use giterated_stack::{AuthenticatedUser, AuthorizedInstance, GiteratedStack, StackOperationState}; |
24 | use serde_json::Value; | |
24 | 25 | |
25 | 26 | use super::DatabaseBackend; |
26 | 27 | |
@@ -82,7 +83,7 @@ pub fn user_get_setting( | ||
82 | 83 | object: &User, |
83 | 84 | operation: GetSetting, |
84 | 85 | state: DatabaseBackend, |
85 | ) -> LocalBoxFuture<'static, Result<AnySetting, OperationError<GetSettingError>>> { | |
86 | ) -> LocalBoxFuture<'static, Result<Value, OperationError<GetSettingError>>> { | |
86 | 87 | let object = object.clone(); |
87 | 88 | |
88 | 89 | async move { |
@@ -92,7 +93,7 @@ pub fn user_get_setting( | ||
92 | 93 | .await |
93 | 94 | .map_err(|e| OperationError::Internal(e.to_string()))?; |
94 | 95 | |
95 | Ok(value) | |
96 | Ok(value.0) | |
96 | 97 | } |
97 | 98 | .boxed_local() |
98 | 99 | } |
@@ -466,7 +467,7 @@ pub fn repository_get_setting( | ||
466 | 467 | object: &Repository, |
467 | 468 | operation: GetSetting, |
468 | 469 | state: DatabaseBackend, |
469 | ) -> LocalBoxFuture<'static, Result<AnySetting, OperationError<GetSettingError>>> { | |
470 | ) -> LocalBoxFuture<'static, Result<Value, OperationError<GetSettingError>>> { | |
470 | 471 | let object = object.clone(); |
471 | 472 | |
472 | 473 | async move { |
@@ -476,7 +477,7 @@ pub fn repository_get_setting( | ||
476 | 477 | .await |
477 | 478 | .map_err(|e| OperationError::Internal(e.to_string()))?; |
478 | 479 | |
479 | Ok(value) | |
480 | Ok(value.0) | |
480 | 481 | } |
481 | 482 | .boxed_local() |
482 | 483 | } |
giterated-daemon/src/database_backend/mod.rs
@@ -22,9 +22,9 @@ use self::handler::{ | ||
22 | 22 | instance_registration_request, repository_commit_before, repository_commit_by_id, |
23 | 23 | repository_diff, repository_diff_patch, repository_file_from_id, repository_file_from_path, |
24 | 24 | repository_get_branches, repository_get_default_branch, repository_get_latest_commit, |
25 | repository_get_statistics, repository_get_value_description, repository_get_value_visibility, | |
26 | repository_info, repository_last_commit_of_file, user_get_repositories, user_get_value_bio, | |
27 | user_get_value_display_name, | |
25 | repository_get_setting, repository_get_statistics, repository_get_value_description, | |
26 | repository_get_value_visibility, repository_info, repository_last_commit_of_file, | |
27 | user_get_repositories, user_get_setting, user_get_value_bio, user_get_value_display_name, | |
28 | 28 | }; |
29 | 29 | |
30 | 30 | #[derive(Clone, Debug)] |
@@ -79,7 +79,9 @@ impl DatabaseBackend { | ||
79 | 79 | |
80 | 80 | builder |
81 | 81 | .object::<Repository>() |
82 | .object_settings(repository_get_setting) | |
82 | 83 | .object::<User>() |
84 | .object_settings(user_get_setting) | |
83 | 85 | .object::<Instance>(); |
84 | 86 | |
85 | 87 | builder |
giterated-stack/src/handler.rs
@@ -14,7 +14,8 @@ use giterated_models::{ | ||
14 | 14 | settings::{GetSetting, GetSettingError, SetSetting, Setting}, |
15 | 15 | value::{AnyValue, GetValue, GetValueTyped, GiteratedObjectValue}, |
16 | 16 | }; |
17 | use tracing::trace; | |
17 | use serde_json::Value; | |
18 | use tracing::{info, trace}; | |
18 | 19 | |
19 | 20 | use crate::{ |
20 | 21 | GiteratedOperationHandler, ObjectMeta, ObjectOperationPair, ObjectValuePair, OperationMeta, |
@@ -437,9 +438,7 @@ impl RuntimeMetadata { | ||
437 | 438 | SettingMeta { |
438 | 439 | name: setting_name, |
439 | 440 | deserialize: Box::new(|bytes| Ok(Box::new(serde_json::from_slice(bytes)?))), |
440 | serialize: Box::new(|source| { | |
441 | serde_json::to_value(source.downcast::<S>().unwrap()) | |
442 | }), | |
441 | serialize: Box::new(|source| Ok(*source.downcast::<Value>().unwrap())), | |
443 | 442 | }, |
444 | 443 | ) |
445 | 444 | .is_some() |
@@ -499,19 +498,21 @@ impl GiteratedStack { | ||
499 | 498 | .network_get_value(object, object_type.clone(), operation, operation_state) |
500 | 499 | .await; |
501 | 500 | } else if message.operation == "get_setting" { |
501 | let operation: GetSetting = serde_json::from_slice(&message.payload.0).unwrap(); | |
502 | info!("1"); | |
502 | 503 | let setting_meta = self |
503 | 504 | .metadata |
504 | 505 | .settings |
505 | .get(&object_type) | |
506 | .get(&operation.setting_name) | |
506 | 507 | .ok_or_else(|| OperationError::Unhandled)?; |
507 | ||
508 | let operation: GetSetting = serde_json::from_slice(&message.payload.0).unwrap(); | |
508 | info!("2"); | |
509 | 509 | let raw_result = self |
510 | 510 | .get_setting(object, object_type.clone(), operation, operation_state) |
511 | 511 | .await; |
512 | ||
512 | info!("3"); | |
513 | 513 | return match raw_result { |
514 | 514 | Ok(success) => { |
515 | info!("3a"); | |
515 | 516 | // Success is the setting type, serialize it |
516 | 517 | let serialized = (setting_meta.serialize)(success).unwrap(); |
517 | 518 | |
@@ -519,6 +520,7 @@ impl GiteratedStack { | ||
519 | 520 | } |
520 | 521 | Err(err) => Err(match err { |
521 | 522 | OperationError::Operation(failure) => { |
523 | info!("3b"); | |
522 | 524 | // We know how to resolve this type |
523 | 525 | let failure: GetSettingError = *failure.downcast().unwrap(); |
524 | 526 | |
@@ -663,12 +665,6 @@ impl GiteratedStack { | ||
663 | 665 | operation.setting_name |
664 | 666 | ); |
665 | 667 | |
666 | let _setting_meta = self | |
667 | .metadata | |
668 | .settings | |
669 | .get(&object_kind) | |
670 | .ok_or_else(|| OperationError::Unhandled)?; | |
671 | ||
672 | 668 | let setting_getter = self |
673 | 669 | .setting_getters |
674 | 670 | .get(&object_kind) |