Ejemplo n.º 1
0
 /**
  * @param $website
  *
  * @since 1.0
  * @author Choate <*****@*****.**>
  * @return bool
  * @throws ForbiddenHttpException
  */
 public static function checkAccess($website)
 {
     if (!\Yii::$app->user->id || !WebsiteHasUser::find()->can($website, \Yii::$app->user->id)) {
         throw new ForbiddenHttpException(\Yii::t('yii', 'You are not allowed to perform this action.'));
     }
     return true;
 }
Ejemplo n.º 2
0
 public function safeDown()
 {
     $this->dropTable('IF EXISTS ' . Websites::tableName());
     $this->dropTable('IF EXISTS ' . Tasks::tableName());
     $this->dropTable('IF EXISTS ' . Deploy::tableName());
     $this->dropTable('IF EXISTS ' . DeployHasTasks::tableName());
     $this->dropTable('IF EXISTS ' . WebsiteHasUser::tableName());
     return true;
 }
Ejemplo n.º 3
0
 public function actionUpdate($id)
 {
     /* @var Websites $model */
     $model = Websites::findOne($id);
     $form = new WebsiteForm();
     if ($form->load($_POST) && $form->validate()) {
         $model->setAttributes($form->getAttributes(null, ['user_id']), false);
         $model->on(Websites::EVENT_AFTER_UPDATE, function ($event) use($form) {
             $model = $event->sender;
             WebsiteHasUser::deleteAll(['website_id' => $model->id]);
             if ($form->user_id) {
                 WebsiteHasUser::batchInsertByCondition(['user_id'], explode(',', $form->user_id), ['website_id' => $model->id]);
             }
         });
         $model->update(false);
         return $this->redirect('index');
     }
     $form->setAttributes($model->getAttributes());
     $form->user_id = implode(',', ArrayHelper::getColumn($model->websiteHasUser, 'user_id'));
     return $this->render('update', ['model' => $form]);
 }
Ejemplo n.º 4
0
 public function getWebsiteHasUser()
 {
     return $this->hasMany(WebsiteHasUser::className(), ['website_id' => 'id']);
 }