Add BackendController/AccesControl

Add the BackendController for all the backend controllers.
Add AccesControl
This commit is contained in:
rocho 2015-11-02 17:27:47 +01:00
parent 1ee0a6bbe9
commit ed1e0b6c2a
17 changed files with 160 additions and 321 deletions

View File

@ -29,43 +29,42 @@ class AdminMenuStructure{
$userMainMenu = null; $userMainMenu = null;
$items = []; $items = [];
if (!Yii::$app->user->isGuest) {
//$today = \Yii::$app->formatter->asDate( time() );
$today = \Yii::$app->formatter->asDate( strtotime('today UTC') );
$tomorrow = \Yii::$app->formatter->asDate( ( 60 *60 *24 + time()));
// if ( $this->can('backend.user.index')){
$items[] = ['label' => 'Felhasználók', 'url' =>['/user/index']];
// }
$items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']];
$items[] = ['label' => 'Kasszák', 'url' =>['/account/index']];
$items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ];
$items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ];
$items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ];
$items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ];
$items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ];
$items[] = ['label' => 'Vendégek', 'url' => ['/customer/index'] ];
$items[] = ['label' => 'Bérletkártyák', 'url' => ['/card/index'] ];
$items[] = ['label' => 'Pénznem', 'url' => ['/currency/index'] ];
//$today = \Yii::$app->formatter->asDate( time() );
$today = \Yii::$app->formatter->asDate( strtotime('today UTC') );
$items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index' , 'TransferSearch[start]' =>$today,'TransferSearch[end]' => $tomorrow ] ]; $tomorrow = \Yii::$app->formatter->asDate( ( 60 *60 *24 + time()));
$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
// if ( $this->can('backend.user.index')){
if ( count($items) > 0 ){ $items[] = ['label' => 'Felhasználók', 'url' =>['/user/index']];
$userMainMenu = ['label' => 'Beállítások', 'url' => null, // }
'items' => $items
]; $items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']];
$items[] = ['label' => 'Kasszák', 'url' =>['/account/index']];
$items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ];
$items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ];
$items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ];
$items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ];
$items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ];
$items[] = ['label' => 'Vendégek', 'url' => ['/customer/index'] ];
$items[] = ['label' => 'Bérletkártyák', 'url' => ['/card/index'] ];
$items[] = ['label' => 'Pénznem', 'url' => ['/currency/index'] ];
$items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index' , 'TransferSearch[start]' =>$today,'TransferSearch[end]' => $tomorrow ] ];
$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
if ( count($items) > 0 ){
$userMainMenu = ['label' => 'Beállítások', 'url' => null,
'items' => $items
];
}
if ( isset($userMainMenu)){
$this->menuItems[] = $userMainMenu;
}
} }
if ( isset($userMainMenu)){
$this->menuItems[] = $userMainMenu;
}
} }

View File

@ -12,31 +12,8 @@ use yii\filters\VerbFilter;
/** /**
* AccountController implements the CRUD actions for Account model. * AccountController implements the CRUD actions for Account model.
*/ */
class AccountController extends Controller class AccountController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => [ 'index','view','create','update'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/** /**
* Lists all Account models. * Lists all Account models.
@ -102,18 +79,6 @@ class AccountController extends Controller
} }
} }
/**
* Deletes an existing Account model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
// public function actionDelete($id)
// {
// $this->findModel($id)->delete();
// return $this->redirect(['index']);
// }
/** /**
* Finds the Account model based on its primary key value. * Finds the Account model based on its primary key value.

View File

@ -14,19 +14,8 @@ use common\models\User;
/** /**
* AccountStateController implements the CRUD actions for AccountState model. * AccountStateController implements the CRUD actions for AccountState model.
*/ */
class AccountStateController extends Controller class AccountStateController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/** /**
* Lists all AccountState models. * Lists all AccountState models.
@ -104,13 +93,13 @@ class AccountStateController extends Controller
* If deletion is successful, the browser will be redirected to the 'index' page. * If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id * @param integer $id
* @return mixed * @return mixed
*/
public function actionDelete($id) public function actionDelete($id)
{ {
$this->findModel($id)->delete(); $this->findModel($id)->delete();
return $this->redirect(['index']); return $this->redirect(['index']);
} }
*/
/** /**
* Finds the AccountState model based on its primary key value. * Finds the AccountState model based on its primary key value.

View File

@ -0,0 +1,40 @@
<?php
namespace backend\controllers;
use Yii;
use common\models\City;
use backend\models\CitySearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\base\Object;
use yii\db\Query;
use yii\helpers\Json;
/**
* CityController implements the CRUD actions for City model.
*/
class BackendController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
// allow authenticated users
[
'actions' => ['create','index','view','update'],
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
}

View File

@ -16,19 +16,26 @@ use yii\helpers\Json;
/** /**
* CardController implements the CRUD actions for Card model. * CardController implements the CRUD actions for Card model.
*/ */
class CardController extends Controller class CardController extends \backend\controllers\BackendController
{ {
public function behaviors()
{ public function behaviors()
return [ {
'verbs' => [ return [
'class' => VerbFilter::className(), 'access' => [
'actions' => [ 'class' => \yii\filters\AccessControl::className(),
'delete' => ['post'], 'rules' => [
], // allow authenticated users
], [
]; 'actions' => ['create','index','view','update','list'],
} 'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/** /**
* Lists all Card models. * Lists all Card models.

View File

@ -15,19 +15,26 @@ use yii\helpers\Json;
/** /**
* CityController implements the CRUD actions for City model. * CityController implements the CRUD actions for City model.
*/ */
class CityController extends Controller class CityController extends \backend\controllers\BackendController
{ {
public function behaviors() public function behaviors()
{ {
return [ return [
'verbs' => [ 'access' => [
'class' => VerbFilter::className(), 'class' => \yii\filters\AccessControl::className(),
'actions' => [ 'rules' => [
'delete' => ['post'], // allow authenticated users
], [
], 'actions' => [ 'create','index','view','update','name-list','zip-list'],
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
]; ];
} }
/** /**
* Lists all City models. * Lists all City models.

View File

@ -12,19 +12,8 @@ use yii\filters\VerbFilter;
/** /**
* CurrencyController implements the CRUD actions for Currency model. * CurrencyController implements the CRUD actions for Currency model.
*/ */
class CurrencyController extends Controller class CurrencyController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/** /**
* Lists all Currency models. * Lists all Currency models.

View File

@ -15,19 +15,8 @@ use backend\models\CustomerUpdate;
/** /**
* CustomerController implements the CRUD actions for Customer model. * CustomerController implements the CRUD actions for Customer model.
*/ */
class CustomerController extends Controller class CustomerController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/** /**
* Lists all Customer models. * Lists all Customer models.
@ -105,7 +94,6 @@ class CustomerController extends Controller
* If deletion is successful, the browser will be redirected to the 'index' page. * If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id * @param integer $id
* @return mixed * @return mixed
*/
public function actionDelete($id) public function actionDelete($id)
{ {
$this->findModel($id)->delete(); $this->findModel($id)->delete();
@ -113,6 +101,7 @@ class CustomerController extends Controller
return $this->redirect(['index']); return $this->redirect(['index']);
} }
*/
/** /**
* Finds the Customer model based on its primary key value. * Finds the Customer model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.

View File

@ -12,31 +12,8 @@ use yii\filters\VerbFilter;
/** /**
* DiscountController implements the CRUD actions for Discount model. * DiscountController implements the CRUD actions for Discount model.
*/ */
class DiscountController extends Controller class DiscountController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => [ 'index','view','create','update'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/** /**
* Lists all Discount models. * Lists all Discount models.

View File

@ -15,32 +15,29 @@ use common\models\User;
/** /**
* ProcurementController implements the CRUD actions for Procurement model. * ProcurementController implements the CRUD actions for Procurement model.
*/ */
class ProcurementController extends Controller class ProcurementController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => [ 'index','view','create','update'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
// allow authenticated users
[
'actions' => ['create','index','view', 'create-product'],
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/** /**
* Lists all Procurement models. * Lists all Procurement models.
* @return mixed * @return mixed

View File

@ -12,32 +12,8 @@ use yii\filters\VerbFilter;
/** /**
* ProductCategoryController implements the CRUD actions for ProductCategory model. * ProductCategoryController implements the CRUD actions for ProductCategory model.
*/ */
class ProductCategoryController extends Controller class ProductCategoryController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => [ 'index','view','create','update'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/** /**
* Lists all ProductCategory models. * Lists all ProductCategory models.

View File

@ -14,31 +14,8 @@ use common\models\ProductCategory;
/** /**
* ProductController implements the CRUD actions for Product model. * ProductController implements the CRUD actions for Product model.
*/ */
class ProductController extends Controller class ProductController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => [ 'index','view','create','update'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/** /**

View File

@ -15,19 +15,8 @@ use common\models\Account;
/** /**
* TicketController implements the CRUD actions for Ticket model. * TicketController implements the CRUD actions for Ticket model.
*/ */
class TicketController extends Controller class TicketController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/** /**
* Lists all Ticket models. * Lists all Ticket models.

View File

@ -13,31 +13,8 @@ use common\models\Account;
/** /**
* TicketTypeController implements the CRUD actions for TicketType model. * TicketTypeController implements the CRUD actions for TicketType model.
*/ */
class TicketTypeController extends Controller class TicketTypeController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => [ 'index','view','create','update'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/** /**
* Lists all TicketType models. * Lists all TicketType models.

View File

@ -14,19 +14,26 @@ use common\models\User;
/** /**
* TransferController implements the CRUD actions for Transfer model. * TransferController implements the CRUD actions for Transfer model.
*/ */
class TransferController extends Controller class TransferController extends \backend\controllers\BackendController
{ {
public function behaviors() public function behaviors()
{ {
return [ return [
'verbs' => [ 'access' => [
'class' => VerbFilter::className(), 'class' => \yii\filters\AccessControl::className(),
'actions' => [ 'rules' => [
'delete' => ['post'], // allow authenticated users
], [
], 'actions' => [ 'index','view' ],
]; 'allow' => true,
} 'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/** /**
* Lists all Transfer models. * Lists all Transfer models.
@ -71,7 +78,6 @@ class TransferController extends Controller
* If update is successful, the browser will be redirected to the 'view' page. * If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id * @param integer $id
* @return mixed * @return mixed
*/
public function actionUpdate($id) public function actionUpdate($id)
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
@ -85,6 +91,7 @@ class TransferController extends Controller
} }
} }
*/
/** /**
* Finds the Transfer model based on its primary key value. * Finds the Transfer model based on its primary key value.

View File

@ -17,32 +17,9 @@ use common\models\UserAccountAssignment;
/** /**
* UserController implements the CRUD actions for User model. * UserController implements the CRUD actions for User model.
*/ */
class UserController extends Controller class UserController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => [ 'index', 'create','update','view'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/** /**
* Lists all User models. * Lists all User models.

View File

@ -13,31 +13,8 @@ use yii\base\Object;
/** /**
* WarehouseController implements the CRUD actions for Warehouse model. * WarehouseController implements the CRUD actions for Warehouse model.
*/ */
class WarehouseController extends Controller class WarehouseController extends \backend\controllers\BackendController
{ {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => [ 'create','update','view','index'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/** /**
* Lists all Warehouse models. * Lists all Warehouse models.