public function testCreateAuditEventWithInvalidProjectValidation() { Yii::app()->user->userModel = User::getByUsername('super'); $user = Yii::app()->user->userModel; $project = new Project(); $project->name = 'Project 1'; $project->owner = $user; $project->description = 'Description'; $this->assertTrue($project->save()); ProjectAuditEvent::deleteAll(); $project->name = null; $projectAuditEvent = new ProjectAuditEvent(); $saved = $projectAuditEvent->logAuditEvent(ProjectAuditEvent::PROJECT_CREATED, $project, 'name', $user); $this->assertTrue($saved); $events = ProjectAuditEvent::getAll('dateTime', true); $this->assertEquals(ProjectAuditEvent::PROJECT_CREATED, $events[0]->eventName); $this->assertEquals($project->id, $events[0]->project->id); $this->assertEquals('name', unserialize($events[0]->serializedData)); }
/** * Logs audit event * @param string $eventName * @param array $data * @param Project $project * @param User $user * @return boolean */ public static function logAuditEvent($eventName, Project $project, $data = null, User $user = null) { assert('is_string($eventName) && $eventName != ""'); assert('$project->id > 0'); if ($user === null) { $user = Yii::app()->user->userModel; if (!$user instanceof User) { throw new NoCurrentUserSecurityException(); } } $projectAuditEvent = new ProjectAuditEvent(); $projectAuditEvent->dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $projectAuditEvent->eventName = $eventName; $projectAuditEvent->user = $user; $projectAuditEvent->project = $project; $projectAuditEvent->serializedData = serialize($data); //Removed the validation on save to fix: https://www.pivotaltracker.com/story/show/70712466 $saved = $projectAuditEvent->save(false); if ($saved) { return true; } else { throw new FailedToSaveModelException(); } }
/** * @param DemoDataHelper $demoDataHelper */ public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); $projects = array(); $super = User::getByUsername('super'); for ($i = 0; $i < $this->resolveQuantityToLoad(); $i++) { $project = new Project(); $project->owner = $demoDataHelper->getRandomByModelName('User'); $account = $demoDataHelper->getRandomByModelName('Account'); $project->accounts->add($account); $this->populateModel($project); $project->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER); $saved = $project->save(); assert('$saved'); $project = Project::getById($project->id); AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($project, Group::getByName(Group::EVERYONE_GROUP_NAME)); $project->save(); assert('$saved'); ProjectAuditEvent::logAuditEvent(ProjectAuditEvent::PROJECT_CREATED, $project, $project->name); self::addDemoTasks($project, 3, $demoDataHelper); $projects[] = $project->id; } $demoDataHelper->setRangeByModelName('Project', $projects[0], $projects[count($projects) - 1]); }
/** * Handle audit of projects after save */ protected function afterSave() { if ($this->getIsNewModel()) { ProjectAuditEvent::logAuditEvent(ProjectAuditEvent::PROJECT_CREATED, $this, $this->name); } elseif ($this->status == Project::STATUS_ARCHIVED) { ProjectAuditEvent::logAuditEvent(ProjectAuditEvent::PROJECT_ARCHIVED, $this, $this->name); } parent::afterSave(); }
/** * Handle audit of projects after save */ protected function afterSave() { if ($this->getIsNewModel()) { ProjectAuditEvent::logAuditEvent(ProjectAuditEvent::PROJECT_CREATED, $this, $this->name); ProjectsNotificationUtil::submitProjectNotificationMessage($this, ProjectAuditEvent::PROJECT_CREATED); } elseif ($this->status == Project::STATUS_ARCHIVED && isset($this->originalAttributeValues['status'])) { ProjectAuditEvent::logAuditEvent(ProjectAuditEvent::PROJECT_ARCHIVED, $this, $this->name); ProjectsNotificationUtil::submitProjectNotificationMessage($this, ProjectAuditEvent::PROJECT_ARCHIVED); } parent::afterSave(); }
/** * Logs event on adding comment to the task * @param Task $task * @param string $comment */ public static function logAddCommentEvent(Task $task, $comment) { assert('$task instanceof Task'); assert('is_string($comment)'); $project = $task->project; $data = array('{comment}' => $comment); ProjectAuditEvent::logAuditEvent(ProjectAuditEvent::COMMENT_ADDED, $project, $data); }