diff --git a/models/User.php b/models/User.php index 72454f0..aac6a2e 100644 --- a/models/User.php +++ b/models/User.php @@ -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; + } } diff --git a/modules/admin/Module.php b/modules/admin/Module.php index 2eeba75..dbf344e 100644 --- a/modules/admin/Module.php +++ b/modules/admin/Module.php @@ -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 diff --git a/modules/api/controllers/DefaultController.php b/modules/api/controllers/DefaultController.php deleted file mode 100644 index 41f3d03..0000000 --- a/modules/api/controllers/DefaultController.php +++ /dev/null @@ -1,20 +0,0 @@ -render('index'); - } -} diff --git a/modules/api/controllers/ItemController.php b/modules/api/controllers/ItemController.php index 9ec0f52..983ca86 100644 --- a/modules/api/controllers/ItemController.php +++ b/modules/api/controllers/ItemController.php @@ -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; diff --git a/modules/api/controllers/PanelController.php b/modules/api/controllers/PanelController.php index dc3d94e..0f03de3 100644 --- a/modules/api/controllers/PanelController.php +++ b/modules/api/controllers/PanelController.php @@ -16,6 +16,7 @@ class PanelController extends Controller { return [ 'schedule-triggers' => ['POST'], + 'update-items' => ['POST'], ]; } diff --git a/modules/api/controllers/TriggerController.php b/modules/api/controllers/TriggerController.php index ff56712..135ff89 100644 --- a/modules/api/controllers/TriggerController.php +++ b/modules/api/controllers/TriggerController.php @@ -55,7 +55,7 @@ class TriggerController extends Controller * @return Trigger * @throws NotFoundHttpException */ - private function findTrigger($id) + protected function findTrigger($id) { $item = Trigger::findOne($id); diff --git a/modules/api/views/default/index.php b/modules/api/views/default/index.php deleted file mode 100644 index aa260c4..0000000 --- a/modules/api/views/default/index.php +++ /dev/null @@ -1,12 +0,0 @@ -
- 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. -
-
- You may customize this page by editing the following file:
- = __FILE__ ?>
-