/** * User Create/Update * @param array $params - user model fields to update */ public static function updateUser($params) { $user = new UserModel(); if ($params['id']) { $user->read($params['id']); } UserCommands::assertUniqueIdentity($user, $params['username'], $params['email']); JsonDecoder::decode($user, $params); $result = $user->write(); return $result; }
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 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) { // 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 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(); } }
public function testUpdateUserRole_JoinTwice_JoinedOnce() { $this->environ->clean(); // setup user and project $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $userId = $this->environ->createUser("existinguser", "Existing Name", "*****@*****.**"); $params = array('id' => $userId); // update user role in project once $updatedUserId = ProjectCommands::updateUserRole($projectId, $userId); // read from disk $sameUser = new UserModel($updatedUserId); $sameProject = new ProjectModel($projectId); // user in project once and project has one user $this->assertEqual($sameProject->listUsers()->count, 1); $this->assertEqual($sameUser->listProjects($this->environ->website->domain)->count, 1); // update user role in project again $updatedUserId = ProjectCommands::updateUserRole($projectId, $userId); // read from disk again $sameProject->read($projectId); $sameUser->read($updatedUserId); // user still in project once and project still has one user $this->assertEqual($sameProject->listUsers()->count, 1); $this->assertEqual($sameUser->listProjects($this->environ->website->domain)->count, 1); }
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)); }