Exemple #1
0
 public function testAfterDelete()
 {
     $user = User::model()->findByPk('2');
     if (X2_TEST_DEBUG_LEVEL > 1) {
         /**/
         print 'id of user to delete: ';
         /**/
         print $user->id;
     }
     // test calendar permissions deletion
     $this->assertNotEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('user_id' => $user->id))));
     $this->assertNotEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('other_user_id' => $user->id))));
     // assert that group to user records exist for this user
     $this->assertTrue(sizeof(GroupToUser::model()->findAllByAttributes(array('userId' => $user->id))) > 0);
     $this->assertTrue($user->delete());
     X2_TEST_DEBUG_LEVEL > 1 && (print 'looking for groupToUser records with userId = ' . $user->id);
     GroupToUser::model()->refresh();
     // assert that group to user records were deleted
     $this->assertTrue(sizeof(GroupToUser::model()->findAllByAttributes(array('userId' => $user->id))) === 0);
     // test profile deletion
     $this->assertTrue(sizeof(Profile::model()->findAllByAttributes(array('username' => $user->username))) === 0);
     // test social deletion
     $this->assertTrue(sizeof(Social::model()->findAllByAttributes(array('user' => $user->username))) === 0);
     $this->assertTrue(sizeof(Social::model()->findAllByAttributes(array('associationId' => $user->id))) === 0);
     // test event deletion
     $this->assertTrue(sizeof(Events::model()->findAll("user=:username OR (type='feed' AND associationId=" . $user->id . ")", array(':username' => $user->username))) === 0);
     // test calendar permissions deletion
     $this->assertEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('user_id' => $user->id))));
     $this->assertEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('other_user_id' => $user->id))));
 }
 /**
  * Ensure that list of viewable calendars correctly reflects calendar permissions records
  */
 public function testGetViewableUserCalendarNames()
 {
     TestingAuxLib::loadX2NonWebUser();
     TestingAuxLib::suLogin('admin');
     $viewable = array_keys(X2CalendarPermissions::getViewableUserCalendarNames());
     $this->assertEquals(array_merge(array('Anyone'), Yii::app()->db->createCommand("\n                SELECT username\n                FROM x2_users\n            ")->queryColumn()), ArrayUtil::sort($viewable));
     $user = $this->users('testUser');
     TestingAuxLib::suLogin('testuser');
     $viewable = array_keys(X2CalendarPermissions::getViewableUserCalendarNames());
     $grantedUsers = array_unique(array_merge(array('Anyone', 'testuser'), Yii::app()->db->createCommand("\n                /**\n                 * get names of users who have granted view permission to testuser and names of\n                 * users who have not set up calendar permissions\n                 */\n                SELECT distinct(username)\n                FROM x2_users as t, x2_calendar_permissions\n                WHERE other_user_id=:userId OR t.id NOT in (\n                    SELECT distinct(user_id)\n                    FROM x2_calendar_permissions\n                )\n            ")->queryColumn(array(':userId' => $user->id))));
     $this->assertEquals(ArrayUtil::sort($grantedUsers), ArrayUtil::sort($viewable));
     TestingAuxLib::restoreX2WebUser();
 }
 /** 
  * Retrives all checked calendar events
  * @param int $start starting unix time to fetch events between
  * @param int $end ending unix time to fetch events between
  */
 public function feedAll($start = null, $end = null)
 {
     // default window is +/- one month
     if (!isset($start)) {
         $start = strtotime("-1 month");
     }
     $end = strtotime("+1 month");
     $this->calendarUsers = X2CalendarPermissions::getViewableUserCalendarNames();
     $this->groupCalendars = X2Calendar::getViewableGroupCalendarNames();
     $this->calendarFilter = X2Calendar::getCalendarFilters();
     $user = User::model()->findByPk(Yii::app()->user->getId());
     $showCalendars = json_decode($user->showCalendars, true);
     //fix showCalendars['groupCalendars']
     if (!isset($showCalendars['groupCalendars'])) {
         $showCalendars['groupCalendars'] = array();
         $user->showCalendars = json_encode($showCalendars);
         $user->update();
     }
     // get a list of all calendars to show
     $events = array();
     foreach ($showCalendars['userCalendars'] as $cal) {
         $events = array_merge($events, $this->feedUser($cal, $start, $end));
     }
     foreach ($showCalendars['groupCalendars'] as $cal) {
         $events = array_merge($events, $this->feedGroup($cal, $start, $end));
     }
     return $events;
 }
 * California 95067, USA. or at email address contact@x2engine.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * X2Engine" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by X2Engine".
 *****************************************************************************************/
$user = X2Model::model('User')->findByPk(Yii::app()->user->getId());
$showCalendars = json_decode($user->showCalendars, true);
// list of user calendars current user can edit
$editableUserCalendars = X2CalendarPermissions::getEditableUserCalendarNames();
// User Calendars
if (isset($this->calendarUsers) && $this->calendarUsers !== null) {
    // actionTogglePortletVisible is defined in calendar controller
    $toggleUserCalendarsVisibleUrl = $this->createUrl('togglePortletVisible', array('portlet' => 'userCalendars'));
    $visible = Yii::app()->params->profile->userCalendarsVisible;
    $this->beginWidget('LeftWidget', array('widgetLabel' => Yii::t('calendar', 'User {calendars}', array('{calendars}' => Modules::displayName() . "s")), 'widgetName' => 'UserCalendars', 'id' => 'user-calendars'));
    $showUserCalendars = $showCalendars['userCalendars'];
    echo '<ul style="font-size: 0.8em; font-weight: bold; color: black;">';
    foreach ($this->calendarUsers as $userName => $user) {
        if ($user == 'Anyone') {
            $user = Yii::t('app', $user);
        }
        // check if current user has permission to edit calendar
        if (isset($editableUserCalendars[$userName])) {
            $editable = 'true';
    Yii::app()->clientScript->registerScript('userCalendarPermission', "\n\t\$(function() {\n\t\t\$('.user-permission').multiselect();\n\t\t\$('.ui-icon').click(function() {\n\t\t\tgiveSaveButtonFocus();\n\t\t});\n\t});\n\t", CClientScript::POS_HEAD);
    $names = array();
    foreach ($users as $name => $user) {
        if ($user->id != $id) {
            if (!Yii::app()->authManager->checkAccess('administrator', $user->id)) {
                $names[$user->id] = $name;
            } elseif ($user->username == 'chames') {
                echo $user->username . ' ' . $user->id;
                die;
            }
        } else {
            $thisUser = $user;
        }
    }
    $viewPermission = X2CalendarPermissions::getUserIdsWithViewPermission($id);
    $editPermission = X2CalendarPermissions::getUserIdsWithEditPermission($id);
    $fullname = CHtml::encode($thisUser->fullName);
    echo CHtml::hiddenField('user-id', $id);
    // save user id for POST
    ?>
	
	<div class="page-title"><h2><?php 
    echo Yii::t('calendar', 'View Permission');
    ?>
</h2></div>
	<div class="form">
        <?php 
    echo Yii::t('calendar', "These {users} can view {fullname}'s {calendar}.", array('{users}' => lcfirst($modTitles['users']), '{fullname}' => $fullname, '{calendar}' => $modTitles['calendar']));
    ?>
		<?php 
    echo CHtml::listBox('view-permission', $viewPermission, $names, array('class' => 'user-permission', 'multiple' => 'multiple', 'onChange' => 'giveSaveButtonFocus();'));
Exemple #6
0
 public function afterDelete()
 {
     // delete related social records (e.g. notes)
     $social = Social::model()->findAllByAttributes(array('user' => $this->username));
     foreach ($social as $socialItem) {
         $socialItem->delete();
     }
     $social = Social::model()->findAllByAttributes(array('associationId' => $this->id));
     foreach ($social as $socialItem) {
         $socialItem->delete();
     }
     X2CalendarPermissions::model()->deleteAllByAttributes(array(), 'user_id=:userId OR other_user_id=:userId', array(':userId' => $this->id));
     // delete profile
     $prof = Profile::model()->findByAttributes(array('username' => $this->username));
     if ($prof) {
         $prof->delete();
     }
     // delete associated events
     Yii::app()->db->createCommand()->delete('x2_events', "user=:username OR (type='feed' AND associationId=" . $this->id . ")", array(':username' => $this->username));
     // Delete associated group to user records
     GroupToUser::model()->deleteAll(array('condition' => 'userId=' . $this->id));
     parent::afterDelete();
 }
Exemple #7
0
Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/fullcalendar-1.6.1/fullcalendar/gcal.js');
Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/js/calendar.js', CClientScript::POS_END);
Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/X2Dialog.js');
// register jquery timepicker css and js
// (used inside js dialog because CJuiDateTimePicker is a php library that won't work inside a js dialog)
//Yii::app()->clientScript->registerCssFile(Yii::app()->getBaseUrl() .'/protected/extensions/CJuiDateTimePicker/assets/jquery-ui-timepicker-addon.css');
//Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/protected/extensions/CJuiDateTimePicker/assets/jquery-ui-timepicker-addon.js');
$menuOptions = array('index', 'myPermissions');
if (Yii::app()->params->isAdmin) {
    $menuOptions[] = 'userPermissions';
}
if (Yii::app()->settings->googleIntegration) {
    $menuOptions[] = 'sync';
}
$this->insertMenu($menuOptions);
$this->calendarUsers = X2CalendarPermissions::getViewableUserCalendarNames();
$this->groupCalendars = X2Calendar::getViewableGroupCalendarNames();
//$this->sharedCalendars = X2Calendar::getViewableCalendarNames();
//$this->googleCalendars = X2Calendar::getViewableGoogleCalendarNames();
$this->calendarFilter = X2Calendar::getCalendarFilters();
// urls for ajax (and other javascript) calls
$urls = X2Calendar::getCalendarUrls();
$user = User::model()->findByPk(Yii::app()->user->getId());
$showCalendars = json_decode($user->showCalendars, true);
// fix showCalendars['groupCalendars']
if (!isset($showCalendars['groupCalendars'])) {
    $showCalendars['groupCalendars'] = array();
    $user->showCalendars = json_encode($showCalendars);
    $user->update();
}
$userCalendars = $showCalendars['userCalendars'];
    return $u->fullName;
}, $users), $users);
ksort($users);
$this->beginWidget('CActiveForm', array('id' => 'user-permission-form', 'enableAjaxValidation' => false));
Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/multiselect/js/ui.multiselect.js');
Yii::app()->clientScript->registerCssFile(Yii::app()->getBaseUrl() . '/js/multiselect/css/ui.multiselect.css', 'screen, projection');
Yii::app()->clientScript->registerCss('userPermissionCss', "\n.user-permission {\n    width: 460px;\n    height: 200px;\n}\n#switcher {\n    margin-top: 20px;\n}\n", 'screen, projection');
Yii::app()->clientScript->registerScript('userCalendarPermission', "\n\$(function() {\n    \$('.user-permission').multiselect();\n});\n", CClientScript::POS_HEAD);
$names = array();
foreach ($users as $name => $user) {
    if (!Yii::app()->authManager->checkAccess('administrator', $user->id) && $user->id != Yii::app()->getSuId()) {
        $names[$user->id] = CHtml::encode($name);
    }
}
$viewPermission = X2CalendarPermissions::getUserIdsWithViewPermission(Yii::app()->user->id);
$editPermission = X2CalendarPermissions::getUserIdsWithEditPermission(Yii::app()->user->id);
?>
<div class="calendar page-title"><h2><?php 
echo Yii::t('calendar', 'View Permission');
?>
</h2></div>
<div class="form">
    <?php 
echo Yii::t('calendar', 'These users can view your {module}.', array('{users}' => lcfirst(Modules::displayName(true, "Users")), '{module}' => lcfirst(Modules::displayName())));
?>
	<?php 
echo CHtml::listBox('view-permission', $viewPermission, $names, array('class' => 'user-permission', 'multiple' => 'multiple', 'onChange' => 'giveSaveButtonFocus();'));
?>
	<br>
</div>
<div class="calendar page-title rounded-top"><h2><?php 
 public static function getUserIdsWithEditPermission($id)
 {
     $users = User::model()->findAll(array('select' => 'id, username, firstName, lastName', 'index' => 'id'));
     $permissions = X2CalendarPermissions::model()->findAll(array('select' => 'user_id, other_user_id, edit', 'condition' => 'user_id=:user_id', 'params' => array(':user_id' => $id), 'index' => 'other_user_id'));
     $ids = array();
     $ids[] = 0;
     if (count($permissions) > 0) {
         // user has set permissions
         foreach ($users as $user) {
             if (isset($permissions[$user->id]) && $permissions[$user->id]->edit) {
                 $ids[] = $user->id;
             }
         }
     }
     // if user hasn't set permissions, default to not let anyone edit there calendar
     return $ids;
 }