|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the |
|
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace DERHANSEN\SfEventMgt\ViewHelpers\Be; |
|
13
|
|
|
|
|
14
|
|
|
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; |
|
15
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* This viewhelper returns if the given action is enabled |
|
19
|
|
|
*/ |
|
20
|
|
|
class IsActionEnabledViewHelper extends AbstractViewHelper |
|
21
|
|
|
{ |
|
22
|
|
|
public function initializeArguments(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$this->registerArgument('action', 'string', 'Name of the action', true); |
|
25
|
|
|
$this->registerArgument('settings', 'array', 'Settings for backend module', true); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Renders a edit link for the given Event UID |
|
30
|
|
|
*/ |
|
31
|
|
|
public function render(): bool |
|
32
|
|
|
{ |
|
33
|
|
|
$action = $this->arguments['action']; |
|
34
|
|
|
$settings = $this->arguments['settings']; |
|
35
|
|
|
return isset($settings['enabledActions'][$action]) && |
|
36
|
|
|
(int)$settings['enabledActions'][$action] === 1 |
|
37
|
|
|
&& $this->checkAccess($action); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Checks, if the current backend user has sufficient table permissions to perform the given action |
|
42
|
|
|
*/ |
|
43
|
|
|
private function checkAccess(string $action): bool |
|
44
|
|
|
{ |
|
45
|
|
|
$result = false; |
|
46
|
|
|
switch ($action) { |
|
47
|
|
|
case 'notify': |
|
48
|
|
|
$result = $this->getBackendUser()->check( |
|
49
|
|
|
'tables_select', |
|
50
|
|
|
'tx_sfeventmgt_domain_model_customnotificationlog' |
|
51
|
|
|
); |
|
52
|
|
|
break; |
|
53
|
|
|
case 'export': |
|
54
|
|
|
$result = $this->getBackendUser()->check('tables_select', 'tx_sfeventmgt_domain_model_registration') && |
|
55
|
|
|
$this->getBackendUser()->check( |
|
56
|
|
|
'tables_select', |
|
57
|
|
|
'tx_sfeventmgt_domain_model_registration_field' |
|
58
|
|
|
) && |
|
59
|
|
|
$this->getBackendUser()->check( |
|
60
|
|
|
'tables_select', |
|
61
|
|
|
'tx_sfeventmgt_domain_model_registration_fieldvalue' |
|
62
|
|
|
); |
|
63
|
|
|
break; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $result; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
private function getBackendUser(): ?BackendUserAuthentication |
|
70
|
|
|
{ |
|
71
|
|
|
return $GLOBALS['BE_USER'] ?? null; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|