Completed
Push — master ( a4e9d3...8e8e92 )
by Nazar
04:38
created

permissions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A admin_users_permissions_get() 0 8 3
A admin_users_permissions_put() 0 8 3
1
<?php
2
/**
3
 * @package    CleverStyle CMS
4
 * @subpackage System module
5
 * @category   modules
6
 * @author     Nazar Mokrynskyi <[email protected]>
7
 * @copyright  Copyright (c) 2015, Nazar Mokrynskyi
8
 * @license    MIT License, see license.txt
9
 */
10
namespace cs\modules\System\api\Controller\admin\users;
11
use
12
	cs\ExitException,
13
	cs\Page,
14
	cs\User;
15
trait permissions {
16
	/**
17
	 * Get user's permissions
18
	 *
19
	 * @param int[] $route_ids
20
	 *
21
	 * @throws ExitException
22
	 */
23
	static function admin_users_permissions_get ($route_ids) {
24
		if (!isset($route_ids[0])) {
25
			throw new ExitException(400);
26
		}
27
		Page::instance()->json(
28
			User::instance()->get_permissions($route_ids[0]) ?: []
29
		);
30
	}
31
	/**
32
	 * Update user's permissions
33
	 *
34
	 * @param int[] $route_ids
35
	 *
36
	 * @throws ExitException
37
	 */
38
	static function admin_users_permissions_put ($route_ids) {
39
		if (!isset($route_ids[0], $_POST['permissions'])) {
40
			throw new ExitException(400);
41
		}
42
		if (!User::instance()->set_permissions($_POST['permissions'], $route_ids[0])) {
43
			throw new ExitException(500);
44
		}
45
	}
46
}
47