public function actionHideWelcome() { $configurationForm = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser(Yii::app()->user->userModel); $configurationForm->hideWelcomeView = true; UserConfigurationFormAdapter::setConfigurationFromForm($configurationForm, Yii::app()->user->userModel); $this->redirect(array($this->getId() . '/index')); }
public static function resolveDefaultNotificationSettingsDefaultValuesByUser(User $user, &$defaultNotificationSettings) { if (UserConfigurationFormAdapter::resolveAndGetValue($user, 'turnOffEmailNotifications')) { foreach ($defaultNotificationSettings as $notificationName => $notificationSetting) { $defaultNotificationSettings[$notificationName]['email'] = false; } } }
protected function resolveSelectedGroup() { $resolvedSelectedGroup = parent::resolveSelectedGroup(); if ($resolvedSelectedGroup === null) { return UserConfigurationFormAdapter::resolveAndGetValue(Yii::app()->user->userModel, 'defaultPermissionGroupSetting', false); } return $resolvedSelectedGroup; }
public static function renderDesktopNotificationsScript() { if (UserConfigurationFormAdapter::resolveAndGetValue(Yii::app()->user->userModel, 'enableDesktopNotifications')) { $makeNotification = "\n if (window.webkitNotifications.checkPermission() == 0)\n {\n nf = window.webkitNotifications.createNotification(image, title, body);\n if (nf.hasOwnProperty('onshow'))\n {\n nf.onshow = function() {setTimeout(function () {nf.close();}, 20000);};\n }\n nf.show();\n return true;\n }\n "; } else { $makeNotification = ""; } // Begin Not Coding Standard $script = "\n var desktopNotifications =\n {\n notify:function(image, title, body)\n {\n " . $makeNotification . "\n return false;\n },\n isSupported:function()\n {\n if (typeof window.webkitNotifications != 'undefined')\n {\n return true\n }\n else\n {\n return false\n }\n },\n requestAutorization:function()\n {\n if (typeof window.webkitNotifications != 'undefined')\n {\n if (window.webkitNotifications.checkPermission() == 1)\n {\n window.webkitNotifications.requestPermission();\n }\n else if (window.webkitNotifications.checkPermission() == 2)\n {\n alert('" . Zurmo::t('ZurmoModule', 'You have blocked desktop notifications for this browser.') . "');\n }\n else\n {\n alert('" . Zurmo::t('ZurmoModule', 'You have already activated desktop notifications for Chrome') . "');\n }\n }\n else\n {\n alert('" . Zurmo::t('ZurmoModule', 'This is only available in Chrome.') . "');\n }\n }\n };\n "; // End Not Coding Standard Yii::app()->clientScript->registerScript('AutoUpdater', $script, CClientScript::POS_HEAD); }
public function testNobodyUserHomePageView() { $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody'); $content = $this->runControllerWithNoExceptionsAndGetContent('home/default/welcome'); $this->assertContains('Welcome to Zurmo', $content); //When hideWelcomeView is on nobody should see HomeView $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($nobody); $form->hideWelcomeView = true; UserConfigurationFormAdapter::setConfigurationFromFormForCurrentUser($form); $content = $this->runControllerWithNoExceptionsAndGetContent('home/default/welcome'); $this->assertContains('HomeView', $content); }
public static function resolveUserDefaultPermissionsByUser(User $user, RedBeanModel $model = null) { $defaultPermissionSettings = UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($user); $nonEveryoneGroup = UserConfigurationFormAdapter::resolveAndGetValue($user, 'defaultPermissionGroupSetting', false); $type = DerivedExplicitReadWriteModelPermissionsElement::resolveUserPermissionConfigurationToPermissionType($defaultPermissionSettings); $explicitReadWriteModelPermissions = compact('type', 'nonEveryoneGroup'); $permissions = compact('explicitReadWriteModelPermissions'); if ($model === null || $model instanceof OwnedSecurableItem) { $owner = array('id' => $user->id); $permissions = compact('owner', 'explicitReadWriteModelPermissions'); } return $permissions; }
public function testSuperUserWelcomeActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //test that the welcome screen appears $content = $this->runControllerWithNoExceptionsAndGetContent('home/default/welcome'); $this->assertContains('Go to the dashboard', $content); //Change setting so user ignores welcome view. $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($super); $form->hideWelcomeView = true; UserConfigurationFormAdapter::setConfigurationFromFormForCurrentUser($form); //Now the welcome screen should not appear $this->runControllerWithRedirectExceptionAndGetContent('home/default/welcome'); }
/** * @param RedBeanModel $relatedModel * @param Comment $comment * @param $senderPerson * @param array $peopleToSendNotification */ public static function sendNotificationOnNewComment(RedBeanModel $relatedModel, Comment $comment, $senderPerson, $peopleToSendNotification) { if (count($peopleToSendNotification) > 0) { foreach ($peopleToSendNotification as $people) { if ($people->primaryEmail->emailAddress !== null && !UserConfigurationFormAdapter::resolveAndGetValue($people, 'turnOffEmailNotifications')) { $subject = self::getEmailSubject($relatedModel); $content = self::getEmailContent($relatedModel, $comment, $people); EmailNotificationUtil::resolveAndSendEmail($senderPerson, array($people), $subject, $content); } } } else { return; } }
/** * @param SecurableItem $model * @param User $user * @throws NotSupportedException */ public static function updatePermissionsWithDefaultForModelByUser(SecurableItem $model, User $user) { if ($model instanceof SecurableItem && count($model->permissions) === 0) { $defaultPermission = UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($user); $nonEveryoneGroup = UserConfigurationFormAdapter::resolveAndGetValue($user, 'defaultPermissionGroupSetting', false); $type = static::resolveDefaultPermissionToExplicitReadWriteModelPermissionsUtilType($defaultPermission); $postData = array('explicitReadWriteModelPermissions' => compact('type', 'nonEveryoneGroup')); $explicitReadWritePermissions = self::resolveAndMakeExplicitReadWriteModelPermissions($postData, $model); $updated = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($model, $explicitReadWritePermissions); if (!$updated) { throw new NotSupportedException(); } } }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); $super = User::getByUsername('super'); $super = User::getByUsername('super'); $super->primaryEmail = new Email(); $super->primaryEmail->emailAddress = '*****@*****.**'; assert($super->save()); // Not Coding Standard //Create alpha group $group = new Group(); $group->name = 'Alpha'; $saved = $group->save(); assert($saved); // Not Coding Standard self::$alphaGroup = $group; //Now set default permissions to owner and users in group Alpha $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($super); $form->defaultPermissionSetting = UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP; $form->defaultPermissionGroupSetting = $group->id; UserConfigurationFormAdapter::setConfigurationFromForm($form, $super); $bobby = UserTestHelper::createBasicUserWithEmailAddress('bobby'); $sarah = UserTestHelper::createBasicUserWithEmailAddress('sarah'); self::$superUserId = $super->id; self::$bobbyUserId = $bobby->id; self::$sarahUserId = $sarah->id; $file = ZurmoTestHelper::createFileModel(); $emailTemplate = new EmailTemplate(); $emailTemplate->builtType = EmailTemplate::BUILT_TYPE_PASTED_HTML; $emailTemplate->modelClassName = 'WorkflowModelTestItem'; $emailTemplate->type = 1; $emailTemplate->name = 'some template'; $emailTemplate->subject = 'some subject [[LAST^NAME]]'; $emailTemplate->htmlContent = 'html content [[STRING]]'; $emailTemplate->textContent = 'text content [[PHONE]]'; $emailTemplate->files->add($file); $saved = $emailTemplate->save(); if (!$saved) { throw new FailedToSaveModelException(); } self::$emailTemplate = $emailTemplate; $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); assert($everyoneGroup->save()); // Not Coding Standard }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; AllPermissionsOptimizationUtil::rebuild(); //create everyone group $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); $everyoneGroup->save(); //Create test users $steven = UserTestHelper::createBasicUser('steven'); $steven->primaryEmail->emailAddress = '*****@*****.**'; //Steven has turned off notifications UserConfigurationFormAdapter::setValue($steven, true, 'turnOffEmailNotifications'); $sally = UserTestHelper::createBasicUser('sally'); $sally->primaryEmail->emailAddress = '*****@*****.**'; $mary = UserTestHelper::createBasicUser('mary'); $mary->primaryEmail->emailAddress = '*****@*****.**'; //give 3 users access, create, delete for mission rights. $steven->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS); $steven->setRight('MissionsModule', MissionsModule::RIGHT_CREATE_MISSIONS); $steven->setRight('MissionsModule', MissionsModule::RIGHT_DELETE_MISSIONS); $saved = $steven->save(); if (!$saved) { throw new NotSupportedException(); } $sally->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS); $sally->setRight('MissionsModule', MissionsModule::RIGHT_CREATE_MISSIONS); $sally->setRight('MissionsModule', MissionsModule::RIGHT_DELETE_MISSIONS); $saved = $sally->save(); if (!$saved) { throw new NotSupportedException(); } $mary->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS); $mary->setRight('MissionsModule', MissionsModule::RIGHT_CREATE_MISSIONS); $mary->setRight('MissionsModule', MissionsModule::RIGHT_DELETE_MISSIONS); $saved = $mary->save(); if (!$saved) { throw new NotSupportedException(); } }
public function testsSendNotificationOnNewComment() { $super = User::getByUsername('super'); $steven = User::getByUsername('steven'); $jack = User::getByUsername('jack'); $conversation = new Conversation(); $conversation->owner = Yii::app()->user->userModel; $conversation->subject = 'My test subject2'; $conversation->description = 'My test description2'; $this->assertTrue($conversation->save()); $comment = new Comment(); $comment->description = 'This is the 1st test comment'; //Confirm no email notifications are sitting in the queue $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); //No message was sent because Steven and Jack don't have primary email address CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $super, array($steven, $jack)); $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $super->primaryEmail->emailAddress = '*****@*****.**'; $steven->primaryEmail->emailAddress = '*****@*****.**'; $jack->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($super->save()); $this->assertTrue($steven->save()); $this->assertTrue($jack->save()); //One email message was sent because to Steven and Jack CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $super, array($steven, $jack)); $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[0]; $this->assertEquals(2, count($emailMessage->recipients)); //One email message was sent to Super but not to Steven UserConfigurationFormAdapter::setValue($steven, true, 'turnOffEmailNotifications'); CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $jack, array($steven, $super)); $this->assertEquals(2, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[1]; $this->assertEquals(1, count($emailMessage->recipients)); }
/** * @depends testListDefault */ public function testListDefaultAfterChange() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); // change default permissions to a specific group, doesn't matter if it does not exist. $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($super); $form->defaultPermissionSetting = UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP; $form->defaultPermissionGroupSetting = 6; UserConfigurationFormAdapter::setConfigurationFromForm($form, $super); unset($form); // validate that settings were saved. $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($super), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP); $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetValue($super, 'defaultPermissionGroupSetting', false), 6); $response = $this->listDefaultPermissionsForCurrentUser($headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertArrayHasKey('data', $response); $this->assertCount(2, $response['data']); $this->assertArrayHasKey('owner', $response['data']); $this->assertCount(1, $response['data']['owner']); $this->assertArrayHasKey('id', $response['data']['owner']); $this->assertEquals($super->id, $response['data']['owner']['id']); $this->assertArrayHasKey('explicitReadWriteModelPermissions', $response['data']); $this->assertCount(2, $response['data']['explicitReadWriteModelPermissions']); $this->assertArrayHasKey('type', $response['data']['explicitReadWriteModelPermissions']); $this->assertEquals(2, $response['data']['explicitReadWriteModelPermissions']['type']); $this->assertArrayHasKey('nonEveryoneGroup', $response['data']['explicitReadWriteModelPermissions']); $this->assertEquals(6, $response['data']['explicitReadWriteModelPermissions']['nonEveryoneGroup']); // change default permissions to owner only. $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($super); $form->defaultPermissionSetting = UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER; UserConfigurationFormAdapter::setConfigurationFromForm($form, $super); unset($form); // validate that settings were saved. $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($super), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER); $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($super, 'defaultPermissionGroupSetting', false)); $response = $this->listDefaultPermissionsForCurrentUser($headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertArrayHasKey('data', $response); $this->assertCount(2, $response['data']); $this->assertArrayHasKey('owner', $response['data']); $this->assertCount(1, $response['data']['owner']); $this->assertArrayHasKey('id', $response['data']['owner']); $this->assertEquals($super->id, $response['data']['owner']['id']); $this->assertArrayHasKey('explicitReadWriteModelPermissions', $response['data']); $this->assertCount(2, $response['data']['explicitReadWriteModelPermissions']); $this->assertArrayHasKey('type', $response['data']['explicitReadWriteModelPermissions']); $this->assertEquals('', $response['data']['explicitReadWriteModelPermissions']['type']); $this->assertArrayHasKey('nonEveryoneGroup', $response['data']['explicitReadWriteModelPermissions']); $this->assertEquals('', $response['data']['explicitReadWriteModelPermissions']['nonEveryoneGroup']); }
/** * Send task email * @param Notification $notification * @param TaskNotificationRules $rule * @param string $action */ protected static function sendTaskEmail(Notification $notification, TaskNotificationRules $rule, $action) { assert('is_string($action)'); if ($notification->owner->primaryEmail->emailAddress !== null && !UserConfigurationFormAdapter::resolveAndGetValue($notification->owner, 'turnOffEmailNotifications')) { $emailMessage = static::makeEmailMessage($notification, $rule, $action); $emailMessage->content = static::makeEmailContent($notification); $emailMessage->sender = static::makeSender(); $emailMessage->recipients->add(static::makeRecipient($notification)); $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT); try { Yii::app()->emailHelper->send($emailMessage); } catch (CException $e) { //Not sure what to do yet when catching an exception here. Currently ignoring gracefully. } } }
/** * Based on the model's attribute value being a explicitReadWriteModelPermissions object, * resolves the selected group value if available. * @return string */ protected function resolveSelectedGroup() { if (!$this->isModelCreateAction() || $this->model->isCopied()) { return parent::resolveSelectedGroup(); } if (null != ($selectedGroup = UserConfigurationFormAdapter::resolveAndGetValue(Yii::app()->user->userModel, 'defaultPermissionGroupSetting', false))) { return $selectedGroup; } else { return parent::resolveSelectedGroup(); } }
/** * @depends testClosingConversations */ public function testSendEmailInNewComment() { if (!SECURITY_OPTIMIZED) { return; } $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $steven = User::getByUsername('steven'); $sally = User::getByUsername('sally'); $mary = User::getByUsername('mary'); $conversations = Conversation::getAll(); $this->assertEquals(2, count($conversations)); $this->assertEquals(0, $conversations[0]->comments->count()); foreach (EmailMessage::getAll() as $emailMessage) { $emailMessage->delete(); } $initalQueued = 0; $conversation = $conversations[0]; $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $steven; $conversation->conversationParticipants->add($conversationParticipant); $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $sally; $conversation->conversationParticipants->add($conversationParticipant); $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $mary; $conversation->conversationParticipants->add($conversationParticipant); UserConfigurationFormAdapter::setValue($mary, true, 'turnOffEmailNotifications'); //Save a new comment $this->setGetArray(array('relatedModelId' => $conversation->id, 'relatedModelClassName' => 'Conversation', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name'))); $content = $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave'); $this->assertEquals(1, $conversation->comments->count()); $this->assertEquals($initalQueued + 1, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[$initalQueued]; $this->assertEquals(2, count($emailMessage->recipients)); $this->assertContains('conversation', $emailMessage->subject); $this->assertContains(strval($conversation), $emailMessage->subject); $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->htmlContent); $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->textContent); }
/** * @param Conversation $conversation * @param $person */ public static function sendEmailInviteToParticipant(Conversation $conversation, $person) { assert('$conversation->id > 0'); assert('$person instanceof User || $person instanceof Contact'); if ($person->primaryEmail->emailAddress !== null && ($person instanceof User && !UserConfigurationFormAdapter::resolveAndGetValue($person, 'turnOffEmailNotifications') || $person instanceof Contact)) { $userToSendMessagesFrom = $conversation->owner; $emailMessage = new EmailMessage(); $emailMessage->owner = Yii::app()->user->userModel; $emailMessage->subject = Zurmo::t('ConversationsModule', 'You have been invited to participate in a conversation'); $emailContent = new EmailMessageContent(); $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate(static::getParticipantInviteEmailTextContent($conversation)); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate(static::getParticipantInviteEmailHtmlContent($conversation)); $emailMessage->content = $emailContent; $sender = new EmailMessageSender(); $sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom); $sender->fromName = strval($userToSendMessagesFrom); $sender->personOrAccount = $userToSendMessagesFrom; $emailMessage->sender = $sender; $recipient = new EmailMessageRecipient(); $recipient->toAddress = $person->primaryEmail->emailAddress; $recipient->toName = strval($person); $recipient->type = EmailMessageRecipient::TYPE_TO; $recipient->personOrAccount = $person; $emailMessage->recipients->add($recipient); $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT); try { Yii::app()->emailHelper->send($emailMessage); } catch (CException $e) { //Not sure what to do yet when catching an exception here. Currently ignoring gracefully. } } }
protected static function sendEmail(Notification $notification) { if ($notification->owner->primaryEmail->emailAddress !== null && !UserConfigurationFormAdapter::resolveAndGetValue($notification->owner, 'turnOffEmailNotifications')) { $userToSendMessagesFrom = BaseControlUserConfigUtil::getUserToRunAs(); $emailMessage = new EmailMessage(); $emailMessage->owner = Yii::app()->user->userModel; $emailMessage->subject = strval($notification); $emailContent = new EmailMessageContent(); $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate($notification->notificationMessage->textContent); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate($notification->notificationMessage->htmlContent); $emailMessage->content = $emailContent; $sender = new EmailMessageSender(); $sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom); $sender->fromName = strval($userToSendMessagesFrom); $emailMessage->sender = $sender; $recipient = new EmailMessageRecipient(); $recipient->toAddress = $notification->owner->primaryEmail->emailAddress; $recipient->toName = strval($notification->owner); $recipient->type = EmailMessageRecipient::TYPE_TO; $recipient->personsOrAccounts->add($notification->owner); $emailMessage->recipients->add($recipient); $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT); if (!$emailMessage->save()) { throw new FailedToSaveModelException(); } try { Yii::app()->emailHelper->sendImmediately($emailMessage); } catch (CException $e) { //Not sure what to do yet when catching an exception here. Currently ignoring gracefully. } } }
public function actionConfigurationEdit($id) { UserAccessUtil::resolveCanCurrentUserAccessAction(intval($id)); $user = User::getById(intval($id)); UserAccessUtil::resolveCanCurrentUserAccessRootUser($user); UserAccessUtil::resolveAccessingASystemUser($user); $title = Zurmo::t('ConfigurationModule', 'Configuration'); $breadCrumbLinks = array(strval($user) => array('default/details', 'id' => $id), $title); $configurationForm = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($user); $postVariableName = get_class($configurationForm); if (isset($_POST[$postVariableName])) { $configurationForm->setAttributes($_POST[$postVariableName]); if ($configurationForm->validate()) { if ($user->id != Yii::app()->user->userModel->id) { UserConfigurationFormAdapter::setConfigurationFromForm($configurationForm, $user); } else { UserConfigurationFormAdapter::setConfigurationFromFormForCurrentUser($configurationForm); } Yii::app()->user->setFlash('notification', Zurmo::t('UsersModule', 'User configuration saved successfully.')); $this->redirect(array($this->getId() . '/details', 'id' => $user->id)); } } $titleBarAndEditView = new UserActionBarAndConfigurationEditView($this->getId(), $this->getModule()->getId(), $user, $configurationForm); $titleBarAndEditView->setCssClasses(array('AdministrativeArea')); $view = new UsersPageView($this->resolveZurmoDefaultOrAdminView($titleBarAndEditView, $breadCrumbLinks, 'UserBreadCrumbView')); echo $view->render(); }
/** * @param DemoDataHelper $demoDataHelper */ public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); assert('$demoDataHelper->isSetRange("Group")'); assert('$demoDataHelper->isSetRange("Role")'); $super = User::getByUsername('super'); $email = new Email(); $email->emailAddress = static::resolveDemoEmailAddress('Super.test'); $super->primaryEmail = $email; $saved = $super->save(); assert('$saved'); UserConfigurationFormAdapter::setValue($super, true, 'turnOffEmailNotifications'); $userAvatarForm = new UserAvatarForm($super); $userAvatarForm->avatarType = User::AVATAR_TYPE_PRIMARY_EMAIL; $saved = $userAvatarForm->save(); assert('$saved'); $user = new User(); $this->populateModel($user); $user->username = '******'; $user->title->value = 'Sir'; $user->firstName = 'Jason'; $user->lastName = 'Blue'; $user->lastLoginDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $email = new Email(); $email->emailAddress = static::resolveDemoEmailAddress('Jason.Blue'); $user->primaryEmail = $email; $user->setPassword($user->username); $saved = $user->save(); assert('$saved'); UserConfigurationFormAdapter::setValue($user, true, 'turnOffEmailNotifications'); $userAvatarForm = new UserAvatarForm($user); $userAvatarForm->avatarType = User::AVATAR_TYPE_PRIMARY_EMAIL; $saved = $userAvatarForm->save(); assert('$saved'); $userStartId = $user->id; $roleIdRange = $demoDataHelper->getRangeByModelName('Role'); $role = Role::getById($roleIdRange['startId']); assert('$role instanceof Role'); $role->users->add($user); $saved = $role->save(); assert('$saved'); foreach (array('jim' => 'Mr.', 'john' => 'Mr.', 'sally' => 'Dr.', 'mary' => 'Mrs.', 'katie' => 'Ms.', 'jill' => 'Ms.', 'sam' => 'Mr.') as $username => $title) { $user = new User(); $this->populateModel($user); $user->username = $username; $user->setPassword($user->username); $user->title->value = $title; $user->firstName = ucfirst($username); $user->lastName = 'Smith'; $email = new Email(); $email->emailAddress = static::resolveDemoEmailAddress($user->firstName); $user->primaryEmail = $email; $user->lastLoginDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $saved = $user->save(); assert('$saved'); UserConfigurationFormAdapter::setValue($user, true, 'turnOffEmailNotifications'); $userAvatarForm = new UserAvatarForm($user); $userAvatarForm->avatarType = User::AVATAR_TYPE_PRIMARY_EMAIL; $saved = $userAvatarForm->save(); assert('$saved'); $roleIdRange = $demoDataHelper->getRangeByModelName('Role'); $role = Role::getById($roleIdRange['startId'] + 1); assert('$role instanceof Role'); $role->users->add($user); $saved = $role->save(); assert('$saved'); } $demoDataHelper->setRangeByModelName('User', $userStartId, $user->id); }
/** * @param Mission $mission */ public static function makeAndSubmitNewMissionNotificationMessage(Mission $mission) { $recipients = array(); $peopleToSendNotification = static::resolvePeopleToSendNotificationToOnNewMission($mission); foreach ($peopleToSendNotification as $person) { if ($person->primaryEmail->emailAddress != null && !UserConfigurationFormAdapter::resolveAndGetValue($person, 'turnOffEmailNotifications')) { $recipients[] = $person; } } EmailNotificationUtil::resolveAndSendEmail($mission->owner, $recipients, static::getEmailSubject($mission), static::getEmailContent($mission)); }
public function testAfterSaveForImportModel() { $testUser = UserTestHelper::createBasicUserWithEmailAddress('jimmy'); UserConfigurationFormAdapter::setValue($testUser, false, 'turnOffEmailNotifications'); Yii::app()->user->userModel = User::getByUsername('super'); $this->assertCount(0, EmailMessage::getAll()); $task = new Task(); $task->name = 'MyTaskWithoutImport'; $task->owner = $testUser; $task->requestedByUser = Yii::app()->user->userModel; $this->assertTrue($task->save()); $this->assertEquals(2, count($task->notificationSubscribers)); $this->assertCount(1, EmailMessage::getAll()); //With import $task = new Task(); $task->setScenario('importModel'); $task->name = 'MyTaskWithImport'; $task->owner = $testUser; $task->requestedByUser = Yii::app()->user->userModel; $this->assertTrue($task->save()); $this->assertEquals(2, count($task->notificationSubscribers)); $this->assertCount(1, EmailMessage::getAll()); }
/** * Based on the model's attribute value being a explicitReadWriteModelPermissions object, * resolves the selected type value. * @return string */ protected function resolveSelectedType() { return UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($this->model->user); }
public function testGetVisibleAndOrderedTabMenuItemsByUser() { $sally = User::getByUsername('sally'); $sally->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS); $this->assertTrue($sally->save()); $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($sally); $customOrderedTabMenuItems = UserConfigurationFormAdapter::getVisibleAndOrderedTabMenuItemsByUser($sally); $this->assertEquals(3, count($customOrderedTabMenuItems)); $form->selectedVisibleAndOrderedTabMenuItems = $customOrderedTabMenuItems; UserConfigurationFormAdapter::setConfigurationFromForm($form, $sally); $sally->removeRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS); $this->assertTrue($sally->save()); $customOrderedTabMenuItems = UserConfigurationFormAdapter::getVisibleAndOrderedTabMenuItemsByUser($sally); $this->assertEquals(2, count($customOrderedTabMenuItems)); }
public function testGlobalDefaultsLoadedOnCreateInAbsenceOfUserDefaultPermissions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); UserConfigurationFormAdapter::setValue($super, null, 'defaultPermissionSetting', false); UserConfigurationFormAdapter::setDefaultPermissionGroupSetting($super, null, null); $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/create'); // test that 'everyone' radio button is checked $this->assertEquals(preg_match('%<input id="Account_explicitReadWriteModelPermissions_type_2" value="1" ' . 'checked="checked" type="radio" name="Account\\[explicitReadWriteModelPermissions\\]\\[type\\]" />%', $content), 1); // test that no downdown item is selected $this->assertEquals(preg_match('%<option value="(\\d+)" selected="selected">(.*)</option>%', $content), 0); // Not Coding Standard }