-
Notifications
You must be signed in to change notification settings - Fork 448
/
Copy pathUserGridRow.php
228 lines (210 loc) · 8.17 KB
/
UserGridRow.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
/**
* @file controllers/grid/settings/user/UserGridRow.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class UserGridRow
*
* @ingroup controllers_grid_settings_user
*
* @brief User grid row definition
*/
namespace PKP\controllers\grid\settings\user;
use APP\facades\Repo;
use PKP\controllers\grid\GridRow;
use PKP\core\PKPApplication;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\linkAction\request\RedirectConfirmationModal;
use PKP\linkAction\request\RemoteActionConfirmationModal;
use PKP\security\Validation;
use PKP\user\User;
class UserGridRow extends GridRow
{
/** @var int the user id of the old user to remove when merging users. */
public $_oldUserId;
/**
* Constructor
*
* @param null|mixed $oldUserId
*/
public function __construct($oldUserId = null)
{
$this->_oldUserId = $oldUserId;
parent::__construct();
}
//
// Overridden methods from GridRow
//
/**
* @copydoc GridRow::initialize()
*
* @param null|mixed $template
*/
public function initialize($request, $template = null)
{
parent::initialize($request, $template);
// Is this a new row or an existing row?
$element = & $this->getData();
assert($element instanceof User);
$rowId = $this->getId();
if (!empty($rowId) && is_numeric($rowId)) {
// Only add row actions if this is an existing row
$router = $request->getRouter();
$actionArgs = [
'gridId' => $this->getGridId(),
'rowId' => $rowId
];
$actionArgs = array_merge($actionArgs, $this->getRequestArgs());
// If this is the grid for merging a user, only show the merge
// linkaction
if ($this->getOldUserId()) {
$actionArgs['oldUserId'] = $this->getOldUserId();
$actionArgs['newUserId'] = $rowId;
// Verify that the old user exists
$oldUser = Repo::user()->get((int) $this->getOldUserId(), true);
// Don't merge a user in itself
if ($oldUser && $actionArgs['oldUserId'] != $actionArgs['newUserId']) {
$this->addAction(
new LinkAction(
'mergeUser',
new RemoteActionConfirmationModal(
$request->getSession(),
__('grid.user.mergeUsers.confirm', ['oldUsername' => $oldUser->getUsername(), 'newUsername' => $element->getUsername()]),
null,
$router->url($request, null, null, 'mergeUsers', null, $actionArgs),
'modal_merge_users'
),
__('grid.user.mergeUsers.mergeIntoUser'),
'merge_users'
)
);
}
// Otherwise display all the default link actions
} else {
$this->addAction(
new LinkAction(
'email',
new AjaxModal(
$router->url($request, null, null, 'editEmail', null, $actionArgs),
__('grid.user.email'),
'modal_email',
true
),
__('grid.user.email'),
'notify'
)
);
$this->addAction(
new LinkAction(
'edit',
new AjaxModal(
$router->url($request, null, null, 'editUser', null, $actionArgs),
__('grid.user.edit'),
'modal_edit',
true
),
__('grid.user.edit'),
'edit'
)
);
if ($element->getDisabled()) {
$actionArgs['enable'] = true;
$this->addAction(
new LinkAction(
'enable',
new AjaxModal(
$router->url($request, null, null, 'editDisableUser', null, $actionArgs),
__('common.enable'),
'enable',
true
),
__('common.enable'),
'enable'
)
);
} else {
$actionArgs['enable'] = false;
$this->addAction(
new LinkAction(
'disable',
new AjaxModal(
$router->url($request, null, null, 'editDisableUser', null, $actionArgs),
__('grid.user.disable'),
'disable',
true
),
__('grid.user.disable'),
'disable'
)
);
}
$this->addAction(
new LinkAction(
'remove',
new RemoteActionConfirmationModal(
$request->getSession(),
__('manager.people.confirmRemove'),
__('common.remove'),
$router->url($request, null, null, 'removeUser', null, $actionArgs),
'modal_delete'
),
__('grid.action.remove'),
'delete'
)
);
$canAdminister = Validation::getAdministrationLevel($this->getId(), $request->getUser()->getId()) === Validation::ADMINISTRATION_FULL;
if (
!Validation::loggedInAs() &&
$request->getUser()->getId() != $this->getId() &&
$canAdminister
) {
$dispatcher = $router->getDispatcher();
$this->addAction(
new LinkAction(
'logInAs',
new RedirectConfirmationModal(
__('grid.user.confirmLogInAs'),
__('grid.action.logInAs'),
$dispatcher->url($request, PKPApplication::ROUTE_PAGE, null, 'login', 'signInAsUser', [$this->getId()])
),
__('grid.action.logInAs'),
'enroll_user'
)
);
}
// do not allow the deletion of your own account.
if (
$request->getUser()->getId() != $this->getId() and
$canAdminister
) {
$this->addAction(
new LinkAction(
'mergeUser',
new AjaxModal(
$router->url($request, null, null, 'mergeUsers', null, ['oldUserId' => $rowId]),
__('grid.user.mergeUsers.mergeUser'),
'modal_merge_users',
true
),
__('grid.user.mergeUsers.mergeUser'),
'merge_users'
)
);
}
}
}
}
/**
* Returns the stored user id of the user to be removed.
*
* @return int the user id.
*/
public function getOldUserId()
{
return $this->_oldUserId;
}
}