implement visible callbacks for tabellisting

This commit is contained in:
envoyr
2022-02-27 20:53:24 +01:00
parent 3186c2b37d
commit 639a262599
4 changed files with 49 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
namespace Froxlor\UI\Callbacks; namespace Froxlor\UI\Callbacks;
use Froxlor\FileDir; use Froxlor\FileDir;
use Froxlor\Settings;
use Froxlor\UI\Panel\UI; use Froxlor\UI\Panel\UI;
/** /**
@@ -44,4 +45,40 @@ class Domain
} }
return UI::getLng('domains.aliasdomain') . ' ' . $attributes['fields']['aliasdomain']; return UI::getLng('domains.aliasdomain') . ' ' . $attributes['fields']['aliasdomain'];
} }
public static function canEditDomain(array $attributes): bool
{
return (bool)$attributes['fields']['caneditdomain'];
}
public static function canViewDomainLogs(array $attributes): bool
{
return (bool)UI::getCurrentUser()['logviewenabled'];
}
public static function canDeleteDomain(array $attributes): bool
{
return $attributes['fields']['parentdomainid'] != '0'
&& empty($attributes['fields']['domainaliasid']);
}
public static function canEditDomainDNS(array $attributes): bool
{
return $attributes['fields']['isbinddomain'] == '1'
&& UI::getCurrentUser()['dnsenabled'] == '1'
&& $attributes['fields']['caneditdomain'] == '1'
&& Settings::Get('system.bind_enable') == '1'
&& Settings::Get('system.dnsenabled') == '1';
}
public function canEditDomainSSL(array $attributes): bool
{
// FIXME: https://github.com/Froxlor/Froxlor/blob/master/templates/Sparkle/customer/domains/domains_domain.tpl#L41
return false;
}
public function canEditDomainAlias(array $attributes): bool
{
return !empty($attributes['fields']['domainaliasid']);
}
} }

View File

@@ -121,6 +121,11 @@ class Listing
// Check each action for a href // Check each action for a href
foreach ($actions as $key => $action) { foreach ($actions as $key => $action) {
// Call user function if visible is an array
if (isset($action['visible']) && is_array($action['visible'])) {
$actions[$key]['visible'] = call_user_func($action['visible'], ['fields' => $item]);
}
// Set link if href is an array // Set link if href is an array
if (isset($action['href']) && is_array($action['href'])) { if (isset($action['href']) && is_array($action['href'])) {
// Search for "columns" in our href array // Search for "columns" in our href array

View File

@@ -47,6 +47,7 @@ return [
'action' => 'edit', 'action' => 'edit',
'id' => ':id' 'id' => ':id'
], ],
'visible' => [Domain::class, 'canEditDomain']
], ],
'logfiles' => [ 'logfiles' => [
'icon' => 'fa fa-file', 'icon' => 'fa fa-file',
@@ -55,6 +56,7 @@ return [
'page' => 'logfiles', 'page' => 'logfiles',
'domain_id' => ':id' 'domain_id' => ':id'
], ],
'visible' => [Domain::class, 'canViewDomainLogs']
], ],
'domaindnseditor' => [ 'domaindnseditor' => [
'icon' => 'fa fa-globe', 'icon' => 'fa fa-globe',
@@ -63,6 +65,7 @@ return [
'page' => 'domaindnseditor', 'page' => 'domaindnseditor',
'domain_id' => ':id' 'domain_id' => ':id'
], ],
'visible' => [Domain::class, 'canEditDomainDNS']
], ],
'delete' => [ 'delete' => [
'icon' => 'fa fa-trash', 'icon' => 'fa fa-trash',
@@ -73,6 +76,7 @@ return [
'action' => 'delete', 'action' => 'delete',
'id' => ':id' 'id' => ':id'
], ],
'visible' => [Domain::class, 'canDeleteDomain']
] ]
] ]
] ]

View File

@@ -16,6 +16,7 @@
* *
*/ */
use Froxlor\Settings;
use Froxlor\UI\Callbacks\Email; use Froxlor\UI\Callbacks\Email;
use Froxlor\UI\Callbacks\Text; use Froxlor\UI\Callbacks\Text;
use Froxlor\UI\Listing; use Froxlor\UI\Listing;
@@ -43,12 +44,12 @@ return [
'label' => $lng['emails']['catchall'], 'label' => $lng['emails']['catchall'],
'field' => 'iscatchall', 'field' => 'iscatchall',
'format_callback' => [Text::class, 'boolean'], 'format_callback' => [Text::class, 'boolean'],
'visible' => \Froxlor\Settings::Get('catchall.catchall_enabled') == '1' 'visible' => Settings::Get('catchall.catchall_enabled') == '1'
], ],
'm.quota' => [ 'm.quota' => [
'label' => $lng['emails']['quota'], 'label' => $lng['emails']['quota'],
'field' => 'quota', 'field' => 'quota',
'visible' => \Froxlor\Settings::Get('system.mail_quota_enabled') == '1' 'visible' => Settings::Get('system.mail_quota_enabled') == '1'
] ]
], ],
'visible_columns' => Listing::getVisibleColumnsForListing('email_list', [ 'visible_columns' => Listing::getVisibleColumnsForListing('email_list', [