|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Welcome to the User controller |
|
4
|
|
|
* |
|
5
|
|
|
* The user controller works this way: |
|
6
|
|
|
* 1. It rubs the lotion on its skin |
|
7
|
|
|
* 2. It does as its told and it does it whenever its told |
|
8
|
|
|
* 3. If it doesn't rub the lotion, it gets the hose again |
|
9
|
|
|
* 4. It puts the lotion in the basket. |
|
10
|
|
|
* 5. Put the fucking lotion in the basket ! |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace HexMakina\kadro\Controllers; |
|
14
|
|
|
|
|
15
|
|
|
use HexMakina\Crudites\Crudites; |
|
16
|
|
|
use HexMakina\kadro\Auth\{Operator,OperatorInterface,ACL,AccessRefusedException}; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
class Operator extends \HexMakina\kadro\Controllers\ORM |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
public function edit() |
|
22
|
|
|
{ |
|
23
|
|
|
parent::edit(); |
|
24
|
|
|
|
|
25
|
|
|
// do we create? or do we edit someone else ? must be admin |
|
26
|
|
|
if (is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id()) { |
|
27
|
|
|
$this->authorize('group_admin'); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function modelClassName(): string |
|
32
|
|
|
{ |
|
33
|
|
|
return "\HexMakina\kadro\Auth\Operator"; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function save() |
|
37
|
|
|
{ |
|
38
|
|
|
if ($this->operator()->operator_id() !== $this->formModel()->get_id()) { |
|
39
|
|
|
$this->authorize('group_admin'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
parent::save(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function before_save() |
|
46
|
|
|
{ |
|
47
|
|
|
//------------------------------------------------------------- PASSWORDS |
|
48
|
|
|
if ($this->formModel()->get('password') != $this->formModel()->get('password_verification')) { |
|
49
|
|
|
$this->add_error('KADRO_operator_ERR_PASSWORDS_MISMATCH'); |
|
50
|
|
|
$this->logger()->warning($this->l('KADRO_operator_ERR_PASSWORDS_MISMATCH')); |
|
51
|
|
|
$this->edit(); |
|
52
|
|
|
} |
|
53
|
|
|
return $this->errors(); // useless call, errors are managed globally but interface expects it.. refactor needed |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function dashboard() |
|
57
|
|
|
{ |
|
58
|
|
|
$real_operator_class = get_class($this->operator()); |
|
59
|
|
|
$this->viewport('users', $real_operator_class::filter([], ['order_by' => [null,'username', 'ASC']])); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function destroy() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->change_active(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function change_active() |
|
68
|
|
|
{ |
|
69
|
|
|
parent::authorize('group_admin'); |
|
70
|
|
|
|
|
71
|
|
|
$operator = Operator::one($this->router()->params()); |
|
72
|
|
|
if ($operator->username() == $this->operator()->username()) { |
|
73
|
|
|
throw new AccessRefusedException(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if (Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true) { |
|
77
|
|
|
$confirmation_message = $operator->is_active() ? 'KADRO_operator_DISABLED' : 'KADRO_operator_ENABLED'; |
|
78
|
|
|
$this->logger()->nice($this->l($confirmation_message, [$operator->name()])); |
|
79
|
|
|
} else { |
|
80
|
|
|
$this->logger()->warning($this->l('CRUDITES_ERR_QUERY_FAILED')); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->router()->hopBack(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function change_acl() |
|
87
|
|
|
{ |
|
88
|
|
|
parent::authorize('group_admin'); |
|
89
|
|
|
|
|
90
|
|
|
$operator = Operator::one(['username' => $this->router()->params('username')]); |
|
91
|
|
|
if ($operator->username() == $this->operator()->username()) { |
|
92
|
|
|
throw new AccessRefusedException(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$permission_id = $this->router()->params('permission_id'); |
|
96
|
|
|
|
|
97
|
|
|
$row_data = ['operator_id' => $operator->operator_id(), 'permission_id' => $permission_id]; |
|
98
|
|
|
$row = ACL::table()->restore($row_data); |
|
99
|
|
|
if ($row->is_new()) { |
|
100
|
|
|
$row = ACL::table()->produce($row_data); |
|
101
|
|
|
$row->persist(); |
|
102
|
|
|
} else { |
|
103
|
|
|
$row->wipe(); |
|
104
|
|
|
} |
|
105
|
|
|
// force reload for permission purposes |
|
106
|
|
|
$this->router()->hopBack(); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: