Browse Source

[Technique] Mise en place AuthorizationChecker #1328

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
4842251273
32 changed files with 109 additions and 114 deletions
  1. +3
    -1
      backend/controllers/DevelopmentController.php
  2. +3
    -4
      backend/views/layouts/header.php
  3. +48
    -45
      backend/views/layouts/left.php
  4. +4
    -2
      backend/views/user/index.php
  5. +3
    -0
      common/logic/AbstractSingleton.php
  6. +0
    -1
      common/logic/ModuleInterface.php
  7. +0
    -26
      common/logic/User/User/Service/UserSolver.php
  8. +0
    -5
      common/logic/User/User/Wrapper/UserContainer.php
  9. +0
    -5
      common/logic/User/User/Wrapper/UserModule.php
  10. +2
    -1
      common/versions/22.10.A.php
  11. +2
    -1
      common/versions/22.11.A.php
  12. +2
    -1
      common/versions/22.11.B.php
  13. +2
    -1
      common/versions/22.12.A.php
  14. +2
    -1
      common/versions/23.1.A.php
  15. +1
    -0
      common/versions/23.10.A.php
  16. +1
    -0
      common/versions/23.10.B.php
  17. +2
    -1
      common/versions/23.3.A.php
  18. +2
    -1
      common/versions/23.4.A.php
  19. +2
    -1
      common/versions/23.6.A.php
  20. +2
    -1
      common/versions/23.6.B.php
  21. +2
    -1
      common/versions/23.7.A.php
  22. +2
    -1
      common/versions/23.8.A.php
  23. +1
    -0
      common/versions/23.8.B.php
  24. +1
    -0
      common/versions/23.9.A.php
  25. +1
    -0
      common/versions/23.9.B.php
  26. +1
    -0
      common/versions/23.9.C.php
  27. +1
    -0
      common/versions/23.9.D.php
  28. +1
    -0
      common/versions/23.9.E.php
  29. +8
    -7
      common/versions/_macros.php
  30. +5
    -4
      common/views/nav_user_top.php
  31. +4
    -1
      frontend/views/layouts/main.php
  32. +1
    -2
      producer/views/layouts/main.php

+ 3
- 1
backend/controllers/DevelopmentController.php View File

foreach ($versionsArray as $version) { foreach ($versionsArray as $version) {
$versionsRenderArray[$version] = [ $versionsRenderArray[$version] = [
'version' => $version, 'version' => $version,
'content' => $this->renderFile('@common/versions/' . $version . '.php')
'content' => $this->renderFile('@common/versions/' . $version . '.php', [
'userCurrent' => $this->getUserCurrent()
])
]; ];
} }



+ 3
- 4
backend/views/layouts/header.php View File

$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();
$producerManager = ProducerManager::getInstance(); $producerManager = ProducerManager::getInstance();
$producer = GlobalParam::getCurrentProducer(); $producer = GlobalParam::getCurrentProducer();
$userCurrent = GlobalParam::getCurrentUser();


?> ?>


<header class="main-header"> <header class="main-header">

<!-- <?= Html::a('<span class="logo-mini"><img src="' . Yii::$app->urlManagerBackend->getBaseUrl() . '/img/logo-distrib.png" /></span><span class="logo-lg"><img src="' . Yii::$app->urlManagerBackend->getBaseUrl() . '/img/logo-distrib.png" /></span>', Yii::$app->homeUrl, ['class' => 'logo']) ?>--> <!-- <?= Html::a('<span class="logo-mini"><img src="' . Yii::$app->urlManagerBackend->getBaseUrl() . '/img/logo-distrib.png" /></span><span class="logo-lg"><img src="' . Yii::$app->urlManagerBackend->getBaseUrl() . '/img/logo-distrib.png" /></span>', Yii::$app->homeUrl, ['class' => 'logo']) ?>-->

<?= Html::a('Opendistrib', Yii::$app->homeUrl, ['class' => 'logo']); ?> <?= Html::a('Opendistrib', Yii::$app->homeUrl, ['class' => 'logo']); ?>


<nav class="navbar navbar-static-top" role="navigation"> <nav class="navbar navbar-static-top" role="navigation">


<ul class="nav navbar-nav"> <ul class="nav navbar-nav">


<?php if ($userModule->isCurrentAdmin()): ?>
<?php if ($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?>
<li class="dropdown producer-menu"> <li class="dropdown producer-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-grain"></span> <span class="glyphicon glyphicon-grain"></span>
</ul> </ul>


</li> </li>
<?php if ($userModule->isCurrentProducer() || $userModule->isCurrentAdmin()): ?>
<?php if ($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)): ?>
<li> <li>
<a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => GlobalParam::getCurrentProducer()->slug]); ?>"> <a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => GlobalParam::getCurrentProducer()->slug]); ?>">
<span class="glyphicon glyphicon-eye-open"></span> <span class="glyphicon glyphicon-eye-open"></span>

+ 48
- 45
backend/views/layouts/left.php View File

*/ */


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\Opendistrib;
use yii\helpers\Html;
use common\logic\Ticket\Ticket\Wrapper\TicketManager;
use common\logic\User\User\Wrapper\UserModule;


$producerManager = $this->getProducerManager(); $producerManager = $this->getProducerManager();
$userModule = $this->getUserModule();
$userModule = UserModule::getInstance();
$userProducerManager = $this->getUserProducerManager(); $userProducerManager = $this->getUserProducerManager();
$ticketManager = $this->getTicketManager(); $ticketManager = $this->getTicketManager();

$producer = GlobalParam::getCurrentProducer(); $producer = GlobalParam::getCurrentProducer();
$userCurrent = GlobalParam::getCurrentUser();
$isUserCurrentGrantedAsAdministrator = $userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent);
$isUserCurrentGrantedAsProducer = $userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent);



?> ?>




$countTicketsProducerUnreadLabel = ''; $countTicketsProducerUnreadLabel = '';
$countTicketsProducerUnread = $ticketManager->countTicketsUnreadByUser($this->getUserCurrent()); $countTicketsProducerUnread = $ticketManager->countTicketsUnreadByUser($this->getUserCurrent());
if($countTicketsProducerUnread && !$userModule->isCurrentAdmin()) {
if($countTicketsProducerUnread && !$isUserCurrentGrantedAsAdministrator) {
$countTicketsProducerUnreadLabel = '<span class="pull-right-container"><small class="label pull-right bg-green">'.$countTicketsProducerUnread.'</small></span>'; $countTicketsProducerUnreadLabel = '<span class="pull-right-container"><small class="label pull-right bg-green">'.$countTicketsProducerUnread.'</small></span>';
} }


$countTicketsAdminUnreadLabel = ''; $countTicketsAdminUnreadLabel = '';
$countTicketsAdminUnread = $ticketManager->countTicketsAdminUnreadByUser($this->getUserCurrent()); $countTicketsAdminUnread = $ticketManager->countTicketsAdminUnreadByUser($this->getUserCurrent());
if($countTicketsAdminUnread && $userModule->isCurrentAdmin()) {
if($countTicketsAdminUnread && $isUserCurrentGrantedAsAdministrator) {
$countTicketsAdminUnreadLabel = '<span class="pull-right-container"><small class="label pull-right bg-green">'.$countTicketsAdminUnread.'</small></span>'; $countTicketsAdminUnreadLabel = '<span class="pull-right-container"><small class="label pull-right bg-green">'.$countTicketsAdminUnread.'</small></span>';
} }


[ [
'options' => ['class' => 'sidebar-menu tree', 'data-widget' => 'tree'], 'options' => ['class' => 'sidebar-menu tree', 'data-widget' => 'tree'],
'items' => [ 'items' => [
['label' => "Besoin d'aide ?", 'options' => ['class' => 'header'], 'visible' => $userModule->isCurrentProducer()],
['label' => "Besoin d'aide ?", 'options' => ['class' => 'header'], 'visible' => $isUserCurrentGrantedAsProducer],
[ [
'label' => 'Support', 'label' => 'Support',
'icon' => 'comments', 'icon' => 'comments',
'url' => ['support/index'], 'url' => ['support/index'],
'visible' => $userModule->isCurrentProducer(),
'visible' => $isUserCurrentGrantedAsProducer,
'template' => '<a href="{url}">{icon} {label}' . $countTicketsProducerUnreadLabel . '</a>' 'template' => '<a href="{url}">{icon} {label}' . $countTicketsProducerUnreadLabel . '</a>'
], ],
['label' => $producer->name, 'options' => ['class' => 'header'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Tableau de bord', 'icon' => 'dashboard', 'url' => ['/dashboard/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Distributions', 'icon' => 'calendar', 'url' => ['/distribution/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => $producer->name, 'options' => ['class' => 'header'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Tableau de bord', 'icon' => 'dashboard', 'url' => ['/dashboard/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Distributions', 'icon' => 'calendar', 'url' => ['/distribution/index'], 'visible' => $isUserCurrentGrantedAsProducer],
[ [
'label' => 'Produits', 'label' => 'Produits',
'icon' => 'clone', 'icon' => 'clone',
'url' => ['/product/index'], 'url' => ['/product/index'],
'visible' => $userModule->isCurrentProducer(),
'visible' => $isUserCurrentGrantedAsProducer,
'active' => Yii::$app->controller->id == 'product', 'active' => Yii::$app->controller->id == 'product',
'items' => [ 'items' => [
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/product/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Catégories', 'icon' => 'book', 'url' => ['/product-category/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Import prix', 'icon' => 'upload', 'url' => ['/product/price-import'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/product/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Catégories', 'icon' => 'book', 'url' => ['/product-category/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Import prix', 'icon' => 'upload', 'url' => ['/product/price-import'], 'visible' => $isUserCurrentGrantedAsProducer],
] ]
], ],
['label' => 'Points de vente', 'icon' => 'map-marker', 'url' => ['/point-sale/index'], 'visible' => $userModule->isCurrentProducer(), 'active' => Yii::$app->controller->id == 'point-sale'],
['label' => 'Points de vente', 'icon' => 'map-marker', 'url' => ['/point-sale/index'], 'visible' => $isUserCurrentGrantedAsProducer, 'active' => Yii::$app->controller->id == 'point-sale'],
[ [
'label' => 'Utilisateurs', 'label' => 'Utilisateurs',
'icon' => 'users', 'icon' => 'users',
'url' => ['/user/index'], 'url' => ['/user/index'],
'items' => [ 'items' => [
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/user/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/user/index'], 'visible' => $isUserCurrentGrantedAsProducer],
[ [
'label' => 'Crédit', 'label' => 'Crédit',
'icon' => 'euro', 'icon' => 'euro',
'url' => ['/credit/index'], 'url' => ['/credit/index'],
'template' => '<a href="{url}">{icon} {label}' . $sumUserProducerCreditsLabel . '</a>', 'template' => '<a href="{url}">{icon} {label}' . $sumUserProducerCreditsLabel . '</a>',
'visible' => $userModule->isCurrentProducer() && $producerManager->getConfig('credit')
'visible' => $isUserCurrentGrantedAsProducer && $producerManager->getConfig('credit')
], ],
['label' => 'Groupes', 'icon' => 'users', 'url' => ['/user-group/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Groupes', 'icon' => 'users', 'url' => ['/user-group/index'], 'visible' => $isUserCurrentGrantedAsProducer],
], ],
], ],
['label' => 'Abonnements', 'icon' => 'repeat', 'url' => ['/subscription/index'], 'visible' => $userModule->isCurrentProducer(), 'active' => Yii::$app->controller->id == 'subscription'],
['label' => 'Communiquer', 'icon' => 'bullhorn', 'url' => ['/communicate/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Abonnements', 'icon' => 'repeat', 'url' => ['/subscription/index'], 'visible' => $isUserCurrentGrantedAsProducer, 'active' => Yii::$app->controller->id == 'subscription'],
['label' => 'Communiquer', 'icon' => 'bullhorn', 'url' => ['/communicate/index'], 'visible' => $isUserCurrentGrantedAsProducer],
[ [
'label' => 'Documents', 'label' => 'Documents',
'icon' => 'clone', 'icon' => 'clone',
'url' => ['/delivery-note/index'], 'url' => ['/delivery-note/index'],
'items' => [ 'items' => [
['label' => 'Bons de livraison', 'icon' => 'sticky-note-o', 'url' => ['/delivery-note/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Factures', 'icon' => 'sticky-note-o', 'url' => ['/invoice/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Devis', 'icon' => 'sticky-note-o', 'url' => ['/quotation/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Bons de livraison', 'icon' => 'sticky-note-o', 'url' => ['/delivery-note/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Factures', 'icon' => 'sticky-note-o', 'url' => ['/invoice/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Devis', 'icon' => 'sticky-note-o', 'url' => ['/quotation/index'], 'visible' => $isUserCurrentGrantedAsProducer],
], ],
], ],
[ [
'icon' => 'line-chart', 'icon' => 'line-chart',
'url' => ['/stats/index'], 'url' => ['/stats/index'],
'items' => [ 'items' => [
['label' => 'Chiffre d\'affaire', 'icon' => 'line-chart', 'url' => ['/stats/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Rapports', 'icon' => 'pencil-square-o', 'url' => ['/report/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Produits', 'icon' => 'table', 'url' => ['/stats/products'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Chiffre d\'affaire', 'icon' => 'line-chart', 'url' => ['/stats/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Rapports', 'icon' => 'pencil-square-o', 'url' => ['/report/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Produits', 'icon' => 'table', 'url' => ['/stats/products'], 'visible' => $isUserCurrentGrantedAsProducer],
], ],
], ],
['label' => 'Paramètres', 'icon' => 'cog', 'url' => ['/producer/update'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Accès', 'icon' => 'lock', 'url' => ['/access/index'], 'visible' => $userModule->isCurrentProducer()],
['label' => "Opendistrib", 'options' => ['class' => 'header'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Paramètres', 'icon' => 'cog', 'url' => ['/producer/update'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Accès', 'icon' => 'lock', 'url' => ['/access/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => "Opendistrib", 'options' => ['class' => 'header'], 'visible' => $isUserCurrentGrantedAsProducer],
[ [
'label' => 'Développement', 'label' => 'Développement',
'icon' => 'code', 'icon' => 'code',
'url' => ['/development/index'], 'url' => ['/development/index'],
'visible' => $userModule->isCurrentProducer(),
'visible' => $isUserCurrentGrantedAsProducer,
'active' => Yii::$app->controller->id == 'development', 'active' => Yii::$app->controller->id == 'development',
'template' => '<a href="{url}">{icon} {label}' . $newVersionOpendistribLabel . '</a>' 'template' => '<a href="{url}">{icon} {label}' . $newVersionOpendistribLabel . '</a>'
], ],
['label' => 'Tarifs', 'icon' => 'euro', 'url' => ['/producer/billing'], 'visible' => $userModule->isCurrentProducer()],
['label' => 'Tarifs', 'icon' => 'euro', 'url' => ['/producer/billing'], 'visible' => $isUserCurrentGrantedAsProducer],


['label' => 'Administration', 'options' => ['class' => 'header'], 'visible' => $userModule->isCurrentAdmin()],
['label' => 'Administration', 'options' => ['class' => 'header'], 'visible' => $isUserCurrentGrantedAsAdministrator],
[ [
'label' => 'Tickets', 'label' => 'Tickets',
'icon' => 'comments', 'icon' => 'comments',
'url' => ['support-admin/index'], 'url' => ['support-admin/index'],
'visible' => $userModule->isCurrentAdmin(),
'visible' => $isUserCurrentGrantedAsAdministrator,
'template' => '<a href="{url}">{icon} {label}' . $countTicketsAdminUnreadLabel . '</a>' 'template' => '<a href="{url}">{icon} {label}' . $countTicketsAdminUnreadLabel . '</a>'
], ],
['label' => 'Producteurs', 'icon' => 'th-list', 'url' => ['/producer-admin/index'], 'visible' => $userModule->isCurrentAdmin()],
['label' => 'Producteurs', 'icon' => 'th-list', 'url' => ['/producer-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator],
[ [
'label' => 'Statistiques', 'label' => 'Statistiques',
'icon' => 'line-chart', 'icon' => 'line-chart',
'url' => ['/stats-admin/matomo'], 'url' => ['/stats-admin/matomo'],
'visible' => $userModule->isCurrentAdmin(),
'visible' => $isUserCurrentGrantedAsAdministrator,
'items' => [ 'items' => [
['label' => 'Matomo', 'icon' => 'line-chart', 'url' => ['/stats-admin/matomo'], 'visible' => $userModule->isCurrentAdmin()],
['label' => 'Chiffre d\'affaire', 'icon' => 'line-chart', 'url' => ['/stats-admin/turnover'], 'visible' => $userModule->isCurrentAdmin()],
['label' => 'Commandes clients', 'icon' => 'calendar', 'url' => ['/stats-admin/customer-orders'], 'visible' => $userModule->isCurrentAdmin()],
['label' => 'Matomo', 'icon' => 'line-chart', 'url' => ['/stats-admin/matomo'], 'visible' => $isUserCurrentGrantedAsAdministrator],
['label' => 'Chiffre d\'affaire', 'icon' => 'line-chart', 'url' => ['/stats-admin/turnover'], 'visible' => $isUserCurrentGrantedAsAdministrator],
['label' => 'Commandes clients', 'icon' => 'calendar', 'url' => ['/stats-admin/customer-orders'], 'visible' => $isUserCurrentGrantedAsAdministrator],
], ],
], ],


['label' => 'Tranches de prix', 'icon' => 'eur', 'url' => ['/producer-price-range-admin/index'], 'visible' => $userModule->isCurrentAdmin()],
['label' => 'Taxes', 'icon' => 'eur', 'url' => ['/tax-rate-admin/index'], 'visible' => $userModule->isCurrentAdmin()],
['label' => 'Communiquer', 'icon' => 'bullhorn', 'url' => ['/communicate-admin/index'], 'visible' => $userModule->isCurrentAdmin()],
['label' => 'Tranches de prix', 'icon' => 'eur', 'url' => ['/producer-price-range-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator],
['label' => 'Taxes', 'icon' => 'eur', 'url' => ['/tax-rate-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator],
['label' => 'Communiquer', 'icon' => 'bullhorn', 'url' => ['/communicate-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator],


//['label' => 'Outils', 'options' => ['class' => 'header'], 'visible' => $userModule->isCurrentAdmin()],
//['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii'], 'visible' => $userModule->isCurrentAdmin()],
//['label' => 'Debug', 'icon' => 'dashboard', 'url' => ['/debug'], 'visible' => $userModule->isCurrentAdmin()],
//['label' => 'Outils', 'options' => ['class' => 'header'], 'visible' => $isUserCurrentGrantedAsAdministrator],
//['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii'], 'visible' => $isUserCurrentGrantedAsAdministrator],
//['label' => 'Debug', 'icon' => 'dashboard', 'url' => ['/debug'], 'visible' => $isUserCurrentGrantedAsAdministrator],
['label' => 'Login', 'url' => ['site/login'], 'visible' => !$userModule->isCurrentConnected()], ['label' => 'Login', 'url' => ['site/login'], 'visible' => !$userModule->isCurrentConnected()],
], ],
] ]

+ 4
- 2
backend/views/user/index.php View File

* termes. * termes.
*/ */


use common\helpers\GlobalParam;
use common\logic\Producer\Producer\Wrapper\ProducerManager; use common\logic\Producer\Producer\Wrapper\ProducerManager;
use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;


$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();
$producerManager = ProducerManager::getInstance(); $producerManager = ProducerManager::getInstance();
$userCurrent = GlobalParam::getCurrentUser();


$this->setTitle('Utilisateurs'); $this->setTitle('Utilisateurs');
$this->addBreadcrumb($this->getTitle()); $this->addBreadcrumb($this->getTitle());
'class' => 'btn btn-default btn-confirm-delete' 'class' => 'btn btn-default btn-confirm-delete'
]); ]);
}, },
'switch' => function($url, $model) use ($userModule) {
if($userModule->isCurrentAdmin()) {
'switch' => function($url, $model) use ($userModule, $userCurrent) {
if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)) {
return Html::a('<span class="glyphicon glyphicon-user"></span>', return Html::a('<span class="glyphicon glyphicon-user"></span>',
Yii::$app->urlManager->createUrl(['user/switch-identity', 'id' => $model->id]), Yii::$app->urlManager->createUrl(['user/switch-identity', 'id' => $model->id]),
[ [

+ 3
- 0
common/logic/AbstractSingleton.php View File

trigger_error("Le clonage n'est pas autorisé.", E_USER_ERROR); trigger_error("Le clonage n'est pas autorisé.", E_USER_ERROR);
}*/ }*/


/**
* @return $this
*/
final public static function getInstance(): self final public static function getInstance(): self
{ {
$c = get_called_class(); $c = get_called_class();

+ 0
- 1
common/logic/ModuleInterface.php View File

interface ModuleInterface interface ModuleInterface
{ {
public function getContainerFqcn(): string; public function getContainerFqcn(): string;
public function getServices(): ContainerInterface;
} }

+ 0
- 26
common/logic/User/User/Service/UserSolver.php View File

return !\Yii::$app->user->isGuest; return !\Yii::$app->user->isGuest;
} }


/**
* Retourne si l'utilisateur courant est un producteur ou non.
*
*/
public function isCurrentProducer(): bool
{
$user = $this->getCurrent();
if ($user) {
return $this->isProducer($user);
}
return false;
}

/**
* Retourne si l'utilisateur courant est un admin ou non.
*
*/
public function isCurrentAdmin(): bool
{
$user = $this->getCurrent();
if ($user) {
return $this->isAdmin($user);
}
return false;
}

/** /**
* Retourne l'ID de l'utilisateur courant connecté. * Retourne l'ID de l'utilisateur courant connecté.
* *

+ 0
- 5
common/logic/User/User/Wrapper/UserContainer.php View File

{ {
return NewsletterManager::getInstance(); return NewsletterManager::getInstance();
} }

public function getAuthorizationChecker(): AuthorizationChecker
{
return AuthorizationChecker::getInstance();
}
} }

+ 0
- 5
common/logic/User/User/Wrapper/UserModule.php View File

return UserContainer::class; return UserContainer::class;
} }


public function getServices(): UserContainer
{
return $this->container;
}

public function getAuthorizationChecker(): AuthorizationChecker public function getAuthorizationChecker(): AuthorizationChecker
{ {
return AuthorizationChecker::getInstance(); return AuthorizationChecker::getInstance();

+ 2
- 1
common/versions/22.10.A.php View File

"[Backend] Facture > créer : tri des utilisateurs par ordre alphabétique", "[Backend] Facture > créer : tri des utilisateurs par ordre alphabétique",
"Correctif connexion personnes morales" "Correctif connexion personnes morales"
] ]
]
],
$userCurrent
); );


?> ?>

+ 2
- 1
common/versions/22.11.A.php View File

"[Administration] Abonnements : suppression des commandes après la date de fin lors de l'arrêt d'un abonnement", "[Administration] Abonnements : suppression des commandes après la date de fin lors de l'arrêt d'un abonnement",
"[Administration] Distributions > calendrier : amélioration chargement automatique des distributions (affichage pastilles vertes)" "[Administration] Distributions > calendrier : amélioration chargement automatique des distributions (affichage pastilles vertes)"
] ]
]
],
$userCurrent
); );


?> ?>

+ 2
- 1
common/versions/22.11.B.php View File

"[Administration] Développement : mise en avant des nouvelles versions et des informations de contact" "[Administration] Développement : mise en avant des nouvelles versions et des informations de contact"
], ],
[] []
]
],
$userCurrent
); );


?> ?>

+ 2
- 1
common/versions/22.12.A.php View File

"[Administration] Abonnements : comportement paiement automatique (déduit, oui, non)" "[Administration] Abonnements : comportement paiement automatique (déduit, oui, non)"
], ],
[] []
]
],
$userCurrent
); );


?> ?>

+ 2
- 1
common/versions/23.1.A.php View File

"[Administration] Documents > listes : optimisation chargement", "[Administration] Documents > listes : optimisation chargement",
"[Espace producteur] Commander : ajustement ordre des points de vente" "[Espace producteur] Commander : ajustement ordre des points de vente"
] ]
]
],
$userCurrent
); );


?> ?>

+ 1
- 0
common/versions/23.10.A.php View File

"[Administration] Correctif problème upload images webp" "[Administration] Correctif problème upload images webp"
] ]
], ],
$userCurrent
); );


?> ?>

+ 1
- 0
common/versions/23.10.B.php View File

], ],
[] []
], ],
$userCurrent
); );


?> ?>

+ 2
- 1
common/versions/23.3.A.php View File

"[Administration] Export vers le logiciel Evoliz : ajout de la TVA + code classification vente" "[Administration] Export vers le logiciel Evoliz : ajout de la TVA + code classification vente"
], ],
[] []
]
],
$userCurrent
); );


?> ?>

+ 2
- 1
common/versions/23.4.A.php View File

[ [
"Logiciel de caisse Tiller : synchronisation des commandes partiellement payées" "Logiciel de caisse Tiller : synchronisation des commandes partiellement payées"
] ]
]
],
$userCurrent
); );


?> ?>

+ 2
- 1
common/versions/23.6.A.php View File

"[Espace producteur] Produits : mise en évidence des noms de produit", "[Espace producteur] Produits : mise en évidence des noms de produit",
"[Site] Profil utilisateur : permettre édition adresse email" "[Site] Profil utilisateur : permettre édition adresse email"
], ],
]
],
$userCurrent
); );


?> ?>

+ 2
- 1
common/versions/23.6.B.php View File

"[Espace producteur] Abonnements : correctif disponibilité produits par point de vente", "[Espace producteur] Abonnements : correctif disponibilité produits par point de vente",
"Abonnements > ajout/modification : prise en compte des contraintes de délai et d'heure limite de commande dans la génération des commandes des distributions à venir" "Abonnements > ajout/modification : prise en compte des contraintes de délai et d'heure limite de commande dans la génération des commandes des distributions à venir"
] ]
]
],
$userCurrent
); );


?> ?>

+ 2
- 1
common/versions/23.7.A.php View File

'[Administration] Distributions > Produits : possibilité de définir une quantité maximum à 0', '[Administration] Distributions > Produits : possibilité de définir une quantité maximum à 0',
'[Technique] Réécriture requêtes bases de données' '[Technique] Réécriture requêtes bases de données'
] ]
]
],
$userCurrent
); );


?> ?>

+ 2
- 1
common/versions/23.8.A.php View File

'[Site & espace producteur] Barre de navigation en haut du site' '[Site & espace producteur] Barre de navigation en haut du site'
], ],
[] []
]
],
$userCurrent
); );


?> ?>

+ 1
- 0
common/versions/23.8.B.php View File

"[Administration et espace producteur] Produits : optimisation de l'affichage des images" "[Administration et espace producteur] Produits : optimisation de l'affichage des images"
] ]
], ],
$userCurrent
); );


?> ?>

+ 1
- 0
common/versions/23.9.A.php View File

"[Technique] ParameterBag : service dédié à la récupération des paramètres système" "[Technique] ParameterBag : service dédié à la récupération des paramètres système"
] ]
], ],
$userCurrent
); );


?> ?>

+ 1
- 0
common/versions/23.9.B.php View File

"[Administration] Tickets admin : flag pour savoir si un ticket a été lu par le producteur" "[Administration] Tickets admin : flag pour savoir si un ticket a été lu par le producteur"
] ]
], ],
$userCurrent
); );


?> ?>

+ 1
- 0
common/versions/23.9.C.php View File

"[Technique] Mise en place Twig" "[Technique] Mise en place Twig"
] ]
], ],
$userCurrent
); );


?> ?>

+ 1
- 0
common/versions/23.9.D.php View File

[], [],
[] []
], ],
$userCurrent
); );


?> ?>

+ 1
- 0
common/versions/23.9.E.php View File

[], [],
[] []
], ],
$userCurrent
); );


?> ?>

+ 8
- 7
common/versions/_macros.php View File

<?php <?php


use common\logic\User\User\Model\User;
use common\logic\User\User\Wrapper\UserModule; use common\logic\User\User\Wrapper\UserModule;


function version(string $date, array $featuresMaintenanceArray, array $featuresMaintenanceAdminArray = []) {
function version(string $date, array $featuresMaintenanceArray, array $featuresMaintenanceAdminArray = [], User $userCurrent) {
release_date($date); release_date($date);
features($featuresMaintenanceArray[0] ?? [], $featuresMaintenanceAdminArray[0] ?? []);
maintenance($featuresMaintenanceArray[1] ?? [], $featuresMaintenanceAdminArray[1] ?? []);
features($featuresMaintenanceArray[0] ?? [], $featuresMaintenanceAdminArray[0] ?? [], $userCurrent);
maintenance($featuresMaintenanceArray[1] ?? [], $featuresMaintenanceAdminArray[1] ?? [], $userCurrent);
} }


function release_date(string $date) { function release_date(string $date) {
echo $html; echo $html;
} }


function features(array $featuresArray, array $featuresAdminArray) {
function features(array $featuresArray, array $featuresAdminArray, User $userCurrent) {
$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();
if(count($featuresArray) > 0 || count($featuresAdminArray) > 0) { if(count($featuresArray) > 0 || count($featuresAdminArray) > 0) {
$html = '<div class="block block-features">'; $html = '<div class="block block-features">';
foreach($featuresArray as $feature) { foreach($featuresArray as $feature) {
$html .= '<li>'.$feature.'</li>'; $html .= '<li>'.$feature.'</li>';
} }
if($userModule->isCurrentAdmin()) {
if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)) {
foreach($featuresAdminArray as $feature) { foreach($featuresAdminArray as $feature) {
$html .= '<li class="admin">'.$feature.'</li>'; $html .= '<li class="admin">'.$feature.'</li>';
} }
} }
} }


function maintenance(array $maintenanceArray, array $maintenanceAdminArray) {
function maintenance(array $maintenanceArray, array $maintenanceAdminArray, User $userCurrent) {
$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();
if(count($maintenanceArray) > 0 || count($maintenanceAdminArray) > 0) { if(count($maintenanceArray) > 0 || count($maintenanceAdminArray) > 0) {
$html = '<div class="block block-maintenance">'; $html = '<div class="block block-maintenance">';
foreach($maintenanceArray as $maintenance) { foreach($maintenanceArray as $maintenance) {
$html .= '<li>'.$maintenance.'</li>'; $html .= '<li>'.$maintenance.'</li>';
} }
if($userModule->isCurrentAdmin()) {
if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)) {
foreach ($maintenanceAdminArray as $maintenance) { foreach ($maintenanceAdminArray as $maintenance) {
$html .= '<li class="admin">' . $maintenance . '</li>'; $html .= '<li class="admin">' . $maintenance . '</li>';
} }

+ 5
- 4
common/views/nav_user_top.php View File

use yii\helpers\Html; use yii\helpers\Html;


$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();

$userCurrent = GlobalParam::getCurrentUser();
$isUserCurrentGrantedAsProducer = $userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent);
$producer = null; $producer = null;
if ($userModule->isCurrentProducer()) {
if ($isUserCurrentGrantedAsProducer) {
$producer = Producer::searchOne(['id' => \Yii::$app->user->identity->id_producer]); $producer = Producer::searchOne(['id' => \Yii::$app->user->identity->id_producer]);
} }


$itemAdministration = [ $itemAdministration = [
'label' => '<span class="glyphicon glyphicon-cog"></span> <span class="link-text">Administration</span>', 'label' => '<span class="glyphicon glyphicon-cog"></span> <span class="link-text">Administration</span>',
'url' => $this->getUrlManagerBackend()->createAbsoluteUrl(['dashboard/index']), 'url' => $this->getUrlManagerBackend()->createAbsoluteUrl(['dashboard/index']),
'visible' => $userModule->isCurrentProducer(),
'visible' => $isUserCurrentGrantedAsProducer,
'linkOptions' => ['class' => 'btn btn-default navbar-btn'] 'linkOptions' => ['class' => 'btn btn-default navbar-btn']
]; ];
$itemProducerSpace = [ $itemProducerSpace = [
'label' => '<span class="glyphicon glyphicon-eye-open"></span> <span class="link-text">Mon espace producteur</span>', 'label' => '<span class="glyphicon glyphicon-eye-open"></span> <span class="link-text">Mon espace producteur</span>',
'url' => $this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer ? $producer->slug : '']), 'url' => $this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer ? $producer->slug : '']),
'visible' => $userModule->isCurrentProducer(),
'visible' => $isUserCurrentGrantedAsProducer,
'linkOptions' => ['class' => 'btn btn-default navbar-btn'] 'linkOptions' => ['class' => 'btn btn-default navbar-btn']
]; ];
$itemProducers = [ $itemProducers = [

+ 4
- 1
frontend/views/layouts/main.php View File

* termes. * termes.
*/ */


use common\helpers\GlobalParam;
use common\logic\User\User\Wrapper\UserModule; use common\logic\User\User\Wrapper\UserModule;
use yii\helpers\Html; use yii\helpers\Html;
use yii\bootstrap\Nav; use yii\bootstrap\Nav;
\frontend\assets\AppAsset::register($this); \frontend\assets\AppAsset::register($this);


$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();
$userCurrent = GlobalParam::getCurrentUser();
$isUserCurrentGrantedAsProducer = $userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent);
$isHome = (Yii::$app->controller->id == 'site' && \Yii::$app->controller->action->id == 'index'); $isHome = (Yii::$app->controller->id == 'site' && \Yii::$app->controller->action->id == 'index');
$producer = null; $producer = null;
if ($userModule->isCurrentProducer()) {
if ($isUserCurrentGrantedAsProducer) {
$producer = Producer::searchOne(['id' => \Yii::$app->user->identity->id_producer]); $producer = Producer::searchOne(['id' => \Yii::$app->user->identity->id_producer]);
} }



+ 1
- 2
producer/views/layouts/main.php View File

*/ */


use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Wrapper\ProducerManager; use common\logic\Producer\Producer\Wrapper\ProducerManager;
use common\logic\User\User\Wrapper\UserModule; use common\logic\User\User\Wrapper\UserModule;
use common\logic\User\UserProducer\Model\UserProducer; use common\logic\User\UserProducer\Model\UserProducer;
$userCurrent = GlobalParam::getCurrentUser(); $userCurrent = GlobalParam::getCurrentUser();
$producerManager = ProducerManager::getInstance(); $producerManager = ProducerManager::getInstance();
$producerUser = null; $producerUser = null;
if($userModule->isCurrentProducer()) {
if($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)) {
$producerUser = $producerManager->findOneProducerById($userCurrent->id_producer); $producerUser = $producerManager->findOneProducerById($userCurrent->id_producer);
} }
$producer = $this->context->getProducerCurrent(); $producer = $this->context->getProducerCurrent();

Loading…
Cancel
Save