Passed
Branch develop (def2bd)
by
unknown
26:55
created

Users::getGroups()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 21
rs 9.8333
1
<?php
2
/* Copyright (C) 2015   Jean-François Ferry     <[email protected]>
3
/* Copyright (C) 2020   Thibault FOUCART     	<[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
use Luracast\Restler\RestException;
20
21
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
22
require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
23
24
/**
25
 * API class for users
26
 *
27
 * @access protected
28
 * @class  DolibarrApiAccess {@requires user,external}
29
 */
30
class Users extends DolibarrApi
31
{
32
	/**
33
	 *
34
	 * @var array   $FIELDS     Mandatory fields, checked when create and update object
35
	 */
36
	static $FIELDS = array(
37
		'login',
38
	);
39
40
	/**
41
	 * @var User $user {@type User}
42
	 */
43
	public $useraccount;
44
45
	/**
46
	 * Constructor
47
	 */
48
    public function __construct()
49
    {
50
		global $db, $conf;
51
		$this->db = $db;
52
		$this->useraccount = new User($this->db);
53
	}
54
55
56
	/**
57
	 * List Users
58
	 *
59
	 * Get a list of Users
60
	 *
61
	 * @param string	$sortfield	Sort field
62
	 * @param string	$sortorder	Sort order
63
	 * @param int		$limit		Limit for list
64
	 * @param int		$page		Page number
65
	 * @param string   	$user_ids   User ids filter field. Example: '1' or '1,2,3'          {@pattern /^[0-9,]*$/i}
66
     * @param  int    $category   Use this param to filter list by category
67
     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
68
	 * @return  array               Array of User objects
69
	 */
70
    public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $category = 0, $sqlfilters = '')
71
    {
72
	    global $db, $conf;
73
74
	    $obj_ret = array();
75
76
		if (!DolibarrApiAccess::$user->rights->user->user->lire) {
77
	        throw new RestException(401, "You are not allowed to read list of users");
78
	    }
79
80
	    // case of external user, $societe param is ignored and replaced by user's socid
81
	    //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe;
82
83
	    $sql = "SELECT t.rowid";
84
	    $sql .= " FROM ".MAIN_DB_PREFIX."user as t";
85
        if ($category > 0) {
86
            $sql .= ", ".MAIN_DB_PREFIX."categorie_user as c";
87
        }
88
	    $sql .= ' WHERE t.entity IN ('.getEntity('user').')';
89
	    if ($user_ids) $sql .= " AND t.rowid IN (".$user_ids.")";
90
91
    	// Select products of given category
92
    	if ($category > 0) {
93
			$sql .= " AND c.fk_categorie = ".$db->escape($category);
94
			$sql .= " AND c.fk_user = t.rowid ";
95
    	}
96
97
	    // Add sql filters
98
        if ($sqlfilters)
99
        {
100
            if (!DolibarrApi::_checkFilters($sqlfilters))
101
            {
102
                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
103
            }
104
	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
105
            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
106
        }
107
108
	    $sql .= $db->order($sortfield, $sortorder);
109
	    if ($limit) {
110
	        if ($page < 0)
111
	        {
112
	            $page = 0;
113
	        }
114
	        $offset = $limit * $page;
115
116
	        $sql .= $db->plimit($limit + 1, $offset);
117
	    }
118
119
	    $result = $db->query($sql);
120
121
	    if ($result)
122
	    {
123
	        $i = 0;
124
	        $num = $db->num_rows($result);
125
	        $min = min($num, ($limit <= 0 ? $num : $limit));
126
	        while ($i < $min)
127
	        {
128
	            $obj = $db->fetch_object($result);
129
	            $user_static = new User($db);
130
	            if ($user_static->fetch($obj->rowid)) {
131
	                $obj_ret[] = $this->_cleanObjectDatas($user_static);
132
	            }
133
	            $i++;
134
	        }
135
	    } else {
136
	        throw new RestException(503, 'Error when retrieve User list : '.$db->lasterror());
137
	    }
138
	    if (!count($obj_ret)) {
139
	        throw new RestException(404, 'No User found');
140
	    }
141
	    return $obj_ret;
142
	}
143
144
	/**
145
	 * Get properties of an user object
146
	 *
147
	 * @param 	int 	$id 					ID of user
148
	 * @param	int		$includepermissions	Set this to 1 to have the array of permissions loaded (not done by default for performance purpose)
149
	 * @return 	array|mixed data without useless information
150
	 *
151
	 * @throws RestException 401     Insufficient rights
152
	 * @throws RestException 404     User or group not found
153
	 */
154
    public function get($id, $includepermissions = 0)
155
    {
156
		//if (!DolibarrApiAccess::$user->rights->user->user->lire) {
157
			//throw new RestException(401);
158
		//}
159
160
		$result = $this->useraccount->fetch($id);
161
		if (!$result)
162
		{
163
			throw new RestException(404, 'User not found');
164
		}
165
166
		if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
167
		{
168
			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
169
		}
170
171
		if ($includepermissions) {
172
			$this->useraccount->getRights();
173
		}
174
175
		return $this->_cleanObjectDatas($this->useraccount);
176
	}
177
178
	/**
179
	 * Get properties of an user object by login
180
	 *
181
	 * @param 	string 	$login 					Login of user
182
	 * @param	int		$includepermissions	Set this to 1 to have the array of permissions loaded (not done by default for performance purpose)
183
	 * @return 	array|mixed data without useless information
184
	 *
185
	 * @url GET login/{login}
186
	 *
187
	 * @throws RestException 401     Insufficient rights
188
	 * @throws RestException 404     User or group not found
189
	 */
190
    public function getByLogin($login, $includepermissions = 0)
191
    {
192
		//if (!DolibarrApiAccess::$user->rights->user->user->lire) {
193
			//throw new RestException(401);
194
		//}
195
196
		$result = $this->useraccount->fetch('', $login);
197
		if (!$result)
198
		{
199
			throw new RestException(404, 'User not found');
200
		}
201
202
		if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
203
		{
204
			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
205
		}
206
207
		if ($includepermissions) {
208
			$this->useraccount->getRights();
209
		}
210
211
		return $this->_cleanObjectDatas($this->useraccount);
212
	}
213
214
	/**
215
	 * Get properties of an user object by Email
216
	 *
217
	 * @param 	string 	$email 					Email of user
218
	 * @param	int		$includepermissions	Set this to 1 to have the array of permissions loaded (not done by default for performance purpose)
219
	 * @return 	array|mixed data without useless information
220
	 *
221
	 * @url GET email/{email}
222
	 *
223
	 * @throws RestException 401     Insufficient rights
224
	 * @throws RestException 404     User or group not found
225
	 */
226
    public function getByEmail($email, $includepermissions = 0)
227
    {
228
		//if (!DolibarrApiAccess::$user->rights->user->user->lire) {
229
			//throw new RestException(401);
230
		//}
231
232
		$result = $this->useraccount->fetch('', '', '', 0, -1, $email);
233
		if (!$result)
234
		{
235
			throw new RestException(404, 'User not found');
236
		}
237
238
		if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
239
		{
240
			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
241
		}
242
243
		if ($includepermissions) {
244
			$this->useraccount->getRights();
245
		}
246
247
		return $this->_cleanObjectDatas($this->useraccount);
248
	}
249
250
    /**
251
     * Get properties of user connected
252
     *
253
     * @url	GET /info
254
     *
255
     * @return  array|mixed Data without useless information
256
     *
257
     * @throws RestException 401     Insufficient rights
258
     * @throws RestException 404     User or group not found
259
     */
260
    public function getInfo()
261
    {
262
        $apiUser = DolibarrApiAccess::$user;
263
264
        $result = $this->useraccount->fetch($apiUser->id);
265
        if (!$result) {
266
            throw new RestException(404, 'User not found');
267
        }
268
269
        if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
270
            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
271
        }
272
273
        $usergroup = new UserGroup($this->db);
274
        $userGroupList = $usergroup->listGroupsForUser($apiUser->id, false);
275
        if (!is_array($userGroupList)) {
276
            throw new RestException(404, 'User group not found');
277
        }
278
279
        $this->useraccount->user_group_list = $this->_cleanUserGroupListDatas($userGroupList);
0 ignored issues
show
Bug introduced by
The property user_group_list does not seem to exist on User.
Loading history...
280
281
        return $this->_cleanObjectDatas($this->useraccount);
282
    }
283
284
	/**
285
	 * Create user account
286
	 *
287
	 * @param array $request_data New user data
288
	 * @return int
289
	 */
290
    public function post($request_data = null)
291
    {
292
	    // check user authorization
293
	    //if(! DolibarrApiAccess::$user->rights->user->creer) {
294
	    //   throw new RestException(401, "User creation not allowed");
295
	    //}
296
	    // check mandatory fields
297
	    /*if (!isset($request_data["login"]))
298
	        throw new RestException(400, "login field missing");
299
	    if (!isset($request_data["password"]))
300
	        throw new RestException(400, "password field missing");
301
	    if (!isset($request_data["lastname"]))
302
	         throw new RestException(400, "lastname field missing");*/
303
	    //assign field values
304
        foreach ($request_data as $field => $value)
305
	    {
306
	          $this->useraccount->$field = $value;
307
	    }
308
309
	    if ($this->useraccount->create(DolibarrApiAccess::$user) < 0) {
310
             throw new RestException(500, 'Error creating', array_merge(array($this->useraccount->error), $this->useraccount->errors));
311
	    }
312
	    return $this->useraccount->id;
313
    }
314
315
316
	/**
317
	 * Update account
318
	 *
319
	 * @param int   $id             Id of account to update
320
	 * @param array $request_data   Datas
321
	 * @return array
322
     *
323
     * @throws 	RestException
324
	 */
325
    public function put($id, $request_data = null)
326
    {
327
		//if (!DolibarrApiAccess::$user->rights->user->user->creer) {
328
			//throw new RestException(401);
329
		//}
330
331
		$result = $this->useraccount->fetch($id);
332
		if (!$result)
333
		{
334
			throw new RestException(404, 'Account not found');
335
		}
336
337
		if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
338
		{
339
			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
340
		}
341
342
		foreach ($request_data as $field => $value)
343
		{
344
			if ($field == 'id') continue;
345
			// The status must be updated using setstatus() because it
346
			// is not handled by the update() method.
347
			if ($field == 'statut') {
348
				$result = $this->useraccount->setstatus($value);
349
				if ($result < 0) {
350
				    throw new RestException(500, 'Error when updating status of user: '.$this->useraccount->error);
351
				}
352
			} else {
353
			    $this->useraccount->$field = $value;
354
			}
355
		}
356
357
		// If there is no error, update() returns the number of affected
358
		// rows so if the update is a no op, the return value is zezo.
359
		if ($this->useraccount->update(DolibarrApiAccess::$user) >= 0)
360
		{
361
			return $this->get($id);
362
		} else {
363
			throw new RestException(500, $this->useraccount->error);
364
		}
365
    }
366
367
368
	/**
369
	 * List the groups of a user
370
	 *
371
	 * @param int $id     Id of user
372
	 * @return array      Array of group objects
373
	 *
374
	 * @throws RestException 403 Not allowed
375
     * @throws RestException 404 Not found
376
	 *
377
	 * @url GET {id}/groups
378
	 */
379
	public function getGroups($id)
380
	{
381
		$obj_ret = array();
382
383
		if (!DolibarrApiAccess::$user->rights->user->user->lire) {
384
			throw new RestException(403);
385
		}
386
387
		$user = new User($this->db);
388
		$result = $user->fetch($id);
389
		if (!$result) {
390
			throw new RestException(404, 'user not found');
391
		}
392
393
		$usergroup = new UserGroup($this->db);
394
		$groups = $usergroup->listGroupsForUser($id, false);
395
		$obj_ret = array();
396
		foreach ($groups as $group) {
397
			$obj_ret[] = $this->_cleanObjectDatas($group);
398
		}
399
		return $obj_ret;
400
	}
401
402
403
    /**
404
	 * Add a user into a group
405
	 *
406
	 * @param   int     $id        User ID
407
	 * @param   int     $group     Group ID
408
	 * @param   int     $entity    Entity ID (valid only for superadmin in multicompany transverse mode)
409
	 * @return  int                1 if success
410
     *
411
	 * @url	GET {id}/setGroup/{group}
412
	 */
413
    public function setGroup($id, $group, $entity = 1)
414
    {
415
416
		global $conf;
417
418
		//if (!DolibarrApiAccess::$user->rights->user->user->supprimer) {
419
			//throw new RestException(401);
420
		//}
421
		$result = $this->useraccount->fetch($id);
422
		if (!$result)
423
		{
424
			throw new RestException(404, 'User not found');
425
		}
426
427
		if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
428
		{
429
			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
430
		}
431
432
		if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && !empty(DolibarrApiAccess::$user->admin) && empty(DolibarrApiAccess::$user->entity))
433
		{
434
			$entity = (!empty($entity) ? $entity : $conf->entity);
435
		} else {
436
			// When using API, action is done on entity of logged user because a user of entity X with permission to create user should not be able to
437
			// hack the security by giving himself permissions on another entity.
438
			$entity = (DolibarrApiAccess::$user->entity > 0 ? DolibarrApiAccess::$user->entity : $conf->entity);
439
		}
440
441
		$result = $this->useraccount->SetInGroup($group, $entity);
442
		if (!($result > 0))
443
		{
444
			throw new RestException(500, $this->useraccount->error);
445
		}
446
447
		return 1;
448
	}
449
450
	/**
451
	 * List Groups
452
	 *
453
	 * Return an array with a list of Groups
454
	 *
455
	 * @url	GET /groups
456
	 *
457
	 * @param string	$sortfield	Sort field
458
	 * @param string	$sortorder	Sort order
459
	 * @param int		$limit		Limit for list
460
	 * @param int		$page		Page number
461
	 * @param string   	$group_ids   Groups ids filter field. Example: '1' or '1,2,3'          {@pattern /^[0-9,]*$/i}
462
	 * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
463
	 * @return  array               Array of User objects
464
	 */
465
    public function listGroups($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $group_ids = 0, $sqlfilters = '')
466
    {
467
	    global $db, $conf;
468
469
	    $obj_ret = array();
470
471
		if (!DolibarrApiAccess::$user->rights->user->group_advance->read) {
472
	        throw new RestException(401, "You are not allowed to read list of groups");
473
	    }
474
475
	    // case of external user, $societe param is ignored and replaced by user's socid
476
	    //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe;
477
478
	    $sql = "SELECT t.rowid";
479
	    $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as t";
480
	    $sql .= ' WHERE t.entity IN ('.getEntity('user').')';
481
	    if ($group_ids) $sql .= " AND t.rowid IN (".$group_ids.")";
482
	    // Add sql filters
483
        if ($sqlfilters)
484
        {
485
            if (!DolibarrApi::_checkFilters($sqlfilters))
486
            {
487
                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
488
            }
489
	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
490
            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
491
        }
492
493
	    $sql .= $db->order($sortfield, $sortorder);
494
	    if ($limit) {
495
	        if ($page < 0)
496
	        {
497
	            $page = 0;
498
	        }
499
	        $offset = $limit * $page;
500
501
	        $sql .= $db->plimit($limit + 1, $offset);
502
	    }
503
504
	    $result = $db->query($sql);
505
506
	    if ($result)
507
	    {
508
	        $i = 0;
509
	        $num = $db->num_rows($result);
510
	        $min = min($num, ($limit <= 0 ? $num : $limit));
511
	        while ($i < $min)
512
	        {
513
	            $obj = $db->fetch_object($result);
514
	            $group_static = new UserGroup($this->db);
515
	            if ($group_static->fetch($obj->rowid)) {
516
	                $obj_ret[] = $this->_cleanObjectDatas($group_static);
517
	            }
518
	            $i++;
519
	        }
520
	    } else {
521
	        throw new RestException(503, 'Error when retrieve Group list : '.$db->lasterror());
522
	    }
523
	    if (!count($obj_ret)) {
524
	        throw new RestException(404, 'No Group found');
525
	    }
526
	    return $obj_ret;
527
	}
528
529
	/**
530
	 * Get properties of an group object
531
	 *
532
	 * Return an array with group informations
533
	 *
534
	 * @url	GET /groups/{group}
535
	 *
536
	 * @param 	int 	$group ID of group
537
	 * @param int       $load_members     Load members list or not {@min 0} {@max 1}
538
	 * @return  array               Array of User objects
539
	 */
540
    public function infoGroups($group, $load_members = 0)
541
    {
542
	    global $db, $conf;
543
544
		if (!DolibarrApiAccess::$user->rights->user->group_advance->read) {
545
	        throw new RestException(401, "You are not allowed to read groups");
546
	    }
547
548
	            $group_static = new UserGroup($this->db);
549
	            $result = $group_static->fetch($group, '', $load_members);
550
551
		if (!$result)
552
		{
553
			throw new RestException(404, 'Group not found');
554
		}
555
556
	    return $this->_cleanObjectDatas($group_static);
557
	}
558
559
	/**
560
	 * Delete account
561
	 *
562
	 * @param   int     $id Account ID
563
	 * @return  array
564
	 */
565
    public function delete($id)
566
    {
567
		//if (!DolibarrApiAccess::$user->rights->user->user->supprimer) {
568
			//throw new RestException(401);
569
		//}
570
		$result = $this->useraccount->fetch($id);
571
		if (!$result)
572
		{
573
			throw new RestException(404, 'User not found');
574
		}
575
576
		if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
577
		{
578
			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
579
		}
580
        $this->useraccount->oldcopy = clone $this->useraccount;
581
		return $this->useraccount->delete(DolibarrApiAccess::$user);
582
	}
583
584
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
585
	/**
586
	 * Clean sensible object datas
587
	 *
588
	 * @param   object  $object    Object to clean
589
	 * @return  array    			Array of cleaned object properties
590
	 */
591
	protected function _cleanObjectDatas($object)
592
	{
593
        // phpcs:enable
594
		global $conf;
595
596
	    $object = parent::_cleanObjectDatas($object);
597
598
	    unset($object->default_values);
599
	    unset($object->lastsearch_values);
600
	    unset($object->lastsearch_values_tmp);
601
602
	    unset($object->total_ht);
603
	    unset($object->total_tva);
604
	    unset($object->total_localtax1);
605
	    unset($object->total_localtax2);
606
	    unset($object->total_ttc);
607
608
	    unset($object->label_incoterms);
609
	    unset($object->location_incoterms);
610
611
	    unset($object->fk_delivery_address);
612
	    unset($object->fk_incoterms);
613
	    unset($object->all_permissions_are_loaded);
614
	    unset($object->shipping_method_id);
615
	    unset($object->nb_rights);
616
	    unset($object->search_sid);
617
	    unset($object->ldap_sid);
618
	    unset($object->clicktodial_loaded);
619
620
	    // List of properties never returned by API, whatever are permissions
621
	    unset($object->pass);
622
	    unset($object->pass_indatabase);
623
	    unset($object->pass_indatabase_crypted);
624
	    unset($object->pass_temp);
625
	    unset($object->api_key);
626
	    unset($object->clicktodial_password);
627
	    unset($object->openid);
628
629
	    unset($object->lines);
630
	    unset($object->modelpdf);
631
	    unset($object->skype);
632
	    unset($object->twitter);
633
	    unset($object->facebook);
634
	    unset($object->linkedin);
635
636
	    $canreadsalary = ((!empty($conf->salaries->enabled) && !empty(DolibarrApiAccess::$user->rights->salaries->read))
637
	    	|| (!empty($conf->hrm->enabled) && !empty(DolibarrApiAccess::$user->rights->hrm->employee->read)));
638
639
		if (!$canreadsalary)
640
		{
641
			unset($object->salary);
642
			unset($object->salaryextra);
643
			unset($object->thm);
644
			unset($object->tjm);
645
		}
646
647
	    return $object;
648
	}
649
650
    /**
651
     * Clean sensible user group list datas
652
     *
653
     * @param   array  $objectList   Array of object to clean
654
     * @return  array                Array of cleaned object properties
655
     */
656
    private function _cleanUserGroupListDatas($objectList)
657
    {
658
        $cleanObjectList = array();
659
660
        foreach ($objectList as $object) {
661
            $cleanObject = parent::_cleanObjectDatas($object);
662
663
            unset($cleanObject->default_values);
664
            unset($cleanObject->lastsearch_values);
665
            unset($cleanObject->lastsearch_values_tmp);
666
667
            unset($cleanObject->total_ht);
668
            unset($cleanObject->total_tva);
669
            unset($cleanObject->total_localtax1);
670
            unset($cleanObject->total_localtax2);
671
            unset($cleanObject->total_ttc);
672
673
            unset($cleanObject->libelle_incoterms);
674
            unset($cleanObject->location_incoterms);
675
676
            unset($cleanObject->fk_delivery_address);
677
            unset($cleanObject->fk_incoterms);
678
            unset($cleanObject->all_permissions_are_loaded);
679
            unset($cleanObject->shipping_method_id);
680
            unset($cleanObject->nb_rights);
681
            unset($cleanObject->search_sid);
682
            unset($cleanObject->ldap_sid);
683
            unset($cleanObject->clicktodial_loaded);
684
685
            unset($cleanObject->datec);
686
            unset($cleanObject->datem);
687
            unset($cleanObject->members);
688
            unset($cleanObject->note);
689
            unset($cleanObject->note_private);
690
691
            $cleanObjectList[] = $cleanObject;
692
        }
693
694
        return $cleanObjectList;
695
    }
696
697
	/**
698
	 * Validate fields before create or update object
699
     *
700
	 * @param   array|null     $data   Data to validate
701
	 * @return  array
702
	 * @throws RestException
703
     */
704
    private function _validate($data)
705
    {
706
        $account = array();
707
        foreach (Users::$FIELDS as $field) {
708
            if (!isset($data[$field]))
709
                throw new RestException(400, "$field field missing");
710
            $account[$field] = $data[$field];
711
        }
712
        return $account;
713
    }
714
}
715