3 namespace wcf\system\clipboard\action
;
5 use wcf\data\clipboard\action\ClipboardAction
;
6 use wcf\data\user\group\UserGroup
;
7 use wcf\data\user\User
;
8 use wcf\data\user\UserAction
;
9 use wcf\system\database\util\PreparedStatementConditionBuilder
;
10 use wcf\system\request\LinkHandler
;
14 * Prepares clipboard editor items for user objects.
16 * @author Alexander Ebert
17 * @copyright 2001-2019 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 class UserClipboardAction
extends AbstractClipboardAction
25 protected $actionClassActions = ['delete', 'resendActivationMail', 'confirmEmail', 'unconfirmEmail'];
30 protected $supportedActions = [
41 'resendActivationMail',
48 public function execute(array $objects, ClipboardAction
$action)
50 $item = parent
::execute($objects, $action);
57 switch ($action->actionName
) {
59 $item->setURL(LinkHandler
::getInstance()->getLink('UserAssignToGroup'));
63 $item->addInternalData(
65 WCF
::getLanguage()->getDynamicVariable(
66 'wcf.clipboard.item.com.woltlab.wcf.user.delete.confirmMessage',
68 'count' => $item->getCount(),
74 case 'exportMailAddress':
75 $item->setURL(LinkHandler
::getInstance()->getLink('UserEmailAddressExport'));
79 $item->setURL(LinkHandler
::getInstance()->getLink('UserMerge'));
83 $item->setURL(LinkHandler
::getInstance()->getLink('UserMail'));
86 case 'sendNewPassword':
89 WCF
::getLanguage()->getDynamicVariable(
90 'wcf.clipboard.item.com.woltlab.wcf.user.sendNewPassword.confirmMessage',
92 'count' => $item->getCount(),
105 public function getClassName()
107 return UserAction
::class;
113 public function getTypeName()
115 return 'com.woltlab.wcf.user';
119 * Returns the ids of the users which can be deleted.
123 protected function validateDelete()
126 if (!WCF
::getSession()->getPermission('admin.user.canDeleteUser')) {
130 return $this->__validateAccessibleGroups(\array_keys
($this->objects
));
134 * Returns the ids of the users which can be banned.
138 protected function validateBan()
141 if (!WCF
::getSession()->getPermission('admin.user.canBanUser')) {
146 foreach ($this->objects
as $user) {
147 if (!$user->banned
) {
148 $userIDs[] = $user->userID
;
152 return $this->__validateAccessibleGroups($userIDs);
156 * Validates accessible groups.
158 * @param int[] $userIDs
159 * @param bool $ignoreOwnUser
162 protected function __validateAccessibleGroups(array $userIDs, $ignoreOwnUser = true)
164 if ($ignoreOwnUser) {
165 foreach ($userIDs as $index => $userID) {
166 if ($userID == WCF
::getUser()->userID
) {
167 unset($userIDs[$index]);
172 // no valid users found
173 if (empty($userIDs)) {
177 // fetch user to group associations
178 $conditions = new PreparedStatementConditionBuilder();
179 $conditions->add("userID IN (?)", [$userIDs]);
181 $sql = "SELECT userID, groupID
182 FROM wcf" . WCF_N
. "_user_to_group
184 $statement = WCF
::getDB()->prepareStatement($sql);
185 $statement->execute($conditions->getParameters());
187 $userToGroup = $statement->fetchMap('userID', 'groupID', false);
189 // validate if user's group is accessible for current user
190 foreach ($userIDs as $index => $userID) {
191 if (!isset($userToGroup[$userID]) ||
!UserGroup
::isAccessibleGroup($userToGroup[$userID])) {
192 unset($userIDs[$index]);
196 return \array_values
($userIDs);
200 * Returns the ids of the users which can be marked as email confirmed.
205 protected function validateConfirmEmail()
208 if (!WCF
::getSession()->getPermission('admin.user.canEnableUser')) {
213 foreach ($this->objects
as $user) {
214 /** @var User $user */
215 if (!$user->isEmailConfirmed()) {
216 $userIDs[] = $user->userID
;
220 return $this->__validateAccessibleGroups($userIDs);
224 * Returns the ids of the users which can be unmarked as email confirmed.
229 protected function validateUnconfirmEmail()
232 if (!WCF
::getSession()->getPermission('admin.user.canEnableUser')) {
237 foreach ($this->objects
as $user) {
238 /** @var User $user */
239 if ($user->isEmailConfirmed()) {
240 $userIDs[] = $user->userID
;
244 return $this->__validateAccessibleGroups($userIDs);
248 * Returns the ids of the users which can be sent new passwords.
252 public function validateSendNewPassword()
255 if (!WCF
::getSession()->getPermission('admin.user.canEditPassword')) {
260 /** @var User $user */
261 foreach ($this->objects
as $user) {
262 if (empty($user->authData
)) {
263 $userIDs[] = $user->userID
;
267 return $this->__validateAccessibleGroups($userIDs);
271 * Returns the ids of the users which can be enabled.
276 protected function validateEnable()
279 if (!WCF
::getSession()->getPermission('admin.user.canEnableUser')) {
284 foreach ($this->objects
as $user) {
285 /** @var User $user */
286 if ($user->pendingActivation()) {
287 $userIDs[] = $user->userID
;
295 * Returns the ids of the users which can be merge.
300 protected function validateMerge()
303 if (!WCF
::getSession()->getPermission('admin.user.canEditUser')) {
307 $userIDs = \array_keys
($this->objects
);
308 if (\
count($userIDs) < 2) {
316 * Returns the ids of the users which aren't activated.
321 protected function validateResendActivationMail()
325 !WCF
::getSession()->getPermission('admin.user.canEnableUser')
326 ||
!(REGISTER_ACTIVATION_METHOD
& User
::REGISTER_ACTIVATION_USER
)
332 foreach ($this->objects
as $user) {
333 /** @var User $user */
334 if ($user->canEmailConfirm()) {
335 $userIDs[] = $user->userID
;
343 * Returns the ids of the users whose contents can be deleted.
348 protected function validateDeleteUserContent()
350 if (!WCF
::getSession()->getPermission('admin.user.canDeleteUser')) {
354 return $this->__validateAccessibleGroups(\array_keys
($this->objects
));