public static function resolveRowCssClasses($grid, $row, $data) { if (is_array($grid->rowCssClass) && ($n = count($grid->rowCssClass)) > 0) { $content = $grid->rowCssClass[$row % $n]; if (!MissionsUtil::hasUserReadMissionLatest($data, Yii::app()->user->userModel)) { $content .= ' unread'; } return $content; } }
public function actionDetails($id) { $mission = static::getModelAndCatchNotFoundAndDisplayError('Mission', intval($id)); ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($mission); AuditEvent::logAuditEvent('ZurmoModule', ZurmoModule::AUDIT_EVENT_ITEM_VIEWED, array(strval($mission), 'MissionsModule'), $mission); MissionsUtil::markUserHasReadLatest($mission, Yii::app()->user->userModel); $detailsView = new MissionDetailsView($this->getId(), $this->getModule()->getId(), $mission); $missionsMashableInboxUrl = Yii::app()->createUrl('mashableInbox/default/list', array('modelClassName' => 'Mission')); $breadCrumbLinks = array(Zurmo::t('MissionsModule', 'Missions') => $missionsMashableInboxUrl, StringUtil::getChoppedStringContent(strval($mission), 25)); $view = new MissionsPageView(ZurmoDefaultViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $detailsView, $breadCrumbLinks, 'MissionBreadCrumbView')); echo $view->render(); }
/** * Override to handle sending email messages on new comment */ protected function afterSuccessfulSave($model) { assert('$model instanceof Item'); parent::afterSuccessfulSave($model); $user = Yii::app()->user->userModel; if ($this->relatedModel instanceof Conversation) { $participants = ConversationsUtil::resolvePeopleToSendNotificationToOnNewComment($this->relatedModel, $user); CommentsUtil::sendNotificationOnNewComment($this->relatedModel, $model, $user, $participants); } elseif ($this->relatedModel instanceof Mission) { $participants = MissionsUtil::resolvePeopleToSendNotificationToOnNewComment($this->relatedModel, $user); CommentsUtil::sendNotificationOnNewComment($this->relatedModel, $model, $user, $participants); } }
/** * @param string $uniquePageId * @param MissionsListConfigurationForm $form * @return RedBeanModelDataProvider */ protected function getDataProvider($uniquePageId, MissionsListConfigurationForm $form) { assert('is_string($uniquePageId)'); assert('$form instanceOf MissionsListConfigurationForm'); $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('dashboardListPageSize'); $mission = new Mission(); return MissionsUtil::makeDataProviderByType($mission, $form->type, $pageSize); }
public function testMissionReadUnreadStatus() { $steven = User::getByUsername('steven'); $sally = User::getByUsername('sally'); $mary = User::getByUsername('mary'); $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $mission = new Mission(); $mission->owner = $steven; $mission->description = 'My test mission description'; $mission->status = Mission::STATUS_AVAILABLE; $this->assertTrue($mission->save()); $missionId = $mission->id; $explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions(); $explicitReadWriteModelPermissions->addReadWritePermitable(Group::getByName(Group::EVERYONE_GROUP_NAME)); ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($mission, $explicitReadWriteModelPermissions); $mission = Mission::getById($missionId); //Confirm users have mission marked as unread but not owner $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $sally)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $mary)); //Super reads the mission $this->setGetArray(array('id' => $missionId)); $this->runControllerWithNoExceptionsAndGetContent('missions/default/details'); $mission = Mission::getById($missionId); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $sally)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $mary)); //Mary marks mission as read and post a comment $this->logoutCurrentUserLoginNewUserAndGetByUsername('mary'); MissionsUtil::markUserHasReadLatest($mission, $mary); $this->setGetArray(array('relatedModelId' => $missionId, 'relatedModelClassName' => 'Mission', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Comment' => array('description' => 'Mary\'s new comment'))); $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave'); $mission = Mission::getById($missionId); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $sally)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $mary)); //Sally reads and takes the mission $this->logoutCurrentUserLoginNewUserAndGetByUsername('sally'); $this->setGetArray(array('id' => $missionId)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('missions/default/details'); $mission = Mission::getById($missionId); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $sally)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $mary)); $this->setGetArray(array('status' => Mission::STATUS_TAKEN, 'id' => $missionId)); $this->runControllerWithNoExceptionsAndGetContent('missions/default/ajaxChangeStatus'); //Every user other than owner and takenby are marked as read latest $mission = Mission::getById($missionId); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $sally)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $mary)); }
/** * @depends testCreateAndGetMissionById */ public function testAddingComments() { $missions = Mission::getAll(); $this->assertEquals(1, count($missions)); $mission = $missions[0]; $steven = User::getByUserName('steven'); $super = User::getByUsername('super'); $latestStamp = $mission->latestDateTime; //latestDateTime should not change when just saving the mission $this->assertTrue($mission->save()); $this->assertEquals($latestStamp, $mission->latestDateTime); sleep(2); // Sleeps are bad in tests, but I need some time to pass //Add comment, this should update the latestDateTime, //and also it should mark takenByUser as not read latest $comment = new Comment(); $comment->description = 'This is my first comment'; $mission->comments->add($comment); $this->assertTrue($mission->save()); $this->assertNotEquals($latestStamp, $mission->latestDateTime); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); //super made the comment, so this should remain the same. $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $super)); //have steven make the comment. Now the owner HasReadLatest, //and takenByUser HasNotReadLatest Yii::app()->user->userModel = $steven; $mission = Mission::getById($mission->id); $comment = new Comment(); $comment->description = 'This is steven`\\s first comment'; $mission->comments->add($comment); $this->assertTrue($mission->save()); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $super)); }
/** * @inheritdoc */ public function getSubjectForEmailNotification() { return MissionsUtil::getEmailSubject($this->model); }
/** * After a mission is saved, if it is new, then a notification should go out to all users alerting them * of a new mission. Depending on the status change of the mission, a notification can go out as well to * the owner or user who has taken the mission. */ protected function afterSave() { if ($this->isNewModel && $this->getScenario() != 'importModel') { MissionsUtil::makeAndSubmitNewMissionNotificationMessage($this); } if (isset($this->originalAttributeValues['status']) && !$this->isNewModel && $this->originalAttributeValues['status'] != $this->status) { if ($this->status == self::STATUS_TAKEN) { $messageContent = Zurmo::t('MissionsModule', 'A mission you created has been taken on by {takenByUserName}', array('{takenByUserName}' => strval($this->takenByUser))); MissionsUtil::makeAndSubmitStatusChangeNotificationMessage($this->owner, $this->id, $messageContent); } elseif ($this->status == self::STATUS_COMPLETED) { $messageContent = Zurmo::t('MissionsModule', 'A mission you created has been completed'); MissionsUtil::makeAndSubmitStatusChangeNotificationMessage($this->owner, $this->id, $messageContent); } elseif ($this->status == self::STATUS_REJECTED && $this->takenByUser->id > 0) { $messageContent = Zurmo::t('MissionsModule', 'A mission you completed has been rejected'); MissionsUtil::makeAndSubmitStatusChangeNotificationMessage($this->takenByUser, $this->id, $messageContent); } elseif ($this->status == self::STATUS_ACCEPTED && $this->takenByUser->id > 0) { $messageContent = Zurmo::t('MissionsModule', 'A mission you completed has been accepted'); MissionsUtil::makeAndSubmitStatusChangeNotificationMessage($this->takenByUser, $this->id, $messageContent); } } parent::afterSave(); }
public function testMarkReadUnreadMassActionByModel() { $super = User::getByUsername('super'); //Conversation model $conversation = new Conversation(); $conversation->owner = $super; $conversation->subject = 'My test conversation subject'; $conversation->description = 'My test conversation description'; $this->assertTrue($conversation->save()); $conversationId = $conversation->id; $this->assertTrue((bool) ConversationsUtil::hasUserReadConversationLatest($conversation, $super)); //Mark conversation as unread $selectedIds = $conversationId; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Conversation', 'MashableInboxForm' => array('massAction' => 'markUnread', 'selectedIds' => $selectedIds))); $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list'); $conversation = Conversation::getById($conversationId); $this->assertFalse((bool) ConversationsUtil::hasUserReadConversationLatest($conversation, $super)); //Mark conversation as read $this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Conversation', 'MashableInboxForm' => array('massAction' => 'markRead', 'selectedIds' => $selectedIds))); $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list'); $conversation = Conversation::getById($conversationId); $this->assertTrue((bool) ConversationsUtil::hasUserReadConversationLatest($conversation, $super)); //Mission model $mission = new Mission(); $mission->owner = $super; $mission->description = 'My test mission description'; $mission->status = Mission::STATUS_AVAILABLE; $this->assertTrue($mission->save()); $missionId = $mission->id; $this->assertTrue((bool) MissionsUtil::hasUserReadMissionLatest($mission, $super)); //Mark mission as unread $selectedIds = $missionId; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Mission', 'MashableInboxForm' => array('massAction' => 'markUnread', 'selectedIds' => $selectedIds))); $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list'); $mission = Mission::getById($missionId); $this->assertFalse((bool) MissionsUtil::hasUserReadMissionLatest($mission, $super)); //Mark mission as read $this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Mission', 'MashableInboxForm' => array('massAction' => 'markRead', 'selectedIds' => $selectedIds))); $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list'); $mission = Mission::getById($missionId); $this->assertTrue((bool) MissionsUtil::hasUserReadMissionLatest($mission, $super)); }
public function testResolvePeopleToSendNotificationToOnNewMission() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $steven = User::getByUsername('steven'); $mary = UserTestHelper::createBasicUser('mary'); $missions = Mission::getAll(); $mission = $missions[0]; $people = MissionsUtil::resolvePeopleToSendNotificationToOnNewMission($mission); $this->assertNotContains($super, $people); $this->assertContains($steven, $people); $this->assertContains($mary, $people); }
public function testResolvePeopleToSendNotificationToOnNewMission() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $steven = User::getByUsername('steven'); $jack = User::getByUsername('jack'); // assert steven is active user $this->assertEquals(1, $steven->isActive); // assert steven is active user $this->assertEquals(1, $jack->isActive); // assert steven have access to missions module $this->assertTrue(RightsUtil::canUserAccessModule('MissionsModule', $steven)); // assert jack dont have access to missions module $this->assertFalse(RightsUtil::canUserAccessModule('MissionsModule', $jack)); $missions = Mission::getAll(); $mission = $missions[0]; $people = MissionsUtil::resolvePeopleToSendNotificationToOnNewMission($mission); // assert active user will get notification on creation of new mission $this->assertEquals(1, count($people)); $this->assertNotContains($super, $people); $this->assertContains($steven, $people); $this->assertNotContains($jack, $people); // Change the user's status to inactive and confirm the changes in rights and isActive attribute. $steven = User::getByUsername('steven'); $steven->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB, RIGHT::DENY); $this->assertTrue($steven->save()); // assert steven is inactive user $this->assertEquals(0, $steven->isActive); $missions = Mission::getAll(); $mission = $missions[0]; $people = MissionsUtil::resolvePeopleToSendNotificationToOnNewMission($mission); // assert inactive user won't get notification on creation of new mission $this->assertEquals(0, count($people)); $this->assertNotContains($super, $people); $this->assertNotContains($steven, $people); $this->assertNotContains($jack, $people); }
/** * Override to handle sending email messages on new comment */ protected function afterSuccessfulSave($model) { assert('$model instanceof Item'); parent::afterSuccessfulSave($model); $user = Yii::app()->user->userModel; if ($this->relatedModel instanceof Conversation) { $participants = ConversationsUtil::resolvePeopleToSendNotificationToOnNewComment($this->relatedModel, $user); CommentsUtil::sendNotificationOnNewComment($this->relatedModel, $model, $participants); } elseif ($this->relatedModel instanceof Mission) { $participants = MissionsUtil::resolvePeopleToSendNotificationToOnNewComment($this->relatedModel, $user); CommentsUtil::sendNotificationOnNewComment($this->relatedModel, $model, $participants); } elseif ($this->relatedModel instanceof Task) { TasksNotificationUtil::submitTaskNotificationMessage($this->relatedModel, TasksNotificationUtil::TASK_NEW_COMMENT, $model->createdByUser, $model); //Log the event if ($this->relatedModel->project->id > 0) { ProjectsUtil::logAddCommentEvent($this->relatedModel, $model->description); } } }