Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ideal-world/bios
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Apr 23, 2024
2 parents f63b211 + fe06fb6 commit fd47e66
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 143 deletions.
1 change: 0 additions & 1 deletion backend/basic/src/rbum/dto/rbum_cert_conf_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ pub struct RbumCertConfDetailResp {
/// 凭证配置id和扩展信息
#[derive(Serialize, Deserialize, Debug)]
#[cfg_attr(feature = "default", derive(poem_openapi::Object, sea_orm::FromQueryResult))]
#[deprecated]
pub struct RbumCertConfIdAndExtResp {
/// Certificate configuration id
///
Expand Down
6 changes: 0 additions & 6 deletions backend/basic/src/rbum/dto/rbum_cert_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ pub struct RbumCertSummaryResp {
///
/// 关联的[凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp)名称
pub rel_rbum_cert_conf_name: Option<String>,
// TODO
pub rel_rbum_cert_conf_code: Option<String>,
/// Associated [resource kind](crate::rbum::rbum_enumeration::RbumCertRelKind)
///
/// 关联的[资源类型](crate::rbum::rbum_enumeration::RbumCertRelKind)
Expand Down Expand Up @@ -367,8 +365,6 @@ pub struct RbumCertSummaryWithSkResp {
///
/// 关联的[凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp)名称
pub rel_rbum_cert_conf_name: Option<String>,
// TODO
pub rel_rbum_cert_conf_code: Option<String>,
/// Associated [resource kind](crate::rbum::rbum_enumeration::RbumCertRelKind)
///
/// 关联的[资源类型](crate::rbum::rbum_enumeration::RbumCertRelKind)
Expand Down Expand Up @@ -439,8 +435,6 @@ pub struct RbumCertDetailResp {
///
/// 关联的[凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp)名称
pub rel_rbum_cert_conf_name: Option<String>,
// TODO
pub rel_rbum_cert_conf_code: Option<String>,
/// Associated [resource kind](crate::rbum::rbum_enumeration::RbumCertRelKind)
///
/// 关联的[资源类型](crate::rbum::rbum_enumeration::RbumCertRelKind)
Expand Down
27 changes: 0 additions & 27 deletions backend/basic/src/rbum/rbum_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ pub struct RbumConfig {
pub task_mq_topic_event: String,
// own_paths:ak -> vcode
pub cache_key_cert_vcode_info_: String,
pub cache_key_cert_vcode_expire_sec: usize,
pub cache_key_cert_code_: String,
pub cache_key_cert_code_expire_sec: usize,
// set_code -> set_id
pub cache_key_set_code_: String,
pub cache_key_set_code_expire_sec: usize,
Expand All @@ -42,9 +39,6 @@ impl Default for RbumConfig {
mq_header_name_operator: "OP".to_string(),
task_mq_topic_event: "rbum::task::event".to_string(),
cache_key_cert_vcode_info_: "rbum:cache:cert:vcode:".to_string(),
cache_key_cert_vcode_expire_sec: 300,
cache_key_cert_code_: "rbum:cache:cert:code:".to_string(),
cache_key_cert_code_expire_sec: 60 * 60 * 24,
cache_key_set_code_: "rbum:cache:set:code:".to_string(),
cache_key_set_code_expire_sec: 60 * 60 * 24,
cache_key_cert_locked_: "rbum:cert:locked:".to_string(),
Expand Down Expand Up @@ -89,9 +83,6 @@ pub trait RbumConfigApi {
fn rbum_conf_task_mq_topic_event(&self) -> String;
fn rbum_conf_mq_header_name_operator(&self) -> String;
fn rbum_conf_cache_key_cert_vcode_info_(&self) -> String;
fn rbum_conf_cache_key_cert_vcode_expire_sec(&self) -> usize;
fn rbum_conf_cache_key_cert_code_(&self) -> String;
fn rbum_conf_cache_key_cert_code_expire_sec(&self) -> usize;
fn rbum_conf_cache_key_set_code_(&self) -> String;
fn rbum_conf_cache_key_set_code_expire_sec(&self) -> usize;
fn rbum_conf_cache_key_cert_locked_(&self) -> String;
Expand Down Expand Up @@ -125,24 +116,6 @@ impl RbumConfigApi for TardisFunsInst {
RbumConfigManager::get_config(self.module_code(), |conf| conf.cache_key_cert_vcode_info_.to_string())
}

// TODO
// #[deprecated]
fn rbum_conf_cache_key_cert_vcode_expire_sec(&self) -> usize {
RbumConfigManager::get_config(self.module_code(), |conf| conf.cache_key_cert_vcode_expire_sec)
}

// TODO
// #[deprecated]
fn rbum_conf_cache_key_cert_code_(&self) -> String {
RbumConfigManager::get_config(self.module_code(), |conf| conf.cache_key_cert_code_.to_string())
}

// TODO
// #[deprecated]
fn rbum_conf_cache_key_cert_code_expire_sec(&self) -> usize {
RbumConfigManager::get_config(self.module_code(), |conf| conf.cache_key_cert_code_expire_sec)
}

fn rbum_conf_cache_key_set_code_(&self) -> String {
RbumConfigManager::get_config(self.module_code(), |conf| conf.cache_key_set_code_.to_string())
}
Expand Down
86 changes: 10 additions & 76 deletions backend/basic/src/rbum/serv/rbum_cert_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,31 +210,6 @@ impl RbumCrudOperation<rbum_cert_conf::ActiveModel, RbumCertConfAddReq, RbumCert
Ok(rbum_cert_conf)
}

// TODO
// #[deprecated]
async fn after_modify_rbum(id: &str, _: &mut RbumCertConfModifyReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let rbum_cert_conf = Self::get_rbum(id, &RbumCertConfFilterReq::default(), funs, ctx).await?;
let key = &format!(
"{}{}",
funs.rbum_conf_cache_key_cert_code_(),
TardisFuns::crypto.base64.encode(format!(
"{}{}{}",
&rbum_cert_conf.kind, &rbum_cert_conf.rel_rbum_domain_id, &rbum_cert_conf.rel_rbum_item_id
))
);
funs.cache()
.set_ex(
key,
&TardisFuns::json.obj_to_string(&RbumCertConfIdAndExtResp {
id: rbum_cert_conf.id.clone(),
ext: rbum_cert_conf.ext.clone(),
})?,
funs.rbum_conf_cache_key_cert_code_expire_sec() as u64,
)
.await?;
Ok(())
}

async fn before_delete_rbum(id: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<Option<RbumCertConfDetailResp>> {
if funs
.db()
Expand All @@ -252,27 +227,6 @@ impl RbumCrudOperation<rbum_cert_conf::ActiveModel, RbumCertConfAddReq, RbumCert
}
Self::check_ownership(id, funs, ctx).await?;
Self::check_exist_before_delete(id, RbumCertServ::get_table_name(), rbum_cert::Column::RelRbumCertConfId.as_str(), funs).await?;
// TODO
// #[deprecated]
let result = Self::peek_rbum(
id,
&RbumCertConfFilterReq {
basic: RbumBasicFilterReq {
with_sub_own_paths: true,
..Default::default()
},
..Default::default()
},
funs,
ctx,
)
.await?;
let key = &format!(
"{}{}",
funs.rbum_conf_cache_key_cert_code_(),
TardisFuns::crypto.base64.encode(format!("{}{}{}", &result.kind, &result.rel_rbum_domain_id, &result.rel_rbum_item_id))
);
funs.cache().del(key).await?;
Ok(None)
}

Expand Down Expand Up @@ -344,7 +298,6 @@ impl RbumCrudOperation<rbum_cert_conf::ActiveModel, RbumCertConfAddReq, RbumCert
}

impl RbumCertConfServ {
#[deprecated]
pub async fn get_rbum_cert_conf_id_and_ext_by_kind_supplier(
kind: &str,
supplier: &str,
Expand All @@ -364,25 +317,10 @@ impl RbumCertConfServ {
if !ignore_status {
conf_info_stat.and_where(Expr::col(rbum_cert_conf::Column::Status).eq(RbumCertConfStatusKind::Enabled.to_int()));
}
//Ldap can be no supplier
if kind != "Ldap" || !supplier.is_empty() {
if !supplier.is_empty() {
conf_info_stat.and_where(Expr::col(rbum_cert_conf::Column::Supplier).eq(supplier));
}
let key = &format!(
"{}{}",
funs.rbum_conf_cache_key_cert_code_(),
TardisFuns::crypto.base64.encode(format!("{kind}{supplier}{rbum_domain_id}{rbum_item_id}"))
);
if let Some(cached_info) = funs.cache().get(key).await? {
Ok(Some(TardisFuns::json.str_to_obj(&cached_info)?))
} else if let Some(rbum_cert_conf_id_and_ext) = funs.db().get_dto::<RbumCertConfIdAndExtResp>(&conf_info_stat).await? {
funs.cache()
.set_ex(
key,
&TardisFuns::json.obj_to_string(&rbum_cert_conf_id_and_ext)?,
funs.rbum_conf_cache_key_cert_code_expire_sec() as u64,
)
.await?;
if let Some(rbum_cert_conf_id_and_ext) = funs.db().get_dto::<RbumCertConfIdAndExtResp>(&conf_info_stat).await? {
Ok(Some(rbum_cert_conf_id_and_ext))
} else {
Ok(None)
Expand Down Expand Up @@ -581,9 +519,9 @@ impl RbumCrudOperation<rbum_cert::ActiveModel, RbumCertAddReq, RbumCertModifyReq
}
}
}
}
if let Some(vcode) = &add_req.vcode {
Self::add_vcode_to_cache(add_req.ak.as_str(), vcode.as_str(), &ctx.own_paths, funs).await?;
if let Some(vcode) = &add_req.vcode {
Self::add_vcode_to_cache(add_req.ak.as_str(), vcode.as_str(), rel_rbum_cert_conf_id, funs, &ctx).await?;
}
}
Ok(())
}
Expand Down Expand Up @@ -742,11 +680,6 @@ impl RbumCrudOperation<rbum_cert::ActiveModel, RbumCertAddReq, RbumCertModifyReq
Expr::col((rbum_cert_conf::Entity, rbum_cert_conf::Column::Name)).if_null(""),
Alias::new("rel_rbum_cert_conf_name"),
)
// TODO
.expr_as(
Expr::col((rbum_cert_conf::Entity, rbum_cert_conf::Column::Name)).if_null(""),
Alias::new("rel_rbum_cert_conf_code"),
)
.from(rbum_cert::Entity)
.left_join(
rbum_cert_conf::Entity,
Expand Down Expand Up @@ -792,13 +725,14 @@ impl RbumCertServ {
///
///
/// 添加动态sk(验证码)到缓存
pub async fn add_vcode_to_cache(ak: &str, vcode: &str, own_paths: &str, funs: &TardisFunsInst) -> TardisResult<()> {
pub async fn add_vcode_to_cache(ak: &str, vcode: &str, cert_conf_id: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let rbum_cert_conf = RbumCertConfServ::peek_rbum(cert_conf_id, &RbumCertConfFilterReq::default(), funs, ctx).await?;

funs.cache()
.set_ex(
format!("{}{}:{}", funs.rbum_conf_cache_key_cert_vcode_info_(), own_paths, ak).as_str(),
format!("{}{}:{}", funs.rbum_conf_cache_key_cert_vcode_info_(), &ctx.own_paths, ak).as_str(),
vcode.to_string().as_str(),
// TODO 可否使用 expire_sec?
funs.rbum_conf_cache_key_cert_vcode_expire_sec() as u64,
rbum_cert_conf.expire_sec as u64,
)
.await?;
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions backend/basic/tests/test_rbum_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,18 +737,18 @@ async fn test_rbum_cert_sk_dynamic(context: &TardisContext) -> TardisResult<()>

info!("【test_rbum_cert】 : Test Add : RbumCertServ::get_and_delete_vcode_in_cache");
assert!(RbumCertServ::get_and_delete_vcode_in_cache("i@sunisle.org", &context.own_paths, &funs).await?.is_none());
RbumCertServ::add_vcode_to_cache("i@sunisle.org", "qqqqq", &context.own_paths, &funs).await?;
RbumCertServ::add_vcode_to_cache("i@sunisle.org", "qqqqq", &cert_conf_mail_vcode_id, &funs, &context).await?;
assert_eq!(
RbumCertServ::get_and_delete_vcode_in_cache("i@sunisle.org", &context.own_paths, &funs).await?.unwrap(),
"qqqqq"
);

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

info!("【test_rbum_cert】 : Test Validate : RbumCertServ::validate with sk_dynamic & expire");
RbumCertServ::add_vcode_to_cache("i@sunisle.org", "xxxx", &context.own_paths, &funs).await?;
RbumCertServ::add_vcode_to_cache("i@sunisle.org", "xxxx", &cert_conf_mail_vcode_id, &funs, &context).await?;
// tardis::tokio::time::sleep(Duration::from_secs(120)).await;
RbumCertServ::get_and_delete_vcode_in_cache("i@sunisle.org", &context.own_paths, &funs).await?;
assert!(RbumCertServ::validate_by_spec_cert_conf("i@sunisle.org", "xxxx", &cert_conf_mail_vcode_id, false, &context.own_paths, &funs).await.is_err());
Expand Down
1 change: 0 additions & 1 deletion backend/basic/tests/test_rbum_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,6 @@ async fn test_rbum_item_with_none_owner_name(context: &TardisContext) -> TardisR

#[derive(Debug, sea_orm::FromQueryResult)]
pub struct IamAccountResp {
pub id: String,
pub ext1_idx: String,
pub ext2: String,
}
Expand Down
4 changes: 2 additions & 2 deletions backend/supports/iam/src/basic/serv/iam_account_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl IamAccountServ {
)
.await?
.into_iter()
.map(|r| (r.rel_rbum_cert_conf_code.unwrap_or("".to_string()), r.ak))
.map(|r| (r.rel_rbum_cert_conf_name.unwrap_or("".to_string()), r.ak))
.collect(),
orgs: IamSetServ::find_set_paths(&account.id, &set_id, funs, &mock_tenant_ctx).await?.into_iter().map(|r| r.into_iter().map(|rr| rr.name).join("/")).collect(),
exts: account_attrs
Expand Down Expand Up @@ -615,7 +615,7 @@ impl IamAccountServ {
)
.await?
.into_iter()
.map(|r| (r.rel_rbum_cert_conf_code.unwrap_or("".to_string()), r.ak))
.map(|r| (r.rel_rbum_cert_conf_name.unwrap_or("".to_string()), r.ak))
.collect(),
orgs: IamSetServ::find_set_paths(&account.id, &set_id, funs, &mock_tenant_ctx).await?.into_iter().map(|r| r.into_iter().map(|rr| rr.name).join("/")).collect(),
});
Expand Down
28 changes: 20 additions & 8 deletions backend/supports/iam/src/basic/serv/iam_cert_mail_vcode_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ impl IamCertMailVCodeServ {

pub async fn resend_activation_mail(account_id: &str, mail: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let vcode = Self::get_vcode();
RbumCertServ::add_vcode_to_cache(mail, &vcode, &ctx.own_paths, funs).await?;
let rel_rbum_cert_conf_id =
IamCertServ::get_cert_conf_id_by_kind(IamCertKernelKind::MailVCode.to_string().as_str(), Some(IamTenantServ::get_id_by_ctx(&ctx, funs)?), funs).await?;
RbumCertServ::add_vcode_to_cache(mail, &vcode, &rel_rbum_cert_conf_id, funs, &ctx).await?;
Self::send_activation_mail(account_id, mail, &vcode, funs, ctx).await
}

Expand Down Expand Up @@ -256,12 +258,12 @@ impl IamCertMailVCodeServ {

pub async fn send_bind_mail(mail: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let ctx = IamAccountServ::new_context_if_account_is_global(ctx, funs).await?;
// let rel_rbum_cert_conf_id =
// IamCertServ::get_cert_conf_id_by_kind(IamCertKernelKind::MailVCode.to_string().as_str(), Some(IamTenantServ::get_id_by_ctx(&ctx, funs)?), funs).await?;
let rel_rbum_cert_conf_id =
IamCertServ::get_cert_conf_id_by_kind(IamCertKernelKind::MailVCode.to_string().as_str(), Some(IamTenantServ::get_id_by_ctx(&ctx, funs)?), funs).await?;
// Self::check_bind_mail(mail, vec![rel_rbum_cert_conf_id], &ctx.owner, funs, &ctx).await?;
let vcode = Self::get_vcode();
let account_name = IamAccountServ::peek_item(&ctx.owner, &IamAccountFilterReq::default(), funs, &ctx).await?.name;
RbumCertServ::add_vcode_to_cache(mail, &vcode, &ctx.own_paths, funs).await?;
RbumCertServ::add_vcode_to_cache(mail, &vcode, &rel_rbum_cert_conf_id, funs, &ctx).await?;
MailClient::send_cert_activate_vcode(mail, Some(account_name), &vcode, funs).await?;
Ok(())
}
Expand Down Expand Up @@ -409,7 +411,7 @@ impl IamCertMailVCodeServ {
},
ak: Some(mail.to_string()),
rel_rbum_kind: Some(RbumCertRelKind::Item),
rel_rbum_cert_conf_ids: Some(vec![tenant_rbum_cert_conf_id]),
rel_rbum_cert_conf_ids: Some(vec![tenant_rbum_cert_conf_id.clone()]),
..Default::default()
},
funs,
Expand All @@ -419,7 +421,7 @@ impl IamCertMailVCodeServ {
> 0
{
let vcode = Self::get_vcode();
RbumCertServ::add_vcode_to_cache(mail, &vcode, &own_paths, funs).await?;
RbumCertServ::add_vcode_to_cache(mail, &vcode, &tenant_rbum_cert_conf_id, funs, &mock_ctx).await?;
MailClient::send_vcode(mail, None, &vcode, funs).await?;
return Ok(());
}
Expand All @@ -432,7 +434,7 @@ impl IamCertMailVCodeServ {
},
ak: Some(mail.to_string()),
rel_rbum_kind: Some(RbumCertRelKind::Item),
rel_rbum_cert_conf_ids: Some(vec![global_rbum_cert_conf_id]),
rel_rbum_cert_conf_ids: Some(vec![global_rbum_cert_conf_id.clone()]),
..Default::default()
},
funs,
Expand All @@ -442,7 +444,17 @@ impl IamCertMailVCodeServ {
> 0
{
let vcode = Self::get_vcode();
RbumCertServ::add_vcode_to_cache(mail, &vcode, "", funs).await?;
RbumCertServ::add_vcode_to_cache(
mail,
&vcode,
&global_rbum_cert_conf_id,
funs,
&TardisContext {
own_paths: "".to_string(),
..Default::default()
},
)
.await?;
MailClient::send_vcode(mail, None, &vcode, funs).await?;
return Ok(());
}
Expand Down
Loading

0 comments on commit fd47e66

Please sign in to comment.