Skip to content

Commit

Permalink
Misc. changes to updates from pull request #246 - Filter ticket quick…
Browse files Browse the repository at this point in the history
… action buttons based on user privlieges - Issue #242
  • Loading branch information
akshay kumar committed Nov 13, 2019
1 parent bedd16c commit a966a85
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
1 change: 0 additions & 1 deletion Controller/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public function loadTicket($ticketId, QuickActionButtonCollection $quickActionBu
$entityManager->flush();
}

$quickActionButtonCollection->setHasPreparedResponsePrivilege(in_array('ROLE_AGENT_MANAGE_WORKFLOW_MANUAL', $this->get('user.service')->getUserPrivileges($user->getId())));
$quickActionButtonCollection->prepareAssets();

return $this->render('@UVDeskCoreFramework//ticket.html.twig', [
Expand Down
30 changes: 15 additions & 15 deletions Tickets/QuickActionButtonCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
namespace Webkul\UVDesk\CoreFrameworkBundle\Tickets;

use Twig\Environment as TwigEnvironment;
use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
use Webkul\UVDesk\CoreFrameworkBundle\Dashboard\DashboardTemplate;
use Webkul\UVDesk\CoreFrameworkBundle\Framework\ExtendableComponentInterface;

class QuickActionButtonCollection implements ExtendableComponentInterface
{
private $collection = [];
private $hasPreparedResponsePrivilege = false;
public function __construct(TwigEnvironment $twig, DashboardTemplate $dashboard)

public function __construct(TwigEnvironment $twig, DashboardTemplate $dashboard, UserService $userService)
{
$this->twig = $twig;
$this->dashboard = $dashboard;
$this->userService = $userService;
}

public function add(QuickActionButtonInterface $quickActionButton)
Expand All @@ -23,13 +25,6 @@ public function add(QuickActionButtonInterface $quickActionButton)

public function injectTemplates()
{

foreach( $this->collection as $key=>$value)
{
if(get_class($value) == "Webkul\UVDesk\AutomationBundle\UIComponents\Ticket\QuickActionButtons\PreparedResponses" && !$this->hasPreparedResponsePrivilege)
unset($this->collection[$key]);
}

return array_reduce($this->collection, function ($stream, $quickActionButton) {
return $stream .= $quickActionButton->renderTemplate($this->twig);
}, '');
Expand All @@ -38,12 +33,17 @@ public function injectTemplates()
public function prepareAssets()
{
foreach ($this->collection as $quickActionButton) {
$quickActionButton->prepareDashboard($this->dashboard);
if ($quickActionButton::getRoles() != null) {
foreach ($quickActionButton::getRoles() as $accessRole) {
if ($this->userService->isAccessAuthorized($accessRole)) {
$quickActionButton->prepareDashboard($this->dashboard);

break;
}
}
} else {
$quickActionButton->prepareDashboard($this->dashboard);
}
}
}

public function setHasPreparedResponsePrivilegeFlag($hasPreparedResponsePrivilege)
{
$this->hasPreparedResponsePrivilege = $hasPreparedResponsePrivilege;
}
}
1 change: 1 addition & 0 deletions Tickets/QuickActionButtonInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

interface QuickActionButtonInterface
{
public static function getRoles() : array;
}
5 changes: 5 additions & 0 deletions UIComponents/Ticket/QuickActionButtons/SavedReplies.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

class SavedReplies implements QuickActionButtonInterface
{
public static function getRoles() : array
{
return [];
}

public function renderTemplate(TwigEnvironment $twig)
{
return $twig->render('@UVDeskCoreFramework/tickets/quick-actions/saved-replies.html.twig');
Expand Down

0 comments on commit a966a85

Please sign in to comment.