@@ -52,11 +52,6 @@ class AccessController extends BackendController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -64,7 +59,9 @@ class AccessController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -66,7 +66,9 @@ class CommunicateAdminController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->isCurrentAdmin(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsAdministrator($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -64,7 +64,9 @@ class CommunicateController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -56,7 +56,9 @@ class CreditController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -59,16 +59,13 @@ class DashboardController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
], | |||
], | |||
], | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
]; | |||
} | |||
@@ -48,11 +48,6 @@ class DeliveryNoteController extends DocumentController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -60,7 +55,9 @@ class DeliveryNoteController extends DocumentController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -59,7 +59,9 @@ class DevelopmentController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -75,8 +75,9 @@ class DistributionController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
$userModule = $this->getUserModule(); | |||
return $userModule->isCurrentAdmin() || $userModule->isCurrentProducer(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -64,11 +64,6 @@ class DocumentController extends BackendController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -76,7 +71,9 @@ class DocumentController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -69,8 +69,9 @@ class OrderController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->isCurrentProducer() | |||
|| $this->getUserModule()->isCurrentAdmin(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -55,11 +55,6 @@ class PointSaleController extends BackendController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -67,7 +62,9 @@ class PointSaleController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
], | |||
], |
@@ -68,7 +68,9 @@ class ProducerAdminController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->isCurrentAdmin(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsAdministrator($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -72,7 +72,9 @@ class ProducerController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -53,11 +53,6 @@ class ProducerPriceRangeAdminController extends BackendController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -65,7 +60,9 @@ class ProducerPriceRangeAdminController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->isCurrentAdmin(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsAdministrator($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -55,11 +55,6 @@ class ProductCategoryController extends BackendController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -67,7 +62,9 @@ class ProductCategoryController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
], | |||
], |
@@ -68,11 +68,6 @@ class ProductController extends BackendController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -80,7 +75,9 @@ class ProductController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -41,10 +41,8 @@ namespace backend\controllers; | |||
use common\helpers\GlobalParam; | |||
use common\logic\Document\Quotation\Model\QuotationSearch; | |||
use common\logic\Order\Order\Model\Order; | |||
use Yii; | |||
use yii\base\UserException; | |||
use yii\filters\AccessControl; | |||
use yii\filters\VerbFilter; | |||
use yii\helpers\Html; | |||
class QuotationController extends DocumentController | |||
@@ -52,11 +50,6 @@ class QuotationController extends DocumentController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -64,7 +57,9 @@ class QuotationController extends DocumentController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -57,7 +57,9 @@ class ReportController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -67,7 +67,9 @@ class SiteController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
], | |||
[ | |||
@@ -75,7 +77,9 @@ class SiteController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->getCurrentStatus() == User::STATUS_ADMIN; | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsAdministrator($this->getUserCurrent()); | |||
} | |||
], | |||
], |
@@ -56,7 +56,9 @@ class StatsAdminController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->isUserCurrentAdmin(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsAdministrator($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -41,9 +41,6 @@ namespace backend\controllers; | |||
use common\helpers\GlobalParam; | |||
use yii\filters\AccessControl; | |||
use Yii; | |||
use DateTime; | |||
use DateInterval; | |||
use DatePeriod; | |||
class StatsController extends BackendController | |||
{ | |||
@@ -57,7 +54,9 @@ class StatsController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -58,7 +58,9 @@ class SubscriptionController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -51,10 +51,6 @@ class SupportAdminController extends SupportController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -62,7 +58,9 @@ class SupportAdminController extends SupportController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->isCurrentAdmin(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -41,7 +41,6 @@ namespace backend\controllers; | |||
use common\logic\Ticket\Ticket\Model\Ticket; | |||
use common\logic\Ticket\Ticket\Model\TicketSearch; | |||
use yii\filters\AccessControl; | |||
use yii\filters\VerbFilter; | |||
use yii\helpers\Html; | |||
use yii\web\NotFoundHttpException; | |||
@@ -50,11 +49,6 @@ class SupportController extends BackendController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -62,7 +56,9 @@ class SupportController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -39,7 +39,6 @@ | |||
namespace backend\controllers; | |||
use common\logic\Config\TaxRate\Model\TaxRate; | |||
use Yii; | |||
use yii\web\NotFoundHttpException; | |||
use yii\filters\VerbFilter; | |||
use yii\filters\AccessControl; | |||
@@ -66,7 +65,9 @@ class TaxRateAdminController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->isUserCurrentAdmin(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsAdministrator($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -41,15 +41,12 @@ namespace backend\controllers; | |||
use backend\models\CreditForm; | |||
use common\helpers\GlobalParam; | |||
use backend\models\MailForm; | |||
use common\helpers\MeanPayment; | |||
use common\helpers\Password; | |||
use common\logic\Order\Order\Model\OrderSearch; | |||
use common\logic\PointSale\PointSale\Model\PointSale; | |||
use common\logic\PointSale\UserPointSale\Model\UserPointSale; | |||
use common\logic\Payment\Model\Payment; | |||
use common\logic\User\User\Model\User; | |||
use common\logic\User\User\Model\UserSearch; | |||
use common\logic\User\User\Wrapper\UserModule; | |||
use common\logic\User\UserProducer\Model\UserProducer; | |||
use common\logic\User\UserUserGroup\Model\UserUserGroup; | |||
use yii\base\UserException; | |||
@@ -73,7 +70,9 @@ class UserController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
] | |||
], |
@@ -41,10 +41,8 @@ namespace backend\controllers; | |||
use common\helpers\GlobalParam; | |||
use common\logic\User\UserGroup\Model\UserGroupSearch; | |||
use common\logic\User\UserUserGroup\Model\UserUserGroup; | |||
use Yii; | |||
use yii\filters\AccessControl; | |||
use yii\web\NotFoundHttpException; | |||
use yii\filters\VerbFilter; | |||
use yii\helpers\Html; | |||
/** | |||
@@ -56,11 +54,6 @@ class UserGroupController extends BackendController | |||
public function behaviors() | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
@@ -68,7 +61,9 @@ class UserGroupController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule()->hasAccessBackend(); | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsProducer($this->getUserCurrent()); | |||
} | |||
], | |||
], |
@@ -263,6 +263,11 @@ class User extends ActiveRecordCommon implements IdentityInterface | |||
return $this->lastname; | |||
} | |||
public function getStatus(): string | |||
{ | |||
return $this->status; | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ |
@@ -0,0 +1,45 @@ | |||
<?php | |||
namespace common\logic\User\User\Service; | |||
use common\logic\AbstractUtils; | |||
use common\logic\User\User\Model\User; | |||
class AuthorizationChecker extends AbstractUtils | |||
{ | |||
protected UserSolver $userSolver; | |||
public function loadDependencies(): void | |||
{ | |||
$this->userSolver = $this->loadService(UserSolver::class); | |||
} | |||
public function isGrantedAsAdministrator(User $user = null): bool | |||
{ | |||
if(!$user) { | |||
return false; | |||
} | |||
return $this->userSolver->isStatusAdministrator($user); | |||
} | |||
public function isGrantedAsProducer(User $user = null): bool | |||
{ | |||
if(!$user) { | |||
return false; | |||
} | |||
return $this->isGrantedAsAdministrator($user) | |||
|| $this->userSolver->isStatusProducer($user); | |||
} | |||
public function isGrantedAsUser(User $user = null): bool | |||
{ | |||
if(!$user) { | |||
return false; | |||
} | |||
return $this->isGrantedAsProducer($user) | |||
|| $this->userSolver->isStatusUser($user); | |||
} | |||
} |
@@ -130,6 +130,11 @@ class UserSolver extends AbstractService implements SolverInterface | |||
return $user->status == User::STATUS_ADMIN; | |||
} | |||
public function isStatusAdministrator(User $user): bool | |||
{ | |||
return $user->getStatus() == User::STATUS_ADMIN; | |||
} | |||
/** | |||
* Retourne si l'utilisateur est un producteur ou non. | |||
* | |||
@@ -140,6 +145,16 @@ class UserSolver extends AbstractService implements SolverInterface | |||
|| $user->status == User::STATUS_PRODUCER) && $user->id_producer; | |||
} | |||
public function isStatusProducer(User $user): bool | |||
{ | |||
return $user->getStatus() == User::STATUS_PRODUCER; | |||
} | |||
public function isStatusUser(User $user): bool | |||
{ | |||
return $user->getStatus() == User::STATUS_ACTIVE; | |||
} | |||
/** | |||
* Retourne l'utilisateur courant. | |||
* |
@@ -5,14 +5,13 @@ namespace common\logic\User\User\Wrapper; | |||
use common\logic\AbstractContainer; | |||
use common\logic\User\User\Repository\UserRepository; | |||
use common\logic\User\User\Repository\UserRepositoryQuery; | |||
use common\logic\User\User\Service\AuthorizationChecker; | |||
use common\logic\User\User\Service\NewsletterManager; | |||
use common\logic\User\User\Service\NewsletterUtils; | |||
use common\logic\User\User\Service\UserBuilder; | |||
use common\logic\User\User\Service\UserDefinition; | |||
use common\logic\User\User\Service\UserNotifier; | |||
use common\logic\User\User\Service\UsersCreditCsvGenerator; | |||
use common\logic\User\User\Service\UserSolver; | |||
use common\logic\User\User\Service\UserUtils; | |||
class UserContainer extends AbstractContainer | |||
{ | |||
@@ -27,6 +26,7 @@ class UserContainer extends AbstractContainer | |||
UserNotifier::class, | |||
UsersCreditCsvGenerator::class, | |||
NewsletterManager::class, | |||
AuthorizationChecker::class, | |||
]; | |||
} | |||
@@ -59,4 +59,9 @@ class UserContainer extends AbstractContainer | |||
{ | |||
return NewsletterManager::getInstance(); | |||
} | |||
public function getAuthorizationChecker(): AuthorizationChecker | |||
{ | |||
return AuthorizationChecker::getInstance(); | |||
} | |||
} |
@@ -4,6 +4,7 @@ namespace common\logic\User\User\Wrapper; | |||
use common\logic\AbstractModule; | |||
use common\logic\User\User\Repository\UserRepository; | |||
use common\logic\User\User\Service\AuthorizationChecker; | |||
use common\logic\User\User\Service\NewsletterManager; | |||
use common\logic\User\User\Service\UserBuilder; | |||
use common\logic\User\User\Service\UserDefinition; | |||
@@ -19,6 +20,7 @@ use common\logic\User\User\Service\UserSolver; | |||
* @mixin UserNotifier | |||
* @mixin UsersCreditCsvGenerator | |||
* @mixin NewsletterManager | |||
* @mixin AuthorizationChecker | |||
*/ | |||
class UserModule extends AbstractModule | |||
{ | |||
@@ -31,4 +33,9 @@ class UserModule extends AbstractModule | |||
{ | |||
return $this->container; | |||
} | |||
public function getAuthorizationChecker(): AuthorizationChecker | |||
{ | |||
return AuthorizationChecker::getInstance(); | |||
} | |||
} |
@@ -42,7 +42,6 @@ use common\helpers\GlobalParam; | |||
use common\helpers\MeanPayment; | |||
use common\logic\Payment\Model\Payment; | |||
use producer\models\CreditForm; | |||
use yii\data\ActiveDataProvider; | |||
use yii\filters\VerbFilter; | |||
class CreditController extends ProducerBaseController | |||
@@ -54,7 +53,7 @@ class CreditController extends ProducerBaseController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
'stripe-verification' => ['post'], | |||
], |