-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSsoGridTrait.php
More file actions
72 lines (59 loc) · 2.29 KB
/
Copy pathSsoGridTrait.php
File metadata and controls
72 lines (59 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
namespace ADT\FancyAdmin\UI\Components\Grids\Sso;
use ADT\Datagrid\Component\DataGrid;
use ADT\FancyAdmin\DI\Injects\IdentityQueryFactoryInject;
use ADT\FancyAdmin\Model\Entities\Sso;
use ADT\FancyAdmin\Model\Queries\Factories\SsoQueryFactory;
use ADT\FancyAdmin\UI\Components\Grids\Traits\Editable\Editable;
use Contributte\Datagrid\Column\Action\Confirmation\StringConfirmation;
trait SsoGridTrait
{
use Editable;
use IdentityQueryFactoryInject;
public function initGrid(DataGrid $grid): void
{
$grid->addColumnText('name', 'fcadmin.presenters.sso.grid.name');
$grid->addColumnText('realm', 'fcadmin.presenters.sso.grid.realm');
$grid->addColumnText('hostUrl', 'fcadmin.presenters.sso.grid.hostUrl')
->setRenderer(fn(Sso $sso) => \Nette\Utils\Html::el('a')
->href($sso->getHostUrl())
->setAttribute('target', '_blank')
->setText($sso->getHostUrl())
);
$grid->addColumnText('clientId', 'fcadmin.presenters.sso.grid.clientId');
$grid->addColumnText('defaultRole', 'fcadmin.presenters.sso.grid.defaultRole')
->setRenderer(fn(Sso $sso) => $sso->getDefaultRole()?->getName());
$grid->addAction('removeSso', 'fcadmin.presenters.sso.grid.delete', 'removeSso!')
->setIcon('trash')
->setClass('ajax datagrid-delete')
->setConfirmation(new StringConfirmation('fcadmin.presenters.sso.confirms.delete'));
}
public function handleRemoveSso(int $id): void
{
$sso = $this->getEntityManager()->find(
$this->getEntityManager()->findEntityClassByInterface(Sso::class),
$id
);
if ($sso === null) {
$this->getPresenter()->flashMessageError('fcadmin.appGeneral.exceptions.userNotFound');
$this->getPresenter()->redirect('this');
}
$hasIdentities = $this->_identityQueryFactory->create()
->disableSecurityFilter()
->by('sso', $sso)
->count() > 0;
if ($hasIdentities) {
$this->getPresenter()->flashMessageError('fcadmin.presenters.sso.errors.cannotDeleteHasIdentities');
$this->getPresenter()->redirect('this');
}
$this->getEntityManager()->remove($sso);
$this->getEntityManager()->flush();
$this->getPresenter()->flashMessageSuccess('fcadmin.presenters.sso.messages.deleted');
$this->getPresenter()->redirect('this');
}
protected function getQueryObjectFactoryClass(): string
{
return SsoQueryFactory::class;
}
}