AuthorityController.class.php
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* 判断是否有管理权限
*/
namespace Rpc\Controller\Competence;
use Common\Common\Cache;
use Common\Common\Department;
use Common\Service\InviteSettingService;
use VcySDK\EnterprisePlugin;
use VcySDK\Service;
class AuthorityController extends AbstractController
{
/**
* @param $user (API)$this->_login->user
* @return array|bool
*/
public function Index()
{
$user = $this->get_arguments();
if (empty($user)) {
return [false, false];
}
$powers = array($user['memUid']);
if (!empty($user['job'])) {
$powers[] = $user['job']['jobId'];
}
if (!empty($user['role'])) {
$powers[] = $user['role']['roleId'];
}
if (!empty($user['dpName'])) {
$department = Department::instance();
foreach ($user['dpName'] as $item) {
$parentDpIds[$item['dpId']] = $item['dpId'];
$department->list_parent_cdids($item['dpId'], $parentDpIds);
$powers = array_merge($powers, array_values($parentDpIds));
}
}
$settingServ = new InviteSettingService();
$data = $settingServ->get_by_conds([]);
$settings = Cache::instance()->get('Common.AppSetting');
$result = [
// 管理人员权限
false,
// 邀请人员权限
false
];
// 管理人员 权限
if (array_intersect($powers, $settings['manageAuths']['value']['auths'])) {
$result[0] = true;
}
// 邀请人员 权限
if (array_intersect($powers, unserialize($data['invite_udpids'])['auths'])) {
$result[1] = true;
}
// 通讯录是否安装 也会决定 管理人员和邀请人员的权限
$enterprisePluginSdk = new EnterprisePlugin(Service::instance());
$pluginList = $enterprisePluginSdk->listAll();
$pluginList = array_combine_by_key($pluginList, 'plIdentifier');
$contactInstalled = $pluginList['contact']['available'] == EnterprisePlugin::AVAILABLE_OPEN;
$result[1] = $result[1] && $contactInstalled;
// 返回 通讯录是否安装
$result[2] = $contactInstalled;
return $result;
}
}