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
|
|
|
* God bless this mess.
|
7
|
|
|
*
|
8
|
|
|
* @author Luca Agnello <[email protected]>
|
9
|
|
|
* @link https://api.mattermost.com/
|
10
|
|
|
*/
|
11
|
|
|
|
12
|
|
|
namespace Gnello\Mattermost\Models;
|
13
|
|
|
|
14
|
|
|
use GuzzleHttp\RequestOptions;
|
15
|
|
|
use Psr\Http\Message\ResponseInterface;
|
16
|
|
|
|
17
|
|
|
/**
|
18
|
|
|
* Class UserEntity
|
19
|
|
|
*
|
20
|
|
|
* @package Gnello\MattermostRestApi\Entities
|
21
|
|
|
*/
|
22
|
|
|
class UserModel extends AbstractModel
|
23
|
|
|
{
|
24
|
|
|
/**
|
25
|
|
|
* @var string
|
26
|
|
|
*/
|
27
|
|
|
public static $endpoint = '/users';
|
28
|
|
|
|
29
|
|
|
/**
|
30
|
|
|
* @param array $requestOptions
|
31
|
|
|
* @return ResponseInterface
|
32
|
|
|
*/
|
33
|
|
|
public function loginToUserAccount(array $requestOptions)
|
34
|
|
|
{
|
35
|
|
|
return $this->client->post(self::$endpoint . '/login', $requestOptions);
|
36
|
|
|
}
|
37
|
|
|
|
38
|
|
|
/**
|
39
|
|
|
* @return ResponseInterface
|
40
|
|
|
*/
|
41
|
|
|
public function logoutOfUserAccount()
|
42
|
|
|
{
|
43
|
|
|
return $this->client->post(self::$endpoint . '/logout');
|
44
|
|
|
}
|
45
|
|
|
|
46
|
|
|
/**
|
47
|
|
|
* @return ResponseInterface
|
48
|
|
|
*/
|
49
|
|
|
public function getAuthenticatedUser()
|
50
|
|
|
{
|
51
|
|
|
return $this->client->get(self::$endpoint . '/me');
|
52
|
|
|
}
|
53
|
|
|
|
54
|
|
|
/**
|
55
|
|
|
* @param array $requestOptions
|
56
|
|
|
* @return ResponseInterface
|
57
|
|
|
*/
|
58
|
|
|
public function createUser(array $requestOptions)
|
59
|
|
|
{
|
60
|
|
|
return $this->client->post(self::$endpoint, $requestOptions);
|
61
|
|
|
}
|
62
|
|
|
|
63
|
|
|
/**
|
64
|
|
|
* @param array $requestOptions
|
65
|
|
|
* @return ResponseInterface
|
66
|
|
|
*/
|
67
|
|
|
public function getUsers(array $requestOptions)
|
68
|
|
|
{
|
69
|
|
|
return $this->client->get(self::$endpoint, $requestOptions);
|
70
|
|
|
}
|
71
|
|
|
|
72
|
|
|
/**
|
73
|
|
|
* @param array $requestOptions
|
74
|
|
|
* @return ResponseInterface
|
75
|
|
|
*/
|
76
|
|
|
public function getUsersByIds(array $requestOptions)
|
77
|
|
|
{
|
78
|
|
|
return $this->client->post(self::$endpoint . '/ids', $requestOptions);
|
79
|
|
|
}
|
80
|
|
|
|
81
|
|
|
/**
|
82
|
|
|
* @param array $requestOptions
|
83
|
|
|
* @return ResponseInterface
|
84
|
|
|
*/
|
85
|
|
|
public function getUsersByGroupChannelsIds(array $requestOptions = [])
|
86
|
|
|
{
|
87
|
|
|
return $this->client->post(self::$endpoint . '/group_channels', $requestOptions);
|
88
|
|
|
}
|
89
|
|
|
|
90
|
|
|
/**
|
91
|
|
|
* @param array $requestOptions
|
92
|
|
|
* @return ResponseInterface
|
93
|
|
|
*/
|
94
|
|
|
public function searchUsers(array $requestOptions)
|
95
|
|
|
{
|
96
|
|
|
return $this->client->post(self::$endpoint . '/search', $requestOptions);
|
97
|
|
|
}
|
98
|
|
|
|
99
|
|
|
/**
|
100
|
|
|
* @param array $requestOptions
|
101
|
|
|
* @return ResponseInterface
|
102
|
|
|
*/
|
103
|
|
|
public function autocompleteUsers(array $requestOptions)
|
104
|
|
|
{
|
105
|
|
|
return $this->client->get(self::$endpoint . '/autocomplete', $requestOptions);
|
106
|
|
|
}
|
107
|
|
|
|
108
|
|
|
/**
|
109
|
|
|
* @param $userId
|
110
|
|
|
* @return ResponseInterface
|
111
|
|
|
*/
|
112
|
|
|
public function getUser($userId)
|
113
|
|
|
{
|
114
|
|
|
return $this->client->get(self::$endpoint . '/' . $userId);
|
115
|
|
|
}
|
116
|
|
|
|
117
|
|
|
/**
|
118
|
|
|
* @param $userId
|
119
|
|
|
* @param array $requestOptions
|
120
|
|
|
* @return ResponseInterface
|
121
|
|
|
*/
|
122
|
|
|
public function updateUser($userId, array $requestOptions)
|
123
|
|
|
{
|
124
|
|
|
return $this->client->put(self::$endpoint . '/' . $userId, $requestOptions);
|
125
|
|
|
}
|
126
|
|
|
|
127
|
|
|
/**
|
128
|
|
|
* @param $userId
|
129
|
|
|
* @return ResponseInterface
|
130
|
|
|
*/
|
131
|
|
|
public function deactivateUserAccount($userId)
|
132
|
|
|
{
|
133
|
|
|
return $this->client->delete(self::$endpoint . '/' . $userId);
|
134
|
|
|
}
|
135
|
|
|
|
136
|
|
|
/**
|
137
|
|
|
* @param $userId
|
138
|
|
|
* @param array $requestOptions
|
139
|
|
|
* @return ResponseInterface
|
140
|
|
|
*/
|
141
|
|
|
public function patchUser($userId, array $requestOptions)
|
142
|
|
|
{
|
143
|
|
|
return $this->client->put(self::$endpoint . '/' . $userId . '/patch', $requestOptions);
|
144
|
|
|
}
|
145
|
|
|
|
146
|
|
|
/**
|
147
|
|
|
* @param $userId
|
148
|
|
|
* @param array $requestOptions
|
149
|
|
|
* @return ResponseInterface
|
150
|
|
|
*/
|
151
|
|
|
public function updateUserRoles($userId, array $requestOptions)
|
152
|
|
|
{
|
153
|
|
|
return $this->client->put(self::$endpoint . '/' . $userId . '/roles', $requestOptions);
|
154
|
|
|
}
|
155
|
|
|
|
156
|
|
|
/**
|
157
|
|
|
* @param $userId
|
158
|
|
|
* @param array $requestOptions
|
159
|
|
|
* @return ResponseInterface
|
160
|
|
|
*/
|
161
|
|
|
public function updateUserActive($userId, array $requestOptions)
|
162
|
|
|
{
|
163
|
|
|
return $this->client->put(self::$endpoint . '/' . $userId . '/active', $requestOptions);
|
164
|
|
|
}
|
165
|
|
|
|
166
|
|
|
/**
|
167
|
|
|
* @param $userId
|
168
|
|
|
* @return ResponseInterface
|
169
|
|
|
*/
|
170
|
|
|
public function getUserProfileImage($userId)
|
171
|
|
|
{
|
172
|
|
|
return $this->client->get(self::$endpoint . '/' . $userId . '/image');
|
173
|
|
|
}
|
174
|
|
|
|
175
|
|
|
/**
|
176
|
|
|
* @param $userId
|
177
|
|
|
* @param array $requestOptions
|
178
|
|
|
* @return ResponseInterface
|
179
|
|
|
*/
|
180
|
|
|
public function setUserProfileImage($userId, array $requestOptions)
|
181
|
|
|
{
|
182
|
|
|
$internalRequestOptions = self::buildMultipartDataOptions($requestOptions, ['image']);
|
183
|
|
|
|
184
|
|
|
return $this->client->post(self::$endpoint . '/' . $userId . '/image', $internalRequestOptions, RequestOptions::MULTIPART);
|
185
|
|
|
}
|
186
|
|
|
|
187
|
|
|
/**
|
188
|
|
|
* @param $userId
|
189
|
|
|
* @return ResponseInterface
|
190
|
|
|
*/
|
191
|
|
|
public function deleteUserProfileImage($userId)
|
192
|
|
|
{
|
193
|
|
|
return $this->client->delete(self::$endpoint . '/' . $userId . '/image');
|
194
|
|
|
}
|
195
|
|
|
|
196
|
|
|
/**
|
197
|
|
|
* @param $userId
|
198
|
|
|
* @return ResponseInterface
|
199
|
|
|
*/
|
200
|
|
|
public function returnUserDefaultProfileImage($userId)
|
201
|
|
|
{
|
202
|
|
|
return $this->client->get(self::$endpoint . '/' . $userId . '/image/default');
|
203
|
|
|
}
|
204
|
|
|
|
205
|
|
|
/**
|
206
|
|
|
* @param $username
|
207
|
|
|
* @return ResponseInterface
|
208
|
|
|
*/
|
209
|
|
|
public function getUserByUsername($username)
|
210
|
|
|
{
|
211
|
|
|
return $this->client->get(self::$endpoint . '/username/' . $username);
|
212
|
|
|
}
|
213
|
|
|
|
214
|
|
|
/**
|
215
|
|
|
* @param $requestOptions
|
216
|
|
|
* @return ResponseInterface
|
217
|
|
|
*/
|
218
|
|
|
public function getUsersByUsernames(array $requestOptions)
|
219
|
|
|
{
|
220
|
|
|
return $this->client->post(self::$endpoint . '/usernames/', $requestOptions);
|
221
|
|
|
}
|
222
|
|
|
|
223
|
|
|
/**
|
224
|
|
|
* @param array $requestOptions
|
225
|
|
|
* @return ResponseInterface
|
226
|
|
|
*/
|
227
|
|
|
public function resetPassword(array $requestOptions)
|
228
|
|
|
{
|
229
|
|
|
return $this->client->post(self::$endpoint . '/password/reset', $requestOptions);
|
230
|
|
|
}
|
231
|
|
|
|
232
|
|
|
/**
|
233
|
|
|
* @param $userId
|
234
|
|
|
* @param array $requestOptions
|
235
|
|
|
* @return ResponseInterface
|
236
|
|
|
*/
|
237
|
|
|
public function updateUserMfa($userId, array $requestOptions)
|
238
|
|
|
{
|
239
|
|
|
return $this->client->put(self::$endpoint . '/' . $userId . '/mfa', $requestOptions);
|
240
|
|
|
}
|
241
|
|
|
|
242
|
|
|
/**
|
243
|
|
|
* @param $userId
|
244
|
|
|
* @param array $requestOptions
|
245
|
|
|
* @return ResponseInterface
|
246
|
|
|
*/
|
247
|
|
|
public function generateMfaSecret($userId, array $requestOptions)
|
248
|
|
|
{
|
249
|
|
|
return $this->client->post(self::$endpoint . '/' . $userId . '/mfa/generate', $requestOptions);
|
250
|
|
|
}
|
251
|
|
|
|
252
|
|
|
/**
|
253
|
|
|
* @param array $requestOptions
|
254
|
|
|
* @return ResponseInterface
|
255
|
|
|
*/
|
256
|
|
|
public function checkMfa(array $requestOptions)
|
257
|
|
|
{
|
258
|
|
|
return $this->client->post(self::$endpoint . '/mfa', $requestOptions);
|
259
|
|
|
}
|
260
|
|
|
|
261
|
|
|
/**
|
262
|
|
|
* @param $userId
|
263
|
|
|
* @param array $requestOptions
|
264
|
|
|
* @return ResponseInterface
|
265
|
|
|
*/
|
266
|
|
|
public function updateUserPassword($userId, array $requestOptions)
|
267
|
|
|
{
|
268
|
|
|
return $this->client->put(self::$endpoint . '/' . $userId . '/password', $requestOptions);
|
269
|
|
|
}
|
270
|
|
|
|
271
|
|
|
/**
|
272
|
|
|
* @param array $requestOptions
|
273
|
|
|
* @return ResponseInterface
|
274
|
|
|
*/
|
275
|
|
|
public function sendPasswordResetEmail(array $requestOptions)
|
276
|
|
|
{
|
277
|
|
|
return $this->client->post(self::$endpoint . '/password/reset/send', $requestOptions);
|
278
|
|
|
}
|
279
|
|
|
|
280
|
|
|
/**
|
281
|
|
|
* @param $email
|
282
|
|
|
* @return ResponseInterface
|
283
|
|
|
*/
|
284
|
|
|
public function getUserByEmail($email)
|
285
|
|
|
{
|
286
|
|
|
return $this->client->get(self::$endpoint . '/email/' . $email);
|
287
|
|
|
}
|
288
|
|
|
|
289
|
|
|
/**
|
290
|
|
|
* @param $userId
|
291
|
|
|
* @return ResponseInterface
|
292
|
|
|
*/
|
293
|
|
|
public function getUserSessions($userId)
|
294
|
|
|
{
|
295
|
|
|
return $this->client->get(self::$endpoint . '/' . $userId . '/sessions');
|
296
|
|
|
}
|
297
|
|
|
|
298
|
|
|
/**
|
299
|
|
|
* @param $userId
|
300
|
|
|
* @param array $requestOptions
|
301
|
|
|
* @return ResponseInterface
|
302
|
|
|
*/
|
303
|
|
|
public function revokeUserSession($userId, array $requestOptions)
|
304
|
|
|
{
|
305
|
|
|
return $this->client->post(self::$endpoint . '/' . $userId . '/sessions/revoke', $requestOptions);
|
306
|
|
|
}
|
307
|
|
|
|
308
|
|
|
/**
|
309
|
|
|
* @param $userId
|
310
|
|
|
* @return ResponseInterface
|
311
|
|
|
*/
|
312
|
|
|
public function revokeAllUserSessions($userId)
|
313
|
|
|
{
|
314
|
|
|
return $this->client->post(self::$endpoint . '/' . $userId . '/sessions/revoke/all');
|
315
|
|
|
}
|
316
|
|
|
|
317
|
|
|
/**
|
318
|
|
|
* @param array $requestOptions
|
319
|
|
|
* @return ResponseInterface
|
320
|
|
|
*/
|
321
|
|
|
public function attachMobileDevice(array $requestOptions)
|
322
|
|
|
{
|
323
|
|
|
return $this->client->put(self::$endpoint . '/sessions/device', $requestOptions);
|
324
|
|
|
}
|
325
|
|
|
|
326
|
|
|
/**
|
327
|
|
|
* @param $userId
|
328
|
|
|
* @return ResponseInterface
|
329
|
|
|
*/
|
330
|
|
|
public function getUserAudits($userId)
|
331
|
|
|
{
|
332
|
|
|
return $this->client->get(self::$endpoint . '/' . $userId . '/audits');
|
333
|
|
|
}
|
334
|
|
|
|
335
|
|
|
/**
|
336
|
|
|
* @param array $requestOptions
|
337
|
|
|
* @return ResponseInterface
|
338
|
|
|
*/
|
339
|
|
|
public function verifyUserEmail(array $requestOptions)
|
340
|
|
|
{
|
341
|
|
|
return $this->client->post(self::$endpoint . '/email/verify', $requestOptions);
|
342
|
|
|
}
|
343
|
|
|
|
344
|
|
|
/**
|
345
|
|
|
* @param array $requestOptions
|
346
|
|
|
* @return ResponseInterface
|
347
|
|
|
*/
|
348
|
|
|
public function sendVerificationEmail(array $requestOptions)
|
349
|
|
|
{
|
350
|
|
|
return $this->client->post(self::$endpoint . '/email/verify/send', $requestOptions);
|
351
|
|
|
}
|
352
|
|
|
|
353
|
|
|
/**
|
354
|
|
|
* @param array $requestOptions
|
355
|
|
|
* @return ResponseInterface
|
356
|
|
|
*/
|
357
|
|
|
public function switchLoginMethod(array $requestOptions)
|
358
|
|
|
{
|
359
|
|
|
return $this->client->post(self::$endpoint . '/login/switch', $requestOptions);
|
360
|
|
|
}
|
361
|
|
|
|
362
|
|
|
/**
|
363
|
|
|
* @param $userId
|
364
|
|
|
* @param array $requestOptions
|
365
|
|
|
* @return ResponseInterface
|
366
|
|
|
*/
|
367
|
|
|
public function createToken($userId, array $requestOptions)
|
368
|
|
|
{
|
369
|
|
|
return $this->client->post(self::$endpoint . '/' . $userId . '/tokens', $requestOptions);
|
370
|
|
|
}
|
371
|
|
|
|
372
|
|
|
/**
|
373
|
|
|
* @param $userId
|
374
|
|
|
* @param array $requestOptions
|
375
|
|
|
* @return ResponseInterface
|
376
|
|
|
*/
|
377
|
|
|
public function getTokens($userId, array $requestOptions)
|
378
|
|
|
{
|
379
|
|
|
return $this->client->get(self::$endpoint . '/' . $userId . '/tokens', $requestOptions);
|
380
|
|
|
}
|
381
|
|
|
|
382
|
|
|
/**
|
383
|
|
|
* @param $tokenId
|
384
|
|
|
* @return ResponseInterface
|
385
|
|
|
*/
|
386
|
|
|
public function getToken($tokenId)
|
387
|
|
|
{
|
388
|
|
|
return $this->client->get(self::$endpoint . '/tokens/' . $tokenId);
|
389
|
|
|
}
|
390
|
|
|
|
391
|
|
|
/**
|
392
|
|
|
* @param array $requestOptions
|
393
|
|
|
* @return ResponseInterface
|
394
|
|
|
*/
|
395
|
|
|
public function revokeToken(array $requestOptions)
|
396
|
|
|
{
|
397
|
|
|
return $this->client->post(self::$endpoint . '/tokens/revoke', $requestOptions);
|
398
|
|
|
}
|
399
|
|
|
|
400
|
|
|
/**
|
401
|
|
|
* @param array $requestOptions
|
402
|
|
|
* @return ResponseInterface
|
403
|
|
|
*/
|
404
|
|
|
public function disablePersonalAccessToken(array $requestOptions)
|
405
|
|
|
{
|
406
|
|
|
return $this->client->post(self::$endpoint . '/tokens/disable', $requestOptions);
|
407
|
|
|
}
|
408
|
|
|
|
409
|
|
|
/**
|
410
|
|
|
* @param array $requestOptions
|
411
|
|
|
* @return ResponseInterface
|
412
|
|
|
*/
|
413
|
|
|
public function enablePersonalAccessToken(array $requestOptions)
|
414
|
|
|
{
|
415
|
|
|
return $this->client->post(self::$endpoint . '/tokens/enable', $requestOptions);
|
416
|
|
|
}
|
417
|
|
|
|
418
|
|
|
/**
|
419
|
|
|
* @param array $requestOptions
|
420
|
|
|
* @return ResponseInterface
|
421
|
|
|
*/
|
422
|
|
|
public function searchTokens(array $requestOptions)
|
423
|
|
|
{
|
424
|
|
|
return $this->client->post(self::$endpoint . '/tokens/search', $requestOptions);
|
425
|
|
|
}
|
426
|
|
|
|
427
|
|
|
/**
|
428
|
|
|
* @param $userId
|
429
|
|
|
* @return ResponseInterface
|
430
|
|
|
*/
|
431
|
|
|
public function getUserStatus($userId)
|
432
|
|
|
{
|
433
|
|
|
return $this->client->get(self::$endpoint . '/' . $userId . '/status');
|
434
|
|
|
}
|
435
|
|
|
|
436
|
|
|
/**
|
437
|
|
|
* @param $userId
|
438
|
|
|
* @param array $requestOptions
|
439
|
|
|
* @return ResponseInterface
|
440
|
|
|
*/
|
441
|
|
|
public function updateUserStatus($userId, array $requestOptions)
|
442
|
|
|
{
|
443
|
|
|
return $this->client->put(self::$endpoint . '/' . $userId . '/status', $requestOptions);
|
444
|
|
|
}
|
445
|
|
|
|
446
|
|
|
/**
|
447
|
|
|
* @param $userId
|
448
|
|
|
* @param array $requestOptions
|
449
|
|
|
* @return ResponseInterface
|
450
|
|
|
*/
|
451
|
|
|
public function updateUserAuthenticationMethod($userId, array $requestOptions)
|
452
|
|
|
{
|
453
|
|
|
return $this->client->put(self::$endpoint . '/' . $userId . '/auth', $requestOptions);
|
454
|
|
|
}
|
455
|
|
|
|
456
|
|
|
/**
|
457
|
|
|
* @return ResponseInterface
|
458
|
|
|
*/
|
459
|
|
|
public function getTotalCountOfUsersInTheSystem()
|
460
|
|
|
{
|
461
|
|
|
return $this->client->get(self::$endpoint . '/stats');
|
462
|
|
|
}
|
463
|
|
|
|
464
|
|
|
/**
|
465
|
|
|
* @param $userId
|
466
|
|
|
* @return ResponseInterface
|
467
|
|
|
*/
|
468
|
|
|
public function promoteGuestToUser($userId)
|
469
|
|
|
{
|
470
|
|
|
return $this->client->post(self::$endpoint . '/' . $userId . '/promote');
|
471
|
|
|
}
|
472
|
|
|
|
473
|
|
|
/**
|
474
|
|
|
* @param $userId
|
475
|
|
|
* @return ResponseInterface
|
476
|
|
|
*/
|
477
|
|
|
public function demoteUserToGuest($userId)
|
478
|
|
|
{
|
479
|
|
|
return $this->client->post(self::$endpoint . '/' . $userId . '/demote');
|
480
|
|
|
}
|
481
|
|
|
}
|
482
|
|
|
|