|
1
|
|
|
<?php |
|
2
|
|
|
class LeadsAPI extends Http\Rest\DataTableAPI |
|
3
|
|
|
{ |
|
4
|
|
|
public function __construct() |
|
5
|
|
|
{ |
|
6
|
|
|
parent::__construct('profiles', 'position', 'short_name'); |
|
|
|
|
|
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
public function setup($app) |
|
10
|
|
|
{ |
|
11
|
|
|
parent::setup($app); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
View Code Duplication |
protected function validateIsAdmin($request) |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
$user = $request->getAttribute('user'); |
|
17
|
|
|
if($user === false) |
|
18
|
|
|
{ |
|
19
|
|
|
throw new Exception('Must be logged in', \Http\Rest\ACCESS_DENIED); |
|
20
|
|
|
} |
|
21
|
|
|
if(!$user->isInGroupNamed('LDAPAdmins')) |
|
22
|
|
|
{ |
|
23
|
|
|
throw new Exception('Must be Admin', \Http\Rest\ACCESS_DENIED); |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
protected function canCreate($request) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->validateIsAdmin($request); |
|
30
|
|
|
return true; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function canUpdate($request, $entity) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->validateIsAdmin($request); |
|
36
|
|
|
return true; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected function hasPositionAccess() |
|
40
|
|
|
{ |
|
41
|
|
|
return ($this->user->isInGroupNamed('Leads') || |
|
|
|
|
|
|
42
|
|
|
$this->user->isInGroupNamed('CC') || |
|
43
|
|
|
$this->user->isInGroupNamed('AFs')); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function getPositionsByType($type, $auth) |
|
47
|
|
|
{ |
|
48
|
|
|
switch($type) |
|
49
|
|
|
{ |
|
50
|
|
|
case 'aar': |
|
51
|
|
|
$aarGroup = $auth->getGroupByName('AAR'); |
|
52
|
|
|
return $aarGroup->members(true, false); |
|
53
|
|
|
case 'af': |
|
54
|
|
|
$afGroup = $auth->getGroupByName('AFs'); |
|
55
|
|
|
return $afGroup->members(true, false); |
|
56
|
|
|
case 'cc': |
|
57
|
|
|
$ccGroup = $auth->getGroupByName('CC'); |
|
58
|
|
|
return $ccGroup->members(true, false); |
|
59
|
|
|
case 'lead': |
|
60
|
|
|
$leadGroup = $auth->getGroupByName('Leads'); |
|
61
|
|
|
return $leadGroup->members(true, false); |
|
62
|
|
|
default: |
|
63
|
|
|
$filter = new \Data\Filter('ou eq '.$type); |
|
64
|
|
|
return $auth->getUsersByFilter($filter); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function getPositionsWithParams($params) |
|
69
|
|
|
{ |
|
70
|
|
|
$auth = AuthProvider::getInstance(); |
|
71
|
|
|
if(isset($params['type'])) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->getPositionsByType($params['type'], $auth); |
|
74
|
|
|
} |
|
75
|
|
|
$leads = array(); |
|
76
|
|
|
$leadGroup = $auth->getGroupByName('Leads'); |
|
77
|
|
|
$aarGroup = $auth->getGroupByName('AAR'); |
|
78
|
|
|
$afGroup = $auth->getGroupByName('AFs'); |
|
79
|
|
|
$ccGroup = $auth->getGroupByName('CC'); |
|
80
|
|
|
$leads = array_merge($leads, $leadGroup->members(true, false)); |
|
81
|
|
|
$leads = array_merge($leads, $aarGroup->members(true, false)); |
|
82
|
|
|
$leads = array_merge($leads, $afGroup->members(true, false)); |
|
83
|
|
|
$leads = array_merge($leads, $ccGroup->members(true, false)); |
|
84
|
|
|
return $leads; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function readEntries($request, $response, $args) |
|
88
|
|
|
{ |
|
89
|
|
|
if($this->canRead($request) === false || $this->hasPositionAccess() === false) |
|
90
|
|
|
{ |
|
91
|
|
|
return $response->withStatus(401); |
|
92
|
|
|
} |
|
93
|
|
|
$dataTable = $this->getDataTable(); |
|
|
|
|
|
|
94
|
|
|
$odata = $request->getAttribute('odata', new \ODataParams(array())); |
|
95
|
|
|
$leads = $this->getPositionsWithParams($request->getQueryParams()); |
|
96
|
|
|
$leads = $odata->filterArrayPerSelect($leads); |
|
97
|
|
|
return $response->withJson($leads); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
|
101
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: