* finish task #7274.
This commit is contained in:
@@ -3,7 +3,7 @@ $filter = new stdclass();
|
||||
$filter->rules = new stdclass();
|
||||
$filter->rules->md5 = '/^[a-z0-9]{32}$/';
|
||||
$filter->rules->base64 = '/^[a-zA-Z0-9\+\/\=]+$/';
|
||||
$filter->rules->checked = '/^[0-9,]+$/';
|
||||
$filter->rules->checked = '/^[0-9,\-]+$/';
|
||||
$filter->rules->idList = '/^[0-9\|]+$/';
|
||||
$filter->rules->lang = '/^[a-zA-Z_\-]+$/';
|
||||
$filter->rules->any = '/./';
|
||||
@@ -47,6 +47,7 @@ $filter->user = new stdclass();
|
||||
$filter->block = new stdclass();
|
||||
$filter->file = new stdclass();
|
||||
$filter->repo = new stdclass();
|
||||
$filter->webhook = new stdclass();
|
||||
|
||||
$filter->block->default = new stdclass();
|
||||
$filter->block->main = new stdclass();
|
||||
@@ -93,6 +94,7 @@ $filter->testtask->default = new stdclass();
|
||||
$filter->todo->export = new stdclass();
|
||||
$filter->upgrade->license = new stdclass();
|
||||
$filter->user->login = new stdclass();
|
||||
$filter->webhook->bind = new stdclass();
|
||||
|
||||
$filter->bug->batchcreate->cookie['preBranch'] = 'int';
|
||||
$filter->bug->browse->cookie['bugModule'] = 'int';
|
||||
@@ -239,3 +241,5 @@ $filter->repo->diff->cookie['arrange'] = 'reg::word';
|
||||
$filter->repo->diff->cookie['repoPairs'] = 'array';
|
||||
$filter->repo->view->cookie['repoPairs'] = 'array';
|
||||
$filter->repo->ajaxsynccommit->cookie['syncBranch'] = 'reg::any';
|
||||
|
||||
$filter->webhook->bind->get['whiteListDept'] = 'reg::checked';
|
||||
|
||||
@@ -7,6 +7,7 @@ class dingapi
|
||||
private $token;
|
||||
private $expires;
|
||||
private $errors = array();
|
||||
public $maxRequest = 100;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
@@ -52,10 +53,11 @@ class dingapi
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getAllUsers()
|
||||
public function getAllUsers($whiteListDept = '')
|
||||
{
|
||||
$depts = $this->getAllDepts();
|
||||
$depts = $this->getAllDepts($whiteListDept);
|
||||
if($this->isError()) return array('result' => 'fail', 'message' => $this->errors);
|
||||
if(empty($whiteListDept) and count($depts) > $this->maxRequest) return array('result' => 'fail', 'message' => 'moreRequest');
|
||||
|
||||
set_time_limit(0);
|
||||
$users = array();
|
||||
@@ -80,12 +82,11 @@ class dingapi
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getAllDepts()
|
||||
public function getAllDepts($whiteList = '')
|
||||
{
|
||||
$response = $this->queryAPI($this->apiUrl . "department/list?access_token={$this->token}");
|
||||
if($this->isError()) return false;
|
||||
|
||||
$whiteList = array();
|
||||
if($whiteList)
|
||||
{
|
||||
$parentIdList = array();
|
||||
@@ -93,7 +94,7 @@ class dingapi
|
||||
foreach($response->department as $dept)
|
||||
{
|
||||
if(!empty($dept->parentid)) $parentIdList[$dept->id] = $dept->parentid;
|
||||
if(in_array($dept->name, $whiteList)) $whiteListParent[$dept->id] = $dept->id;
|
||||
if(strpos(",{$whiteList},", ",{$dept->id},") !== false) $whiteListParent[$dept->id] = $dept->id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +130,26 @@ class dingapi
|
||||
return $deptPairs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top depts.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getTopDepts()
|
||||
{
|
||||
$response = $this->queryAPI($this->apiUrl . "department/list?access_token={$this->token}");
|
||||
if($this->isError()) return array('result' => 'fail', 'message' => $this->errors);
|
||||
|
||||
$topDepts = array();
|
||||
foreach($response->department as $dept)
|
||||
{
|
||||
if(isset($dept->parentid) and $dept->parentid == '1') $topDepts[$dept->id] = $dept->name;
|
||||
}
|
||||
|
||||
return array('result' => 'success', 'data' => $topDepts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message
|
||||
*
|
||||
|
||||
@@ -1029,12 +1029,13 @@ $lang->extension->methodOrder[50] = 'upgrade';
|
||||
|
||||
/* Webhook. */
|
||||
$lang->resource->webhook = new stdclass();
|
||||
$lang->resource->webhook->browse = 'browse';
|
||||
$lang->resource->webhook->create = 'create';
|
||||
$lang->resource->webhook->edit = 'edit';
|
||||
$lang->resource->webhook->delete = 'delete';
|
||||
$lang->resource->webhook->log = 'log';
|
||||
$lang->resource->webhook->bind = 'bind';
|
||||
$lang->resource->webhook->browse = 'browse';
|
||||
$lang->resource->webhook->create = 'create';
|
||||
$lang->resource->webhook->edit = 'edit';
|
||||
$lang->resource->webhook->delete = 'delete';
|
||||
$lang->resource->webhook->log = 'log';
|
||||
$lang->resource->webhook->bind = 'bind';
|
||||
$lang->resource->webhook->chooseDept = 'chooseDept';
|
||||
|
||||
$lang->webhook->methodOrder[5] = 'browse';
|
||||
$lang->webhook->methodOrder[10] = 'create';
|
||||
@@ -1042,6 +1043,7 @@ $lang->webhook->methodOrder[15] = 'edit';
|
||||
$lang->webhook->methodOrder[20] = 'delete';
|
||||
$lang->webhook->methodOrder[25] = 'log';
|
||||
$lang->webhook->methodOrder[30] = 'bind';
|
||||
$lang->webhook->methodOrder[35] = 'chooseDept';
|
||||
|
||||
/* Others. */
|
||||
$lang->resource->api = new stdclass();
|
||||
|
||||
@@ -179,7 +179,7 @@ class webhook extends control
|
||||
{
|
||||
$this->app->loadClass('dingapi', true);
|
||||
$dingapi = new dingapi($webhook->secret->appKey, $webhook->secret->appSecret, $webhook->secret->agentId);
|
||||
$response = $dingapi->getAllUsers();
|
||||
$response = $dingapi->getAllUsers($this->get->whiteListDept);
|
||||
}
|
||||
elseif($webhook->type == 'wechatuser')
|
||||
{
|
||||
@@ -190,6 +190,12 @@ class webhook extends control
|
||||
|
||||
if($response['result'] == 'fail')
|
||||
{
|
||||
if($response['message'] == 'moreRequest')
|
||||
{
|
||||
echo js::error($this->webhook->error->moreDept);
|
||||
die(js::locate($this->createLink('webhook', 'chooseDept', "id=$id")));
|
||||
}
|
||||
|
||||
echo js::error($response['message']);
|
||||
die(js::locate($this->createLink('webhook', 'browse')));
|
||||
}
|
||||
@@ -225,6 +231,44 @@ class webhook extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* choose dept.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function chooseDept($id)
|
||||
{
|
||||
$webhook = $this->webhook->getById($id);
|
||||
if($webhook->type != 'dinguser' && $webhook->type != 'wechatuser')
|
||||
{
|
||||
echo js::alert($this->lang->webhook->note->bind);
|
||||
die(js::locate($this->createLink('webhook', 'browse')));
|
||||
}
|
||||
$webhook->secret = json_decode($webhook->secret);
|
||||
|
||||
if($webhook->type == 'dinguser')
|
||||
{
|
||||
$this->app->loadClass('dingapi', true);
|
||||
$dingapi = new dingapi($webhook->secret->appKey, $webhook->secret->appSecret, $webhook->secret->agentId);
|
||||
$response = $dingapi->getTopDepts();
|
||||
}
|
||||
|
||||
if($response['result'] == 'fail')
|
||||
{
|
||||
echo js::error($response['message']);
|
||||
die(js::locate($this->createLink('webhook', 'browse')));
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->webhook->chooseDept;
|
||||
$this->view->position[] = $this->lang->webhook->chooseDept;
|
||||
|
||||
$this->view->topDepts = $response['data'];
|
||||
$this->view->webhookID = $id;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send data by async.
|
||||
*
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
$lang->webhook->common = 'Webhook';
|
||||
$lang->webhook->list = 'Webhook列表';
|
||||
$lang->webhook->api = '接口';
|
||||
$lang->webhook->entry = '应用';
|
||||
$lang->webhook->log = '日志';
|
||||
$lang->webhook->bind = '绑定用户';
|
||||
$lang->webhook->assigned = '指派给';
|
||||
$lang->webhook->setting = '设置';
|
||||
$lang->webhook->common = 'Webhook';
|
||||
$lang->webhook->list = 'Webhook列表';
|
||||
$lang->webhook->api = '接口';
|
||||
$lang->webhook->entry = '应用';
|
||||
$lang->webhook->log = '日志';
|
||||
$lang->webhook->bind = '绑定用户';
|
||||
$lang->webhook->chooseDept = '选择同步部门';
|
||||
$lang->webhook->assigned = '指派给';
|
||||
$lang->webhook->setting = '设置';
|
||||
|
||||
$lang->webhook->browse = '浏览Webhook';
|
||||
$lang->webhook->create = '添加Webhook';
|
||||
@@ -90,4 +91,5 @@ $lang->webhook->note->typeList['weixin'] = '请在企业微信中添加一个
|
||||
$lang->webhook->note->typeList['default'] = '从第三方系统获取webhook并填写到此处。';
|
||||
|
||||
$lang->webhook->error = new stdclass();
|
||||
$lang->webhook->error->curl = '需要加载php-curl扩展。';
|
||||
$lang->webhook->error->curl = '需要加载php-curl扩展。';
|
||||
$lang->webhook->error->moreDept = '部门太多,获取用户可能会超时,请先选择同步部门。';
|
||||
|
||||
59
module/webhook/view/choosedept.html.php
Normal file
59
module/webhook/view/choosedept.html.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* The choose dept view file of webhook module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
|
||||
* @license ZPL (http://zpl.pub/page/zplv12.html)
|
||||
* @author Yidong Wang <yidong@cnezsoft.com>
|
||||
* @package webhook
|
||||
* @version $Id$
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
?>
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<div id='mainContent' class='main-content'>
|
||||
<div class='center-block mw-800px'>
|
||||
<div class='main-header'>
|
||||
<h2><?php echo $lang->webhook->chooseDept?></h2>
|
||||
</div>
|
||||
<table id='deptList' class='table table-fixed table-bordered active-disabled table-hover'>
|
||||
<tbody>
|
||||
<?php foreach($topDepts as $deptID => $deptName):?>
|
||||
<tr>
|
||||
<td><?php echo html::checkbox('deptID', array($deptID => $deptName));?></td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td>
|
||||
<?php echo html::selectAll();?>
|
||||
<?php echo html::selectReverse();?>
|
||||
<?php echo html::commonButton($lang->save, '', 'btn btn-primary save');?>
|
||||
<?php echo html::a($this->createLink('webhook', 'browse'), $lang->goback, '', "class='btn'");?>
|
||||
</td>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(function()
|
||||
{
|
||||
$('#deptList tfoot .save').click(function()
|
||||
{
|
||||
var whiteListDept = '';
|
||||
$('#deptList tbody tr td :checkbox[id^=deptID]:checked').each(function()
|
||||
{
|
||||
whiteListDept += ',' + $(this).val();
|
||||
});
|
||||
if(whiteListDept) whiteListDept = whiteListDept.substr(1);
|
||||
|
||||
var sign = config.requestType == 'PATH_INFO' ? '?' : '&';
|
||||
var link = createLink('webhook', 'bind', "id=<?php echo $webhookID;?>") + sign + "whiteListDept=" + whiteListDept;
|
||||
location.href = link;
|
||||
|
||||
return false;
|
||||
})
|
||||
})
|
||||
</script>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
Reference in New Issue
Block a user