/** * 配置项目 * * @param $projectId * @return string * @throws \Exception */ public function actionGroup($projectId) { // 配置信息 $project = $this->findModel($projectId); // 添加用户 if (\Yii::$app->request->getIsPost() && \Yii::$app->request->post('user')) { Group::addGroupUser($projectId, \Yii::$app->request->post('user')); } // 项目的分组用户 $group = Group::find()->with('user')->where(['project_id' => $projectId])->indexBy('user_id')->orderBy(['type' => SORT_DESC])->asArray()->all(); // 所有用户 $users = User::find()->select(['id', 'email', 'realname'])->where(['is_email_verified' => 1])->asArray()->all(); return $this->render('group', ['conf' => $project, 'users' => $users, 'group' => $group]); }
/** * 配置项目 * * @param $projectId * @return string * @throws \Exception */ public function actionGroup($projectId) { // 配置信息 $project = Project::findOne($projectId); if (!$project) { throw new \Exception('项目不存在:)'); } if ($project->user_id != $this->uid) { throw new \Exception('不可以操作其它人的项目:)'); } // 添加用户 if (\Yii::$app->request->getIsPost() && \Yii::$app->request->post('user')) { Group::addGroupUser($projectId, \Yii::$app->request->post('user')); } // 项目的分组用户 $group = Group::find()->with('user')->where(['project_id' => $projectId])->indexBy('user_id')->asArray()->all(); // 所有用户 $users = User::find()->select(['id', 'email', 'realname'])->where(['is_email_verified' => 1])->asArray()->all(); return $this->render('group', ['conf' => $project, 'users' => $users, 'group' => $group]); }
/** * 添加数据保存事件afterSave * * @author wushuiyong * @param bool $insert * @param array $changedAttributes */ public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); // 插入一条管理员关系 if ($insert) { Group::addGroupUser($this->attributes['id'], [$this->attributes['user_id']], Group::TYPE_ADMIN); } }
/** * 添加数据保存事件afterSave * * @author wushuiyong * @param bool $insert * @param array $changedAttributes */ public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); // 修改了项目repo_url,本地检出代码将被清空 if (isset($changedAttributes['repo_url'])) { $projectDir = static::getDeployFromDir(); if (file_exists($projectDir)) { $folder = new Folder($this); $folder->removeLocalProjectWorkspace($projectDir); } } // 插入一条管理员关系 if ($insert) { Group::addGroupUser($this->attributes['id'], [$this->attributes['user_id']], Group::TYPE_ADMIN); } }