Browse Source

Utilisateurs > Messages : permission uniquement pour l'administrateur

feature/rotating_product
Guillaume Bourgeois 5 months ago
parent
commit
cf4f932db0
2 changed files with 14 additions and 5 deletions
  1. +9
    -4
      backend/controllers/UserController.php
  2. +5
    -1
      backend/views/user/_menu_navigation.php

+ 9
- 4
backend/controllers/UserController.php View File

'allow' => true, 'allow' => true,
'roles' => ['@'], 'roles' => ['@'],
'matchCallback' => function ($rule, $action) { 'matchCallback' => function ($rule, $action) {
return $this->getUserModule()
->getAuthorizationChecker()
->isGrantedAsProducer($this->getUserCurrent());
$userCurrent = $this->getUserCurrent();
$authorizationChecker = $this->getUserModule()->getAuthorizationChecker();
if(in_array($action->id, ['messages', 'message-delete'])) {
return $authorizationChecker->isGrantedAsAdministrator($userCurrent);
}
else {
return $authorizationChecker->isGrantedAsProducer($userCurrent);
}
} }
]
],
], ],
], ],
]; ];

+ 5
- 1
backend/views/user/_menu_navigation.php View File

<?php <?php


use common\helpers\GlobalParam;
use domain\Order\Order\OrderModule; use domain\Order\Order\OrderModule;
use domain\User\User\User; use domain\User\User\User;
use domain\User\User\UserModule; use domain\User\User\UserModule;
$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();
$orderModule = OrderModule::getInstance(); $orderModule = OrderModule::getInstance();


$userCurrent = GlobalParam::getCurrentUser();
$credit = $userModule->getRepository()->getCredit($user); $credit = $userModule->getRepository()->getCredit($user);
$countOrders = $orderModule->getRepository()->countOrdersByUser($user); $countOrders = $orderModule->getRepository()->countOrdersByUser($user);
$countUserMessages = $this->getUserMessageModule()->getRepository()->countUserMessagesByUser($user); $countUserMessages = $this->getUserMessageModule()->getRepository()->countUserMessagesByUser($user);
<?= menu_navigation_item('update', 'Profil', $action, $user) ?> <?= menu_navigation_item('update', 'Profil', $action, $user) ?>
<?= menu_navigation_item('credit', 'Cagnotte <span class="label label-default badge">'.Price::format($credit).'</span>', $action, $user) ?> <?= menu_navigation_item('credit', 'Cagnotte <span class="label label-default badge">'.Price::format($credit).'</span>', $action, $user) ?>
<?= menu_navigation_item('orders', 'Commandes <span class="label label-default badge">'.$countOrders.'</span>', $action, $user) ?> <?= menu_navigation_item('orders', 'Commandes <span class="label label-default badge">'.$countOrders.'</span>', $action, $user) ?>
<?= menu_navigation_item('messages', 'Messages <span class="label label-default badge">'.$countUserMessages.'</span>', $action, $user) ?>
<?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?>
<?= menu_navigation_item('messages', 'Messages <span class="label label-default badge">'.$countUserMessages.'</span>', $action, $user) ?>
<?php endif; ?>
</ul> </ul>





Loading…
Cancel
Save