Skip to content

Commit

Permalink
reach: Fix reach config use optional signature, fix query instance co…
Browse files Browse the repository at this point in the history
…nfig (#512)

* reach: fix reach instance trigger path

* allow signature id to be empty

* reach: fix query instance config
  • Loading branch information
4t145 authored Oct 27, 2023
1 parent 099b01d commit c160b4e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
4 changes: 3 additions & 1 deletion support/reach/src/dto/trigger/global_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ use tardis::{

use crate::dto::*;
/// 添加 用户触达触发实例配置请求
#[derive(Debug, poem_openapi::Object, Serialize, Deserialize)]
#[derive(Debug, poem_openapi::Object, Serialize, Deserialize, Default)]
pub struct ReachTriggerGlobalConfigAddReq {
/// 关联的触发场景id
pub rel_reach_trigger_scene_id: String,
/// 关联的触达通道
pub rel_reach_channel: ReachChannelKind,
#[serde(default)]
#[oai(default)]
/// 用户触达消息签名Id
pub rel_reach_msg_signature_id: String,
/// 用户触达消息模板Id
Expand Down
25 changes: 12 additions & 13 deletions support/reach/src/serv/trigger_global_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@ impl
.count(Query::select().column(trigger_scene::Column::Id).from(trigger_scene::Entity).and_where(trigger_scene::Column::Id.eq(&add_req.rel_reach_trigger_scene_id)))
.await?
{
return Err(funs.err().bad_request("reach_trigger_global_config", "before_add_rbum", "rel_reach_trigger_scene_id is exist", ""));
return Err(funs.err().bad_request("reach_trigger_global_config", "before_add_rbum", "rel_reach_trigger_scene_id doesn't exist", ""));
}
if 1 != funs
.db()
.count(
Query::select()
.column(message_signature::Column::Id)
.from(message_signature::Entity)
.and_where(message_signature::Column::Id.eq(&add_req.rel_reach_msg_signature_id)),
)
.await?
{
return Err(funs.err().bad_request("reach_trigger_global_config", "before_add_rbum", "rel_reach_msg_signature_id is exist", ""));
if !add_req.rel_reach_msg_signature_id.is_empty() && 1 != funs
.db()
.count(
Query::select()
.column(message_signature::Column::Id)
.from(message_signature::Entity)
.and_where(message_signature::Column::Id.eq(&add_req.rel_reach_msg_signature_id)),
)
.await? {
return Err(funs.err().bad_request("reach_trigger_global_config", "before_add_rbum", "rel_reach_msg_signature_id doesn't exist", ""));
}
if 1 != funs
.db()
Expand All @@ -60,7 +59,7 @@ impl
)
.await?
{
return Err(funs.err().bad_request("reach_trigger_global_config", "before_add_rbum", "rel_reach_msg_template_id is exist", ""));
return Err(funs.err().bad_request("reach_trigger_global_config", "before_add_rbum", "rel_reach_msg_template_id doesn't exist", ""));
}
let mut filter = ReachTriggerGlobalConfigFilterReq {
rel_reach_trigger_scene_id: Some(add_req.rel_reach_trigger_scene_id.clone()),
Expand Down
1 change: 1 addition & 0 deletions support/reach/src/serv/trigger_instance_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl ReachTriggerInstanceConfigService {
filter.rel_reach_channel = Some(req.rel_reach_channel);
filter.rel_reach_trigger_scene_id = Some(req.rel_reach_trigger_scene_id.clone());
filter.receive_group_code = Some(vec![req.receive_group_code.clone()]);
filter.rel_item_id = Some(req.rel_item_id.clone());
if let Some(trigger_instance_config) = Self::find_one_rbum(&filter, funs, ctx).await? {
if req.delete_kind {
Self::delete_rbum(&trigger_instance_config.id, funs, ctx).await?;
Expand Down
24 changes: 11 additions & 13 deletions support/reach/src/task/message_send_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Default for MessageSendListener {
}

impl MessageSendListener {
async fn execute_send_account(&self, message: message::Model, template: message_template::Model) -> TardisResult<()> {
async fn execute_send_account(&self, message: message::Model, template: message_template::Model, _signarure: Option<message_signature::Model>) -> TardisResult<()> {
let content_replace: ContentReplace = message.content_replace.parse()?;
let cfg = self.funs.conf::<ReachConfig>();
let _lock = self.sync.lock().await;
Expand Down Expand Up @@ -132,20 +132,18 @@ impl MessageSendListener {
else {
continue;
};
let Some(_signature) = db
.get_dto::<message_signature::Model>(
Query::select()
.columns(message_signature::Column::iter())
.from(message_signature::Entity)
.and_where(message_signature::Column::Id.eq(&message.rel_reach_msg_signature_id)),
)
.await?
else {
continue;
};
// signature is not necessary now
// let signature = db
// .get_dto::<message_signature::Model>(
// Query::select()
// .columns(message_signature::Column::iter())
// .from(message_signature::Entity)
// .and_where(message_signature::Column::Id.eq(&message.rel_reach_msg_signature_id)),
// )
// .await?;
match message.receive_kind {
ReachReceiveKind::Account => {
let _res = self.execute_send_account(message, template).await;
let _res = self.execute_send_account(message, template, None).await;
}
ReachReceiveKind::Tenant => {
// do nothing
Expand Down

0 comments on commit c160b4e

Please sign in to comment.