Skip to content

Commit 06f5ca6

Browse files
authored
Merge pull request #6214 from WoltLab/6.2-UserGroupAssignmentListPage-to-grid-view
Migrate `UserGroupAssignmentListPage` to grid view
2 parents fca6a27 + 9f733ac commit 06f5ca6

File tree

10 files changed

+337
-69
lines changed

10 files changed

+337
-69
lines changed

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

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<header class="contentHeader">
44
<div class="contentHeaderTitle">
5-
<h1 class="contentTitle">{lang}wcf.acp.group.assignment.list{/lang}{if $items} <span class="badge badgeInverse">{#$items}</span>{/if}</h1>
5+
<h1 class="contentTitle">{lang}wcf.acp.group.assignment.list{/lang} <span class="badge badgeInverse">{#$gridView->countRows()}</span></h1>
66
</div>
77

88
<nav class="contentHeaderNavigation">
@@ -14,67 +14,8 @@
1414
</nav>
1515
</header>
1616

17-
{hascontent}
18-
<div class="paginationTop">
19-
{content}{pages print=true assign=pagesLinks controller="UserGroupAssignmentList" link="pageNo=%d"}{/content}
20-
</div>
21-
{/hascontent}
22-
23-
{if $objects|count}
24-
<div class="section tabularBox" id="userGroupAssignmentTableContainer">
25-
<table class="table jsObjectActionContainer" data-object-action-class-name="wcf\data\user\group\assignment\UserGroupAssignmentAction">
26-
<thead>
27-
<tr>
28-
<th class="columnID columnAssignmentID" colspan="2"><span>{lang}wcf.global.objectID{/lang}</span></th>
29-
<th class="columnTitle columnAssignmentName"><span>{lang}wcf.global.name{/lang}</span></th>
30-
<th class="columnTitle columnGroupName"><span>{lang}wcf.acp.group.assignment.userGroup{/lang}</span></th>
31-
32-
{event name='columnHeads'}
33-
</tr>
34-
</thead>
35-
36-
<tbody class="jsReloadPageWhenEmpty">
37-
{foreach from=$objects item='assignment'}
38-
<tr class="jsUserGroupAssignmentRow jsObjectActionObject" data-object-id="{@$assignment->getObjectID()}">
39-
<td class="columnIcon">
40-
{objectAction action="toggle" isDisabled=$assignment->isDisabled}
41-
<a href="{link controller='UserGroupAssignmentEdit' object=$assignment}{/link}" title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip">{icon name='pencil'}</a>
42-
{objectAction action="delete" objectTitle=$assignment->getTitle()}
43-
44-
{event name='rowButtons'}
45-
</td>
46-
<td class="columnID columnAssignmentID">{@$assignment->assignmentID}</td>
47-
<td class="columnTitle columnAssignmentName">
48-
<a href="{link controller='UserGroupAssignmentEdit' object=$assignment}{/link}">{$assignment->title}</a>
49-
</td>
50-
<td class="columnDigits columnGroupName">
51-
{$assignment->getUserGroup()->getName()}
52-
</td>
53-
54-
{event name='columns'}
55-
</tr>
56-
{/foreach}
57-
</tbody>
58-
</table>
59-
</div>
60-
61-
<footer class="contentFooter">
62-
{hascontent}
63-
<div class="paginationBottom">
64-
{content}{@$pagesLinks}{/content}
65-
</div>
66-
{/hascontent}
67-
68-
<nav class="contentFooterNavigation">
69-
<ul>
70-
<li><a href="{link controller='UserGroupAssignmentAdd'}{/link}" class="button">{icon name='plus'} <span>{lang}wcf.acp.group.assignment.button.add{/lang}</span></a></li>
71-
72-
{event name='contentFooterNavigation'}
73-
</ul>
74-
</nav>
75-
</footer>
76-
{else}
77-
<woltlab-core-notice type="info">{lang}wcf.global.noItems{/lang}</woltlab-core-notice>
78-
{/if}
17+
<div class="section">
18+
{unsafe:$gridView->render()}
19+
</div>
7920

8021
{include file='footer'}

wcfsetup/install/files/lib/acp/page/UserGroupAssignmentListPage.class.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace wcf\acp\page;
44

55
use wcf\data\user\group\assignment\UserGroupAssignmentList;
6-
use wcf\page\MultipleLinkPage;
6+
use wcf\page\AbstractGridViewPage;
7+
use wcf\system\gridView\AbstractGridView;
8+
use wcf\system\gridView\admin\UserGroupAssignmentGridView;
79

810
/**
911
* Lists the available automatic user group assignments.
@@ -14,7 +16,7 @@
1416
*
1517
* @property UserGroupAssignmentList $objectList
1618
*/
17-
class UserGroupAssignmentListPage extends MultipleLinkPage
19+
class UserGroupAssignmentListPage extends AbstractGridViewPage
1820
{
1921
/**
2022
* @inheritDoc
@@ -26,8 +28,9 @@ class UserGroupAssignmentListPage extends MultipleLinkPage
2628
*/
2729
public $neededPermissions = ['admin.user.canManageGroupAssignment'];
2830

29-
/**
30-
* @inheritDoc
31-
*/
32-
public $objectListClassName = UserGroupAssignmentList::class;
31+
#[\Override]
32+
protected function createGridViewController(): AbstractGridView
33+
{
34+
return new UserGroupAssignmentGridView();
35+
}
3336
}

wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ static function (\wcf\event\endpoint\ControllerCollecting $event) {
199199
$event->register(new \wcf\system\endpoint\controller\core\paid\subscriptions\users\DeleteSubscriptionUser());
200200
$event->register(new \wcf\system\endpoint\controller\core\templates\DeleteTemplate());
201201
$event->register(new \wcf\system\endpoint\controller\core\tags\DeleteTag());
202+
$event->register(new \wcf\system\endpoint\controller\core\users\groups\assignment\DeleteAssignment());
203+
$event->register(new \wcf\system\endpoint\controller\core\users\groups\assignment\EnableAssignment());
204+
$event->register(new \wcf\system\endpoint\controller\core\users\groups\assignment\DisableAssignment());
202205
}
203206
);
204207

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace wcf\event\gridView\admin;
4+
5+
use wcf\event\IPsr14Event;
6+
use wcf\system\gridView\admin\UserGroupAssignmentGridView;
7+
8+
/**
9+
* Indicates that the user group assignment grid view has been initialized.
10+
*
11+
* @author Olaf Braun
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.2
15+
*/
16+
final class UserGroupAssignmentGridViewInitialized implements IPsr14Event
17+
{
18+
public function __construct(public readonly UserGroupAssignmentGridView $gridView)
19+
{
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace wcf\event\interaction\admin;
4+
5+
use wcf\event\IPsr14Event;
6+
use wcf\system\interaction\admin\UserGroupAssignmentInteractions;
7+
8+
/**
9+
* Indicates that the provider for user group assignment interactions is collecting interactions.
10+
*
11+
* @author Olaf Braun
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.2
15+
*/
16+
final class UserGroupAssignmentInteractionCollecting implements IPsr14Event
17+
{
18+
public function __construct(public readonly UserGroupAssignmentInteractions $param)
19+
{
20+
}
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace wcf\system\endpoint\controller\core\users\groups\assignment;
4+
5+
use Laminas\Diactoros\Response\JsonResponse;
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
use wcf\data\user\group\assignment\UserGroupAssignment;
9+
use wcf\data\user\group\assignment\UserGroupAssignmentAction;
10+
use wcf\http\Helper;
11+
use wcf\system\endpoint\DeleteRequest;
12+
use wcf\system\endpoint\IController;
13+
use wcf\system\WCF;
14+
15+
/**
16+
* API endpoint for deleting user group assignments.
17+
*
18+
* @author Olaf Braun
19+
* @copyright 2001-2025 WoltLab GmbH
20+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21+
* @since 6.2
22+
*/
23+
#[DeleteRequest("/core/users/groups/assignments/{id:\d+}")]
24+
final class DeleteAssignment implements IController
25+
{
26+
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
27+
{
28+
$this->assertAssignmentCanBeDeleted();
29+
30+
$assignment = Helper::fetchObjectFromRequestParameter($variables['id'], UserGroupAssignment::class);
31+
32+
(new UserGroupAssignmentAction([$assignment], 'delete'))->executeAction();
33+
34+
return new JsonResponse([]);
35+
}
36+
37+
private function assertAssignmentCanBeDeleted(): void
38+
{
39+
WCF::getSession()->checkPermissions(['admin.management.canManageCronjob']);
40+
}
41+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace wcf\system\endpoint\controller\core\users\groups\assignment;
4+
5+
use Laminas\Diactoros\Response\JsonResponse;
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
use wcf\data\user\group\assignment\UserGroupAssignment;
9+
use wcf\data\user\group\assignment\UserGroupAssignmentAction;
10+
use wcf\http\Helper;
11+
use wcf\system\endpoint\IController;
12+
use wcf\system\endpoint\PostRequest;
13+
use wcf\system\exception\PermissionDeniedException;
14+
use wcf\system\WCF;
15+
16+
/**
17+
* API endpoint for disabling user group assignments.
18+
*
19+
* @author Olaf Braun
20+
* @copyright 2001-2025 WoltLab GmbH
21+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
22+
* @since 6.2
23+
*/
24+
#[PostRequest("/core/users/groups/assignments/{id:\d+}/disable")]
25+
final class DisableAssignment implements IController
26+
{
27+
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
28+
{
29+
$assignment = Helper::fetchObjectFromRequestParameter($variables['id'], UserGroupAssignment::class);
30+
31+
$this->assertAssignmentCanBeDisabled($assignment);
32+
33+
(new UserGroupAssignmentAction([$assignment], 'toggle'))->executeAction();
34+
35+
return new JsonResponse([]);
36+
}
37+
38+
private function assertAssignmentCanBeDisabled(UserGroupAssignment $assignment): void
39+
{
40+
WCF::getSession()->checkPermissions(['admin.management.canManageCronjob']);
41+
42+
if ($assignment->isDisabled) {
43+
throw new PermissionDeniedException();
44+
}
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace wcf\system\endpoint\controller\core\users\groups\assignment;
4+
5+
use Laminas\Diactoros\Response\JsonResponse;
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
use wcf\data\user\group\assignment\UserGroupAssignment;
9+
use wcf\data\user\group\assignment\UserGroupAssignmentAction;
10+
use wcf\http\Helper;
11+
use wcf\system\endpoint\IController;
12+
use wcf\system\endpoint\PostRequest;
13+
use wcf\system\exception\PermissionDeniedException;
14+
use wcf\system\WCF;
15+
16+
/**
17+
* API endpoint for enabling user group assignments.
18+
*
19+
* @author Olaf Braun
20+
* @copyright 2001-2025 WoltLab GmbH
21+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
22+
* @since 6.2
23+
*/
24+
#[PostRequest("/core/users/groups/assignments/{id:\d+}/enable")]
25+
final class EnableAssignment implements IController
26+
{
27+
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
28+
{
29+
$assignment = Helper::fetchObjectFromRequestParameter($variables['id'], UserGroupAssignment::class);
30+
31+
$this->assertAssignmentCanBeEnabled($assignment);
32+
33+
(new UserGroupAssignmentAction([$assignment], 'toggle'))->executeAction();
34+
35+
return new JsonResponse([]);
36+
}
37+
38+
private function assertAssignmentCanBeEnabled(UserGroupAssignment $assignment): void
39+
{
40+
WCF::getSession()->checkPermissions(['admin.management.canManageCronjob']);
41+
42+
if (!$assignment->isDisabled) {
43+
throw new PermissionDeniedException();
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)