예제 #1
1
 public function run()
 {
     $showSpaces = 30;
     $spaces = array();
     $i = 0;
     foreach (Membership::GetUserSpaces($this->user->id) as $space) {
         if ($space->visibility == Space::VISIBILITY_NONE) {
             continue;
         }
         if ($space->status != Space::STATUS_ENABLED) {
             continue;
         }
         $i++;
         if ($i > $showSpaces) {
             break;
         }
         $spaces[] = $space;
     }
     return $this->render('userSpaces', array('spaces' => $spaces));
 }
예제 #2
0
 /**
  * Form Validator which checks the invite field
  *
  * @param type $attribute
  * @param type $params
  */
 public function checkInvite($attribute, $params)
 {
     // Check if email field is not empty
     if ($this->{$attribute} != "") {
         $invites = explode(",", $this->{$attribute});
         foreach ($invites as $userGuid) {
             $userGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $userGuid);
             if ($userGuid == "") {
                 continue;
             }
             // Try load user
             $user = User::findOne(['guid' => $userGuid]);
             if ($user != null) {
                 $membership = Membership::findOne(['space_id' => $this->space->id, 'user_id' => $user->id]);
                 if ($membership != null && $membership->status == Membership::STATUS_MEMBER) {
                     $this->addError($attribute, Yii::t('SpaceModule.forms_SpaceInviteForm', "User '{username}' is already a member of this space!", ['username' => $user->getDisplayName()]));
                     continue;
                 } else {
                     if ($membership != null && $membership->status == Membership::STATUS_APPLICANT) {
                         $this->addError($attribute, Yii::t('SpaceModule.forms_SpaceInviteForm', "User '{username}' is already an applicant of this space!", ['username' => $user->getDisplayName()]));
                         continue;
                     }
                 }
                 $this->invites[] = $user;
             } else {
                 $this->addError($attribute, Yii::t('SpaceModule.forms_SpaceInviteForm', "User not found!"));
                 continue;
             }
         }
     }
 }
 /**
  * Returns a list of languages
  */
 public function getLanguages()
 {
     $languages = array();
     if (!is_dir($this->getMessageBasePath())) {
         return $languages;
     }
     $files = scandir($this->getMessageBasePath());
     foreach ($files as $file) {
         if ($file == '.' || $file == '..') {
             continue;
         }
         $languages[$file] = $file;
     }
     if (!Yii::$app->request->isConsoleRequest) {
         if (!Yii::$app->user->isAdmin()) {
             $userLanguages = array();
             $spaceLanguages = array_map(function ($space) {
                 return strtolower($space->name);
             }, \humhub\modules\space\models\Membership::GetUserSpaces());
             foreach ($spaceLanguages as $sp) {
                 if (in_array($sp, $languages)) {
                     $userLanguages[$sp] = $sp;
                 }
             }
             return $userLanguages;
         }
     }
     return $languages;
 }
예제 #4
0
 /**
  * Returns an array of all possible space owners
  */
 public function getNewOwnerArray()
 {
     $possibleOwners = [];
     $query = Membership::find()->joinWith(['user', 'user.profile'])->andWhere(['space_membership.group_id' => 'admin']);
     foreach ($query->all() as $membership) {
         $possibleOwners[$membership->user->id] = $membership->user->displayName;
     }
     return $possibleOwners;
 }
 /**
  * Executes the widgets
  */
 public function run()
 {
     // Some member stats
     $statsTotalUsers = User::find()->active()->count();
     $statsUserOnline = \humhub\modules\user\components\Session::getOnlineUsers()->count();
     $statsUserFollow = Follow::find()->where(['object_model' => User::className()])->count();
     $statsUserInMostSpaces = Membership::GetUserInMostSpaces();
     // Render widgets view
     return $this->render('memberStats', array('statsTotalUsers' => $statsTotalUsers, 'statsUserOnline' => $statsUserOnline, 'statsUserFollow' => $statsUserFollow, 'statsUserInMostSpaces' => $statsUserInMostSpaces));
 }
예제 #6
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $friendshipsEnabled = Yii::$app->getModule('friendship')->getIsEnabled();
     $countFriends = 0;
     if ($friendshipsEnabled) {
         $countFriends = Friendship::getFriendsQuery($this->user)->count();
     }
     $countFollowing = $this->user->getFollowingCount(User::className()) + $this->user->getFollowingCount(Space::className());
     $countUserSpaces = Membership::getUserSpaceQuery($this->user)->andWhere(['!=', 'space.visibility', Space::VISIBILITY_NONE])->andWhere(['space.status' => Space::STATUS_ENABLED])->count();
     return $this->render('profileHeader', array('user' => $this->user, 'isProfileOwner' => $this->isProfileOwner, 'friendshipsEnabled' => $friendshipsEnabled, 'countFriends' => $countFriends, 'countFollowers' => $this->user->getFollowerCount(), 'countFollowing' => $countFollowing, 'countSpaces' => $countUserSpaces));
 }
예제 #7
0
 protected function getMembershipQuery()
 {
     $query = Membership::find();
     if (Setting::Get('spaceOrder', 'space') == 0) {
         $query->orderBy('name ASC');
     } else {
         $query->orderBy('last_visit DESC');
     }
     $query->joinWith('space');
     $query->where(['space_membership.user_id' => Yii::$app->user->id, 'space_membership.status' => Membership::STATUS_MEMBER]);
     return $query;
 }
예제 #8
0
 public function actionIndex()
 {
     $query = Membership::find();
     if (Setting::Get('spaceOrder', 'space') == 0) {
         $query->orderBy('name ASC');
     } else {
         $query->orderBy('last_visit DESC');
     }
     $query->joinWith('space');
     $query->where(['space_membership.user_id' => Yii::$app->user->id, 'space_membership.status' => Membership::STATUS_MEMBER]);
     return $this->renderAjax('index', ['memberships' => $query->all()]);
 }
예제 #9
0
 /**
  * Creates data provider instance with search query applied
  * 
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Membership::find();
     $query->andWhere(['space_membership.status' => $this->status]);
     $query->joinWith(['user', 'user.profile']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]);
     $dataProvider->setSort(['attributes' => ['user.profile.firstname' => ['asc' => ['profile.firstname' => SORT_ASC], 'desc' => ['profile.firstname' => SORT_DESC]], 'user.profile.lastname' => ['asc' => ['profile.lastname' => SORT_ASC], 'desc' => ['profile.lastname' => SORT_DESC]], 'user.username', 'last_visit', 'group_id']]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('0=1');
         return $dataProvider;
     }
     $query->andWhere(['space_membership.space_id' => $this->space_id]);
     $query->andFilterWhere(['space_membership.group_id' => $this->group_id]);
     $query->andFilterWhere(['like', 'profile.lastname', $this->getAttribute('user.profile.lastname')]);
     $query->andFilterWhere(['like', 'profile.firstname', $this->getAttribute('user.profile.firstname')]);
     $query->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')]);
     return $dataProvider;
 }
예제 #10
0
 /**
  * On User delete, also delete his space related stuff
  *
  * @param type $event
  */
 public static function onUserDelete($event)
 {
     $user = $event->sender;
     // Check if the user owns some spaces
     foreach (Membership::GetUserSpaces($user->id) as $space) {
         if ($space->isSpaceOwner($user->id)) {
             throw new HttpException(500, Yii::t('SpaceModule.base', 'Could not delete user who is a space owner! Name of Space: {spaceName}', array('spaceName' => $space->name)));
         }
     }
     // Cancel all space memberships
     foreach (Membership::findAll(array('user_id' => $user->id)) as $membership) {
         $membership->space->removeMember($user->id);
     }
     // Cancel all space invites by the user
     foreach (Membership::findAll(array('originator_user_id' => $user->id, 'status' => Membership::STATUS_INVITED)) as $membership) {
         $membership->space->removeMember($membership->user_id);
     }
     return true;
 }
 public function actionIndex()
 {
     // Restore users last selectors
     $lastSelectorsJson = Yii::$app->user->getIdentity()->getSetting('lastSelectors', 'calendar');
     if ($lastSelectorsJson != "") {
         $selectors = Json::decode($lastSelectorsJson);
     } else {
         $selectors = array(ActiveQueryContent::USER_RELATED_SCOPE_OWN, ActiveQueryContent::USER_RELATED_SCOPE_SPACES);
     }
     // Restore users last used filter
     $lastFilterJson = Yii::$app->user->getIdentity()->getSetting('lastFilters', 'calendar');
     if ($lastFilterJson != "") {
         $filters = Json::decode($lastFilterJson);
     } else {
         $filters = array();
     }
     $spaces = Membership::GetUserSpaces();
     $external_sources = CalendarExternalSource::find()->contentContainer(Yii::$app->user->getIdentity())->all();
     return $this->render('index', array('selectors' => $selectors, 'filters' => $filters, 'spaces' => $spaces, 'external_sources' => $external_sources, 'user' => Yii::$app->user->getIdentity()));
 }
 /**
  * This is a special case, because we need to find a space to start the tour
  */
 public function actionStartSpaceTour()
 {
     $space = null;
     // Loop over all spaces where the user is member
     foreach (\humhub\modules\space\models\Membership::GetUserSpaces() as $space) {
         if ($space->isAdmin()) {
             // If user is admin on this space, it´s the perfect match
             break;
         }
     }
     if ($space === null) {
         // If user is not member of any space, try to find a public space
         // to run tour in
         $space = Space::findOne(['!=', 'visibility' => Space::VISIBILITY_NONE]);
     }
     if ($space === null) {
         throw new HttpException(404, 'Could not find any public space to run tour!');
     }
     return $this->redirect($space->createUrl('/space/space', array('tour' => true)));
 }
예제 #13
0
 /**
  * Members Administration Action
  */
 public function actionIndex()
 {
     $space = $this->getSpace();
     $searchModel = new MembershipSearch();
     $searchModel->space_id = $space->id;
     $searchModel->status = Membership::STATUS_MEMBER;
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     // User Group Change
     if (Yii::$app->request->post('dropDownColumnSubmit')) {
         Yii::$app->response->format = 'json';
         $membership = Membership::findOne(['space_id' => $space->id, 'user_id' => Yii::$app->request->post('user_id')]);
         if ($membership === null) {
             throw new \yii\web\HttpException(404, 'Could not find membership!');
         }
         if ($membership->load(Yii::$app->request->post()) && $membership->validate() && $membership->save()) {
             return Yii::$app->request->post();
         }
         return $membership->getErrors();
     }
     return $this->render('index', array('dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'space' => $space));
 }
예제 #14
0
 /**
  * Callback to validate module database records.
  *
  * @param Event $event
  */
 public static function onIntegrityCheck($event)
 {
     $integrityController = $event->sender;
     $integrityController->showTestHeadline("Space Module - Spaces (" . Space::find()->count() . " entries)");
     foreach (Space::find()->all() as $space) {
         foreach ($space->applicants as $applicant) {
             if ($applicant->user == null) {
                 if ($integrityController->showFix("Deleting applicant record id " . $applicant->id . " without existing user!")) {
                     $applicant->delete();
                 }
             }
         }
     }
     $integrityController->showTestHeadline("Space Module - Module (" . models\Module::find()->count() . " entries)");
     foreach (models\Module::find()->joinWith('space')->all() as $module) {
         if ($module->space == null) {
             if ($integrityController->showFix("Deleting space module" . $module->id . " without existing space!")) {
                 $module->delete();
             }
         }
     }
     $integrityController->showTestHeadline("Space Module - Memberships (" . models\Membership::find()->count() . " entries)");
     foreach (models\Membership::find()->joinWith('space')->all() as $membership) {
         if ($membership->space == null) {
             if ($integrityController->showFix("Deleting space membership" . $membership->space_id . " without existing space!")) {
                 $membership->delete();
             }
         }
         if ($membership->user == null) {
             if ($integrityController->showFix("Deleting space membership" . $membership->user_id . " without existing user!")) {
                 $membership->delete();
             }
         }
     }
 }
예제 #15
0
 /**
  * Returns an user list which are space members
  */
 public function actionMembersList()
 {
     $title = Yii::t('SpaceModule.controllers_MembershipController', "<strong>Members</strong>");
     return $this->renderAjaxContent(UserListBox::widget(['query' => Membership::getSpaceMembersQuery($this->getSpace()), 'title' => $title]));
 }
예제 #16
0
 /**
  * Members Administration Action
  */
 public function actionMembers()
 {
     $membersPerPage = 20;
     $space = $this->getSpace();
     // User Role Management
     if (isset($_POST['users'])) {
         $users = Yii::$app->request->post('users');
         // Loop over all users in Form
         foreach ($users as $userGuid) {
             // Get informations
             if (isset($_POST['user_' . $userGuid])) {
                 $userSettings = Yii::$app->request->post('user_' . $userGuid);
                 $user = User::findOne(['guid' => $userGuid]);
                 if ($user != null) {
                     // No changes on the Owner
                     if ($space->isSpaceOwner($user->id)) {
                         continue;
                     }
                     $membership = \humhub\modules\space\models\Membership::findOne(['user_id' => $user->id, 'space_id' => $space->id]);
                     if ($membership != null) {
                         $membership->invite_role = isset($userSettings['inviteRole']) && $userSettings['inviteRole'] == 1 ? 1 : 0;
                         $membership->admin_role = isset($userSettings['adminRole']) && $userSettings['adminRole'] == 1 ? 1 : 0;
                         $membership->share_role = isset($userSettings['shareRole']) && $userSettings['shareRole'] == 1 ? 1 : 0;
                         $membership->save();
                     }
                 }
             }
         }
         // Change owner if changed
         if ($space->isSpaceOwner()) {
             $owner = $space->getSpaceOwner();
             $newOwnerId = Yii::$app->request->post('ownerId');
             if ($newOwnerId != $owner->id) {
                 if ($space->isMember($newOwnerId)) {
                     $space->setSpaceOwner($newOwnerId);
                     // Redirect to current space
                     return $this->redirect($space->createUrl('admin/members'));
                 }
             }
         }
         Yii::$app->getSession()->setFlash('data-saved', Yii::t('SpaceModule.controllers_AdminController', 'Saved'));
     }
     // Updated Users
     $query = $space->getMemberships();
     #$query = Membership::find();
     // Allow User Searches
     $search = Yii::$app->request->post('search');
     if ($search != "") {
         $query->joinWith('user');
         $query->andWhere('user.username LIKE :search OR user.email LIKE :search', [':search' => '%' . $search . '%']);
     }
     $countQuery = clone $query;
     $pagination = new \yii\data\Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $membersPerPage]);
     $query->offset($pagination->offset)->limit($pagination->limit);
     $invitedMembers = Membership::findAll(['space_id' => $space->id, 'status' => Membership::STATUS_INVITED]);
     $members = $query->all();
     return $this->render('members', array('space' => $space, 'pagination' => $pagination, 'members' => $members, 'invited_members' => $invitedMembers, 'search' => $search));
 }
예제 #17
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $query = \humhub\modules\space\models\Membership::getSpaceMembersQuery($this->space);
     $query->limit($this->maxMembers);
     return $this->render('members', ['space' => $this->space, 'maxMembers' => $this->maxMembers, 'users' => $query->all()]);
 }
예제 #18
0
 protected function buildQuery($keyword, $options)
 {
     // Allow *Token*
     \ZendSearch\Lucene\Search\Query\Wildcard::setMinPrefixLength(0);
     $query = new \ZendSearch\Lucene\Search\Query\Boolean();
     foreach (explode(" ", $keyword) as $k) {
         // Require at least 3 non-wildcard characters
         if (strlen($k) > 2) {
             $term = new \ZendSearch\Lucene\Index\Term("*" . $k . "*");
             $query->addSubquery(new \ZendSearch\Lucene\Search\Query\Wildcard($term), true);
         }
     }
     // Add model filter
     if (isset($options['model']) && $options['model'] != "") {
         if (is_array($options['model'])) {
             $boolQuery = new \ZendSearch\Lucene\Search\Query\MultiTerm();
             foreach ($options['model'] as $model) {
                 $boolQuery->addTerm(new \ZendSearch\Lucene\Index\Term($model, 'model'));
             }
             $query->addSubquery($boolQuery, true);
         } else {
             $term = new \ZendSearch\Lucene\Index\Term($options['model'], 'model');
             $query->addSubquery(new \ZendSearch\Lucene\Search\Query\Term($term), true);
         }
     }
     // Add type filter
     if (isset($options['type']) && $options['type'] != "") {
         if (is_array($options['type'])) {
             $boolQuery = new \ZendSearch\Lucene\Search\Query\MultiTerm();
             foreach ($options['type'] as $model) {
                 $boolQuery->addTerm(new \ZendSearch\Lucene\Index\Term($type), 'type');
             }
             $query->addSubquery($boolQuery, true);
         } else {
             $term = new \ZendSearch\Lucene\Index\Term($options['type'], 'type');
             $query->addSubquery(new \ZendSearch\Lucene\Search\Query\Term($term), true);
         }
     }
     // Add custom filters
     if (isset($options['filters']) && is_array($options['filters'])) {
         foreach ($options['filters'] as $field => $value) {
             $term = new \ZendSearch\Lucene\Index\Term($value, $field);
             $query->addSubquery(new \ZendSearch\Lucene\Search\Query\Term($term), true);
         }
     }
     if ($options['checkPermissions'] && !Yii::$app->request->isConsoleRequest) {
         $permissionQuery = new \ZendSearch\Lucene\Search\Query\Boolean();
         if (Yii::$app->user->isGuest) {
             // Guest Content
             $guestContentQuery = new \ZendSearch\Lucene\Search\Query\Boolean();
             $guestContentQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(self::DOCUMENT_VISIBILITY_PUBLIC, 'visibility')), true);
             $guestContentQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(self::DOCUMENT_TYPE_CONTENT, 'type')), true);
             $guestContentQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(Space::className(), 'containerModel')), true);
             $guestSpaceListQuery = new \ZendSearch\Lucene\Search\Query\MultiTerm();
             foreach (Space::find()->where(['visibility' => Space::VISIBILITY_ALL])->all() as $space) {
                 $guestSpaceListQuery->addTerm(new \ZendSearch\Lucene\Index\Term($space->id, 'containerPk'));
             }
             $guestContentQuery->addSubquery($guestSpaceListQuery, true);
             $permissionQuery->addSubquery($guestContentQuery);
             // Guest Spaces
             $guestSpacesQuery = new \ZendSearch\Lucene\Search\Query\Boolean();
             $guestSpacesQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(self::DOCUMENT_TYPE_SPACE, 'type')), true);
             $guestSpacesQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(self::DOCUMENT_VISIBILITY_PUBLIC, 'visibility')), true);
             $permissionQuery->addSubquery($guestSpacesQuery);
             $permissionQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(self::DOCUMENT_TYPE_USER, 'type')));
         } else {
             //--- Public Content
             $permissionQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(self::DOCUMENT_VISIBILITY_PUBLIC, 'visibility')));
             //--- Private Space Content
             $privateSpaceContentQuery = new \ZendSearch\Lucene\Search\Query\Boolean();
             $privateSpaceContentQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(self::DOCUMENT_VISIBILITY_PRIVATE, 'visibility')), true);
             $privateSpaceContentQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(Space::className(), 'containerModel')), true);
             $privateSpacesListQuery = new \ZendSearch\Lucene\Search\Query\MultiTerm();
             foreach (\humhub\modules\space\models\Membership::GetUserSpaces() as $space) {
                 $privateSpacesListQuery->addTerm(new \ZendSearch\Lucene\Index\Term($space->id, 'containerPk'));
             }
             $privateSpaceContentQuery->addSubquery($privateSpacesListQuery, true);
             $permissionQuery->addSubquery($privateSpaceContentQuery);
         }
         $query->addSubquery($permissionQuery, true);
     }
     if (count($options['limitSpaces']) > 0) {
         $spaceBaseQuery = new \ZendSearch\Lucene\Search\Query\Boolean();
         $spaceBaseQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(Space::className(), 'containerModel')), true);
         $spaceIdQuery = new \ZendSearch\Lucene\Search\Query\MultiTerm();
         foreach ($options['limitSpaces'] as $space) {
             $spaceIdQuery->addTerm(new \ZendSearch\Lucene\Index\Term($space->id, 'containerPk'));
         }
         $spaceBaseQuery->addSubquery($spaceIdQuery, true);
         $query->addSubquery($spaceBaseQuery, true);
     }
     return $query;
 }
예제 #19
0
 * box when the criteria is met.
 *
 * Criteria = if they're not looking
 * at a Space or a User and they are
 * a member in more than one space.
 *
 * Later on (in views/wall/widgets/contentForm.php)
 * we set up a listener on #post_to_space which updates
 * the fields that tell Humhub where the post is
 * originating from.
 */
use yii\helpers\Html;
?>

<?php 
$userSpaces = \humhub\modules\space\models\Membership::GetUserSpaces();
if (count($userSpaces) > 1 && Yii::$app->request->get('sguid') == null && Yii::$app->request->get('uguid') == null) {
    $showSpacePicker = true;
} else {
    $showSpacePicker = false;
}
?>

<div <?php 
if (!$showSpacePicker) {
    echo "style='display:none !important;'";
}
?>
>
    <select id="post_to_space" class="btn-group selectpicker show-tick form-control" <?php 
if (!$showSpacePicker) {
예제 #20
0
 /**
  * Delete Action
  *
  * Its only possible if the user is not owner of a workspace.
  */
 public function actionDelete()
 {
     $isSpaceOwner = false;
     $user = Yii::$app->user->getIdentity();
     if (!Yii::$app->user->canDeleteAccount()) {
         throw new HttpException(500, 'Account deletion not allowed');
     }
     foreach (\humhub\modules\space\models\Membership::GetUserSpaces() as $space) {
         if ($space->isSpaceOwner($user->id)) {
             $isSpaceOwner = true;
         }
     }
     $model = new \humhub\modules\user\models\forms\AccountDelete();
     if (!$isSpaceOwner && $model->load(Yii::$app->request->post()) && $model->validate()) {
         $user->delete();
         Yii::$app->user->logout();
         return $this->goHome();
     }
     return $this->render('delete', array('model' => $model, 'isSpaceOwner' => $isSpaceOwner));
 }
예제 #21
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $query = Membership::getUserSpaceQuery($this->user)->andWhere(['!=', 'space.visibility', Space::VISIBILITY_NONE])->andWhere(['space.status' => Space::STATUS_ENABLED]);
     $showMoreLink = $query->count() > $this->maxSpaces;
     return $this->render('userSpaces', ['user' => $this->user, 'spaces' => $query->limit($this->maxSpaces)->all(), 'showMoreLink' => $showMoreLink]);
 }
예제 #22
0
 /**
  * Delete Action
  *
  * Its only possible if the user is not owner of a workspace.
  */
 public function actionDelete()
 {
     $isSpaceOwner = false;
     $user = Yii::$app->user->getIdentity();
     if ($user->auth_mode != User::AUTH_MODE_LOCAL) {
         throw new HttpException(500, 'This is not a local account! You cannot delete it. (e.g. LDAP)!');
     }
     foreach (\humhub\modules\space\models\Membership::GetUserSpaces() as $space) {
         if ($space->isSpaceOwner($user->id)) {
             $isSpaceOwner = true;
         }
     }
     $model = new \humhub\modules\user\models\forms\AccountDelete();
     if (!$isSpaceOwner && $model->load(Yii::$app->request->post()) && $model->validate()) {
         $user->delete();
         Yii::$app->user->logout();
         $this->redirect(Yii::$app->homeUrl);
     }
     return $this->render('delete', array('model' => $model, 'isSpaceOwner' => $isSpaceOwner));
 }
예제 #23
0
 /**
  * Deletes a user permanently
  */
 public function actionDelete()
 {
     $id = (int) Yii::$app->request->get('id');
     $doit = (int) Yii::$app->request->get('doit');
     $user = User::findOne(['id' => $id]);
     if ($user == null) {
         throw new HttpException(404, Yii::t('AdminModule.controllers_UserController', 'User not found!'));
     } elseif (Yii::$app->user->id == $id) {
         throw new HttpException(400, Yii::t('AdminModule.controllers_UserController', 'You cannot delete yourself!'));
     }
     if ($doit == 2) {
         $this->forcePostRequest();
         foreach (\humhub\modules\space\models\Membership::GetUserSpaces($user->id) as $space) {
             if ($space->isSpaceOwner($user->id)) {
                 $space->addMember(Yii::$app->user->id);
                 $space->setSpaceOwner(Yii::$app->user->id);
             }
         }
         $user->delete();
         return $this->redirect(['/admin/user']);
     }
     return $this->render('delete', array('model' => $user));
 }
예제 #24
0
 public function actionSpaceMembershipList()
 {
     $query = \humhub\modules\space\models\Membership::getUserSpaceQuery($this->getUser());
     if (!$this->getUser()->isCurrentUser()) {
         $query->andWhere(['!=', 'space.visibility', \humhub\modules\space\models\Space::VISIBILITY_NONE]);
     }
     $title = Yii::t('UserModule.widgets_views_userSpaces', '<strong>Member</strong> in these spaces');
     return $this->renderAjaxContent(\humhub\modules\space\widgets\ListBox::widget(['query' => $query, 'title' => $title]));
 }
예제 #25
0
 public function getApplicants()
 {
     $query = $this->hasMany(Membership::className(), ['space_id' => 'id']);
     $query->andWhere(['space_membership.status' => Membership::STATUS_APPLICANT]);
     return $query;
 }
 /**
  * Remove Membership
  *
  * @param $userId UserId of User to Remove
  */
 public function removeMember($userId = "")
 {
     if ($userId == "") {
         $userId = Yii::$app->user->id;
     }
     $user = User::findOne(['id' => $userId]);
     $membership = $this->getMembership($userId);
     if ($this->isSpaceOwner($userId)) {
         return false;
     }
     if ($membership == null) {
         return true;
     }
     // If was member, create a activity for that
     if ($membership->status == Membership::STATUS_MEMBER) {
         $activity = new \humhub\modules\space\activities\MemberRemoved();
         $activity->source = $this->owner;
         $activity->originator = $user;
         $activity->create();
     } elseif ($membership->status == Membership::STATUS_INVITED && $membership->originator !== null) {
         // Was invited, but declined the request - inform originator
         $notification = new \humhub\modules\space\notifications\InviteDeclined();
         $notification->source = $this->owner;
         $notification->originator = $user;
         $notification->send($membership->originator);
     } elseif ($membership->status == Membership::STATUS_APPLICANT) {
         $notification = new \humhub\modules\space\notifications\ApprovalRequestDeclined();
         $notification->source = $this->owner;
         $notification->originator = Yii::$app->user->getIdentity();
         $notification->send($user);
     }
     foreach (Membership::findAll(['user_id' => $userId, 'space_id' => $this->owner->id]) as $membership) {
         $membership->delete();
     }
     $notificationApproval = new \humhub\modules\space\notifications\ApprovalRequest();
     $notificationApproval->source = $this->owner;
     $notificationApproval->originator = $user;
     $notificationApproval->delete();
     $notificationInvite = new \humhub\modules\space\notifications\Invite();
     $notificationInvite->source = $this->owner;
     $notificationInvite->delete($user);
 }
예제 #27
0
파일: User.php 프로젝트: kreativmind/humhub
 /**
  * Before Delete of a User
  *
  */
 public function beforeDelete()
 {
     // We don't allow deletion of users who owns a space - validate that
     foreach (\humhub\modules\space\models\Membership::GetUserSpaces($this->id) as $space) {
         if ($space->isSpaceOwner($this->id)) {
             throw new Exception("Tried to delete a user which is owner of a space!");
         }
     }
     // Disable all enabled modules
     foreach ($this->getAvailableModules() as $moduleId => $module) {
         if ($this->isModuleEnabled($moduleId)) {
             $this->disableModule($moduleId);
         }
     }
     // Delete profile image
     $this->getProfileImage()->delete();
     // Remove from search index
     Yii::$app->search->delete($this);
     // Cleanup related tables
     Invite::deleteAll(['user_originator_id' => $this->id]);
     Follow::deleteAll(['user_id' => $this->id]);
     Follow::deleteAll(['object_model' => $this->className(), 'object_id' => $this->id]);
     Password::deleteAll(['user_id' => $this->id]);
     Profile::deleteAll(['user_id' => $this->id]);
     GroupUser::deleteAll(['user_id' => $this->id]);
     Session::deleteAll(['user_id' => $this->id]);
     return parent::beforeDelete();
 }
예제 #28
0
 protected function buildQuery($keyword, $options)
 {
     $query = new \ZendSearch\Lucene\Search\Query\Boolean();
     foreach (explode(" ", $keyword) as $k) {
         // Require at least 3 non-wildcard characters
         if (strlen($k) > 2) {
             $term = new \ZendSearch\Lucene\Index\Term($k . "*");
             $query->addSubquery(new \ZendSearch\Lucene\Search\Query\Wildcard($term), true);
         }
     }
     // Add model filter
     if (isset($options['model']) && $options['model'] != "") {
         if (is_array($options['model'])) {
             $boolQuery = new \ZendSearch\Lucene\Search\Query\MultiTerm();
             foreach ($options['model'] as $model) {
                 $boolQuery->addTerm(new \ZendSearch\Lucene\Index\Term($model, 'model'));
             }
             $query->addSubquery($boolQuery, true);
         } else {
             $term = new \ZendSearch\Lucene\Index\Term($options['model'], 'model');
             $query->addSubquery(new \ZendSearch\Lucene\Search\Query\Term($term), true);
         }
     }
     // Add type filter
     if (isset($options['type']) && $options['type'] != "") {
         if (is_array($options['type'])) {
             $boolQuery = new \ZendSearch\Lucene\Search\Query\MultiTerm();
             foreach ($options['type'] as $model) {
                 $boolQuery->addTerm(new \ZendSearch\Lucene\Index\Term($type), 'type');
             }
             $query->addSubquery($boolQuery, true);
         } else {
             $term = new \ZendSearch\Lucene\Index\Term($options['type'], 'type');
             $query->addSubquery(new \ZendSearch\Lucene\Search\Query\Term($term), true);
         }
     }
     if ($options['checkPermissions'] && !Yii::$app->request->isConsoleRequest) {
         $permissionQuery = new \ZendSearch\Lucene\Search\Query\Boolean();
         //--- Public Content
         $permissionQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(self::DOCUMENT_VISIBILITY_PUBLIC, 'visibility')));
         //--- Private Space Content
         $privateSpaceContentQuery = new \ZendSearch\Lucene\Search\Query\Boolean();
         $privateSpaceContentQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(self::DOCUMENT_VISIBILITY_PRIVATE, 'visibility')), true);
         $privateSpaceContentQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(Space::className(), 'containerModel')), true);
         $privateSpacesListQuery = new \ZendSearch\Lucene\Search\Query\MultiTerm();
         foreach (\humhub\modules\space\models\Membership::GetUserSpaces() as $space) {
             $privateSpacesListQuery->addTerm(new \ZendSearch\Lucene\Index\Term($space->id, 'containerPk'));
         }
         $privateSpaceContentQuery->addSubquery($privateSpacesListQuery, true);
         $permissionQuery->addSubquery($privateSpaceContentQuery);
         $query->addSubquery($permissionQuery, true);
     }
     if (count($options['limitSpaces']) > 0) {
         $spaceBaseQuery = new \ZendSearch\Lucene\Search\Query\Boolean();
         $spaceBaseQuery->addSubquery(new \ZendSearch\Lucene\Search\Query\Term(new \ZendSearch\Lucene\Index\Term(Space::className(), 'containerModel')), true);
         $spaceIdQuery = new \ZendSearch\Lucene\Search\Query\MultiTerm();
         foreach ($options['limitSpaces'] as $space) {
             $spaceIdQuery->addTerm(new \ZendSearch\Lucene\Index\Term($space->id, 'containerPk'));
         }
         $spaceBaseQuery->addSubquery($spaceIdQuery, true);
         $query->addSubquery($spaceBaseQuery, true);
     }
     return $query;
 }