Skip to content

Commit 6e01d3c

Browse files
authored
chore: fix tests and done some of TODO (#723)
1 parent e9b341d commit 6e01d3c

File tree

70 files changed

+284
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+284
-311
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ backend/services/spacegate/devsh/
3838
.pre-commit-config.yaml
3939

4040
.uuid
41+
backend/services/bios-all/dev.sh

backend/basic/src/dto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl BasicQueryCondInfo {
3131
/// 检查传入的 ``check_vars`` 是否满足 ``conds`` 中的条件
3232
///
3333
/// The outer level is the `OR` relationship, the inner level is the `AND` relationship
34-
pub fn check_or_and_conds(conds: &Vec<Vec<BasicQueryCondInfo>>, check_vars: &HashMap<String, Value>) -> TardisResult<bool> {
34+
pub fn check_or_and_conds(conds: &[Vec<BasicQueryCondInfo>], check_vars: &HashMap<String, Value>) -> TardisResult<bool> {
3535
let is_match = conds.iter().any(|and_conds| {
3636
and_conds.iter().all(|cond| match check_vars.get(&cond.field) {
3737
Some(check_val) => match &cond.op {

backend/basic/src/rbum/helper/rbum_scope_helper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub fn unsafe_fill_ctx(request: &tardis::web::poem::Request, funs: &TardisFunsIn
276276
roles.push(extend_role.to_string());
277277
}
278278
}
279-
ctx.owner = bios_ctx.owner.clone();
279+
ctx.owner.clone_from(&bios_ctx.owner);
280280
ctx.roles = roles;
281281
ctx.groups = bios_ctx.groups;
282282
ctx.own_paths = bios_ctx.own_paths;
@@ -296,7 +296,7 @@ pub fn unsafe_fill_owner_only(request: &tardis::web::poem::Request, funs: &Tardi
296296
do_unsafe_fill_ctx(
297297
request,
298298
|bios_ctx, ctx| {
299-
ctx.owner = bios_ctx.owner.clone();
299+
ctx.owner.clone_from(&bios_ctx.owner);
300300
},
301301
funs,
302302
ctx,

backend/basic/src/rbum/serv/rbum_cert_serv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl RbumCrudOperation<rbum_cert::ActiveModel, RbumCertAddReq, RbumCertModifyReq
520520
}
521521
}
522522
if let Some(vcode) = &add_req.vcode {
523-
Self::add_vcode_to_cache(&add_req.ak, vcode, rel_rbum_cert_conf_id, funs, &ctx).await?;
523+
Self::add_vcode_to_cache(&add_req.ak, vcode, rel_rbum_cert_conf_id, funs, ctx).await?;
524524
}
525525
}
526526
Ok(())

backend/basic/src/rbum/serv/rbum_item_serv.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use crate::rbum::helper::rbum_event_helper;
2727
use crate::rbum::rbum_config::RbumConfigApi;
2828
use crate::rbum::rbum_enumeration::{RbumCertRelKind, RbumRelFromKind, RbumScopeLevelKind};
2929
use crate::rbum::serv::rbum_cert_serv::{RbumCertConfServ, RbumCertServ};
30-
use crate::rbum::serv::rbum_crud_serv::{RbumCrudOperation, RbumCrudQueryPackage, ID_FIELD_NAME};
30+
#[cfg(feature = "with-mq")]
31+
use crate::rbum::serv::rbum_crud_serv::ID_FIELD_NAME;
32+
use crate::rbum::serv::rbum_crud_serv::{RbumCrudOperation, RbumCrudQueryPackage};
3133
use crate::rbum::serv::rbum_domain_serv::RbumDomainServ;
3234
use crate::rbum::serv::rbum_kind_serv::{RbumKindAttrServ, RbumKindServ};
3335
use crate::rbum::serv::rbum_rel_serv::RbumRelServ;

backend/basic/src/spi/spi_initializer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ pub mod common_pg {
240240
let compatible_type = TardisFuns::json.json_to_obj(ext.get("compatible_type").unwrap_or(&tardis::serde_json::Value::String("None".to_string())).clone())?;
241241
let client = TardisRelDBClient::init(&DBModuleConfig {
242242
url: bs_cert.conn_uri.parse().expect("invalid url"),
243-
max_connections: ext.get("max_connections").map(|c| c.as_u64()).flatten().unwrap_or(5) as u32,
244-
min_connections: ext.get("min_connections").map(|c| c.as_u64()).flatten().unwrap_or(1) as u32,
243+
max_connections: ext.get("max_connections").and_then(|c| c.as_u64()).unwrap_or(5) as u32,
244+
min_connections: ext.get("min_connections").and_then(|c| c.as_u64()).unwrap_or(1) as u32,
245245
connect_timeout_sec: None,
246246
idle_timeout_sec: None,
247247
compatible_type,

backend/basic/tests/test_rbum_cert.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,24 +731,24 @@ async fn test_rbum_cert_sk_dynamic(context: &TardisContext) -> TardisResult<()>
731731
tardis::tokio::time::sleep(Duration::from_millis(100)).await;
732732
info!("【test_rbum_cert】 : Test Validate : RbumCertServ::validate with sk_dynamic");
733733
RbumCertServ::validate_by_spec_cert_conf("i@sunisle.org", "123456", &cert_conf_mail_vcode_id, false, &context.own_paths, &funs).await?;
734-
// todo will the verification code be deleted if the verification is successful?
734+
// TODO will the verification code be deleted if the verification is successful?
735735
RbumCertServ::get_and_delete_vcode_in_cache("i@sunisle.org", &context.own_paths, &funs).await?;
736736
assert!(RbumCertServ::validate_by_spec_cert_conf("i@sunisle.org", "123456", &cert_conf_mail_vcode_id, false, &context.own_paths, &funs).await.is_err());
737737

738738
info!("【test_rbum_cert】 : Test Add : RbumCertServ::get_and_delete_vcode_in_cache");
739739
assert!(RbumCertServ::get_and_delete_vcode_in_cache("i@sunisle.org", &context.own_paths, &funs).await?.is_none());
740-
RbumCertServ::add_vcode_to_cache("i@sunisle.org", "qqqqq", &cert_conf_mail_vcode_id, &funs, &context).await?;
740+
RbumCertServ::add_vcode_to_cache("i@sunisle.org", "qqqqq", &cert_conf_mail_vcode_id, &funs, context).await?;
741741
assert_eq!(
742742
RbumCertServ::get_and_delete_vcode_in_cache("i@sunisle.org", &context.own_paths, &funs).await?.unwrap(),
743743
"qqqqq"
744744
);
745745

746746
info!("【test_rbum_cert】 : Test Validate : RbumCertServ::validate with sk_dynamic");
747-
RbumCertServ::add_vcode_to_cache("i@sunisle.org", "xxxx", &cert_conf_mail_vcode_id, &funs, &context).await?;
747+
RbumCertServ::add_vcode_to_cache("i@sunisle.org", "xxxx", &cert_conf_mail_vcode_id, &funs, context).await?;
748748
RbumCertServ::validate_by_spec_cert_conf("i@sunisle.org", "xxxx", &cert_conf_mail_vcode_id, false, &context.own_paths, &funs).await?;
749749

750750
info!("【test_rbum_cert】 : Test Validate : RbumCertServ::validate with sk_dynamic & expire");
751-
RbumCertServ::add_vcode_to_cache("i@sunisle.org", "xxxx", &cert_conf_mail_vcode_id, &funs, &context).await?;
751+
RbumCertServ::add_vcode_to_cache("i@sunisle.org", "xxxx", &cert_conf_mail_vcode_id, &funs, context).await?;
752752
// tardis::tokio::time::sleep(Duration::from_secs(120)).await;
753753
RbumCertServ::get_and_delete_vcode_in_cache("i@sunisle.org", &context.own_paths, &funs).await?;
754754
assert!(RbumCertServ::validate_by_spec_cert_conf("i@sunisle.org", "xxxx", &cert_conf_mail_vcode_id, false, &context.own_paths, &funs).await.is_err());

backend/basic/tests/test_rbum_rel.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ async fn test_rbum_rel_with_set(context: &TardisContext) -> TardisResult<()> {
325325

326326
assert!(
327327
!RbumRelServ::check_rel(
328-
&mut RbumRelCheckReq {
328+
&RbumRelCheckReq {
329329
tag: "bind".to_string(),
330330
from_rbum_kind: RbumRelFromKind::Item,
331331
from_rbum_id: context.owner.to_string(),
@@ -1156,7 +1156,7 @@ async fn test_rbum_rel_use(context: &TardisContext) -> TardisResult<()> {
11561156
// Environment not match
11571157
assert!(
11581158
!RbumRelServ::check_rel(
1159-
&mut RbumRelCheckReq {
1159+
&RbumRelCheckReq {
11601160
tag: "bind".to_string(),
11611161
from_rbum_kind: RbumRelFromKind::Item,
11621162
from_rbum_id: item_reldb_inst1_id.to_string(),
@@ -1174,7 +1174,7 @@ async fn test_rbum_rel_use(context: &TardisContext) -> TardisResult<()> {
11741174
// Environment not match
11751175
assert!(
11761176
!RbumRelServ::check_rel(
1177-
&mut RbumRelCheckReq {
1177+
&RbumRelCheckReq {
11781178
tag: "bind".to_string(),
11791179
from_rbum_kind: RbumRelFromKind::Item,
11801180
from_rbum_id: item_reldb_inst1_id.to_string(),
@@ -1194,7 +1194,7 @@ async fn test_rbum_rel_use(context: &TardisContext) -> TardisResult<()> {
11941194

11951195
assert!(
11961196
RbumRelServ::check_rel(
1197-
&mut RbumRelCheckReq {
1197+
&RbumRelCheckReq {
11981198
tag: "bind".to_string(),
11991199
from_rbum_kind: RbumRelFromKind::Item,
12001200
from_rbum_id: item_reldb_inst1_id.to_string(),
@@ -1231,7 +1231,7 @@ async fn test_rbum_rel_use(context: &TardisContext) -> TardisResult<()> {
12311231

12321232
assert!(
12331233
!RbumRelServ::check_rel(
1234-
&mut RbumRelCheckReq {
1234+
&RbumRelCheckReq {
12351235
tag: "bind".to_string(),
12361236
from_rbum_kind: RbumRelFromKind::Item,
12371237
from_rbum_id: item_reldb_inst1_id.to_string(),

backend/gateways/spacegate-plugins/src/plugin/audit_log.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::extension::audit_log_param::{AuditLogParam, LogParamContent};
3434
use crate::extension::before_encrypt_body::BeforeEncryptBody;
3535
use crate::extension::cert_info::CertInfo;
3636

37-
pub const CODE: &str = "audit_log";
37+
pub const CODE: &str = "audit-log";
3838

3939
#[cfg(feature = "schema")]
4040
use spacegate_plugin::schemars;

backend/gateways/spacegate-plugins/src/plugin/auth.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,9 @@ impl SgPluginAuthConfig {
7676
}
7777
}
7878

79-
let cache_url: Url = if self.cache_url.is_empty() {
80-
//todo get from gateways
81-
// init_dto.gateway_parameters.redis_url.as_deref().unwrap_or("redis://127.0.0.1:6379")
82-
"redis://127.0.0.1:6379"
83-
} else {
84-
self.cache_url.as_str()
85-
}
86-
.parse()
87-
.map_err(|e| TardisError::internal_error(&format!("[SG.Filter.Auth]invalid redis url: {e:?}"), "-1"))?;
79+
let cache_url: Url = if self.cache_url.is_empty() { "redis://127.0.0.1:6379" } else { self.cache_url.as_str() }
80+
.parse()
81+
.map_err(|e| TardisError::internal_error(&format!("[SG.Filter.Auth]invalid redis url: {e:?}"), "-1"))?;
8882

8983
let mut tardis_config = tardis::TardisFuns::clone_config();
9084
tardis_config.cs.insert(bios_auth::auth_constants::DOMAIN_CODE.to_string(), serde_json::to_value(self.auth_config.clone())?);
@@ -207,7 +201,7 @@ impl AuthPlugin {
207201
// 用于过滤和管理同一个请求多次通过本插件的情况
208202
// 如果是多次请求,那么直接返回跳过本插件
209203
async fn is_same_req(&self, req: &mut SgRequest) -> Result<bool, BoxError> {
210-
let cache = req.get_redis_client_by_gateway_name().ok_or_else(|| "missing gateway name")?;
204+
let cache = req.get_redis_client_by_gateway_name().ok_or("missing gateway name")?;
211205
let mut conn = cache.get_conn().await;
212206
if let Some(is_same) = req.headers().get(&self.header_is_same_req) {
213207
if conn.exists(format!("{}{}", self.cache_key_is_same_req, is_same.to_str()?)).await? {

backend/gateways/spacegate-plugins/src/plugin/ip_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use spacegate_shell::plugin::Plugin;
1111
use spacegate_shell::{BoxError, SgBody, SgResponseExt};
1212

1313
use tardis::{log, serde_json};
14-
pub const CODE: &str = "ip_time";
14+
pub const CODE: &str = "ip-time";
1515

1616
mod ip_time_rule;
1717
#[cfg(test)]

backend/gateways/spacegate-plugins/src/plugin/op_redis_publisher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct RedisPublisherPlugin {
4040
}
4141

4242
impl Plugin for RedisPublisherPlugin {
43+
//FIXME fix code to kebab-case
4344
const CODE: &'static str = "op_redis_publisher";
4445

4546
#[cfg(feature = "schema")]

backend/middlewares/flow/src/api/cc/flow_cc_model_api.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct FlowCcModelApi;
2525
#[poem_openapi::OpenApi(prefix_path = "/cc/model")]
2626
impl FlowCcModelApi {
2727
/// Add Model
28-
///
28+
///
2929
/// 添加模型
3030
#[oai(path = "/", method = "post")]
3131
async fn add(&self, mut add_req: Json<FlowModelAddReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<String> {
@@ -37,7 +37,7 @@ impl FlowCcModelApi {
3737
}
3838

3939
/// Modify Model By Model Id
40-
///
40+
///
4141
/// 修改模型
4242
#[oai(path = "/:flow_model_id", method = "patch")]
4343
async fn modify(&self, flow_model_id: Path<String>, mut modify_req: Json<FlowModelModifyReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
@@ -49,7 +49,7 @@ impl FlowCcModelApi {
4949
}
5050

5151
/// Get Model By Model Id
52-
///
52+
///
5353
/// 获取模型
5454
#[oai(path = "/:flow_model_id", method = "get")]
5555
async fn get(&self, flow_model_id: Path<String>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<FlowModelAggResp> {
@@ -59,7 +59,7 @@ impl FlowCcModelApi {
5959
}
6060

6161
/// Find Models
62-
///
62+
///
6363
/// 获取模型列表
6464
#[oai(path = "/", method = "get")]
6565
#[allow(clippy::too_many_arguments)]
@@ -127,7 +127,7 @@ impl FlowCcModelApi {
127127
}
128128

129129
/// Delete Model By Model Id
130-
///
130+
///
131131
/// 删除模型
132132
///
133133
/// Valid only when model is not used
@@ -143,7 +143,7 @@ impl FlowCcModelApi {
143143
}
144144

145145
/// Bind State By Model Id [Deprecated]
146-
///
146+
///
147147
/// 绑定状态 [已废弃]
148148
#[oai(path = "/:flow_model_id/bind_state", method = "post")]
149149
async fn bind_state(&self, flow_model_id: Path<String>, req: Json<FlowModelBindStateReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
@@ -164,7 +164,7 @@ impl FlowCcModelApi {
164164
}
165165

166166
/// Unbind State By Model Id [Deprecated]
167-
///
167+
///
168168
/// 解绑状态 [已废弃]
169169
#[oai(path = "/:flow_model_id/unbind_state", method = "post")]
170170
async fn unbind_state(&self, flow_model_id: Path<String>, req: Json<FlowModelUnbindStateReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
@@ -185,7 +185,7 @@ impl FlowCcModelApi {
185185
}
186186

187187
/// Resort states [Deprecated]
188-
///
188+
///
189189
/// 状态重新排序 [已废弃]
190190
#[oai(path = "/:flow_model_id/resort_state", method = "post")]
191191
async fn resort_state(&self, flow_model_id: Path<String>, req: Json<FlowModelSortStatesReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
@@ -216,7 +216,7 @@ impl FlowCcModelApi {
216216
}
217217

218218
/// Resort transitions [Deprecated]
219-
///
219+
///
220220
/// 动作重新排序 [已废弃]
221221
#[oai(path = "/:flow_model_id/resort_transition", method = "post")]
222222
async fn resort_transition(
@@ -252,8 +252,8 @@ impl FlowCcModelApi {
252252
TardisResp::ok(Void {})
253253
}
254254

255-
/// copy parent model to current own_paths
256-
///
255+
/// copy parent model to current own_paths
256+
///
257257
/// 复制父级模型到当前 own_paths
258258
#[oai(path = "/add_custom_model", method = "post")]
259259
async fn add_custom_model(&self, req: Json<FlowModelAddCustomModelReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Vec<FlowModelAddCustomModelResp>> {
@@ -269,7 +269,7 @@ impl FlowCcModelApi {
269269
}
270270

271271
/// find rel states by model_id
272-
///
272+
///
273273
/// 获取关联状态
274274
#[oai(path = "/find_rel_status", method = "get")]
275275
async fn find_rel_states(
@@ -286,7 +286,7 @@ impl FlowCcModelApi {
286286
}
287287

288288
/// modify related state [Deprecated]
289-
///
289+
///
290290
/// 编辑关联的状态 [已废弃]
291291
#[oai(path = "/:flow_model_id/modify_rel_state", method = "patch")]
292292
async fn modify_rel_state(&self, flow_model_id: Path<String>, req: Json<FlowStateRelModelModifyReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {

backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct FlowCiModelApi;
1818
#[poem_openapi::OpenApi(prefix_path = "/ci/model")]
1919
impl FlowCiModelApi {
2020
/// Get model detail
21-
///
21+
///
2222
/// 获取模型详情
2323
#[oai(path = "/detail", method = "get")]
2424
async fn get_detail(
@@ -53,7 +53,7 @@ impl FlowCiModelApi {
5353
}
5454

5555
/// find rel states by model_id
56-
///
56+
///
5757
/// 获取关联状态
5858
#[oai(path = "/find_rel_status", method = "get")]
5959
async fn find_rel_states(
@@ -71,7 +71,7 @@ impl FlowCiModelApi {
7171
}
7272

7373
/// add custom model by template_id
74-
///
74+
///
7575
/// 添加自定义模型
7676
#[oai(path = "/add_custom_model", method = "post")]
7777
async fn add_custom_model(

backend/middlewares/flow/src/dto/flow_external_dto.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,56 @@ use super::{flow_state_dto::FlowSysStateKind, flow_transition_dto::FlowTransitio
1010
#[derive(Serialize, Deserialize, Debug, Default, poem_openapi::Object)]
1111
pub struct FlowExternalReq {
1212
/// Type of request initiated, ex: query field, modification field, status change notification...
13-
///
13+
///
1414
/// 发起请求的类型,例:查询字段,修改字段,状态变更通知..
1515
pub kind: FlowExternalKind,
1616
/// When kind is ModifyField, the field is modified in a specific way, for example: validate the content, post action, precondition trigger ...
17-
///
17+
///
1818
/// 当 kind 为 ModifyField 时,字段被修改的具体操作方式,例:验证内容,后置动作,前置条件触发..
1919
pub callback_op: Option<FlowExternalCallbackOp>,
2020
/// The tag corresponding to the current business
21-
///
21+
///
2222
/// 当前业务对应的 tag
2323
pub curr_tag: String,
2424
/// Current Business ID
25-
///
25+
///
2626
/// 当前业务ID
2727
pub curr_bus_obj_id: String,
2828
/// Workflow Instance ID
29-
///
29+
///
3030
/// 工作流实例ID
3131
pub inst_id: String,
3232
/// Modified State ID
33-
///
33+
///
3434
/// 修改后的状态ID
3535
pub target_state: Option<String>,
3636
/// Modified state type
37-
///
37+
///
3838
/// 修改后的状态类型
3939
pub target_sys_state: Option<FlowSysStateKind>,
4040
/// Status ID before modification
41-
///
41+
///
4242
/// 修改前的状态ID
4343
pub original_state: Option<String>,
4444
/// Type of state before modification
45-
///
45+
///
4646
/// 修改前的状态类型
4747
pub original_sys_state: Option<FlowSysStateKind>,
4848
/// Name of the action actually triggered (business side logging operation)
49-
///
49+
///
5050
/// 实际触发的动作名称(业务方记录操作日志)
5151
pub transition_name: Option<String>,
5252
pub owner_paths: String,
5353
/// When kind is QueryField, batch pass business IDs
54-
///
54+
///
5555
/// 当 kind 为 QueryField 时,批量传入业务ID
5656
pub obj_ids: Vec<String>,
5757
/// Whether the request triggers a notification
58-
///
58+
///
5959
/// 请求是否触发通知
6060
pub notify: Option<bool>,
6161
/// 扩展字段
62-
///
62+
///
6363
/// Extended params
6464
pub params: Vec<FlowExternalParams>,
6565
}

0 commit comments

Comments
 (0)