|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Canvas\Api\Controllers; |
|
6
|
|
|
|
|
7
|
|
|
use Canvas\Models\UserWebhooks; |
|
8
|
|
|
use Canvas\Validation; |
|
9
|
|
|
use Exception; |
|
10
|
|
|
use Phalcon\Http\Response; |
|
11
|
|
|
use GuzzleHttp\Client; |
|
12
|
|
|
use Canvas\Webhooks; |
|
13
|
|
|
use Phalcon\Mvc\Model\ValidationFailed; |
|
14
|
|
|
use Phalcon\Validation\Validator\PresenceOf; |
|
15
|
|
|
use function Canvas\Core\isJson; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class LanguagesController. |
|
19
|
|
|
* |
|
20
|
|
|
* @package Canvas\Api\Controllers |
|
21
|
|
|
* |
|
22
|
|
|
* @property Users $userData |
|
23
|
|
|
* @property Request $request |
|
24
|
|
|
* @property Config $config |
|
25
|
|
|
* @property Apps $app |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
class UserWebhooksController extends BaseController |
|
29
|
|
|
{ |
|
30
|
|
|
/* |
|
31
|
|
|
* fields we accept to create |
|
32
|
|
|
* |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $createFields = [ |
|
36
|
|
|
'webhooks_id', |
|
37
|
|
|
'url', |
|
38
|
|
|
'method', |
|
39
|
|
|
'format' |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
/* |
|
43
|
|
|
* fields we accept to create |
|
44
|
|
|
* |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $updateFields = [ |
|
48
|
|
|
'webhooks_id', |
|
49
|
|
|
'url', |
|
50
|
|
|
'method', |
|
51
|
|
|
'format' |
|
52
|
|
|
]; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* set objects. |
|
56
|
|
|
* |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
|
|
public function onConstruct() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->model = new UserWebhooks(); |
|
62
|
|
|
$this->model->users_id = $this->userData->getId(); |
|
63
|
|
|
$this->model->companies_id = $this->userData->currentCompanyId(); |
|
64
|
|
|
$this->model->apps_id = $this->app->getId(); |
|
65
|
|
|
$this->additionalSearchFields = [ |
|
66
|
|
|
['is_deleted', ':', '0'], |
|
67
|
|
|
['apps_id', ':', $this->app->getId()], |
|
68
|
|
|
['companies_id', ':', '0|' . $this->userData->currentCompanyId()], |
|
69
|
|
|
]; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Given the weebhook id, we run a test for it. |
|
74
|
|
|
* |
|
75
|
|
|
* @param integer $id |
|
|
|
|
|
|
76
|
|
|
* @return Response |
|
77
|
|
|
*/ |
|
78
|
|
|
public function execute(string $name): Response |
|
79
|
|
|
{ |
|
80
|
|
|
$request = $this->request->getPostData(); |
|
81
|
|
|
$validation = new Validation(); |
|
82
|
|
|
$validation->add('module', new PresenceOf(['message' => 'module is required to know what webhook to run'])); |
|
83
|
|
|
$validation->add('action', new PresenceOf(['message' => 'action is required'])); |
|
84
|
|
|
|
|
85
|
|
|
if (isset($request['data'])) { |
|
86
|
|
|
$validation->add('data', new PresenceOf(['message' => 'data is required'])); |
|
87
|
|
|
if (!isJson($request['data'])) { |
|
88
|
|
|
throw new ValidationFailed('Data is not a valid json format text'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$validation->validate($request); |
|
93
|
|
|
|
|
94
|
|
|
$systemModule = $request['module']; |
|
95
|
|
|
$data = isset($request['data']) ? json_decode($request['data'], true) : []; |
|
96
|
|
|
$action = $request['action']; |
|
97
|
|
|
|
|
98
|
|
|
return $this->response( |
|
99
|
|
|
Webhooks::process( |
|
100
|
|
|
$systemModule, |
|
101
|
|
|
$data, |
|
102
|
|
|
$action |
|
103
|
|
|
) |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.