From: joshuaruesweg Date: Wed, 16 Dec 2020 15:26:54 +0000 (+0100) Subject: Add clipboard action to delete user content X-Git-Tag: 5.4.0_Alpha_1~473^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=19389b7e8f8a2f951f72b336626e5f7e195badfc;p=GitHub%2FWoltLab%2FWCF.git Add clipboard action to delete user content --- diff --git a/com.woltlab.wcf/clipboardAction.xml b/com.woltlab.wcf/clipboardAction.xml index e4b159bd48..3f48d79925 100644 --- a/com.woltlab.wcf/clipboardAction.xml +++ b/com.woltlab.wcf/clipboardAction.xml @@ -16,72 +16,79 @@ wcf\acp\page\UserListPage - + wcf\system\clipboard\action\UserClipboardAction 3 wcf\acp\page\UserListPage - + wcf\system\clipboard\action\UserClipboardAction 4 wcf\acp\page\UserListPage - + wcf\system\clipboard\action\UserClipboardAction 5 wcf\acp\page\UserListPage - + wcf\system\clipboard\action\UserClipboardAction 6 wcf\acp\page\UserListPage - + wcf\system\clipboard\action\UserClipboardAction 7 wcf\acp\page\UserListPage - + wcf\system\clipboard\action\UserClipboardAction 8 wcf\acp\page\UserListPage - + wcf\system\clipboard\action\UserClipboardAction 9 wcf\acp\page\UserListPage - + wcf\system\clipboard\action\UserClipboardAction 10 wcf\acp\page\UserListPage - + wcf\system\clipboard\action\UserClipboardAction 11 wcf\acp\page\UserListPage + + wcf\system\clipboard\action\UserClipboardAction + 12 + + wcf\acp\page\UserListPage + + wcf\system\clipboard\action\UserContentClipboardAction - 12 + 13 wcf\acp\page\UserListPage diff --git a/wcfsetup/install/files/acp/templates/userList.tpl b/wcfsetup/install/files/acp/templates/userList.tpl index 1984ced19a..53323e7dd6 100644 --- a/wcfsetup/install/files/acp/templates/userList.tpl +++ b/wcfsetup/install/files/acp/templates/userList.tpl @@ -45,12 +45,14 @@ WCF.ACP.User.SendNewPasswordHandler.init(); {/if} - require(['Language', 'WoltLabSuite/Core/Acp/Ui/User/Editor'], function (Language, AcpUiUserList) { + require(['Language', 'WoltLabSuite/Core/Acp/Ui/User/Editor', 'WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Clipboard'], function (Language, AcpUiUserList, AcpUserContentRemoveClipboard) { Language.addObject({ 'wcf.acp.user.action.sendNewPassword.confirmMessage': '{jslang}wcf.acp.user.action.sendNewPassword.confirmMessage{/jslang}' }); new AcpUiUserList(); + + new AcpUserContentRemoveClipboard(); }); {event name='javascriptInit'} diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Clipboard.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Clipboard.js new file mode 100644 index 0000000000..a14b0bc127 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Clipboard.js @@ -0,0 +1,93 @@ +/** + * Handles the user content remove clipboard action. + * + * @author Joshua Ruesweg + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Clipboard + * @since 5.4 + */ +define(["require", "exports", "tslib", "../../../Worker", "../../../../../Ajax", "../../../../../Language", "../../../../../Ui/Dialog", "../../../../../Event/Handler"], function (require, exports, tslib_1, Worker_1, Ajax, Language, Dialog_1, EventHandler) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.AcpUserContentRemoveClipboard = void 0; + Worker_1 = tslib_1.__importDefault(Worker_1); + Ajax = tslib_1.__importStar(Ajax); + Language = tslib_1.__importStar(Language); + Dialog_1 = tslib_1.__importDefault(Dialog_1); + EventHandler = tslib_1.__importStar(EventHandler); + class AcpUserContentRemoveClipboard { + /** + * Initializes the content remove handler. + */ + constructor() { + this.dialogId = "userContentRemoveClipboardPrepareDialog"; + EventHandler.add("com.woltlab.wcf.clipboard", "com.woltlab.wcf.user", (data) => { + if (data.data.actionName === "com.woltlab.wcf.user.deleteUserContent") { + this.userIds = data.data.parameters.objectIDs; + Ajax.api(this); + } + }); + } + /** + * Executes the remove content worker. + */ + executeWorker(objectTypes) { + new Worker_1.default({ + // dialog + dialogId: "removeContentWorker", + dialogTitle: Language.get("wcf.acp.content.removeContent"), + // ajax + className: "wcf\\system\\worker\\UserContentRemoveWorker", + parameters: { + userIDs: this.userIds, + contentProvider: objectTypes, + }, + }); + } + /** + * Handles a click on the submit button in the overlay. + */ + submit() { + const objectTypes = Array.from(this.dialogContent.querySelectorAll("input.contentProviderObjectType")) + .filter((element) => element.checked) + .map((element) => element.name); + Dialog_1.default.close(this.dialogId); + if (objectTypes.length > 0) { + window.setTimeout(() => { + this.executeWorker(objectTypes); + }, 200); + } + } + get dialogContent() { + return Dialog_1.default.getDialog(this.dialogId).content; + } + _ajaxSuccess(data) { + Dialog_1.default.open(this, data.returnValues.template); + const submitButton = this.dialogContent.querySelector('input[type="submit"]'); + submitButton.addEventListener("click", () => this.submit()); + } + _ajaxSetup() { + return { + data: { + actionName: "prepareRemoveContent", + className: "wcf\\data\\user\\UserAction", + parameters: { + userIDs: this.userIds, + }, + }, + }; + } + _dialogSetup() { + return { + id: this.dialogId, + options: { + title: Language.get("wcf.acp.content.removeContent"), + }, + source: null, + }; + } + } + exports.AcpUserContentRemoveClipboard = AcpUserContentRemoveClipboard; + exports.default = AcpUserContentRemoveClipboard; +}); diff --git a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php index f8bfc47628..b2e459d56c 100644 --- a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php @@ -25,7 +25,7 @@ class UserClipboardAction extends AbstractClipboardAction { /** * @inheritDoc */ - protected $supportedActions = ['assignToGroup', 'ban', 'confirmEmail', 'delete', 'enable', 'exportMailAddress', 'merge', 'sendMail', 'sendNewPassword', 'resendActivationMail', 'unconfirmEmail']; + protected $supportedActions = ['assignToGroup', 'ban', 'confirmEmail', 'delete', 'deleteUserContent', 'enable', 'exportMailAddress', 'merge', 'sendMail', 'sendNewPassword', 'resendActivationMail', 'unconfirmEmail']; /** * @inheritDoc @@ -282,4 +282,14 @@ class UserClipboardAction extends AbstractClipboardAction { return $userIDs; } + + /** + * Returns the ids of the users whose contents can be deleted. + * + * @return integer[] + * @since 5.4 + */ + protected function validateDeleteUserContent() { + return $this->__validateAccessibleGroups(array_keys($this->objects)); + } } diff --git a/wcfsetup/install/files/lib/system/worker/UserContentRemoveWorker.class.php b/wcfsetup/install/files/lib/system/worker/UserContentRemoveWorker.class.php index cccb8e8e0d..61488b02d8 100644 --- a/wcfsetup/install/files/lib/system/worker/UserContentRemoveWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/UserContentRemoveWorker.class.php @@ -240,6 +240,10 @@ class UserContentRemoveWorker extends AbstractWorker { $dataArray[$this->generateKey()] = $this->data; WCF::getSession()->register(self::USER_CONTENT_REMOVE_WORKER_SESSION_NAME, $dataArray); + + ClipboardHandler::getInstance()->unmark(array_map(function (User $user) { + return $user->userID; + }, $this->user), ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user')); } /** diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Clipboard.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Clipboard.ts new file mode 100644 index 0000000000..b0b596db1b --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Clipboard.ts @@ -0,0 +1,126 @@ +/** + * Handles the user content remove clipboard action. + * + * @author Joshua Ruesweg + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Clipboard + * @since 5.4 + */ + +import AcpUiWorker from "../../../Worker"; +import * as Ajax from "../../../../../Ajax"; +import * as Language from "../../../../../Language"; +import UiDialog from "../../../../../Ui/Dialog"; +import { AjaxCallbackSetup } from "../../../../../Ajax/Data"; +import { DialogCallbackSetup } from "../../../../../Ui/Dialog/Data"; +import * as EventHandler from "../../../../../Event/Handler"; + +interface AjaxResponse { + returnValues: { + template: string; + }; +} + +interface EventData { + data: { + actionName: string; + internalData: any[]; + label: string; + parameters: { + objectIDs: number[]; + url: string; + }; + }; + listItem: HTMLElement; +} + +export class AcpUserContentRemoveClipboard { + public userIds: number[]; + private readonly dialogId = "userContentRemoveClipboardPrepareDialog"; + + /** + * Initializes the content remove handler. + */ + constructor() { + EventHandler.add("com.woltlab.wcf.clipboard", "com.woltlab.wcf.user", (data: EventData) => { + if (data.data.actionName === "com.woltlab.wcf.user.deleteUserContent") { + this.userIds = data.data.parameters.objectIDs; + + Ajax.api(this); + } + }); + } + + /** + * Executes the remove content worker. + */ + private executeWorker(objectTypes: string[]): void { + new AcpUiWorker({ + // dialog + dialogId: "removeContentWorker", + dialogTitle: Language.get("wcf.acp.content.removeContent"), + + // ajax + className: "wcf\\system\\worker\\UserContentRemoveWorker", + parameters: { + userIDs: this.userIds, + contentProvider: objectTypes, + }, + }); + } + + /** + * Handles a click on the submit button in the overlay. + */ + private submit(): void { + const objectTypes = Array.from( + this.dialogContent.querySelectorAll("input.contentProviderObjectType"), + ) + .filter((element) => element.checked) + .map((element) => element.name); + + UiDialog.close(this.dialogId); + + if (objectTypes.length > 0) { + window.setTimeout(() => { + this.executeWorker(objectTypes); + }, 200); + } + } + + get dialogContent(): HTMLElement { + return UiDialog.getDialog(this.dialogId)!.content; + } + + _ajaxSuccess(data: AjaxResponse): void { + UiDialog.open(this, data.returnValues.template); + + const submitButton = this.dialogContent.querySelector('input[type="submit"]') as HTMLElement; + submitButton.addEventListener("click", () => this.submit()); + } + + _ajaxSetup(): ReturnType { + return { + data: { + actionName: "prepareRemoveContent", + className: "wcf\\data\\user\\UserAction", + parameters: { + userIDs: this.userIds, + }, + }, + }; + } + + _dialogSetup(): ReturnType { + return { + id: this.dialogId, + options: { + title: Language.get("wcf.acp.content.removeContent"), + }, + source: null, + }; + } +} + +export default AcpUserContentRemoveClipboard; diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 5b95ebf093..a220ab02bc 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3429,6 +3429,7 @@ Fehler sind beispielsweise: + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 5016fae125..ac810dfb59 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3353,6 +3353,7 @@ Errors are: +