/** * @param ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->id = new Id(); $this->_projectModel = $projectModel; $databaseName = $projectModel->databaseName(); parent::__construct(MessageModelMongoMapper::connect($databaseName), $id); }
/** * @param ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->id = new Id(); $this->itemKeys = new ArrayOf(); $this->name = ""; $databaseName = $projectModel->databaseName(); parent::__construct(self::mapper($databaseName), $id); }
/** * @param ProjectModel $projectModel * @param int $newerThanTimestamp */ public function __construct($projectModel, $newerThanTimestamp = null) { if (!is_null($newerThanTimestamp)) { $startDate = new UTCDateTime(1000 * $newerThanTimestamp); parent::__construct(self::mapper($projectModel->databaseName()), array('dateModified' => array('$gte' => $startDate)), array(), array('key' => 1)); } else { parent::__construct(self::mapper($projectModel->databaseName()), array(), array(), array('key' => 1)); } }
/** * @param ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->id = new Id(); $this->content = ''; $this->regarding = new SemDomTransFieldReference(); $this->entryRef = new Id(); $databaseName = $projectModel->databaseName(); parent::__construct(self::mapper($databaseName), $id); }
/** * @param ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->items = new ArrayOf(function () { return new LexOptionListItem(); }); $this->id = new Id(); $this->canDelete = true; $databaseName = $projectModel->databaseName(); parent::__construct(self::mapper($databaseName), $id); }
/** * Removes a user from the collection * Project references to this user are also removed */ public function remove() { foreach ($this->projects->refs as $id) { /* @var Id $id */ $project = new ProjectModel($id->asString()); $project->removeUser($this->id->asString()); $project->write(); } parent::remove(); }
/** * @param ProjectModel $projectModel * @param int $newerThanTimestamp */ public function __construct($projectModel, $newerThanTimestamp = null) { new LexProjectModel($projectModel->id->asString()); if (!is_null($newerThanTimestamp)) { $startDate = new UTCDateTime(1000 * $newerThanTimestamp); parent::__construct(self::mapper($projectModel->databaseName()), array('isDeleted' => true, 'dateModified' => array('$gte' => $startDate)), array()); } else { parent::__construct(self::mapper($projectModel->databaseName()), array('isDeleted' => true), array()); } }
public function getProjectMember($projectId, $userName) { $userId = $this->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; }
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; }
/** * @param ProjectModel $projectModel * @param int $newerThanTimestamp * @param int $limit * @param int $skip */ public function __construct($projectModel, $newerThanTimestamp = null, $limit = 0, $skip = 0) { $this->entries = new ArrayOf(function () use($projectModel) { return new LexCommentModel($projectModel); }); // sort ascending by creation date if (!is_null($newerThanTimestamp)) { $startDate = new UTCDateTime($newerThanTimestamp * 1000); parent::__construct(self::mapper($projectModel->databaseName()), array('isDeleted' => false, 'dateModified' => array('$gte' => $startDate)), array(), array('dateCreated' => 1), $limit, $skip); } else { parent::__construct(self::mapper($projectModel->databaseName()), array('isDeleted' => false), array(), array('dateCreated' => 1), $limit, $skip); } }
/** * @param ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->id = new Id(); $this->workflowState = "open"; // default workflow state $this->description = ''; $this->title = ''; $this->textRef = new IdReference(); $this->answers = new MapOf(function () { return new AnswerModel(); }); $databaseName = $projectModel->databaseName(); parent::__construct(QuestionModelMongoMapper::connect($databaseName), $id); }
public function create() { $environ = new MongoTestEnvironment(); $environ->clean(); $this->website = $environ->website; $this->project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $this->project->appName = 'sfchecks'; $this->project->write(); $this->question = new QuestionModel($this->project); $this->question->write(); $this->userId = $environ->createUser('test_user', 'Test User', '*****@*****.**'); $this->projectId = $this->project->id->asString(); $this->questionId = $this->question->id->asString(); }
/** * @param ProjectModel $projectModel * @param int $newerThanTimestamp * @param int $limit * @param int $skip */ public function __construct($projectModel, $newerThanTimestamp = null, $limit = 0, $skip = 0) { // for use with readAsModels() $this->entries = new ArrayOf(function () use($projectModel) { return new LexEntryModel($projectModel); }); $lexProject = new LexProjectModel($projectModel->id->asString()); $this->_config = $lexProject->config; if (!is_null($newerThanTimestamp)) { $startDate = new UTCDateTime(1000 * $newerThanTimestamp); parent::__construct(self::mapper($projectModel->databaseName()), array('dateModified' => array('$gte' => $startDate), 'isDeleted' => false), array(), array(), $limit, $skip); } else { parent::__construct(self::mapper($projectModel->databaseName()), array('isDeleted' => false), array(), array(), $limit, $skip); } }
/** * @param ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->id = new Id(); $this->key = ''; $this->name = new SemDomTransTranslatedForm(); $this->description = new SemDomTransTranslatedForm(); $this->searchKeys = new ArrayOf(function () { return new SemDomTransTranslatedForm(); }); $this->questions = new ArrayOf(function () { return new SemDomTransQuestion(); }); $databaseName = $projectModel->databaseName(); parent::__construct(self::mapper($databaseName), $id); }
public function run($userId, $mode = 'test') { $testMode = $mode != 'run'; $message = "Ensure DB Indexes\n"; $numberOfIndexesCreated = 0; $website = Website::get(); $onDevMachine = strpos($website->domain, 'dev.') !== false; $onLocalMachine = strrpos($website->domain, '.local') !== false; $message .= "\n------------- Main Database:\n"; $mainCollectionName = ProjectModelMongoMapper::instance()->getCollectionName(); $mainIndexes = ProjectModelMongoMapper::instance()->INDEXES_REQUIRED; $mainIndexesToCreate = MongoStore::getIndexesNotSetInCollection(SF_DATABASE, $mainCollectionName, $mainIndexes); $numberOfIndexesCreated += count($mainIndexesToCreate); $message .= count($mainIndexesToCreate) . " main indexes created.\n"; if (($onDevMachine || $onLocalMachine) && MongoStore::hasDB(SF_TEST_DATABASE)) { $message .= "\n------------- Test Database:\n"; $mainIndexesToCreate = MongoStore::getIndexesNotSetInCollection(SF_TEST_DATABASE, $mainCollectionName, $mainIndexes); $numberOfIndexesCreated += count($mainIndexesToCreate); $message .= count($mainIndexesToCreate) . " test indexes created.\n"; } if (!$testMode) { MongoStore::ensureIndexesInCollection(SF_DATABASE, $mainCollectionName, $mainIndexes); if (($onDevMachine || $onLocalMachine) && MongoStore::hasDB(SF_TEST_DATABASE)) { MongoStore::ensureIndexesInCollection(SF_TEST_DATABASE, $mainCollectionName, $mainIndexes); } } // loop over every project $projectList = new ProjectListModel(); $projectList->read(); foreach ($projectList->entries as $projectParams) { $project = ProjectModel::getById($projectParams['id']); if ($project->appName == 'lexicon') { $message .= "\n------------- {$project->projectName} project:\n"; $lexiconCollectionName = LexEntryModel::mapper($project->databaseName())->getCollectionName(); $lexiconIndexes = LexEntryModel::mapper($project->databaseName())->INDEXES_REQUIRED; $lexiconIndexesToCreate = MongoStore::getIndexesNotSetInCollection($project->databaseName(), $lexiconCollectionName, $lexiconIndexes); $numberOfIndexesCreated += count($lexiconIndexesToCreate); $optionListCollectionName = LexOptionListModel::mapper($project->databaseName())->getCollectionName(); $optionListIndexes = LexOptionListModel::mapper($project->databaseName())->INDEXES_REQUIRED; $optionListIndexesToCreate = MongoStore::getIndexesNotSetInCollection($project->databaseName(), $optionListCollectionName, $optionListIndexes); $numberOfIndexesCreated += count($optionListIndexesToCreate); if (count($lexiconIndexesToCreate) + count($optionListIndexesToCreate) > 0) { $message .= count($lexiconIndexesToCreate) . " lexicon indexes created.\n"; $message .= count($optionListIndexesToCreate) . " option list indexes created.\n"; } else { $message .= "No indexes needed creating.\n"; } if (!$testMode) { MongoStore::ensureIndexesInCollection($project->databaseName(), $lexiconCollectionName, $lexiconIndexes); MongoStore::ensureIndexesInCollection($project->databaseName(), $optionListCollectionName, $optionListIndexes); } } } if ($numberOfIndexesCreated > 0) { $message .= "\nCreated {$numberOfIndexesCreated} DB Indexes.\n\n"; } else { $message .= "\nAll indexes were present.\n\n"; } return $message; }
public function run($userId, $mode = 'test') { $testMode = $mode != 'run'; $message = "Import Other Language Semantic Domain Projects\n\n"; $languages = array('es', 'fa', 'hi', 'id', 'km', 'ko', 'ne', 'pt', 'ru', 'te', 'th', 'ur', 'zh-CN'); //$languages = array('es', 'fa'); $languageData = new LanguageData(); $languageData->read(); foreach ($languages as $lang) { $projectCode = SemDomTransProjectModel::projectCode($lang); $languageName = $languageData->getLanguage($lang)->name; $projectName = SemDomTransProjectModel::projectName($lang, $languageName); $existingProject = new SemDomTransProjectModel(); $existingProject->readByCode($lang); if ($existingProject->id->asString() != '') { $message .= "{$projectName} already exists! Removing...\n"; if (!$testMode) { $existingProject->remove(); } } if (!$testMode) { $projectId = self::_createEmptyProject($lang, $languageName, $userId); $projectModel = ProjectModel::getById($projectId); $xmlFilePath = APPPATH . "resources/languageforge/semdomtrans/LocalizedLists-{$lang}.xml"; $projectModel->importFromFile($xmlFilePath); } $message .= "Finished importing the {$projectName} \n"; } return $message; }
/** * @param ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->id = new Id(); $this->projectRef = new IdReference($projectModel->id->asString()); $this->textRef = new IdReference(); $this->questionRef = new IdReference(); $this->userRef = new IdReference(); $this->userRef2 = new IdReference(); $this->entryRef = new IdReference(); $this->action = $this::UNKNOWN; $this->date = new \DateTime(); // set the timestamp to now $this->actionContent = new MapOf(); // strings $this->addContent($this::PROJECT, $projectModel->projectName); $databaseName = $projectModel->databaseName(); parent::__construct(ActivityModelMongoMapper::connect($databaseName), $id); }
/** * @param string $projectId * @param string $userId * @returns array - the DTO array */ public static function encode($projectId) { $projectModel = ProjectModel::getById($projectId); $list = $projectModel->listUsers(); $data = array(); $data['userCount'] = $list->count; $data['users'] = $list->entries; $data['project'] = array('roles' => $projectModel->getRolesList(), 'ownerRef' => $projectModel->ownerRef, 'name' => $projectModel->projectName, 'appLink' => "/app/{$projectModel->appName}/{$projectId}/"); return $data; }
/** * @param ProjectModel|LexProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->setReadOnlyProp('authorInfo'); $this->setReadOnlyProp('replies'); $this->setReadOnlyProp('score'); $this->setReadOnlyProp('status'); $this->setPrivateProp('isDeleted'); $this->id = new Id(); $this->entryRef = new IdReference(); $this->isDeleted = false; $this->replies = new ArrayOf(function () { return new LexCommentReply(); }); $this->status = self::STATUS_OPEN; $this->score = 0; $this->authorInfo = new LexAuthorInfo(); $this->regarding = new LexCommentFieldReference(); $databaseName = $projectModel->databaseName(); parent::__construct(self::mapper($databaseName), $id); }
public function testInitializeNewProject_defaultPartOfSpeechOptionListExists() { $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $optionLists = new LexOptionListListModel($project); $optionLists->read(); $this->assertCount(0, $optionLists->entries); $project = ProjectModel::getById($project->id->asString()); $project->initializeNewProject(); $optionLists->read(); $this->assertTrue(count($optionLists->entries) > 0); $this->assertEquals('adj', $optionLists->entries[0]['items'][0]['key']); }
public function testUserCanAccessMethod_projectPageDto_NotAMember_false() { $userId = self::$environ->createUser('user', 'user', '*****@*****.**', SystemRoles::USER); $project = self::$environ->createProject('projectForTest', 'projTestCode'); $project->appName = 'sfchecks'; $project->write(); $projectId = $project->id->asString(); $project = ProjectModel::getById($projectId); $rh = new RightsHelper($userId, $project, self::$environ->website); $result = $rh->userCanAccessMethod('project_pageDto', array()); $this->assertFalse($result); }
public function checkProject($projectId) { $project = new ProjectModel($projectId); $this->projectsChecked++; $this->info("Checking {$project->projectName}"); if ($project->projectName == '') { $this->warn("{$projectId} has an empty projectName"); } if ($project->projectCode == '') { $this->warn("{$project->projectName} has an empty projectCode. This will certainly cause failures"); } // check that a database exists for this project try { $databaseName = $project->databaseName(); } catch (\Exception $e) { $databaseName = ""; } if (!MongoStore::hasDB($databaseName)) { $newProjectCode = str_replace(' ', '_', strtolower($project->projectName)); $newDatabaseName = 'sf_' . $newProjectCode; if (MongoStore::hasDB($newDatabaseName)) { $this->warn("projectCode does not correspond to an existing MongoDb but projectName does (db migration required)"); $this->fix("Changed projectCode to {$newProjectCode}"); $this->projectsFixed++; $project->projectCode = $newProjectCode; } else { $this->warn("{$project->projectName} has no corresponding database. (could indicate a brand new project with no data"); } } if ($project->siteName == '') { $this->warn("{$project->projectName} has no corresponding website (will not appear on any site)"); } if ($project->appName == '') { $this->warn("{$project->projectName} has no app associated with it"); } if ($this->makeChanges) { $project->write(); } }
public function run($userId, $mode = 'test') { $testMode = $mode != 'run'; $message = "Fix project site name integrity\n\n"; // loop over every project $projectlist = new ProjectListModel(); $projectlist->read(); $fixCount = 0; foreach ($projectlist->entries as $projectParams) { // foreach existing project $projectId = $projectParams['id']; $project = new ProjectModel($projectId); $hostname = $project->siteName; $website = Website::get($hostname); if (!$website) { // the website does not exist anymore $message .= "{$hostname} does not exist anymore..."; // see if there is a redirect $redirect = Website::getRawRedirect($hostname); if ($redirect) { $message .= "changed to {$redirect}\n"; $project->siteName = $redirect; $fixCount++; if (!$testMode) { $project->write(); } } else { $message .= "ERROR: dont know what to change it to since no redirect is available\n"; } } } if ($fixCount > 0) { $message .= "\n\nFixed siteNames in {$fixCount} project(s)\n\n"; } else { $message .= "\n\nNo non-existent siteNames were found in the projects collection\n\n"; } return $message; }
public function testWrite_TwoModels_ReadBackBothModelsOk() { $model = new UserModel(); $model->email = '*****@*****.**'; $model->username = '******'; $id = $model->write(); $this->assertNotNull($id); $this->assertInternalType('string', $id); $otherModel = new UserModel($id); $this->assertEquals($id, $otherModel->id->asString()); $this->assertEquals('*****@*****.**', $otherModel->email); $this->assertEquals('SomeUser', $otherModel->username); $model = new ProjectModel(); $model->language = 'SomeLanguage'; $model->projectName = 'SomeProject'; $id = $model->write(); $this->assertNotNull($id); $this->assertInternalType('string', $id); $otherModel = new ProjectModel($id); $this->assertEquals($id, $otherModel->id->asString()); $this->assertEquals('SomeLanguage', $otherModel->language); $this->assertEquals('SomeProject', $otherModel->projectName); }
public static function encode($projectId) { $dto = array(); $project = ProjectModel::getById($projectId); $methodPrefix = 'project_management_report_' . $project->appName . '_'; $reports = array(); foreach (get_class_methods('\\Api\\Service\\Sf') as $methodName) { if (strpos($methodName, $methodPrefix) !== FALSE) { $reportId = explode($methodPrefix, $methodName)[1]; $displayName = ucwords(preg_replace('/([A-Z])/', ' $1', $reportId)); $reportId = $project->appName . '_' . $reportId; array_push($reports, array('id' => $reportId, 'name' => $displayName)); } } $dto['reports'] = $reports; return $dto; }
public function onAuthenticationSuccess(Request $request, TokenInterface $token) { $username = $token->getUser()->getUsername(); $user = new UserModel(); $website = Website::get(); // automatically logout if 1) the user doesn't exist or 2) the user is not a system admin and has no site rights on the current site 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'); } $projectId = $user->getCurrentProjectId($website->domain); // redirect to page before the login screen was presented, or to the default project for this user $referer = $this->determineTargetUrl($request); $url = '/app/projects'; if ($referer and strpos($referer, '/app/') !== false) { $url = $referer; } elseif ($projectId && ProjectModel::projectExistsOnWebsite($projectId, $website)) { $project = ProjectModel::getById($projectId); if ($project->userIsMember($user->id->asString())) { $url = '/app/' . $project->appName . '/' . $projectId; } } return $this->httpUtils->createRedirectResponse($request, $url); }
/** * @param string $projectId * @param string $userId * @param Website $website * @param string $appName - refers to the application being used by the user * @return array */ public static function getSessionData($projectId, $userId, $website, $appName = '') { $sessionData = array(); $sessionData['userId'] = (string) $userId; $sessionData['baseSite'] = $website->base; // Rights $user = new UserModel($userId); $sessionData['userSiteRights'] = $user->getRightsArray($website); $sessionData['username'] = $user->username; if ($projectId) { $project = ProjectModel::getById($projectId); $sessionData['project'] = array(); $sessionData['project']['id'] = (string) $projectId; $sessionData['project']['projectName'] = $project->projectName; if ($project->isArchived) { $sessionData['project']['projectName'] .= " [ARCHIVED]"; } $sessionData['project']['appName'] = $project->appName; $sessionData['project']['appLink'] = "/app/{$project->appName}/{$projectId}/"; $sessionData['project']['ownerRef'] = $project->ownerRef->asString(); $sessionData['project']['userIsProjectOwner'] = $project->isOwner($userId); $sessionData['project']['slug'] = $project->databaseName(); $sessionData['project']['isArchived'] = $project->isArchived; $sessionData['userProjectRights'] = $project->getRightsArray($userId); $sessionData['projectSettings'] = $project->getPublicSettings($userId); } if ($appName) { $sessionData['helps'] = HelpContentCommands::getSessionData($appName, $website); } // 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 __construct($id = '') { parent::__construct($id); }
public function checkPermissions($methodName, $params) { if (!self::isAnonymousMethod($methodName)) { if (!$this->userId) { throw new UserNotAuthenticatedException("Your session has timed out. Please login again."); } try { $projectModel = ProjectModel::getById($this->projectId); } catch (\Exception $e) { $projectModel = null; } $rightsHelper = new RightsHelper($this->userId, $projectModel, $this->website); if (!$rightsHelper->userCanAccessMethod($methodName, $params)) { throw new UserUnauthorizedException("Insufficient privileges accessing API method '{$methodName}'"); } } }
/** * @param string $code * @return bool */ public static function projectCodeExists($code) { $project = new ProjectModel(); return $project->readByProperties(array('projectCode' => $code)); }