public static function run($mode = 'test') { $testMode = $mode != 'run'; print "Remove users who have no siteRole AND are not system admins AND never logged in\n\n"; $userlist = new CustomUserListModel(); $userlist->read(); print "Found " . count($userlist->entries) . " users in the userlist\n"; $usersMissingSiteRole = 0; $now = new \DateTime(); foreach ($userlist->entries as $userParams) { // foreach user from the custom list // if last_login has any valid meaning, we need UserProfileModel. Otherwise, can use UserModel $user = new UserModel($userParams['id']); // Since UserProfileModel::last_login isn't being populated, we use the following criteria that a user never logged in: // emailPending (account never activated), no username, and validationExpirationDate expired if ($user->role != SystemRoles::SYSTEM_ADMIN && count(array_keys($user->siteRole->getArrayCopy())) == 0 && (!empty($user->emailPending) && empty($user->username) && $user->validationExpirationDate < $now)) { if (!$testMode) { $user->remove(); } $usersMissingSiteRole++; print "Removed [id: {$user->id} "; // Some of these criteria are never printed because of newer checks for empty if (!empty($user->username)) { print "username: {$user->username}; "; } if (!empty($user->email)) { print "email: {$user->email}; "; } if (!empty($user->emailPending)) { print "emailPending: {$user->emailPending}; "; } if (!empty($user->last_login)) { print "lastLogin: {$user->last_login}; "; } if (!empty($user->role)) { print "role: {$user->role}; "; } print "]\n"; } } if ($usersMissingSiteRole > 0) { print "\n\nRemoved {$usersMissingSiteRole} users missing siteRole from the users collection\n\n"; } else { print "\n\nNo user missing siteRoles found in the users collection\n\n"; } }
public function testGetActivityForProject_DeletedUser_DtoAsExpected() { $environ = new MongoTestEnvironment(); $environ->clean(); $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $text = new TextModel($project); $text->title = "Text 1"; $text->content = "text content"; $textId = $text->write(); ActivityCommands::addText($project, $textId, $text); $userId = $environ->createUser("user1", "user1", "*****@*****.**"); ActivityCommands::addUserToProject($project, $userId); // Workflow is first to create a question $question = new QuestionModel($project); $question->title = "the question"; $question->description = "question description"; $question->textRef->id = $textId; $questionId = $question->write(); ActivityCommands::addQuestion($project, $questionId, $question); // Then to add an answer to a question $answer = new AnswerModel(); $answer->content = "first answer"; $answer->score = 10; $answer->userRef->id = $userId; $answer->textHightlight = "text highlight"; $question->writeAnswer($answer); $activityId = ActivityCommands::addAnswer($project, $questionId, $answer); // now delete the user $user = new UserModel($userId); $user->remove(); $dto = ActivityListDto::getActivityForProject($project); $expectedProjectRef = ['id' => $project->id->asString(), 'type' => 'sfchecks']; $this->assertEquals('add_answer', $dto[$activityId]['action']); $this->assertEquals($expectedProjectRef, $dto[$activityId]['projectRef']); $this->assertEquals($project->projectName, $dto[$activityId]['content']['project']); $this->assertEquals($textId, $dto[$activityId]['textRef']); $this->assertEquals($text->title, $dto[$activityId]['content']['text']); $this->assertEquals($questionId, $dto[$activityId]['questionRef']); $this->assertEquals($question->title, $dto[$activityId]['content']['question']); $this->assertEquals($answer->content, $dto[$activityId]['content']['answer']); $this->assertEquals('', $dto[$activityId]['userRef']); $this->assertEquals('user1', $dto[$activityId]['content']['user']); }
public function testUserRemove_UserMemberOfProject_ProjectLinkRemovedAsWell() { $environ = new MongoTestEnvironment(); $environ->clean(); $userId = $environ->createUser('user1', 'user1', 'user1'); $user = new UserModel($userId); $project = $environ->createProject('testProject', 'testProjectCode'); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $project->write(); $user->addProject($project->id->asString()); $user->write(); // delete the user $user->remove(); // re-read the project $project->read($project->id->asString()); $this->assertFalse($project->userIsMember($userId)); }
/** * @param array $userIds * @return int Total number of users removed. */ public static function deleteUsers($userIds) { CodeGuard::checkTypeAndThrow($userIds, 'array'); $count = 0; foreach ($userIds as $userId) { CodeGuard::checkTypeAndThrow($userId, 'string'); $userModel = new UserModel($userId); $userModel->remove(); $count++; } return $count; }