1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* This Driver is based entirely on official documentation of the Mattermost Web
|
4
|
|
|
* Services API and you can extend it by following the directives of the documentation.
|
5
|
|
|
*
|
6
|
|
|
* For the full copyright and license information, please read the LICENSE.txt
|
7
|
|
|
* file that was distributed with this source code. For the full list of
|
8
|
|
|
* contributors, visit https://github.com/gnello/php-mattermost-driver/contributors
|
9
|
|
|
*
|
10
|
|
|
* God bless this mess.
|
11
|
|
|
*
|
12
|
|
|
* @author Luca Agnello <[email protected]>
|
13
|
|
|
* @link https://api.mattermost.com/
|
14
|
|
|
*/
|
15
|
|
|
|
16
|
|
|
namespace Gnello\Mattermost\Models;
|
17
|
|
|
|
18
|
|
|
use GuzzleHttp\RequestOptions;
|
19
|
|
|
use Psr\Http\Message\ResponseInterface;
|
20
|
|
|
|
21
|
|
|
/**
|
22
|
|
|
* Class TeamModel
|
23
|
|
|
*
|
24
|
|
|
* @package Gnello\Mattermost
|
25
|
|
|
*/
|
26
|
|
|
class TeamModel extends AbstractModel
|
27
|
|
|
{
|
28
|
|
|
/**
|
29
|
|
|
* @var string
|
30
|
|
|
*/
|
31
|
|
|
public static $endpoint = '/teams';
|
32
|
|
|
|
33
|
|
|
/**
|
34
|
|
|
* @param array $requestOptions
|
35
|
|
|
* @return ResponseInterface
|
36
|
|
|
*/
|
37
|
|
|
public function createTeam(array $requestOptions)
|
38
|
|
|
{
|
39
|
|
|
return $this->client->post(self::$endpoint, $requestOptions);
|
40
|
|
|
}
|
41
|
|
|
|
42
|
|
|
/**
|
43
|
|
|
* @param array $requestOptions
|
44
|
|
|
* @return ResponseInterface
|
45
|
|
|
*/
|
46
|
|
|
public function getTeams(array $requestOptions)
|
47
|
|
|
{
|
48
|
|
|
return $this->client->get(self::$endpoint, $requestOptions);
|
49
|
|
|
}
|
50
|
|
|
|
51
|
|
|
/**
|
52
|
|
|
* @param $teamId
|
53
|
|
|
* @return ResponseInterface
|
54
|
|
|
*/
|
55
|
|
|
public function getTeam($teamId)
|
56
|
|
|
{
|
57
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId);
|
58
|
|
|
}
|
59
|
|
|
|
60
|
|
|
/**
|
61
|
|
|
* @param $teamId
|
62
|
|
|
* @param array $requestOptions
|
63
|
|
|
* @return ResponseInterface
|
64
|
|
|
*/
|
65
|
|
|
public function updateTeam($teamId, array $requestOptions)
|
66
|
|
|
{
|
67
|
|
|
return $this->client->put(self::$endpoint . '/' . $teamId, $requestOptions);
|
68
|
|
|
}
|
69
|
|
|
|
70
|
|
|
/**
|
71
|
|
|
* @param $teamId
|
72
|
|
|
* @return ResponseInterface
|
73
|
|
|
*/
|
74
|
|
|
public function deleteTeam($teamId)
|
75
|
|
|
{
|
76
|
|
|
return $this->client->delete(self::$endpoint . '/' . $teamId);
|
77
|
|
|
}
|
78
|
|
|
|
79
|
|
|
/**
|
80
|
|
|
* @param $teamId
|
81
|
|
|
* @param array $requestOptions
|
82
|
|
|
* @return ResponseInterface
|
83
|
|
|
*/
|
84
|
|
|
public function patchTeam($teamId, array $requestOptions)
|
85
|
|
|
{
|
86
|
|
|
return $this->client->put(self::$endpoint . '/' . $teamId . '/patch', $requestOptions);
|
87
|
|
|
}
|
88
|
|
|
|
89
|
|
|
/**
|
90
|
|
|
* @param $teamId
|
91
|
|
|
* @param array $requestOptions
|
92
|
|
|
* @return ResponseInterface
|
93
|
|
|
*/
|
94
|
|
|
public function updateTeamPrivacy($teamId, array $requestOptions)
|
95
|
|
|
{
|
96
|
|
|
return $this->client->put(self::$endpoint . '/' . $teamId . '/privacy', $requestOptions);
|
97
|
|
|
}
|
98
|
|
|
|
99
|
|
|
/**
|
100
|
|
|
* @param $teamId
|
101
|
|
|
* @return ResponseInterface
|
102
|
|
|
*/
|
103
|
|
|
public function restoreTeam($teamId)
|
104
|
|
|
{
|
105
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/restore');
|
106
|
|
|
}
|
107
|
|
|
|
108
|
|
|
/**
|
109
|
|
|
* @param $teamName
|
110
|
|
|
* @return ResponseInterface
|
111
|
|
|
*/
|
112
|
|
|
public function getTeamByName($teamName)
|
113
|
|
|
{
|
114
|
|
|
return $this->client->get(self::$endpoint . '/name/' . $teamName);
|
115
|
|
|
}
|
116
|
|
|
|
117
|
|
|
/**
|
118
|
|
|
* @param array $requestOptions
|
119
|
|
|
* @return ResponseInterface
|
120
|
|
|
*/
|
121
|
|
|
public function searchTeams(array $requestOptions)
|
122
|
|
|
{
|
123
|
|
|
return $this->client->post(self::$endpoint . '/search', $requestOptions);
|
124
|
|
|
}
|
125
|
|
|
|
126
|
|
|
/**
|
127
|
|
|
* @param $teamName
|
128
|
|
|
* @return ResponseInterface
|
129
|
|
|
*/
|
130
|
|
|
public function checkTeamExists($teamName)
|
131
|
|
|
{
|
132
|
|
|
return $this->client->get(self::$endpoint . '/name/' . $teamName . '/exists');
|
133
|
|
|
}
|
134
|
|
|
|
135
|
|
|
/**
|
136
|
|
|
* @param $userId
|
137
|
|
|
* @return ResponseInterface
|
138
|
|
|
*/
|
139
|
|
|
public function getUserTeams($userId)
|
140
|
|
|
{
|
141
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams');
|
142
|
|
|
}
|
143
|
|
|
|
144
|
|
|
/**
|
145
|
|
|
* @param $teamId
|
146
|
|
|
* @param array $requestOptions
|
147
|
|
|
* @return ResponseInterface
|
148
|
|
|
*/
|
149
|
|
|
public function getTeamMembers($teamId, array $requestOptions)
|
150
|
|
|
{
|
151
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/members', $requestOptions);
|
152
|
|
|
}
|
153
|
|
|
|
154
|
|
|
/**
|
155
|
|
|
* @param $teamId
|
156
|
|
|
* @param array $requestOptions
|
157
|
|
|
* @return ResponseInterface
|
158
|
|
|
*/
|
159
|
|
|
public function addUser($teamId, array $requestOptions)
|
160
|
|
|
{
|
161
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/members', $requestOptions);
|
162
|
|
|
}
|
163
|
|
|
|
164
|
|
|
/**
|
165
|
|
|
* @param array $requestOptions
|
166
|
|
|
* @return ResponseInterface
|
167
|
|
|
*/
|
168
|
|
|
public function addUserFromInvite(array $requestOptions)
|
169
|
|
|
{
|
170
|
|
|
return $this->client->get(self::$endpoint . '/members/invite', $requestOptions);
|
171
|
|
|
}
|
172
|
|
|
|
173
|
|
|
/**
|
174
|
|
|
* @param $teamId
|
175
|
|
|
* @param array $requestOptions
|
176
|
|
|
* @return ResponseInterface
|
177
|
|
|
*/
|
178
|
|
|
public function addMultipleUsers($teamId, array $requestOptions)
|
179
|
|
|
{
|
180
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/members/batch', $requestOptions);
|
181
|
|
|
}
|
182
|
|
|
|
183
|
|
|
/**
|
184
|
|
|
* @param $userId
|
185
|
|
|
* @param array $requestOptions
|
186
|
|
|
* @return ResponseInterface
|
187
|
|
|
*/
|
188
|
|
|
public function getTeamMembersForUser($userId, array $requestOptions)
|
189
|
|
|
{
|
190
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams/members', $requestOptions);
|
191
|
|
|
}
|
192
|
|
|
|
193
|
|
|
/**
|
194
|
|
|
* @param $teamId
|
195
|
|
|
* @param $userId
|
196
|
|
|
* @return ResponseInterface
|
197
|
|
|
*/
|
198
|
|
|
public function getTeamMember($teamId, $userId)
|
199
|
|
|
{
|
200
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/members/' . $userId);
|
201
|
|
|
}
|
202
|
|
|
|
203
|
|
|
/**
|
204
|
|
|
* @param $teamId
|
205
|
|
|
* @param $userId
|
206
|
|
|
* @return ResponseInterface
|
207
|
|
|
*/
|
208
|
|
|
public function removeUser($teamId, $userId)
|
209
|
|
|
{
|
210
|
|
|
return $this->client->delete(self::$endpoint . '/' . $teamId . '/members/' . $userId);
|
211
|
|
|
}
|
212
|
|
|
|
213
|
|
|
/**
|
214
|
|
|
* @param $teamId
|
215
|
|
|
* @param array $requestOptions
|
216
|
|
|
* @return ResponseInterface
|
217
|
|
|
*/
|
218
|
|
|
public function getTeamMembersByIds($teamId, array $requestOptions)
|
219
|
|
|
{
|
220
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/members/ids', $requestOptions);
|
221
|
|
|
}
|
222
|
|
|
|
223
|
|
|
/**
|
224
|
|
|
* @param $teamId
|
225
|
|
|
* @return ResponseInterface
|
226
|
|
|
*/
|
227
|
|
|
public function getTeamStats($teamId)
|
228
|
|
|
{
|
229
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/stats');
|
230
|
|
|
}
|
231
|
|
|
|
232
|
|
|
/**
|
233
|
|
|
* @param $teamId
|
234
|
|
|
* @return ResponseInterface
|
235
|
|
|
*/
|
236
|
|
|
public function regenerateInviteID($teamId)
|
237
|
|
|
{
|
238
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/regenerate_invite_id');
|
239
|
|
|
}
|
240
|
|
|
|
241
|
|
|
/**
|
242
|
|
|
* @param $teamId
|
243
|
|
|
* @return ResponseInterface
|
244
|
|
|
*/
|
245
|
|
|
public function getTeamIcon($teamId)
|
246
|
|
|
{
|
247
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/image');
|
248
|
|
|
}
|
249
|
|
|
|
250
|
|
|
/**
|
251
|
|
|
* @param $teamId
|
252
|
|
|
* @param array $requestOptions
|
253
|
|
|
* @return ResponseInterface
|
254
|
|
|
*/
|
255
|
|
|
public function setTeamIcon($teamId, array $requestOptions)
|
256
|
|
|
{
|
257
|
|
|
$internalRequestOptions = self::buildMultipartDataOptions($requestOptions, ['image']);
|
258
|
|
|
|
259
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/image', $internalRequestOptions, RequestOptions::MULTIPART);
|
260
|
|
|
}
|
261
|
|
|
|
262
|
|
|
/**
|
263
|
|
|
* @param $teamId
|
264
|
|
|
* @return ResponseInterface
|
265
|
|
|
*/
|
266
|
|
|
public function removeTeamIcon($teamId)
|
267
|
|
|
{
|
268
|
|
|
return $this->client->delete(self::$endpoint . '/' . $teamId . '/image');
|
269
|
|
|
}
|
270
|
|
|
|
271
|
|
|
/**
|
272
|
|
|
* @param $teamId
|
273
|
|
|
* @param $userId
|
274
|
|
|
* @param array $requestOptions
|
275
|
|
|
* @return ResponseInterface
|
276
|
|
|
*/
|
277
|
|
|
public function updateTeamMemberRoles($teamId, $userId, array $requestOptions)
|
278
|
|
|
{
|
279
|
|
|
return $this->client->put(self::$endpoint . '/' . $teamId . '/members/' . $userId . '/roles', $requestOptions);
|
280
|
|
|
}
|
281
|
|
|
|
282
|
|
|
/**
|
283
|
|
|
* @param $teamId
|
284
|
|
|
* @param $userId
|
285
|
|
|
* @param array $requestOptions
|
286
|
|
|
* @return ResponseInterface
|
287
|
|
|
*/
|
288
|
|
|
public function updateSchemeDerivedRolesOfMember($teamId, $userId, array $requestOptions)
|
289
|
|
|
{
|
290
|
|
|
return $this->client->put(self::$endpoint . '/' . $teamId . '/members/' . $userId . '/schemeRoles', $requestOptions);
|
291
|
|
|
}
|
292
|
|
|
|
293
|
|
|
/**
|
294
|
|
|
* @param $userId
|
295
|
|
|
* @param array $requestOptions
|
296
|
|
|
* @return ResponseInterface
|
297
|
|
|
*/
|
298
|
|
|
public function getUserTotalUnreadMessagesFromTeams($userId, array $requestOptions = [])
|
299
|
|
|
{
|
300
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams/unread', $requestOptions);
|
301
|
|
|
}
|
302
|
|
|
|
303
|
|
|
/**
|
304
|
|
|
* @param $userId
|
305
|
|
|
* @param $teamId
|
306
|
|
|
* @return ResponseInterface
|
307
|
|
|
*/
|
308
|
|
|
public function getUserTotalUnreadMessagesFromTeam($userId, $teamId)
|
309
|
|
|
{
|
310
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams/' . $teamId . '/unread');
|
311
|
|
|
}
|
312
|
|
|
|
313
|
|
|
/**
|
314
|
|
|
* @param $teamId
|
315
|
|
|
* @param array $requestOptions
|
316
|
|
|
* @return ResponseInterface
|
317
|
|
|
*/
|
318
|
|
|
public function inviteUsersByEmail($teamId, array $requestOptions)
|
319
|
|
|
{
|
320
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/invite/email', $requestOptions);
|
321
|
|
|
}
|
322
|
|
|
|
323
|
|
|
/**
|
324
|
|
|
* @param $teamId
|
325
|
|
|
* @param array $requestOptions
|
326
|
|
|
* @return ResponseInterface
|
327
|
|
|
*/
|
328
|
|
|
public function inviteGuestsByEmail($teamId, array $requestOptions)
|
329
|
|
|
{
|
330
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/invite-guests/email', $requestOptions);
|
331
|
|
|
}
|
332
|
|
|
|
333
|
|
|
/**
|
334
|
|
|
* @return ResponseInterface
|
335
|
|
|
*/
|
336
|
|
|
public function invalidateActiveEmailInvitations()
|
337
|
|
|
{
|
338
|
|
|
return $this->client->delete(self::$endpoint . '/invites/email');
|
339
|
|
|
}
|
340
|
|
|
|
341
|
|
|
/**
|
342
|
|
|
* @param $teamId
|
343
|
|
|
* @param array $requestOptions
|
344
|
|
|
* @return ResponseInterface
|
345
|
|
|
*/
|
346
|
|
|
public function importTeamFromOtherApplication($teamId, array $requestOptions)
|
347
|
|
|
{
|
348
|
|
|
$internalRequestOptions = self::buildMultipartDataOptions($requestOptions, ['file', 'filesize', 'importFrom']);
|
349
|
|
|
|
350
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/import', $internalRequestOptions, RequestOptions::MULTIPART);
|
351
|
|
|
}
|
352
|
|
|
|
353
|
|
|
/**
|
354
|
|
|
* @param $inviteId
|
355
|
|
|
* @return ResponseInterface
|
356
|
|
|
*/
|
357
|
|
|
public function getInviteInfoForTeam($inviteId)
|
358
|
|
|
{
|
359
|
|
|
return $this->client->get(self::$endpoint . '/invite/' . $inviteId);
|
360
|
|
|
}
|
361
|
|
|
|
362
|
|
|
/**
|
363
|
|
|
* @param $teamId
|
364
|
|
|
* @param array $requestOptions
|
365
|
|
|
* @return ResponseInterface
|
366
|
|
|
*/
|
367
|
|
|
public function setTeamScheme($teamId, array $requestOptions)
|
368
|
|
|
{
|
369
|
|
|
return $this->client->put(self::$endpoint . '/' . $teamId . '/scheme', $requestOptions);
|
370
|
|
|
}
|
371
|
|
|
|
372
|
|
|
/**
|
373
|
|
|
* @param $teamId
|
374
|
|
|
* @param array $requestOptions
|
375
|
|
|
* @return ResponseInterface
|
376
|
|
|
*/
|
377
|
|
|
public function getTeamMembersMinusGroupMembers($teamId, array $requestOptions)
|
378
|
|
|
{
|
379
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/members_minus_group_members', $requestOptions);
|
380
|
|
|
}
|
381
|
|
|
|
382
|
|
|
/**
|
383
|
|
|
* @param $teamId
|
384
|
|
|
* @param array $requestOptions
|
385
|
|
|
* @return ResponseInterface
|
386
|
|
|
*/
|
387
|
|
|
public function getPublicChannels($teamId, array $requestOptions)
|
388
|
|
|
{
|
389
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/channels', $requestOptions);
|
390
|
|
|
}
|
391
|
|
|
|
392
|
|
|
/**
|
393
|
|
|
* @param $teamId
|
394
|
|
|
* @param array $requestOptions
|
395
|
|
|
* @return ResponseInterface
|
396
|
|
|
*/
|
397
|
|
|
public function getDeletedChannels($teamId, array $requestOptions)
|
398
|
|
|
{
|
399
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/channels/deleted', $requestOptions);
|
400
|
|
|
}
|
401
|
|
|
|
402
|
|
|
/**
|
403
|
|
|
* @param $teamId
|
404
|
|
|
* @param array $requestOptions
|
405
|
|
|
* @return ResponseInterface
|
406
|
|
|
*/
|
407
|
|
|
public function searchChannels($teamId, array $requestOptions)
|
408
|
|
|
{
|
409
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/channels/search', $requestOptions);
|
410
|
|
|
}
|
411
|
|
|
}
|
412
|
|
|
|