예제 #1
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::model()->findByAttributes(array('guid' => $userGuid));
             if ($user != null) {
                 $membership = SpaceMembership::model()->findByAttributes(array('space_id' => $this->space->id, 'user_id' => $user->id));
                 if ($membership != null && $membership->status == SpaceMembership::STATUS_MEMBER) {
                     $this->addError($attribute, Yii::t('SpaceModule.forms_SpaceInviteForm', "User is already member!"));
                     continue;
                 }
             } else {
                 $this->addError($attribute, Yii::t('SpaceModule.forms_SpaceInviteForm', "User not found!"));
                 continue;
             }
             $this->invites[] = $user;
         }
     }
 }
예제 #2
0
 public function run()
 {
     $currentSpace = null;
     $currentSpaceGuid = "";
     if (isset(Yii::app()->params['currentSpace']) && Yii::app()->params['currentSpace'] != null) {
         $currentSpace = Yii::app()->params['currentSpace'];
         $currentSpaceGuid = $currentSpace->guid;
     }
     $this->render('yourSpacesMenu', array('currentSpace' => $currentSpace, 'currentSpaceGuid' => $currentSpaceGuid, 'usersSpaces' => SpaceMembership::GetUserSpaces()));
 }
예제 #3
0
 public function actionIndex()
 {
     $criteria = new CDbCriteria();
     if (HSetting::Get('spaceOrder', 'space') == 0) {
         $criteria->order = 'name ASC';
     } else {
         $criteria->order = 'last_visit DESC';
     }
     $memberships = SpaceMembership::model()->with('space')->findAllByAttributes(array('user_id' => Yii::app()->user->id, 'status' => SpaceMembership::STATUS_MEMBER), $criteria);
     $this->renderPartial('index', array('memberships' => $memberships), false, true);
 }
예제 #4
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 (SpaceMembership::GetUserSpaces($user->id) as $space) {
         if ($space->isSpaceOwner($user->id)) {
             throw new CHttpException(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 (SpaceMembership::model()->findAllByAttributes(array('user_id' => $user->id)) as $membership) {
         $membership->space->removeMember($user->id);
     }
     // Cancel all space invites by the user
     foreach (SpaceMembership::model()->findAllByAttributes(array('originator_user_id' => $user->id, 'status' => SpaceMembership::STATUS_INVITED)) as $membership) {
         $membership->space->removeMember($membership->user_id);
     }
     return true;
 }
예제 #5
0
 /**
  * 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 (SpaceMembership::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::model()->find('visibility!=' . Space::VISIBILITY_NONE);
     }
     if ($space === null) {
         throw new CHttpException(404, 'Could not find any public space to run tour!');
     }
     $this->redirect($space->getUrl(array('tour' => true)));
 }
예제 #6
0
 public function run()
 {
     $showSpaces = 30;
     $spaces = array();
     $i = 0;
     foreach (SpaceMembership::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;
     }
     $this->render('userSpaces', array('spaces' => $spaces));
 }
예제 #7
0
파일: Space.php 프로젝트: skapl/design
 /**
  * Before deletion of a Space
  */
 protected function beforeDelete()
 {
     foreach (SpaceSetting::model()->findAllByAttributes(array('space_id' => $this->id)) as $spaceSetting) {
         $spaceSetting->delete();
     }
     // Disable all enabled modules
     foreach ($this->getAvailableModules() as $moduleId => $module) {
         if ($this->isModuleEnabled($moduleId)) {
             $this->disableModule($moduleId);
         }
     }
     HSearch::getInstance()->deleteModel($this);
     $this->getProfileImage()->delete();
     // Remove all Follwers
     UserFollow::model()->deleteAllByAttributes(array('object_id' => $this->id, 'object_model' => 'Space'));
     //Delete all memberships:
     //First select, then delete - done to make sure that SpaceMembership::beforeDelete() is triggered
     $spaceMemberships = SpaceMembership::model()->findAllByAttributes(array('space_id' => $this->id));
     foreach ($spaceMemberships as $spaceMembership) {
         $spaceMembership->delete();
     }
     UserInvite::model()->deleteAllByAttributes(array('space_invite_id' => $this->id));
     // Delete all content objects of this space
     foreach (Content::model()->findAllByAttributes(array('space_id' => $this->id)) as $content) {
         $content->delete();
     }
     // When this workspace is used in a group as default workspace, delete the link
     foreach (Group::model()->findAllByAttributes(array('space_id' => $this->id)) as $group) {
         $group->space_id = "";
         $group->save();
     }
     Wall::model()->deleteAllByAttributes(array('id' => $this->wall_id));
     return parent::beforeDelete();
 }
예제 #8
0
파일: User.php 프로젝트: ahdail/humhub
 /**
  * Before Delete of a User
  *
  */
 public function beforeDelete()
 {
     // We don't allow deletion of users who owns a space - validate that
     foreach (SpaceMembership::GetUserSpaces($this->id) as $workspace) {
         if ($workspace->isSpaceOwner($this->id)) {
             throw new Exception("Tried to delete a user which is owner of a space!");
         }
     }
     UserSetting::model()->deleteAllByAttributes(array('user_id' => $this->id));
     // Disable all enabled modules
     foreach ($this->getAvailableModules() as $moduleId => $module) {
         if ($this->isModuleEnabled($moduleId)) {
             $this->disableModule($moduleId);
         }
     }
     HSearch::getInstance()->deleteModel($this);
     // Delete Profile Image
     $this->getProfileImage()->delete();
     // Delete all pending invites
     UserInvite::model()->deleteAllByAttributes(array('user_originator_id' => $this->id));
     Follow::model()->deleteAllByAttributes(array('user_id' => $this->id));
     Follow::model()->deleteAllByAttributes(array('object_model' => 'User', 'object_id' => $this->id));
     // Delete all group admin assignments
     GroupAdmin::model()->deleteAllByAttributes(array('user_id' => $this->id));
     // Delete wall entries
     WallEntry::model()->deleteAllByAttributes(array('wall_id' => $this->wall_id));
     // Deletes all content created by this user
     foreach (Content::model()->findAllByAttributes(array('user_id' => $this->id)) as $content) {
         $content->delete();
     }
     foreach (Content::model()->findAllByAttributes(array('created_by' => $this->id)) as $content) {
         $content->delete();
     }
     // Delete all passwords
     foreach (UserPassword::model()->findAllByAttributes(array('user_id' => $this->id)) as $password) {
         $password->delete();
     }
     return parent::beforeDelete();
 }
예제 #9
0
 /**
  * Members Administration Action
  */
 public function actionMembers()
 {
     $membersPerPage = 10;
     $space = $this->getSpace();
     // User Role Management
     if (isset($_POST['users'])) {
         $users = Yii::app()->request->getParam('users');
         // Loop over all users in Form
         foreach ($users as $userGuid) {
             // Get informations
             if (isset($_POST['user_' . $userGuid])) {
                 $userSettings = Yii::app()->request->getParam('user_' . $userGuid);
                 $user = User::model()->findByAttributes(array('guid' => $userGuid));
                 if ($user != null) {
                     // No changes on the Owner
                     if ($space->isSpaceOwner($user->id)) {
                         continue;
                     }
                     $membership = SpaceMembership::model()->findByAttributes(array('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->getParam('ownerId');
             if ($newOwnerId != $owner->id) {
                 if ($space->isMember($newOwnerId)) {
                     $space->setSpaceOwner($newOwnerId);
                     // Redirect to current space
                     $this->redirect($this->createUrl('admin/members', array('sguid' => $this->getSpace()->guid)));
                 }
             }
         }
         Yii::app()->user->setFlash('data-saved', Yii::t('SpaceModule.controllers_AdminController', 'Saved'));
     }
     // Updated Users
     $criteria = new CDbCriteria();
     $criteria->condition = "1";
     // Allow User Searches
     $search = Yii::app()->request->getQuery('search');
     if ($search != "") {
         $criteria->join = "LEFT JOIN user ON memberships.user_id = user.id ";
         $criteria->condition .= " AND (";
         $criteria->condition .= ' user.username LIKE :search';
         $criteria->condition .= ' OR user.email like :search';
         $criteria->condition .= " ) ";
         $criteria->params = array(':search' => '%' . $search . '%');
     }
     //ToDo: Better Counting
     $allMemberCount = count($space->memberships($criteria));
     $pages = new CPagination($allMemberCount);
     $pages->setPageSize($membersPerPage);
     $pages->applyLimit($criteria);
     $members = $space->memberships($criteria);
     $invited_members = SpaceMembership::model()->findAllByAttributes(array('space_id' => $space->id, 'status' => SpaceMembership::STATUS_INVITED));
     $this->render('members', array('space' => $space, 'members' => $members, 'invited_members' => $invited_members, 'item_count' => $allMemberCount, 'page_size' => $membersPerPage, 'search' => $search, 'pages' => $pages));
 }
예제 #10
0
파일: index.php 프로젝트: ahdail/humhub
<?php

$count = 0;
?>

<?php 
foreach (SpaceMembership::GetUserSpaces() as $space) {
    ?>
    <li>
        <a href="<?php 
    echo $space->getUrl();
    ?>
">
            <div class="media">
                <!-- Show user image -->
                <img class="media-object img-rounded pull-left" alt="24x24" data-src="holder.js/24x24"
                     style="width: 24px; height: 24px;"
                     src="<?php 
    echo $space->getProfileImage()->getUrl();
    ?>
">
                <!-- Show space image, if you are outside from a space -->
                <div class="media-body">
                    <!-- Show content -->
                    <strong><?php 
    echo $space->name;
    ?>
</strong>

                    <div id="space-badge-<?php 
    echo $count;
예제 #11
0
 /**
  * Delete Action
  *
  * Its only possible if the user is not owner of a workspace.
  */
 public function actionDelete()
 {
     $isSpaceOwner = false;
     $user = Yii::app()->user->getModel();
     if ($user->auth_mode != User::AUTH_MODE_LOCAL) {
         throw new CHttpException(500, 'This is not a local account! You cannot delete it. (e.g. LDAP)!');
     }
     foreach (SpaceMembership::GetUserSpaces() as $space) {
         // Oups, we are owner in this workspace!
         if ($space->isSpaceOwner($user->id)) {
             $isSpaceOwner = true;
         }
     }
     $model = new AccountDeleteForm();
     if (!$isSpaceOwner) {
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         if (isset($_POST['AccountDeleteForm'])) {
             $_POST['AccountDeleteForm'] = Yii::app()->input->stripClean($_POST['AccountDeleteForm']);
             $model->attributes = $_POST['AccountDeleteForm'];
             if ($model->validate()) {
                 $user->delete();
                 Yii::app()->user->logout();
                 $this->redirect(Yii::app()->homeUrl);
             }
         }
     }
     $this->render('delete', array('model' => $model, 'isSpaceOwner' => $isSpaceOwner));
 }
예제 #12
0
$this->widget('application.modules_core.user.widgets.UserPickerWidget', array('inputId' => 'notifyUserInput', 'userSearchUrl' => $userSearchUrl, 'maxUsers' => 10, 'userGuid' => Yii::app()->user->guid, 'placeholderText' => Yii::t('WallModule.widgets_views_contentForm', 'Add a member to notify'), 'focus' => true));
?>
        </div>

        <?php 
/**  
 * If they're looking at a Space or User, use default functionality.
 * If they're on the dashboard, implement "post to space" selector.
 *
 * Once we've established they are on a "post to space" page and check 
 * if the user is a member of more than one group. If the user is only 
 * in one space, we prefill the fields and the select box is hidden.
 * If the user is in multiple spaces, we set up our listeners and disable
 * the post button until a selection is made
 */
$userSpaces = SpaceMembership::GetUserSpaces();
$showSpacePicker = count($userSpaces) > 1 ? true : false;
// Use default behaviour when in a Space or Profile
if (Yii::app()->params['currentSpace'] || Yii::app()->params['currentUser']) {
    echo CHtml::hiddenField("containerGuid", $contentContainer->guid);
    echo CHtml::hiddenField("containerClass", get_class($contentContainer));
} else {
    if (count($userSpaces) == 0) {
        // if the user isn't in any spaces hide post area
        ?>
            <script type="text/javascript">
                $(function() {
                    $("#contentFormBody").hide();
                });
            </script>
        <?php 
 /**
  * Remove Membership
  *
  * @param $userId UserId of User to Remove
  */
 public function removeMember($userId = "")
 {
     if ($userId == "") {
         $userId = Yii::app()->user->id;
     }
     $user = User::model()->findByPk($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 == SpaceMembership::STATUS_MEMBER) {
         $activity = new Activity();
         $activity->content->space_id = $this->getOwner()->id;
         $activity->content->visibility = Content::VISIBILITY_PRIVATE;
         $activity->type = "ActivitySpaceMemberRemoved";
         $activity->created_by = $userId;
         $activity->save();
         $activity->fire();
     }
     // Was invited, but declined the request
     if ($membership->status == SpaceMembership::STATUS_INVITED) {
         SpaceInviteDeclinedNotification::fire($membership->originator_user_id, $user, $this->getOwner());
     }
     foreach (SpaceMembership::model()->findAllByAttributes(array('user_id' => $userId, 'space_id' => $this->getOwner()->id)) as $membership) {
         $membership->delete();
     }
     // Cleanup Notifications
     SpaceApprovalRequestNotification::remove($userId, $this->getOwner());
     SpaceInviteNotification::remove($userId, $this->getOwner());
     SpaceApprovalRequestNotification::remove($userId, $this->getOwner());
 }
예제 #14
0
 /**
  * Returns a JSON Object which contains a lot of informations about
  * current states like new posts on workspaces
  */
 public function actionGetFrontEndInfo()
 {
     $json = array();
     $json['workspaces'] = array();
     $criteria = new CDbCriteria();
     $criteria->order = 'last_visit DESC';
     $memberships = SpaceMembership::model()->with('workspace')->findAllByAttributes(array('user_id' => Yii::app()->user->id, 'status' => SpaceMembership::STATUS_MEMBER), $criteria);
     foreach ($memberships as $membership) {
         $workspace = $membership->workspace;
         $info = array();
         $info['name'] = CHtml::encode($workspace->name);
         #$info['id'] = $workspace->id;	# should be hidden at frontend
         $info['guid'] = $workspace->guid;
         $info['totalItems'] = $workspace->countItems();
         $info['newItems'] = $membership->countNewItems();
         $json['workspaces'][] = $info;
     }
     // New notification count
     $sql = "SELECT count(id)\n\t\tFROM notification\n\t\tWHERE  user_id = :user_id AND seen != 1";
     $connection = Yii::app()->db;
     $command = $connection->createCommand($sql);
     $userId = Yii::app()->user->id;
     $command->bindParam(":user_id", $userId);
     $json['newNotifications'] = $command->queryScalar();
     print CJSON::encode($json);
     Yii::app()->end();
 }
 /**
  * Delete users that are not space members anymore
  *
  * @param $spaceId
  * @throws CDbException
  */
 private function deleteMissingUsers($spaceId)
 {
     $attributes = array('space_id' => $spaceId);
     $reputationUsers = ReputationUser::model()->findAllByAttributes($attributes);
     foreach ($reputationUsers as $user) {
         $criteria = new CDbCriteria();
         $criteria->condition = 'space_id=:spaceId AND user_id=:userId';
         $criteria->params = array(':spaceId' => $spaceId, ':userId' => $user->user_id);
         if (SpaceMembership::model()->count($criteria) <= 0) {
             $user->delete();
         }
     }
 }
예제 #16
0
 /**
  * Returns a list of all spaces of the given userId
  *
  * @param type $userId
  */
 public static function GetUserSpaces($userId = "")
 {
     // Take current userid if none is given
     if ($userId == "") {
         $userId = Yii::app()->user->id;
     }
     $cacheId = "userSpaces_" . $userId;
     $cacheValue = Yii::app()->cache->get($cacheId);
     $orderSetting = HSetting::Get('spaceOrder', 'space');
     if ($cacheValue === false) {
         $criteria = new CDbCriteria();
         if ($orderSetting == 0) {
             $criteria->order = 'name ASC';
         } else {
             $criteria->order = 'last_visit DESC';
         }
         $spaces = array();
         $memberships = SpaceMembership::model()->with('space')->findAllByAttributes(array('user_id' => $userId, 'status' => SpaceMembership::STATUS_MEMBER), $criteria);
         foreach ($memberships as $membership) {
             $spaces[] = $membership->space;
         }
         Yii::app()->cache->set($cacheId, $spaces, HSetting::Get('expireTime', 'cache'));
         return $spaces;
     } else {
         return $cacheValue;
     }
 }
예제 #17
0
 /**
  * Deletes a user permanently
  */
 public function actionDelete()
 {
     $id = (int) Yii::app()->request->getQuery('id');
     $doit = (int) Yii::app()->request->getQuery('doit');
     $user = User::model()->resetScope()->findByPk($id);
     if ($user == null) {
         throw new CHttpException(404, Yii::t('AdminModule.controllers_UserController', 'User not found!'));
     } elseif (Yii::app()->user->id == $id) {
         throw new CHttpException(400, Yii::t('AdminModule.controllers_UserController', 'You cannot delete yourself!'));
     }
     if ($doit == 2) {
         $this->forcePostRequest();
         foreach (SpaceMembership::GetUserSpaces() as $workspace) {
             if ($workspace->isSpaceOwner($user->id)) {
                 $workspace->addMember(Yii::app()->user->id);
                 $workspace->setSpaceOwner(Yii::app()->user->id);
             }
         }
         $user->delete();
         $this->redirect(Yii::app()->createUrl('admin/user'));
     }
     $this->render('delete', array('model' => $user));
 }
예제 #18
0
 /**
  * When a user clicks on the Accept Invite Link, this action is called.
  * After this the user should be member of this workspace.
  */
 public function actionInviteAccept()
 {
     // Get Current Space
     $space = $this->getSpace();
     // Load Pending Membership
     $membership = SpaceMembership::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'space_id' => $space->id));
     if ($membership == null) {
         throw new CHttpException(404, Yii::t('SpaceModule.controllers_SpaceController', 'There is no pending invite!'));
     }
     // Check there are really an Invite
     if ($membership->status == SpaceMembership::STATUS_INVITED) {
         $space->addMember(Yii::app()->user->id);
         //SpaceInviteAcceptedNotification::fire($membership->originator_user_id, Yii::app()->user, $space);
     }
     $this->redirect($space->getUrl());
 }