Пример #1
0
 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');
 }
Пример #3
0
 /**
  * 修改密码处理.
  *
  * @access pubic
  * @return void
  */
 public function changePwdAction()
 {
     $userName = $this->getLoginedUserInfo('userName');
     $oldPwd = I('post.oldpwd', '');
     $newPwd = I('post.newpwd', '');
     $verifyNewPwd = I('post.verifyNewpwd', '');
     // 确认新密码.
     $data = ['userName' => $userName, 'userOldPasswd' => $oldPwd, 'userNewPasswd' => $newPwd, 'verifyNewPwd' => $verifyNewPwd];
     $modelUser = new UserModel();
     // 校验用户名和密码规则.
     if (!$modelUser->validate($modelUser->ruleChangePwd)->create($data)) {
         $this->setAjaxData(Message::FAILED, $modelUser->getError())->myAjaxReturn();
     }
     // 校验旧密码.
     $res = $modelUser->checkLogin($userName, $this->encryptMyPwd($oldPwd));
     if (FALSE === $res) {
         $this->setAjaxData(Message::FAILED, '旧密码错误')->myAjaxReturn();
     }
     // 旧密码验证通过, 重置新密码.
     $res = $modelUser->resetPwd($userName, $this->encryptMyPwd($newPwd));
     if ($res) {
         $result = $this->_logOff();
         // 修改密码后退出登录状态.
         $this->setAjaxData(Message::SUCCESS, '修改密码成功', $result)->myAjaxReturn();
     }
     $this->setAjaxData(Message::SUCCESS, '修改密码失败')->myAjaxReturn();
 }
Пример #4
0
 /**
  * @param string $projectId
  * @param string $userId
  * @param Website $website
  * @return array
  */
 public static function getSessionData($projectId, $userId, $website)
 {
     $sessionData = array();
     $sessionData['userId'] = (string) $userId;
     $sessionData['baseSite'] = $website->base;
     // Rights
     $user = new UserModel($userId);
     $sessionData['userSiteRights'] = $user->getRightsArray($website);
     if ($projectId) {
         $project = ProjectModel::getById($projectId);
         $sessionData['project'] = array();
         $sessionData['project']['id'] = (string) $projectId;
         $sessionData['project']['projectName'] = $project->projectName;
         $sessionData['project']['appName'] = $project->appName;
         $sessionData['project']['appLink'] = "/app/{$project->appName}/{$projectId}/";
         $sessionData['project']['ownerRef'] = $project->ownerRef->asString();
         $sessionData['project']['slug'] = $project->databaseName();
         $sessionData['userProjectRights'] = $project->getRightsArray($userId);
         $sessionData['projectSettings'] = $project->getPublicSettings($userId);
     }
     // File Size
     $postMax = self::fromValueWithSuffix(ini_get("post_max_size"));
     $uploadMax = self::fromValueWithSuffix(ini_get("upload_max_filesize"));
     $fileSizeMax = min(array($postMax, $uploadMax));
     $sessionData['fileSizeMax'] = $fileSizeMax;
     //return JsonEncoder::encode($sessionData);  // This is handled elsewhere
     return $sessionData;
 }
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     $username = $token->getUser()->getUsername();
     $user = new UserModel();
     $website = Website::get();
     if (!$user->readByUserName($username) or $user->role != SystemRoles::SYSTEM_ADMIN and !($user->siteRole->offsetExists($website->domain) and $user->siteRole[$website->domain] != SiteRoles::NONE)) {
         return $this->httpUtils->createRedirectResponse($request, '/app/logout');
     }
     $request->getSession()->set('user_id', $user->id->asString());
     $request->getSession()->set('user', array('username' => $username));
     $projectId = $user->getDefaultProjectId($website->domain);
     if ($projectId) {
         $request->getSession()->set('projectId', $projectId);
     }
     $referer = $this->determineTargetUrl($request);
     if ($referer and strpos($referer, '/app/') !== false) {
         return $this->httpUtils->createRedirectResponse($request, $referer);
     } elseif ($projectId) {
         $project = ProjectModel::getById($projectId);
         $url = '/app/' . $project->appName . '/' . $projectId;
         return $this->httpUtils->createRedirectResponse($request, $url);
     } else {
         return $this->httpUtils->createRedirectResponse($request, '/');
     }
 }
 public function checkUser($userId)
 {
     $this->usersChecked++;
     $user = new UserModel($userId);
     if ($this->makeChanges) {
         $user->write();
     }
 }
Пример #7
0
 /**
  * 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());
 }
Пример #8
0
 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();
 }
Пример #10
0
 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 encodeIdReference($key, $model)
 {
     if ($key == 'ownerRef') {
         $user = new UserModel();
         if ($user->exists($model->asString())) {
             $user->read($model->asString());
             return array('id' => $user->id->asString(), 'username' => $user->username);
         } else {
             return '';
         }
     } else {
         return $model->asString();
     }
 }
 public function encodeIdReference($key, $model)
 {
     if ($key == 'createdByUserRef' || $key == 'modifiedByUserRef') {
         $user = new UserModel();
         if ($user->exists($model->asString())) {
             $user->read($model->asString());
             return array('id' => $user->id->asString(), 'avatar_ref' => $user->avatar_ref, 'name' => $user->name, 'username' => $user->username);
         } else {
             return '';
         }
     } else {
         return $model->asString();
     }
 }
 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);
 }
Пример #15
0
 public function encodeIdReference($key, $model)
 {
     // TODO ownerRef is declared in ProjectModel as an IdReference.  Here, it gets encoded as an Array 2014-08 DDW
     // Trello: https://trello.com/c/Zw0aLLYv
     if ($key == 'ownerRef') {
         $user = new UserModel();
         if ($user->exists($model->asString())) {
             $user->read($model->asString());
             return array('id' => $user->id->asString(), 'username' => $user->username);
         } else {
             return '';
         }
     } else {
         return $model->asString();
     }
 }
 public function __construct($id = '')
 {
     $this->setPrivateProp('shouldBePrivate');
     $this->setReadOnlyProp('shouldBeReadOnly');
     $this->shouldBePrivate = 'default';
     $this->shouldBeReadOnly = 'default';
     parent::__construct($id);
 }
Пример #17
0
 /**
  * @param string $userId
  * @param Website $website
  * @param boolean $isArchivedList - set true to list archived projects
  * @return array - the DTO array
  */
 public static function encode($userId, $website, $isArchivedList = false)
 {
     $user = new UserModel($userId);
     $canListAllProjects = $user->hasRight(Domain::PROJECTS + Operation::VIEW, $website);
     $projectList = new ProjectList_UserModel($website->domain);
     if ($canListAllProjects) {
         $projectList->readAll($isArchivedList);
     } else {
         $projectList->readUserProjects($userId);
     }
     $data = array();
     $data['entries'] = array();
     $count = 0;
     foreach ($projectList->entries as $entry) {
         $project = new ProjectModel($entry['id']);
         $role = ProjectRoles::NONE;
         if (count($project->users) > 0) {
             if (isset($project->users[$userId]) && isset($project->users[$userId]->role)) {
                 $role = $project->users[$userId]->role;
             }
         }
         $entry['role'] = $role;
         if (array_key_exists('ownerRef', $entry) and $entry['ownerRef']) {
             $entry['ownerId'] = $entry['ownerRef']->{'$id'};
         } else {
             $entry['ownerId'] = '';
             // for legacy projects that don't have an owner
         }
         unset($entry['ownerRef']);
         $entry['dateModified'] = $project->dateModified->format(\DateTime::RFC2822);
         $data['entries'][] = $entry;
         $count++;
     }
     $data['count'] = $count;
     // Default sort list on project names
     usort($data['entries'], function ($a, $b) {
         $sortOn = 'projectName';
         if (array_key_exists($sortOn, $a) && array_key_exists($sortOn, $b)) {
             return strtolower($a[$sortOn]) > strtolower($b[$sortOn]) ? 1 : -1;
         } else {
             return 0;
         }
     });
     return $data;
 }
Пример #18
0
 public function forgotPassword(Request $request, Application $app)
 {
     $username = $request->request->get('_username');
     $identityCheck = UserCommands::checkIdentity($username, '', $this->website);
     if (!$identityCheck->usernameExists) {
         $app['session']->getFlashBag()->add('errorMessage', 'User not found.');
         return $this->view($request, $app, 'forgot_password');
     }
     $user = new UserModel();
     $user->readByUserName($username);
     if (!$identityCheck->usernameExistsOnThisSite and $user->role != SystemRoles::SYSTEM_ADMIN) {
         $app['session']->getFlashBag()->add('errorMessage', sprintf('Username "%s" not available on "%s". Use "Create an Account".', $username, $this->website->domain));
         return $this->view($request, $app, 'forgot_password');
     }
     Communicate::sendForgotPasswordVerification($user, $this->website);
     $app['session']->getFlashBag()->add('infoMessage', 'Password Reset email sent for username "' . $username . '"');
     return $app->redirect('/auth/login');
 }
 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);
 }
Пример #20
0
 public function __construct($id = '')
 {
     $this->id = new Id();
     $this->projectsProperties = new MapOf(function ($data) {
         return new ProjectProperties();
     });
     $this->projectUserProfiles = new MapOf(function ($data) {
         return new SfchecksUserProfile();
     });
     parent::__construct($id);
 }
Пример #21
0
 public function encodeIdReference($key, $model)
 {
     if ($model->asString() == '') {
         return '';
     }
     if ($key == 'userRef' || $key == 'userRef2') {
         $user = new UserModel();
         if ($user->exists($model->asString())) {
             $user->read($model->asString());
             return array('id' => $user->id->asString(), 'avatar_ref' => $user->avatar_ref, 'username' => $user->username);
         } else {
             return '';
         }
     } elseif ($key == 'projectRef') {
         $project = new ProjectModel($model->asString());
         return array('id' => $project->id->asString(), 'type' => $project->appName);
     } elseif ($key == 'textRef') {
         $text = new TextModel($this->_project);
         if ($text->exists($model->asString())) {
             return $model->asString();
         } else {
             return '';
         }
     } elseif ($key == 'questionRef') {
         $question = new QuestionModel($this->_project);
         if ($question->exists($model->asString())) {
             return $model->asString();
         } else {
             return '';
         }
     } elseif ($key == 'entryRef') {
         $entry = new LexEntryModel($this->_project);
         if ($entry->exists($model->asString())) {
             return $model->asString();
         } else {
             return '';
         }
     } else {
         return $model->asString();
     }
 }
Пример #22
0
 /**
  * @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 \Api\Model\UserModel($userId);
         $userModel->remove();
         $count++;
     }
     return $count;
 }
 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));
 }
Пример #27
0
 protected function populateHeaderMenuViewdata()
 {
     $this->data['isAdmin'] = false;
     // setup specific variables for header
     $this->data['isLoggedIn'] = $this->_isLoggedIn;
     $featuredProjectList = new FeaturedProjectListModel();
     $featuredProjectList->read();
     $this->data['featuredProjects'] = $featuredProjectList->entries;
     if ($this->_isLoggedIn) {
         if ($this->_user->role) {
             $this->data['isAdmin'] = SystemRoles::hasRight($this->_user->role, Domain::USERS + Operation::CREATE);
         }
         $this->data['userName'] = $this->_user->username;
         $this->data['smallAvatarUrl'] = '/Site/views/shared/image/avatar/' . $this->_user->avatar_ref;
         $projects = $this->_user->listProjects($this->website->domain);
         $this->data['projects_count'] = $projects->count;
         $this->data['projects'] = $projects->entries;
     }
 }
 public function __construct($id = '')
 {
     $this->fruitsMap = new MapOf(function ($data) {
         if (array_key_exists('numOfSlices', $data)) {
             return new Apple();
         } elseif (array_key_exists('peelThickness', $data)) {
             return new Orange();
         } else {
             return new Fruit();
         }
     });
     $this->fruitsArray = new ArrayOf(function ($data) {
         if (array_key_exists('numOfSlices', $data)) {
             return new Apple();
         } elseif (array_key_exists('peelThickness', $data)) {
             return new Orange();
         } else {
             return new Fruit();
         }
     });
     parent::__construct($id);
 }
Пример #29
0
 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 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);
 }