Skip to content

Commit bfd52c2

Browse files
authored
Merge pull request #6402 from WoltLab/6.2-refactor-user-group-copy
Migrate user group copy to `FormBuilderDialogInteraction`
2 parents 1630c1b + 80819f0 commit bfd52c2

11 files changed

Lines changed: 214 additions & 149 deletions

File tree

ts/WoltLabSuite/Core/Acp/Component/User/Group/Copy.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

ts/WoltLabSuite/Core/Component/Interaction/FormBuilderDialog.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function handleFormBuilderDialogAction(
2020
interactionEffect: InteractionEffect = InteractionEffect.ReloadItem,
2121
detail: Payload,
2222
): Promise<void> {
23-
const { ok } = await dialogFactory().usingFormBuilder().fromEndpoint(endpoint);
23+
const { ok, result } = await dialogFactory().usingFormBuilder().fromEndpoint<Payload>(endpoint);
2424

2525
if (!ok) {
2626
return;
@@ -32,6 +32,7 @@ async function handleFormBuilderDialogAction(
3232
bubbles: true,
3333
detail: {
3434
...detail,
35+
...result,
3536
_reloadPage: String(interactionEffect === InteractionEffect.ReloadPage),
3637
},
3738
}),
@@ -41,6 +42,7 @@ async function handleFormBuilderDialogAction(
4142
new CustomEvent<Payload>("interaction:invalidate-all", {
4243
detail: {
4344
...detail,
45+
...result,
4446
},
4547
}),
4648
);
@@ -50,6 +52,7 @@ async function handleFormBuilderDialogAction(
5052
bubbles: true,
5153
detail: {
5254
...detail,
55+
...result,
5356
},
5457
}),
5558
);

wcfsetup/install/files/acp/templates/userGroupAdd.tpl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{include file='header' pageTitle='wcf.acp.group.'|concat:$action}
22

33
<script data-relocate="true">
4-
{if $action == 'edit' && $group->canCopy()}
5-
require(['WoltLabSuite/Core/Acp/Component/User/Group/Copy'], ({ init }) => {
6-
init();
7-
});
8-
{/if}
9-
104
$(function() {
115
{if $action === 'add' && $isBlankForm}
126
elBySelAll('.jsBbcodeSelectOptionHtml input[type="checkbox"]', undefined, function (checkbox) {
@@ -43,12 +37,20 @@
4337
</li>
4438
{/if}
4539

46-
{if $group->canCopy()}
47-
<li><button type="button" class="jsButtonUserGroupCopy button" data-endpoint="{link controller="UserGroupCopy" id=$groupID}{/link}">{icon name='copy'} <span>{lang}wcf.acp.group.button.copy{/lang}</span></button></li>
48-
{/if}
49-
5040
<li>
5141
{unsafe:$interactionContextMenu->render()}
42+
<script data-relocate="true">
43+
{
44+
const container = document.getElementById('{unsafe:$interactionContextMenu->getContainerID()|encodeJS}');
45+
container.addEventListener('interaction:invalidate-all', (event) => {
46+
if (event.detail.interaction === 'copy') {
47+
setTimeout(() => {
48+
window.location.href = event.detail.redirectURL;
49+
}, 2000);
50+
}
51+
});
52+
}
53+
</script>
5254
</li>
5355
{/if}
5456

wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Component/User/Group/Copy.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/FormBuilderDialog.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/lib/acp/action/UserGroupCopyAction.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private function getForm(): Psr15DialogForm
8989
{
9090
$form = new Psr15DialogForm(
9191
UserGroupCopyAction::class,
92-
WCF::getLanguage()->get('wcf.acp.dashboard.configure')
92+
WCF::getLanguage()->get('wcf.acp.group.copy')
9393
);
9494
$form->appendChildren([
9595
FormContainer::create('section')

wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
namespace wcf\data\user\group;
44

55
use wcf\data\AbstractDatabaseObjectAction;
6+
use wcf\system\exception\PermissionDeniedException;
7+
use wcf\system\request\LinkHandler;
8+
use wcf\system\user\group\command\CopyUserGroup;
9+
use wcf\system\WCF;
610

711
/**
812
* Executes user group-related actions.
@@ -20,6 +24,12 @@ class UserGroupAction extends AbstractDatabaseObjectAction
2024
*/
2125
public $className = UserGroupEditor::class;
2226

27+
/**
28+
* editor object for the copied user group
29+
* @var UserGroupEditor
30+
*/
31+
public $groupEditor;
32+
2333
/**
2434
* @inheritDoc
2535
*/
@@ -38,7 +48,7 @@ class UserGroupAction extends AbstractDatabaseObjectAction
3848
/**
3949
* @inheritDoc
4050
*/
41-
protected $requireACP = ['create', 'delete', 'update'];
51+
protected $requireACP = ['copy', 'create', 'delete', 'update'];
4252

4353
/**
4454
* @inheritDoc
@@ -71,4 +81,47 @@ public function update()
7181
$object->updateGroupOptions($this->parameters['options']);
7282
}
7383
}
84+
85+
/**
86+
* Validates the 'copy' action.
87+
* @deprecated 6.2 Use `CopyUserGroup` instead.
88+
*/
89+
public function validateCopy()
90+
{
91+
WCF::getSession()->checkPermissions([
92+
'admin.user.canAddGroup',
93+
'admin.user.canEditGroup',
94+
]);
95+
96+
$this->readBoolean('copyACLOptions');
97+
$this->readBoolean('copyMembers');
98+
$this->readBoolean('copyUserGroupOptions');
99+
100+
$this->groupEditor = $this->getSingleObject();
101+
if (!$this->groupEditor->canCopy()) {
102+
throw new PermissionDeniedException();
103+
}
104+
}
105+
106+
/**
107+
* Copies a user group.
108+
* @deprecated 6.2 Use `CopyUserGroup` instead.
109+
*/
110+
public function copy()
111+
{
112+
$command = new CopyUserGroup(
113+
$this->groupEditor->getDecoratedObject(),
114+
$this->parameters['copyUserGroupOptions'],
115+
$this->parameters['copyMembers'],
116+
$this->parameters['copyACLOptions']
117+
);
118+
$group = $command();
119+
120+
return [
121+
'groupID' => $group->groupID,
122+
'redirectURL' => LinkHandler::getInstance()->getLink('UserGroupEdit', [
123+
'id' => $group->groupID,
124+
]),
125+
];
126+
}
74127
}

wcfsetup/install/files/lib/system/interaction/admin/UserGroupInteractions.class.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
namespace wcf\system\interaction\admin;
44

5+
use wcf\acp\action\UserGroupCopyAction;
56
use wcf\data\user\group\UserGroup;
67
use wcf\event\interaction\admin\UserGroupInteractionCollecting;
78
use wcf\system\event\EventHandler;
89
use wcf\system\interaction\AbstractInteractionProvider;
910
use wcf\system\interaction\DeleteInteraction;
11+
use wcf\system\interaction\FormBuilderDialogInteraction;
12+
use wcf\system\interaction\InteractionEffect;
13+
use wcf\system\request\LinkHandler;
1014

1115
/**
1216
* Interaction provider for user groups.
@@ -21,7 +25,16 @@ final class UserGroupInteractions extends AbstractInteractionProvider
2125
public function __construct()
2226
{
2327
$this->addInteractions([
24-
new DeleteInteraction("core/users/groups/%s", static fn(UserGroup $group) => $group->isDeletable())
28+
new DeleteInteraction("core/users/groups/%s", static fn(UserGroup $group) => $group->isDeletable()),
29+
new FormBuilderDialogInteraction(
30+
'copy',
31+
LinkHandler::getInstance()->getControllerLink(UserGroupCopyAction::class, ['id' => '%s']),
32+
'wcf.acp.group.button.copy',
33+
static function (UserGroup $group): bool {
34+
return $group->canCopy();
35+
},
36+
InteractionEffect::ReloadList
37+
)
2538
]);
2639

2740
EventHandler::getInstance()->fire(

0 commit comments

Comments
 (0)