Example #1
0
 /**
  * Tests if user automatically added to the groupĀ“s default space
  */
 public function testCreateGroupSpaceAdd()
 {
     Yii::$app->getModule('user')->settings->set('auth.needApproval', 0);
     $space = Space::findOne(['id' => 1]);
     $user = new User();
     $user->username = "******";
     $user->email = "*****@*****.**";
     $this->assertTrue($user->save());
     $group = Group::findOne(['id' => 1]);
     $group->addUser($user);
     $this->assertTrue($space->isMember($user->id));
 }
Example #2
0
 /**
  * Aligns the given group selection with the db
  * @return boolean
  */
 public function save()
 {
     //Check old group selection and remove non selected groups
     foreach ($this->currentGroups as $userGroup) {
         if (!$this->isInGroupSelection($userGroup)) {
             $this->user->getGroupUsers()->where(['group_id' => $userGroup->id])->one()->delete();
         }
     }
     //Add all selectedGroups to the given user
     foreach ($this->groupSelection as $groupId) {
         if (!$this->isCurrentlyMemberOf($groupId)) {
             Group::findOne($groupId)->addUser($this->user);
         }
     }
     return true;
 }
Example #3
0
 /**
  * Aligns the given group selection with the db
  * @return boolean
  */
 public function afterSave($insert, $changedAttributes)
 {
     //Check old group selection and remove non selected groups
     foreach ($this->currentGroups as $userGroup) {
         if (!$this->isInGroupSelection($userGroup)) {
             $this->getGroupUsers()->where(['group_id' => $userGroup->id])->one()->delete();
         }
     }
     $this->groupSelection = $this->groupSelection == null ? [] : $this->groupSelection;
     //Add all new selectedGroups to the given user
     foreach ($this->groupSelection as $groupId) {
         if (!$this->isCurrentlyMemberOf($groupId)) {
             Group::findOne($groupId)->addUser($this);
         }
     }
     return parent::afterSave($insert, $changedAttributes);
 }
Example #4
0
 /**
  * Deletes a group
  *
  * On deletion all group members will be moved to another group.
  */
 public function actionDelete()
 {
     $group = Group::findOne(['id' => Yii::$app->request->get('id')]);
     if ($group == null) {
         throw new \yii\web\HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group not found!'));
     }
     $model = new \humhub\modules\admin\models\forms\AdminDeleteGroupForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         foreach (User::findAll(['group_id' => $group->id]) as $user) {
             $user->group_id = $model->group_id;
             $user->save();
         }
         $group->delete();
         $this->redirect(Url::toRoute("/admin/group"));
     }
     $alternativeGroups = \yii\helpers\ArrayHelper::map(Group::find()->where('id != :id', array(':id' => $group->id))->all(), 'id', 'name');
     return $this->render('delete', array('group' => $group, 'model' => $model, 'alternativeGroups' => $alternativeGroups));
 }
 /**
  * Action for the members section of the directory
  *
  * @todo Dont pass lucene hits to view, build user array inside of action
  */
 public function actionMembers()
 {
     $keyword = Yii::$app->request->get('keyword', "");
     $page = (int) Yii::$app->request->get('page', 1);
     $groupId = (int) Yii::$app->request->get('groupId', "");
     $group = null;
     if ($groupId) {
         $group = \humhub\modules\user\models\Group::findOne(['id' => $groupId]);
     }
     $searchOptions = ['model' => \humhub\modules\user\models\User::className(), 'page' => $page, 'pageSize' => $this->module->pageSize];
     if ($this->module->memberListSortField != "") {
         $searchOptions['sortField'] = $this->module->memberListSortField;
     }
     if ($group !== null) {
         $searchOptions['filters'] = ['groupId' => $group->id];
     }
     $searchResultSet = Yii::$app->search->find($keyword, $searchOptions);
     $pagination = new \yii\data\Pagination(['totalCount' => $searchResultSet->total, 'pageSize' => $searchResultSet->pageSize]);
     \yii\base\Event::on(Sidebar::className(), Sidebar::EVENT_INIT, function ($event) {
         $event->sender->addWidget(\humhub\modules\directory\widgets\NewMembers::className(), [], ['sortOrder' => 10]);
         $event->sender->addWidget(\humhub\modules\directory\widgets\MemberStatistics::className(), [], ['sortOrder' => 20]);
     });
     return $this->render('members', array('keyword' => $keyword, 'group' => $group, 'users' => $searchResultSet->getResultInstances(), 'pagination' => $pagination));
 }
Example #6
0
 public function setUpApproved()
 {
     $userInvite = Invite::findOne(['email' => $this->email]);
     if ($userInvite !== null) {
         // User was invited to a space
         if ($userInvite->source == Invite::SOURCE_INVITE) {
             $space = \humhub\modules\space\models\Space::findOne(['id' => $userInvite->space_invite_id]);
             if ($space != null) {
                 $space->addMember($this->id);
             }
         }
         // Delete/Cleanup Invite Entry
         $userInvite->delete();
     }
     // Auto Assign User to the Group Space
     $group = Group::findOne(['id' => $this->group_id]);
     if ($group != null && $group->space_id != "") {
         $space = \humhub\modules\space\models\Space::findOne(['id' => $group->space_id]);
         if ($space !== null) {
             $space->addMember($this->id);
         }
     }
     // Auto Add User to the default spaces
     foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $space) {
         $space->addMember($this->id);
     }
 }
Example #7
0
 public function actionAdminUserSearch()
 {
     Yii::$app->response->format = 'json';
     $keyword = Yii::$app->request->get('keyword');
     $group = Group::findOne(Yii::$app->request->get('id'));
     return UserPicker::filter(['query' => $group->getUsers(), 'keyword' => $keyword, 'fillQuery' => User::find(), 'disableFillUser' => false]);
 }
Example #8
0
 public function setUpApproved()
 {
     $userInvite = Invite::findOne(['email' => $this->email]);
     if ($userInvite !== null) {
         // User was invited to a space
         if ($userInvite->source == Invite::SOURCE_INVITE) {
             $space = \humhub\modules\space\models\Space::findOne(['id' => $userInvite->space_invite_id]);
             if ($space != null) {
                 $space->addMember($this->id);
             }
         }
         // Delete/Cleanup Invite Entry
         $userInvite->delete();
     }
     // Auto Assign User to the Group Space
     $group = Group::findOne(['id' => $this->group_id]);
     if ($group != null && $group->space_id != "") {
         $space = \humhub\modules\space\models\Space::findOne(['id' => $group->space_id]);
         if ($space !== null) {
             $space->addMember($this->id);
         }
     }
     // Auto Add User to the default spaces
     foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $space) {
         $space->addMember($this->id);
     }
     // Create new wall record for this user
     $wall = new \humhub\modules\content\models\Wall();
     $wall->object_model = $this->className();
     $wall->object_id = $this->id;
     $wall->save();
     $this->wall_id = $wall->id;
     $this->update(false, ['wall_id']);
 }
 public function getGroup()
 {
     return \humhub\modules\user\models\Group::findOne($this->groupId);
 }