/**
  * Get approval groups
  */
 public function getGroups()
 {
     if (Yii::$app->user->isAdmin()) {
         return \humhub\modules\user\models\Group::find()->all();
     } else {
         $groups = [];
         foreach (\humhub\modules\user\models\GroupAdmin::find()->joinWith('group')->where(['user_id' => Yii::$app->user->id])->all() as $groupAdmin) {
             if ($groupAdmin->group !== null) {
                 $groups[] = $groupAdmin->group;
             }
         }
         return $groups;
     }
 }
Exemple #2
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     if ($this->scenario == 'edit') {
         \humhub\modules\user\models\GroupAdmin::deleteAll(['group_id' => $this->id]);
         $adminUsers = array();
         foreach (explode(",", $this->adminGuids) as $adminGuid) {
             // Ensure guids valid characters
             $adminGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $adminGuid);
             // Try load user
             $user = \humhub\modules\user\models\User::findOne(['guid' => $adminGuid]);
             if ($user != null) {
                 $groupAdmin = new GroupAdmin();
                 $groupAdmin->user_id = $user->id;
                 $groupAdmin->group_id = $this->id;
                 $groupAdmin->save();
             }
         }
     }
     parent::afterSave($insert, $changedAttributes);
 }
Exemple #3
0
 /**
  * User can approve other users
  *
  * @return boolean
  */
 public function canApproveUsers()
 {
     if ($this->super_admin == 1) {
         return true;
     }
     if (GroupAdmin::find()->where(['user_id' => $this->id])->count() != 0) {
         return true;
     }
     return false;
 }
Exemple #4
0
 public function getAdmins()
 {
     return $this->hasMany(GroupAdmin::className(), ['group_id' => 'id']);
 }
 /**
  * Callback to validate module database records.
  *
  * @param Event $event
  */
 public static function onIntegrityCheck($event)
 {
     $integrityController = $event->sender;
     $integrityController->showTestHeadline("User Module - Users (" . User::find()->count() . " entries)");
     foreach (User::find()->joinWith(['profile', 'group'])->all() as $user) {
         if ($user->profile == null) {
             $integrityController->showWarning("User with id " . $user->id . " has no profile record!");
         }
         if ($user->group == null) {
             $integrityController->showWarning("User with id " . $user->id . " has no group assignment!");
         }
     }
     $integrityController->showTestHeadline("User Module - GroupAdmin (" . GroupAdmin::find()->count() . " entries)");
     foreach (GroupAdmin::find()->joinWith(['user'])->all() as $groupAdmin) {
         if ($groupAdmin->user == null) {
             if ($integrityController->showFix("Deleting group admin " . $groupAdmin->id . " without existing user!")) {
                 $groupAdmin->delete();
             }
         }
     }
     $integrityController->showTestHeadline("User Module - Password (" . Password::find()->count() . " entries)");
     foreach (Password::find()->joinWith(['user'])->all() as $password) {
         if ($password->user == null) {
             if ($integrityController->showFix("Deleting password " . $password->id . " without existing user!")) {
                 $password->delete();
             }
         }
     }
     $integrityController->showTestHeadline("User Module - Profile (" . Profile::find()->count() . " entries)");
     foreach (Profile::find()->joinWith(['user'])->all() as $profile) {
         if ($profile->user == null) {
             if ($integrityController->showFix("Deleting profile " . $profile->user_id . " without existing user!")) {
                 $profile->delete();
             }
         }
     }
     $integrityController->showTestHeadline("User Module - Mentioning (" . Mentioning::find()->count() . " entries)");
     foreach (Mentioning::find()->joinWith(['user'])->all() as $mentioning) {
         if ($mentioning->user == null) {
             if ($integrityController->showFix("Deleting mentioning " . $mentioning->id . " of non existing user!")) {
                 $mentioning->delete();
             }
         }
         if ($mentioning->getPolymorphicRelation() == null) {
             if ($integrityController->showFix("Deleting mentioning " . $mentioning->id . " of non target!")) {
                 $mentioning->delete();
             }
         }
     }
     $integrityController->showTestHeadline("User Module - Follow (" . Follow::find()->count() . " entries)");
     foreach (Follow::find()->joinWith(['user'])->all() as $follow) {
         if ($follow->user == null) {
             if ($integrityController->showFix("Deleting follow " . $follow->id . " of non existing user!")) {
                 $follow->delete();
             }
         }
         if ($follow->getTarget() == null) {
             if ($integrityController->showFix("Deleting follow " . $follow->id . " of non target!")) {
                 $follow->delete();
             }
         }
     }
     $integrityController->showTestHeadline("User Module - Modules (" . models\Module::find()->count() . " entries)");
     foreach (models\Module::find()->joinWith(['user'])->all() as $module) {
         if ($module->user == null) {
             if ($integrityController->showFix("Deleting user-module " . $module->id . " of non existing user!")) {
                 $module->delete();
             }
         }
     }
 }