Skip to content

Commit 05294ff

Browse files
committed
Add endpoints to disable or enable contact options and recipients
1 parent 28e819c commit 05294ff

File tree

8 files changed

+214
-1
lines changed

8 files changed

+214
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,13 @@ static function (\wcf\event\endpoint\ControllerCollecting $event) {
249249
$event->register(new \wcf\system\endpoint\controller\core\contact\options\DeleteOption());
250250
$event->register(new \wcf\system\endpoint\controller\core\contact\options\ChangeShowOrder());
251251
$event->register(new \wcf\system\endpoint\controller\core\contact\options\GetShowOrder());
252+
$event->register(new \wcf\system\endpoint\controller\core\contact\options\DisableOption());
253+
$event->register(new \wcf\system\endpoint\controller\core\contact\options\EnableOption());
252254
$event->register(new \wcf\system\endpoint\controller\core\contact\recipients\DeleteRecipient());
253255
$event->register(new \wcf\system\endpoint\controller\core\contact\recipients\ChangeShowOrder());
254256
$event->register(new \wcf\system\endpoint\controller\core\contact\recipients\GetShowOrder());
257+
$event->register(new \wcf\system\endpoint\controller\core\contact\recipients\DisableRecipient());
258+
$event->register(new \wcf\system\endpoint\controller\core\contact\recipients\EnableRecipient());
255259
}
256260
);
257261

wcfsetup/install/files/lib/data/contact/option/ContactOptionAction.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use wcf\data\AbstractDatabaseObjectAction;
66
use wcf\data\ISortableAction;
7+
use wcf\data\TDatabaseObjectToggle;
78
use wcf\data\TI18nDatabaseObjectAction;
89
use wcf\system\exception\UserInputException;
910
use wcf\system\WCF;
@@ -21,6 +22,7 @@
2122
class ContactOptionAction extends AbstractDatabaseObjectAction implements ISortableAction
2223
{
2324
use TI18nDatabaseObjectAction;
25+
use TDatabaseObjectToggle;
2426

2527
/**
2628
* @inheritDoc
@@ -45,7 +47,7 @@ class ContactOptionAction extends AbstractDatabaseObjectAction implements ISorta
4547
/**
4648
* @inheritDoc
4749
*/
48-
protected $requireACP = ['create', 'delete', 'update', 'updatePosition'];
50+
protected $requireACP = ['create', 'delete', 'update', 'updatePosition', 'toggle'];
4951

5052
/**
5153
* @inheritDoc
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\contact\options;
4+
5+
use Laminas\Diactoros\Response\JsonResponse;
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
use wcf\data\contact\option\ContactOption;
9+
use wcf\data\contact\option\ContactOptionAction;
10+
use wcf\http\Helper;
11+
use wcf\system\endpoint\IController;
12+
use wcf\system\endpoint\PostRequest;
13+
use wcf\system\exception\IllegalLinkException;
14+
use wcf\system\WCF;
15+
16+
/**
17+
* @author Olaf Braun
18+
* @copyright 2001-2025 WoltLab GmbH
19+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20+
* @since 6.2
21+
*/
22+
#[PostRequest("/core/contact/options/{id:\d+}/disable")]
23+
final class DisableOption implements IController
24+
{
25+
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
26+
{
27+
$this->assertOptionCanBeDisabled();
28+
29+
$option = Helper::fetchObjectFromRequestParameter($variables['id'], ContactOption::class);
30+
31+
if (!$option->isDisabled) {
32+
(new ContactOptionAction([$option], 'toggle'))->executeAction();
33+
}
34+
35+
return new JsonResponse([]);
36+
}
37+
38+
private function assertOptionCanBeDisabled(): void
39+
{
40+
if (!\MODULE_CONTACT_FORM) {
41+
throw new IllegalLinkException();
42+
}
43+
44+
WCF::getSession()->checkPermissions(["admin.contact.canManageContactForm"]);
45+
}
46+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace wcf\system\endpoint\controller\core\contact\options;
4+
5+
use Laminas\Diactoros\Response\JsonResponse;
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
use wcf\data\contact\option\ContactOption;
9+
use wcf\data\contact\option\ContactOptionAction;
10+
use wcf\http\Helper;
11+
use wcf\system\endpoint\IController;
12+
use wcf\system\endpoint\PostRequest;
13+
use wcf\system\exception\IllegalLinkException;
14+
use wcf\system\WCF;
15+
16+
/**
17+
* API endpoint for enabling a contact option.
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/contact/options/{id:\d+}/enable")]
25+
final class EnableOption implements IController
26+
{
27+
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
28+
{
29+
$this->assertOptionCanBeEnabled();
30+
31+
$option = Helper::fetchObjectFromRequestParameter($variables['id'], ContactOption::class);
32+
33+
if ($option->isDisabled) {
34+
(new ContactOptionAction([$option], 'toggle'))->executeAction();
35+
}
36+
37+
return new JsonResponse([]);
38+
}
39+
40+
private function assertOptionCanBeEnabled(): void
41+
{
42+
if (!\MODULE_CONTACT_FORM) {
43+
throw new IllegalLinkException();
44+
}
45+
46+
WCF::getSession()->checkPermissions(["admin.contact.canManageContactForm"]);
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace wcf\system\endpoint\controller\core\contact\recipients;
4+
5+
use Laminas\Diactoros\Response\JsonResponse;
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
use wcf\data\contact\recipient\ContactRecipient;
9+
use wcf\data\contact\recipient\ContactRecipientAction;
10+
use wcf\http\Helper;
11+
use wcf\system\endpoint\IController;
12+
use wcf\system\endpoint\PostRequest;
13+
use wcf\system\exception\IllegalLinkException;
14+
use wcf\system\WCF;
15+
16+
/**
17+
* API endpoint for disabling a contact recipient.
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/contact/recipients/{id:\d+}/disable")]
25+
final class DisableRecipient implements IController
26+
{
27+
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
28+
{
29+
$this->assertRecipientCanBeDisabled();
30+
31+
$recipient = Helper::fetchObjectFromRequestParameter($variables['id'], ContactRecipient::class);
32+
33+
if (!$recipient->isDisabled) {
34+
(new ContactRecipientAction([$recipient], 'toggle'))->executeAction();
35+
}
36+
37+
return new JsonResponse([]);
38+
}
39+
40+
private function assertRecipientCanBeDisabled(): void
41+
{
42+
if (!\MODULE_CONTACT_FORM) {
43+
throw new IllegalLinkException();
44+
}
45+
46+
WCF::getSession()->checkPermissions(["admin.contact.canManageContactForm"]);
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace wcf\system\endpoint\controller\core\contact\recipients;
4+
5+
use Laminas\Diactoros\Response\JsonResponse;
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
use wcf\data\contact\recipient\ContactRecipient;
9+
use wcf\data\contact\recipient\ContactRecipientAction;
10+
use wcf\http\Helper;
11+
use wcf\system\endpoint\IController;
12+
use wcf\system\endpoint\PostRequest;
13+
use wcf\system\exception\IllegalLinkException;
14+
use wcf\system\WCF;
15+
16+
/**
17+
* API endpoint for enabling a contact recipient.
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/contact/recipients/{id:\d+}/enable")]
25+
final class EnableRecipient implements IController
26+
{
27+
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
28+
{
29+
$this->assertRecipientCanBeEnabled();
30+
31+
$recipient = Helper::fetchObjectFromRequestParameter($variables['id'], ContactRecipient::class);
32+
33+
if ($recipient->isDisabled) {
34+
(new ContactRecipientAction([$recipient], 'toggle'))->executeAction();
35+
}
36+
37+
return new JsonResponse([]);
38+
}
39+
40+
private function assertRecipientCanBeEnabled(): void
41+
{
42+
if (!\MODULE_CONTACT_FORM) {
43+
throw new IllegalLinkException();
44+
}
45+
46+
WCF::getSession()->checkPermissions(["admin.contact.canManageContactForm"]);
47+
}
48+
}

wcfsetup/install/files/lib/system/gridView/admin/ContactOptionGridView.class.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use wcf\system\interaction\admin\ContactOptionInteractions;
2121
use wcf\system\interaction\Divider;
2222
use wcf\system\interaction\EditInteraction;
23+
use wcf\system\interaction\ToggleInteraction;
2324
use wcf\system\WCF;
2425

2526
/**
@@ -66,6 +67,14 @@ public function __construct()
6667
]);
6768
$this->setInteractionProvider($provider);
6869

70+
$this->addQuickInteraction(
71+
new ToggleInteraction(
72+
"isDisabled",
73+
"core/contact/options/%s/enable",
74+
"core/contact/options/%s/disable"
75+
)
76+
);
77+
6978
$this->addRowLink(new GridViewRowLink(ContactOptionEditForm::class));
7079

7180
$this->setSortField("showOrder");

wcfsetup/install/files/lib/system/gridView/admin/ContactRecipientGridView.class.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use wcf\system\interaction\admin\ContactRecipientInteractions;
2020
use wcf\system\interaction\Divider;
2121
use wcf\system\interaction\EditInteraction;
22+
use wcf\system\interaction\ToggleInteraction;
2223
use wcf\system\WCF;
2324

2425
/**
@@ -64,6 +65,13 @@ public function __construct()
6465
new EditInteraction(ContactRecipientEditForm::class),
6566
]);
6667
$this->setInteractionProvider($provider);
68+
$this->addQuickInteraction(
69+
new ToggleInteraction(
70+
"isDisabled",
71+
"core/contact/recipients/%s/enable",
72+
"core/contact/recipients/%s/disable"
73+
)
74+
);
6775

6876
$this->addRowLink(new GridViewRowLink(ContactRecipientEditForm::class));
6977

0 commit comments

Comments
 (0)