mirror of
https://github.com/CyanoFresh/SmartHomePHP.git
synced 2026-02-20 03:11:26 +01:00
Close #36 - admin panel only for admins
This commit is contained in:
@@ -23,6 +23,8 @@ use yii\web\IdentityInterface;
|
||||
* @property integer $created_at
|
||||
* @property integer $updated_at
|
||||
*
|
||||
* @property boolean $isAdmin
|
||||
*
|
||||
* @property string $password write-only password
|
||||
*/
|
||||
class User extends ActiveRecord implements IdentityInterface
|
||||
@@ -273,4 +275,12 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
{
|
||||
return $this->hasMany(History::className(), ['user_id' => 'id'])->inverseOf('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsAdmin()
|
||||
{
|
||||
return $this->group === self::GROUP_ADMIN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace app\modules\admin;
|
||||
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* admin module definition class
|
||||
@@ -13,6 +15,26 @@ class Module extends \yii\base\Module
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $controllerNamespace = 'app\modules\admin\controllers';
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return ArrayHelper::merge(parent::behaviors(), [
|
||||
'access' => [
|
||||
'class' => AccessControl::className(),
|
||||
'rules' => [
|
||||
[
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
'matchCallback' => function () {
|
||||
return Yii::$app->user->identity->isAdmin;
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\api\controllers;
|
||||
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Default controller for the `api` module
|
||||
*/
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* Renders the index view for the module
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ namespace app\modules\api\controllers;
|
||||
|
||||
use app\models\Board;
|
||||
use app\models\Item;
|
||||
use app\models\Trigger;
|
||||
use app\modules\api\components\WebSocketAPIBridge;
|
||||
use Yii;
|
||||
use yii\base\InvalidParamException;
|
||||
|
||||
@@ -16,6 +16,7 @@ class PanelController extends Controller
|
||||
{
|
||||
return [
|
||||
'schedule-triggers' => ['POST'],
|
||||
'update-items' => ['POST'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class TriggerController extends Controller
|
||||
* @return Trigger
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
private function findTrigger($id)
|
||||
protected function findTrigger($id)
|
||||
{
|
||||
$item = Trigger::findOne($id);
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<div class="api-default-index">
|
||||
<h1><?= $this->context->action->uniqueId ?></h1>
|
||||
<p>
|
||||
This is the view content for action "<?= $this->context->action->id ?>".
|
||||
The action belongs to the controller "<?= get_class($this->context) ?>"
|
||||
in the "<?= $this->context->module->id ?>" module.
|
||||
</p>
|
||||
<p>
|
||||
You may customize this page by editing the following file:<br>
|
||||
<code><?= __FILE__ ?></code>
|
||||
</p>
|
||||
</div>
|
||||
@@ -18,19 +18,19 @@
|
||||
[
|
||||
'options' => ['class' => 'sidebar-menu'],
|
||||
'items' => [
|
||||
['label' => 'Smart Home', 'options' => ['class' => 'header']],
|
||||
['label' => 'Управление', 'options' => ['class' => 'header']],
|
||||
['label' => 'Панель Управления', 'icon' => 'fa fa-sliders', 'url' => ['/panel/index']],
|
||||
['label' => 'История', 'icon' => 'fa fa-th-list', 'url' => ['/history/index']],
|
||||
|
||||
['label' => 'Администрирование', 'options' => ['class' => 'header']],
|
||||
['label' => 'Элементы', 'icon' => 'fa fa-toggle-on', 'url' => ['/admin/item/index']],
|
||||
['label' => 'Устройства', 'icon' => 'fa fa-hdd-o', 'url' => ['/admin/board/index']],
|
||||
['label' => 'Триггеры', 'icon' => 'fa fa-feed', 'url' => ['/admin/trigger/index']],
|
||||
['label' => 'Задачи', 'icon' => 'fa fa-check', 'url' => ['/admin/task/index']],
|
||||
['label' => 'Комнаты', 'icon' => 'fa fa-folder-open', 'url' => ['/admin/room/index']],
|
||||
['label' => 'Параметры', 'icon' => 'fa fa-cogs', 'url' => ['/admin/setting/index']],
|
||||
// ['label' => 'История', 'icon' => 'fa fa-bar-chart', 'url' => ['/admin/history/index']],
|
||||
['label' => 'Пользователи', 'icon' => 'fa fa-users', 'url' => ['/admin/user/index']],
|
||||
['label' => 'Администрирование', 'options' => ['class' => 'header'], 'visible' => Yii::$app->user->identity->isAdmin],
|
||||
['label' => 'Элементы', 'icon' => 'fa fa-toggle-on', 'url' => ['/admin/item/index'], 'visible' => Yii::$app->user->identity->isAdmin],
|
||||
['label' => 'Устройства', 'icon' => 'fa fa-hdd-o', 'url' => ['/admin/board/index'], 'visible' => Yii::$app->user->identity->isAdmin],
|
||||
['label' => 'Триггеры', 'icon' => 'fa fa-feed', 'url' => ['/admin/trigger/index'], 'visible' => Yii::$app->user->identity->isAdmin],
|
||||
['label' => 'Задачи', 'icon' => 'fa fa-check', 'url' => ['/admin/task/index'], 'visible' => Yii::$app->user->identity->isAdmin],
|
||||
['label' => 'Комнаты', 'icon' => 'fa fa-folder-open', 'url' => ['/admin/room/index'], 'visible' => Yii::$app->user->identity->isAdmin],
|
||||
['label' => 'Параметры', 'icon' => 'fa fa-cogs', 'url' => ['/admin/setting/index'], 'visible' => Yii::$app->user->identity->isAdmin],
|
||||
// ['label' => 'История', 'icon' => 'fa fa-bar-chart', 'url' => ['/admin/history/index'], 'visible' => Yii::$app->user->identity->isAdmin],
|
||||
['label' => 'Пользователи', 'icon' => 'fa fa-users', 'url' => ['/admin/user/index'], 'visible' => Yii::$app->user->identity->isAdmin],
|
||||
],
|
||||
]
|
||||
) ?>
|
||||
|
||||
Reference in New Issue
Block a user