function testEncode_EntriesAndLoadPartial_PartialOk() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($userId); $user->role = SystemRoles::USER; $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->addProject($projectId); $user->write(); $project->write(); $sense = new Sense(); $sense->definition->form('en', 'apple'); for ($i = 9; $i >= 0; $i--) { $entry = new LexEntryModel($project); $entry->lexeme->form('th', 'Apfel' . $i); $entry->senses[] = $sense; $entry->write(); } $result = LexDbeDto::encode($projectId, $userId, null, 5); $this->assertEqual(count($result['entries']), 5); $this->assertEqual($result['itemCount'], 5); $this->assertEqual($result['itemTotalCount'], 10); $this->assertEqual($result['entries'][0]['lexeme']['th']['value'], 'Apfel0', 'Apfel0 should sort first'); $this->assertEqual($result['entries'][4]['lexeme']['th']['value'], 'Apfel4', 'Apfel4 should sort first'); $result = LexDbeDto::encode($projectId, $userId, null, 9); $this->assertEqual(count($result['entries']), 1); $this->assertEqual($result['itemCount'], 1); $this->assertEqual($result['itemTotalCount'], 10); $this->assertEqual($result['entries'][0]['lexeme']['th']['value'], 'Apfel0', 'Apfel0 should sort first'); }
public function testUpdateConfig_ConfigPersists() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($userId); $user->role = SystemRoles::USER; $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->addProject($projectId); $user->write(); $project->write(); $config = json_decode(json_encode(LexBaseViewDto::encode($projectId, $userId)['config']), true); $this->assertTrue($config['tasks']['addMeanings']['visible']); $this->assertEqual($config['entry']['fields']['lexeme']['inputSystems'][0], 'th'); $config['tasks']['addMeanings']['visible'] = false; $config['entry']['fields']['lexeme']['inputSystems'] = array('my', 'th'); LexProjectCommands::updateConfig($projectId, $config); $project2 = new LexiconProjectModel($projectId); // test for a few default values $this->assertEqual($project2->inputSystems['en']->tag, 'en'); $this->assertTrue($project2->config->tasks['dbe']->visible); $this->assertEqual($project2->config->entry->fields['lexeme']->label, 'Word'); // test for updated values $this->assertFalse($project2->config->tasks['addMeanings']->visible); $this->assertEqual($project2->config->entry->fields['lexeme']->inputSystems[0], 'my'); $this->assertEqual($project2->config->entry->fields['lexeme']->inputSystems[1], 'th'); }
public function checkUser($userId) { $this->usersChecked++; $user = new UserModel($userId); if ($this->makeChanges) { $user->write(); } }
/** * Removes this project from the collection. * User references to this project are also removed */ public function remove() { foreach ($this->users as $userId => $roleObj) { $user = new UserModel($userId); $user->removeProject($this->id->asString()); $user->write(); } $this->rrmdir($this->getAssetsFolderPath()); MapperUtils::dropAllCollections($this->databaseName()); ProjectModelMongoMapper::instance()->remove($this->id->asString()); }
public function getProjectMember($projectId, $userName) { $userId = $this->e->createUser($userName, $userName, '*****@*****.**'); $user = new UserModel($userId); $user->addProject($projectId); $user->write(); $project = new ProjectModel($projectId); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $project->write(); return $userId; }
/** * Writes a user to the users collection. * * @param string $username * @param string $name * @param string $email * @param string $role * @return string id */ public function createUser($username, $name, $email, $role = SystemRoles::USER) { $userModel = new Api\Model\UserModel(); $userModel->username = $username; $userModel->name = $name; $userModel->email = $email; $userModel->avatar_ref = $username . ".png"; $userModel->role = $role; $userModel->active = true; $userModel->siteRole[$this->website->domain] = $this->website->userDefaultSiteRole; return $userModel->write(); }
public function run($mode = 'test') { $testMode = $mode == 'test'; $message = ""; $userlist = new UserListModel(); $userlist->read(); $badUserRoles = 0; foreach ($userlist->entries as $userParams) { // foreach existing user $userId = $userParams['id']; $user = new UserModel($userId); if (!$user->role) { $user->role = SystemRoles::USER; if (!$testMode) { $user->write(); } $badUserRoles++; $message .= "Fixed role of user {$userId}\n"; } } if ($badUserRoles > 0) { $message .= "\n\nFixed {$badUserRoles} non-existent user roles from the users collection\n\n"; } else { $message .= "\n\nNo non-existent user roles found in the users collection\n\n"; } $projectlist = new ProjectListModel(); $projectlist->read(); $badProjectUserRoles = 0; foreach ($projectlist->entries as $projectParams) { // foreach existing project $projectId = $projectParams['id']; $project = new ProjectModel($projectId); $projectUserRefs = array_keys($project->users); foreach ($projectUserRefs as $ref) { // foreach user that is a member of this project if (!isset($project->users[$ref]->role)) { $project->users[$ref]->role = ProjectRoles::CONTRIBUTOR; $badProjectUserRoles++; $message .= "Fixed role of user {$ref} for project {$projectId}\n"; } } if (!$testMode) { $project->write(); } } if ($badProjectUserRoles > 0) { $message .= "\n\nFixed {$badProjectUserRoles} non-existent user roles from the projects collection\n\n"; } else { $message .= "\n\nNo non-existent user roles found in the projects collection\n\n"; } return $message; }
public function run($userId, $mode = 'test') { $testMode = $mode != 'run'; $message = "Fix site roles integrity\n\n"; // loop over every project $projectlist = new ProjectListModel(); $projectlist->read(); $fixCount = array(); foreach ($projectlist->entries as $projectParams) { // foreach existing project $projectId = $projectParams['id']; $project = new ProjectModel($projectId); $hostname = $project->siteName; $website = Website::get($hostname); $fixCount[$hostname] = 0; $projectUserRefs = array_keys($project->users->getArrayCopy()); $message .= "------------- " . $project->projectName . "\n"; foreach ($projectUserRefs as $userId) { // foreach user that is a member of this project $user = new UserModel($userId); if (!array_key_exists($hostname, $user->siteRole) && $user->username != '') { $message .= "Fixed user '" . $user->username . "' who did not have a site role on " . $hostname . "\n"; $fixCount[$hostname]++; $user->siteRole[$hostname] = $website->userDefaultSiteRole; if (!$testMode) { $user->write(); } } } } // loop over users who do not belong to any projects $userlist = new UserListModel(); $userlist->read(); foreach ($userlist->entries as $userParams) { // foreach existing user $userId = $userParams['id']; $user = new UserModel($userId); if (count($user->projects->refs) == 0 && count(array_keys($user->siteRole->getArrayCopy())) == 0) { $message .= "Warning: user '" . $user->username . "' has no projects and no siteRoles on any site!\n"; } } foreach ($fixCount as $site => $count) { if ($count > 0) { $message .= "\n\n{$site} : Fixed {$count} non-existent site roles \n\n"; } else { $message .= "\n\n{$site} : Nothing to do \n\n"; } } return $message; }
public function testUserCanAccessMethod_projectSettings_projectMember_false() { $userId = $this->environ->createUser('user', 'user', '*****@*****.**', SystemRoles::USER); $user = new UserModel($userId); $project = $this->environ->createProject('projectForTest', 'projTestCode'); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $project->appName = 'sfchecks'; $project->write(); $user->addProject($projectId); $user->write(); $project = ProjectModel::getById($projectId); $rh = new RightsHelper($userId, $project, $this->environ->website); $result = $rh->userCanAccessMethod('project_settings', array()); $this->assertFalse($result); }
public function testEncode_ProjectWithUser_DtoCorrect() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($userId); $user->role = SystemRoles::USER; $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->addProject($projectId); $user->write(); $project->write(); $dto = ManageUsersDto::encode($projectId); $this->assertEqual($dto['userCount'], 1); $this->assertIsA($dto['users'], 'array'); $this->assertEqual($dto['users'][0]['id'], $userId); $this->assertEqual($dto['users'][0]['name'], 'Name'); $this->assertEqual($dto['users'][0]['role'], ProjectRoles::CONTRIBUTOR); }
public function testEncode_ProjectWith2Users1Unvalidated_DtoCorrect1User() { $e = new MongoTestEnvironment(); $e->clean(); $user1Id = $e->createUser("", "", ""); $user1 = new UserModel($user1Id); $user1->role = SystemRoles::USER; $user2Id = $e->createUser("User", "Name", "*****@*****.**"); $user2 = new UserModel($user2Id); $user2->role = SystemRoles::USER; $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($user1Id, ProjectRoles::CONTRIBUTOR); $user1->addProject($projectId); $user1->write(); $project->addUser($user2Id, ProjectRoles::CONTRIBUTOR); $user2->addProject($projectId); $user2->write(); $project->write(); $text1 = new TextModel($project); $text1->title = "Some Title"; $text1->write(); $text2 = new TextModel($project); $text2->title = "Archived Title"; $text2->isArchived = true; $text2->write(); $dto = ProjectSettingsDto::encode($projectId, $user2Id); $this->assertEqual($dto['count'], 1); $this->assertIsA($dto['entries'], 'array'); $this->assertEqual($dto['entries'][0]['id'], $user2Id); $this->assertEqual($dto['entries'][0]['name'], 'Name'); $this->assertEqual($dto['entries'][0]['role'], ProjectRoles::CONTRIBUTOR); $this->assertEqual(count($dto['archivedTexts']), 1); $this->assertEqual($dto['archivedTexts'][0]['title'], 'Archived Title'); $this->assertTrue(count($dto['rights']) > 0, "No rights in dto"); $this->assertEqual($dto['bcs']['op'], 'settings'); $this->assertEqual($dto['bcs']['project'], array('id' => $projectId, 'crumb' => SF_TESTPROJECT)); $this->assertFalse(isset($dto['project']['users'])); $this->assertEqual($dto['project']['id'], $projectId); }
public function testWrite_TwoModels_ReadBackBothModelsOk() { $model = new UserModel(); $model->email = "*****@*****.**"; $model->username = "******"; $id = $model->write(); $this->assertNotNull($id); $this->assertIsA($id, 'string'); $otherModel = new UserModel($id); $this->assertEqual($id, $otherModel->id->asString()); $this->assertEqual('*****@*****.**', $otherModel->email); $this->assertEqual('SomeUser', $otherModel->username); $model = new ProjectModel(); $model->language = "SomeLanguage"; $model->projectName = "SomeProject"; $id = $model->write(); $this->assertNotNull($id); $this->assertIsA($id, 'string'); $otherModel = new ProjectModel($id); $this->assertEqual($id, $otherModel->id->asString()); $this->assertEqual('SomeLanguage', $otherModel->language); $this->assertEqual('SomeProject', $otherModel->projectName); }
public function testEncode_ProjectWithUser_DtoCorrect() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($userId); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE, 'sfchecks'); $project->ownerRef->id = $userId; $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->addProject($projectId); $user->write(); $project->write(); $dto = ProjectManagementDto::encode($projectId); $this->assertTrue(count($dto['reports']) > 0); $foundUserEngagementReport = false; foreach ($dto['reports'] as $report) { if ($report['id'] == 'sfchecks_userEngagementReport') { $foundUserEngagementReport = true; } } $this->assertTrue($foundUserEngagementReport); }
public function testEncode_2Questions1Archived_DtoCorrect1ArchivedQuestion() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($userId); $user->role = SystemRoles::USER; $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::MANAGER); $user->addProject($projectId); $user->write(); $project->write(); $text = new TextModel($project); $text->title = "Text Title"; $textId = $text->write(); $question1 = new QuestionModel($project); $question1->title = "Some Title"; $question1->textRef->id = $textId; $question1->write(); $question2 = new QuestionModel($project); $question2->title = "Archived Title"; $question2->textRef->id = $textId; $question2->isArchived = true; $question2->write(); $dto = TextSettingsDto::encode($projectId, $textId, $userId); $this->assertIsA($dto['text'], 'array'); $this->assertEqual($dto['text']['id'], $textId); $this->assertEqual($dto['text']['title'], 'Text Title'); $this->assertIsA($dto['archivedQuestions'], 'array'); $this->assertEqual(count($dto['archivedQuestions']), 1); $this->assertEqual($dto['archivedQuestions'][0]['title'], 'Archived Title'); $this->assertTrue(count($dto['rights']) > 0, "No rights in dto"); $this->assertEqual($dto['bcs']['op'], 'settings'); $this->assertEqual($dto['bcs']['project'], array('id' => $projectId, 'crumb' => SF_TESTPROJECT)); }
public function testSendJoinRequest_PropertiesFromToBodyOk() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $adminId = $e->createUser('admin', 'Admin', '*****@*****.**'); $admin = new UserModel($adminId); $userId = $e->createUser('User', 'Name', '*****@*****.**'); $user = new UserModel($userId); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $delivery = new MockCommunicateDelivery(); $project->addUser($adminId, $e->website->userDefaultSiteRole); $project->write(); $admin->addProject($project->id->asString()); $admin->write(); Communicate::sendJoinRequest($user, $admin, $project, $e->website, $delivery); // What's in the delivery? $senderEmail = 'no-reply@' . $e->website->domain; $expectedFrom = array($senderEmail => $e->website->name); $expectedTo = array($admin->email => $admin->name); $this->assertEqual($expectedFrom, $delivery->from); $this->assertEqual($expectedTo, $delivery->to); $this->assertPattern('/' . $user->name . '/', $delivery->subject); $this->assertPattern('/' . $e->website->domain . '\\/app\\/usermanagement/', $delivery->content); }
public function run($mode = 'test') { $testMode = $mode == 'test'; $message = ""; $userlist = new UserListModel(); $userlist->read(); $userIds = array_map(function ($e) { return $e['id']; }, $userlist->entries); $projectlist = new ProjectListModel(); $projectlist->read(); $projectIds = array_map(function ($e) { return $e['id']; }, $projectlist->entries); $deadProjectLinks = 0; foreach ($userlist->entries as $userParams) { // foreach existing user $userId = $userParams['id']; $user = new UserModel($userId); $userProjectRefs = $user->projects->refs; foreach ($userProjectRefs as $ref) { // foreach project the user belongs to if (!in_array($ref, $projectIds)) { $user->removeProject($ref); // remove dead project link $deadProjectLinks++; $message .= "Removed dead project link {$ref} from user {$userId}\n"; } } if (!$testMode) { $user->write(); } } if ($deadProjectLinks > 0) { $message .= "\n\nRemoved {$deadProjectLinks} dead project links from the users collection\n\n"; } else { $message .= "\n\nNo dead project links were found\n\n"; } $deadUserLinks = 0; foreach ($projectlist->entries as $projectParams) { // foreach existing project $projectId = $projectParams['id']; $project = new ProjectModel($projectId); $projectUserRefs = array_keys($project->users); foreach ($projectUserRefs as $ref) { // foreach user that is a member of this project if (!in_array($ref, $userIds)) { $project->removeUser($ref); // remove dead user link $deadUserLinks++; $message .= "Removed dead user link {$ref} for project {$projectId}\n"; } } if (!$testMode) { $project->write(); } } if ($deadUserLinks > 0) { $message .= "\n\nRemoved {$deadUserLinks} dead user links from the projects collection\n\n"; } else { $message .= "\n\nNo dead user links were found\n\n"; } return $message; }
public function testUpdateFromRegistration_ExpiredKey_UserNotUpdatedAndKeyConsumed() { $this->environ->clean(); $user = new UserModel(); $user->emailPending = '*****@*****.**'; $key = $user->setValidation(1); $date = $user->validationExpirationDate; $date->sub(new DateInterval('P2D')); $user->validationExpirationDate = $date; $userId = $user->write(); // save data for rest of this test $this->save['userId'] = $userId; $userArray = array('id' => '', 'username' => 'joe', 'name' => 'joe user', 'password' => 'password'); $this->environ->inhibitErrorDisplay(); $this->expectException(); UserCommands::updateFromRegistration($key, $userArray, $this->environ->website); // nothing runs in the current test function after an exception. IJH 2014-11 }
public function testMultipleUnreadModels_multipleUsers_multipleUpdates_multipleVisitsToQuestionPage_usersHaveDifferentUnreadStates() { $e = new MongoTestEnvironment(); $e->clean(); $project = $e->createProject("unread_test", "unreadCode"); $projectId = $project->id->asString(); $userId1 = $e->createUser('user1', 'user1', 'user1'); $user1 = new UserModel($userId1); $user1->addProject($project->id->asString()); $user1->write(); $userId2 = $e->createUser('user2', 'user2', 'user2'); $user2 = new UserModel($userId2); $user2->addProject($project->id->asString()); $user2->write(); $userId3 = $e->createUser('user3', 'user3', 'user3'); $user3 = new UserModel($userId3); $user3->addProject($project->id->asString()); $user3->write(); $answer1 = array('content' => "test answer 1", 'id' => ''); $answer2 = array('content' => "test answer 2", 'id' => ''); $text = new TextModel($project); $text->title = "Text 1"; $usx = MongoTestEnvironment::usxSample(); $text->content = $usx; $textId = $text->write(); $question = new QuestionModel($project); $question->title = "test question"; $question->textRef->id = $textId; $questionId = $question->write(); $answer1Dto = QuestionCommands::updateAnswer($projectId, $questionId, $answer1, $userId1); $answer2Dto = QuestionCommands::updateAnswer($projectId, $questionId, $answer2, $userId2); $answer1 = array_pop($answer1Dto); $answer1Id = $answer1['id']; $answer2 = array_pop($answer2Dto); $answer2Id = $answer2['id']; // the answer author does NOT get their answer marked as unread $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 1); // the answer author does NOT get their answer marked as unread $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 1); $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 2); // user1 visits question page $pageDto = QuestionCommentDto::encode($projectId, $questionId, $userId1); $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 1); $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 2); // user2 visits question page $pageDto = QuestionCommentDto::encode($projectId, $questionId, $userId2); $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 2); // user2 visits question page $pageDto = QuestionCommentDto::encode($projectId, $questionId, $userId3); $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); }
public function testChangePassword_SystemAdminChangeOtherUser_Succeeds() { $this->environ->clean(); $adminModel = new Api\Model\UserModel(); $adminModel->username = '******'; $adminModel->role = SystemRoles::SYSTEM_ADMIN; $adminId = $adminModel->write(); $userModel = new Api\Model\UserModel(); $userModel->username = '******'; $userModel->role = SystemRoles::NONE; $userId = $userModel->write(); $this->assertNotEqual($adminId, $userId); UserCommands::changePassword($userId, 'somepass', $adminId); $passwordModel = new PasswordModel($userId); $result = $passwordModel->verifyPassword('somepass'); $this->assertTrue($result, 'Could not verify changed password'); }
public function testEncode_UserOf1Project2Projects_DtoReturnsProjectCount1() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($userId); $user->role = SystemRoles::USER; $user->write(); $project1 = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId1 = $project1->id->asString(); $project1->addUser($userId, ProjectRoles::CONTRIBUTOR); $project1->ownerRef->id = $userId; $project1->write(); $project2 = $e->createProject(SF_TESTPROJECT2, SF_TESTPROJECTCODE2); $project2->ownerRef->id = $userId; $project2->write(); $dto = ProjectListDto::encode($userId, $e->website); $this->assertEqual($dto['count'], 1); $this->assertIsA($dto['entries'], 'array'); $this->assertEqual($dto['entries'][0]['id'], $projectId1); $this->assertEqual($dto['entries'][0]['projectName'], SF_TESTPROJECT); $this->assertEqual($dto['entries'][0]['role'], ProjectRoles::CONTRIBUTOR); }
public function testRemoveUsers_ProjectOwner_NotRemovedFromProject() { $this->environ->clean(); // setup project and users. user1 is the project owner $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $user1Id = $this->environ->createUser("user1name", "User1 Name", "*****@*****.**"); $user2Id = $this->environ->createUser("user2name", "User2 Name", "*****@*****.**"); $user1 = new UserModel($user1Id); $user2 = new UserModel($user2Id); $project->addUser($user1->id->asString(), ProjectRoles::CONTRIBUTOR); $project->addUser($user2->id->asString(), ProjectRoles::CONTRIBUTOR); $project->ownerRef = $user2Id; $project->write(); $user1->addProject($project->id->asString()); $user1->write(); $user2->addProject($project->id->asString()); $user2->write(); // save data for rest of this test $this->save['projectId'] = $projectId; $this->save['user1Id'] = $user1Id; $this->save['user2Id'] = $user2Id; // remove users from project. user1 still remains as project owner $userIds = array($user1->id->asString(), $user2->id->asString()); $this->expectException(); $this->environ->inhibitErrorDisplay(); ProjectCommands::removeUsers($projectId, $userIds); // nothing runs in the current test function after an exception. IJH 2014-11 }
public function testHasForgottenPassword_KeySetConsumeKey_HasForgottenKeyConsumed() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser('user1', 'User1', 'user1'); $user = new UserModel($userId); $user->setForgotPassword(7); $user->write(); $hasForgottenPassword = $user->hasForgottenPassword(true); $this->assertTrue($hasForgottenPassword); $this->assertFalse($user->resetPasswordKey); $today = new \DateTime(); $hourMargin = 60; $this->assertWithinMargin($user->resetPasswordExpirationDate->getTimestamp(), $today->getTimestamp(), $hourMargin); }
public function testRemoveProject_ProjectHasMembers_UserRefsToProjectAreRemoved() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser('user1', 'user1', 'user1'); $user = new UserModel($userId); $project = $e->createProject('testProject', 'testProjCode'); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $projectId = $project->write(); $user->addProject($project->id->asString()); $user->write(); // delete the project $project->remove(); // re-read the user $user->read($userId); $this->assertFalse($user->isMemberOfProject($projectId)); }
$adminUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['adminName'], 'email' => $constants['adminEmail'], 'username' => $constants['adminUsername'], 'password' => $constants['adminPassword'], 'active' => true, 'role' => SystemRoles::SYSTEM_ADMIN), $website); $managerUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['managerName'], 'email' => $constants['managerEmail'], 'username' => $constants['managerUsername'], 'password' => $constants['managerPassword'], 'active' => true, 'role' => SystemRoles::USER), $website); $memberUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['memberName'], 'email' => $constants['memberEmail'], 'username' => $constants['memberUsername'], 'password' => $constants['memberPassword'], 'active' => true, 'role' => SystemRoles::USER), $website); $expiredUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['expiredName'], 'email' => $constants['expiredEmail'], 'username' => $constants['expiredUsername'], 'password' => $constants['memberPassword'], 'active' => true, 'role' => SystemRoles::USER), $website); $resetUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['resetName'], 'email' => $constants['resetEmail'], 'username' => $constants['resetUsername'], 'password' => $constants['memberPassword'], 'active' => true, 'role' => SystemRoles::USER), $website); // set forgot password with expired date $today = new DateTime(); $expiredUser = new UserModel($expiredUserId); $expiredUser->resetPasswordKey = $constants['expiredPasswordKey']; $expiredUser->resetPasswordExpirationDate = $today; $expiredUser->write(); // set forgot password with valid date $resetUser = new UserModel($resetUserId); $resetUser->resetPasswordKey = $constants['resetPasswordKey']; $resetUser->resetPasswordExpirationDate = $today->add(new DateInterval('P5D')); $resetUser->write(); $projectType = null; if ($site == 'scriptureforge') { $projectType = SfProjectModel::SFCHECKS_APP; } else { if ($site == 'languageforge') { $projectType = LfProjectModel::LEXICON_APP; } } $testProject = ProjectCommands::createProject($constants['testProjectName'], $constants['testProjectCode'], $projectType, $adminUserId, $website); $testProjectModel = new ProjectModel($testProject); $testProjectModel->projectCode = $constants['testProjectCode']; $testProjectModel->allowInviteAFriend = $constants['testProjectAllowInvites']; $testProjectModel->write(); $otherProject = ProjectCommands::createProject($constants['otherProjectName'], $constants['otherProjectCode'], $projectType, $managerUserId, $website); $otherProjectModel = new ProjectModel($otherProject);
/** * * @param UserModel $user * @param UserModel $admin * @param ProjectModel $projectModel * @param Website $website * @param DeliveryInterface $delivery */ public static function sendJoinRequest($user, $admin, $projectModel, $website, DeliveryInterface $delivery = null) { $user->setValidation(7); $user->write(); $to = array($admin->email => $admin->name); $subject = $user->name . ' join request'; $vars = array('user' => $user, 'admin' => $admin, 'project' => $projectModel, 'link' => $website->baseUrl() . '/app/usermanagement/' . $projectModel->id->asString() . '#/joinRequests'); self::sendTemplateEmail($to, $subject, 'JoinRequest', $vars, $website, $delivery); }
/** * Sends an email to invite emailee to join the project * @param string $projectId * @param string $inviterUserId * @param Website $website * @param string $toEmail * @param DeliveryInterface $delivery * @throws \Exception * @return string $userId */ public static function sendInvite($projectId, $inviterUserId, $website, $toEmail, DeliveryInterface $delivery = null) { $newUser = new UserModel(); $inviterUser = new UserModel($inviterUserId); $project = new ProjectModel($projectId); $newUser->emailPending = $toEmail; // Check if email already exists in an account $identityCheck = UserCommands::checkIdentity('', $toEmail, $website); if ($identityCheck->emailExists) { $newUser->readByProperty('email', $toEmail); } // Make sure the user exists on the site if (!$newUser->hasRoleOnSite($website)) { $newUser->siteRole[$website->domain] = $website->userDefaultSiteRole; } // Determine if user is already a member of the project if ($project->userIsMember($newUser->id->asString())) { return $newUser->id; } // Add the user to the project $newUser->addProject($project->id->asString()); $userId = $newUser->write(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $project->write(); if (!$identityCheck->emailExists) { // Email communication with new user Communicate::sendInvite($inviterUser, $newUser, $project, $website, $delivery); } else { // Tell existing user they're now part of the project Communicate::sendAddedToProject($inviterUser, $newUser, $project, $website, $delivery); } return $userId; }
/** * Removes users from the project (two-way unlink) * @param Id $projectId * @param array $userIds array<string> */ public static function removeUsers($projectId, $userIds) { $project = new ProjectModel($projectId); foreach ($userIds as $userId) { // Guard against removing project owner if ($userId != $project->ownerRef->id) { $user = new UserModel($userId); $project->removeUser($user->id->asString()); $user->removeProject($project->id->asString()); $project->write(); $user->write(); } else { throw new \Exception("Cannot remove project owner"); } } }
public function testGetActivityForUser_TwoProjectsTwoDomains_UnreadHasOneProject() { $e = new MongoTestEnvironment('scriptureforge.org'); $e->clean(); $project1 = $e->createProject(SF_TESTPROJECTCODE, SF_TESTPROJECTCODE); $project2 = $e->createProject(SF_TESTPROJECTCODE2, SF_TESTPROJECTCODE2); $project2->siteName = 'languageforge.org'; $project2->write(); $userId = $e->createUser('joe', 'joe', 'joe'); $user = new UserModel($userId); $user->addProject($project1->id->asString()); $user->addProject($project2->id->asString()); $project1->addUser($userId, ProjectRoles::CONTRIBUTOR); $project2->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->write(); $project1->write(); $project2->write(); $text = new TextModel($project1); $text->title = "Text 1"; $text->content = "text content"; $textId = $text->write(); $a1 = ActivityCommands::addText($project1, $textId, $text); $text = new TextModel($project2); $text->title = "Text 2"; $text->content = "text content"; $textId = $text->write(); $a2 = ActivityCommands::addText($project2, $textId, $text); $dto = ActivityListDto::getActivityForUser($project1->siteName, $userId); $this->assertEqual(count($dto['unread']), 1); }