From 5af6fc121891eaa5ab7ad1496c5f6706ecbb8320 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 3 Dec 2019 11:45:28 +0800 Subject: [PATCH] * finish task #6611. --- module/action/model.php | 2 +- module/message/model.php | 18 ++++++++++-------- module/webhook/model.php | 12 +++++++----- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/module/action/model.php b/module/action/model.php index 6527f2fd1a..3d168742bb 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -64,7 +64,7 @@ class actionModel extends model $this->file->updateObjectID($this->post->uid, $objectID, $objectType); - $this->loadModel('message')->send($objectType, $objectID, $actionType, $actionID); + $this->loadModel('message')->send($objectType, $objectID, $actionType, $actionID, $actor); return $actionID; } diff --git a/module/message/model.php b/module/message/model.php index 693328dbe4..b190edfc51 100644 --- a/module/message/model.php +++ b/module/message/model.php @@ -65,7 +65,7 @@ class messageModel extends model * @access public * @return void */ - public function send($objectType, $objectID, $actionType, $actionID) + public function send($objectType, $objectID, $actionType, $actionID, $actor = '') { $messageSetting = $this->config->message->setting; if(is_string($messageSetting)) $messageSetting = json_decode($messageSetting, true); @@ -86,7 +86,7 @@ class messageModel extends model $actions = $messageSetting['webhook']['setting']; if(isset($actions[$objectType]) and in_array($actionType, $actions[$objectType])) { - $this->loadModel('webhook')->send($objectType, $objectID, $actionType, $actionID); + $this->loadModel('webhook')->send($objectType, $objectID, $actionType, $actionID, $actor); } } @@ -95,7 +95,7 @@ class messageModel extends model $actions = $messageSetting['message']['setting']; if(isset($actions[$objectType]) and in_array($actionType, $actions[$objectType])) { - $this->loadModel('message')->saveNotice($objectType, $objectID, $actionType, $actionID); + $this->saveNotice($objectType, $objectID, $actionType, $actionID, $actor); } } } @@ -110,21 +110,23 @@ class messageModel extends model * @access public * @return void */ - public function saveNotice($objectType, $objectID, $actionType, $actionID) + public function saveNotice($objectType, $objectID, $actionType, $actionID, $actor = '') { - if(empty($this->app->user->account)) return false; + if(empty($actor)) $actor = $this->app->user->account; + if(empty($actor)) return false; $this->loadModel('action'); + $user = $this->loadModel('user')->getById($actor); $table = $this->config->objectTables[$objectType]; $field = $this->config->action->objectNameFields[$objectType]; $object = $this->dao->select('*')->from($table)->where('id')->eq($objectID)->fetch(); $toList = $this->getToList($object, $objectType); if(empty($toList)) return false; - if($toList == $this->app->user->account) return false; + if($toList == $actor) return false; $moduleName = $objectType == 'case' ? 'testcase' : $objectType; $space = common::checkNotCN() ? ' ' : ''; - $data = $this->app->user->realname . $space . $this->lang->action->label->$actionType . $space . $this->lang->action->objectTypes[$objectType]; + $data = $user->realname . $space . $this->lang->action->label->$actionType . $space . $this->lang->action->objectTypes[$objectType]; $data .= ' ' . html::a(helper::createLink($moduleName, 'view', "id=$objectID"), "[#{$objectID}::{$object->$field}]"); $notify = new stdclass(); @@ -133,7 +135,7 @@ class messageModel extends model $notify->toList = $toList; $notify->data = $data; $notify->status = 'wait'; - $notify->createdBy = $this->app->user->account; + $notify->createdBy = $actor; $notify->createdDate = helper::now(); $this->dao->insert(TABLE_NOTIFY)->data($notify)->exec(); diff --git a/module/webhook/model.php b/module/webhook/model.php index c59dcc51af..f0f6a31401 100644 --- a/module/webhook/model.php +++ b/module/webhook/model.php @@ -253,7 +253,7 @@ class webhookModel extends model * @access public * @return bool */ - public function send($objectType, $objectID, $actionType, $actionID) + public function send($objectType, $objectID, $actionType, $actionID, $actor = '') { static $webhooks = array(); if(!$webhooks) $webhooks = $this->getList(); @@ -272,7 +272,7 @@ class webhookModel extends model if(empty($openIdList)) continue; } - $this->saveData($id, $actionID, $postData); + $this->saveData($id, $actionID, $postData, $actor); continue; } @@ -517,7 +517,7 @@ class webhookModel extends model if($webhook->type == 'dingapi') { - $webhook->secret = json_decode($webhook->secret); + if(is_string($webhook->secret)) $webhook->secret = json_decode($webhook->secret); $openIdList = $this->getOpenIdList($webhook->id, $actionID); if(empty($openIdList)) return false; @@ -571,14 +571,16 @@ class webhookModel extends model * @access public * @return bool */ - public function saveData($webhookID, $actionID, $data) + public function saveData($webhookID, $actionID, $data, $actor = '') { + if(empty($actor)) $actor = $this->app->user->account; + $webhookData = new stdclass(); $webhookData->objectType = 'webhook'; $webhookData->objectID = $webhookID; $webhookData->action = $actionID; $webhookData->data = $data; - $webhookData->createdBy = $this->app->user->account; + $webhookData->createdBy = $actor; $webhookData->createdDate = helper::now(); $this->dao->insert(TABLE_NOTIFY)->data($webhookData)->exec();