Esempio n. 1
0
 public function actionSetuprbac()
 {
     $permissions = [$this->module->id . ':view', $this->module->id . ':create', $this->module->id . ':update', $this->module->id . ':updateOwn', $this->module->id . ':delete', $this->module->id . ':deleteOwn'];
     \app\modules\member\models\LetAuthItem::deleteAll(['in', 'name', $permissions]);
     \app\modules\member\models\LetAuthItemChild::deleteAll(['in', 'child', $permissions]);
     $auth = Yii::$app->authManager;
     // Rule
     $rule = $auth->getRule('isAuthor');
     if (empty($rule)) {
         $rule = new \app\rbac\AuthorRule();
         $auth->add($rule);
     }
     // Permission
     $admin = $auth->getRole('admin');
     $member = $auth->getRole('member');
     foreach ($permissions as $permission) {
         $create = $auth->createPermission($permission);
         if ($permission == $this->module->id . ':create') {
             $auth->add($create);
             $auth->addChild($member, $create);
         } elseif ($permission == $this->module->id . ':updateOwn' or $permission == $this->module->id . ':deleteOwn') {
             $create->ruleName = $rule->name;
             $auth->add($create);
             $auth->addChild($member, $create);
         } else {
             $auth->add($create);
         }
         $auth->addChild($admin, $create);
         unset($create);
     }
     $updateOwn = $auth->getPermission($this->module->id . ':updateOwn');
     $update = $auth->getPermission($this->module->id . ':update');
     $auth->addChild($updateOwn, $update);
 }
Esempio n. 2
0
 /**
  * Delete a role
  */
 public function actionDeleteitem()
 {
     $id = Yii::$app->request->post('id');
     $model = LetAuthItem::find()->where('name = :id', [':id' => $id])->one();
     if ($model === null) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     echo $model->delete() ? 1 : 0;
 }
Esempio n. 3
0
 public function search($params)
 {
     $query = LetAuthItem::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['type' => $this->type, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'rule_name', $this->rule_name])->andFilterWhere(['like', 'data', $this->data]);
     return $dataProvider;
 }
Esempio n. 4
0
 /**
  * Assign roles to id.
  * @param string
  * @return mixed
  */
 public function actionAssign()
 {
     $auth = Yii::$app->authManager;
     $user_id = Yii::$app->request->get('user_id');
     if (empty($user_id)) {
         return $this->redirect(['backend/default/index']);
     }
     if (Yii::$app->request->post()) {
         //delete all roles of id
         $auth->revokeAll($user_id);
         $roles = Yii::$app->request->post('role');
         foreach ($roles as $role) {
             $adminRole = $auth->getRole($role);
             $auth->assign($adminRole, $user_id);
         }
     }
     $assign['itemsRole'] = ArrayHelper::map(LetAuthItem::getItems(LetAuthItem::TYPE_ROLE), 'name', 'name');
     $assign['checked'] = ArrayHelper::map($auth->getRolesByUser($user_id), 'name', 'name');
     $assign['user_id'] = $user_id;
     return $this->render('assign', $assign);
 }