private function assertKuser()
 {
     // check copied values
     $this->assertEquals($this->systemUser->getFirstName(), $this->kuser->getFirstName(), 'first_name for ' . $this->getParams());
     $this->assertEquals($this->systemUser->getLastName(), $this->kuser->getLastName(), 'last_name for ' . $this->getParams());
     $this->assertEquals($this->systemUser->getEmail(), $this->kuser->getPuserId(), 'puserid for ' . $this->getParams());
     $this->assertEquals($this->adminConsolePartnerId, $this->kuser->getPartnerId(), 'partner_id for ' . $this->getParams());
     $this->assertEquals($this->systemUser->getEmail(), $this->kuser->getEmail(), 'email for ' . $this->getParams());
     $this->assertEquals($this->systemUser->getName(), $this->kuser->getScreenName(), 'screen_name for ' . $this->getParams());
     $this->assertEquals($this->systemUser->getName(), $this->kuser->getFullName(), 'full_name for ' . $this->getParams());
     if ($this->systemUser->getStatus == systemUser::SYSTEM_USER_ACTIVE) {
         $this->assertEquals(KuserStatus::ACTIVE, $this->kuser->getStatus(), 'status ' . $this->getParams());
     } else {
         $this->assertEquals(KuserStatus::BLOCKED, $this->kuser->getStatus(), 'status ' . $this->getParams());
     }
     $this->assertEquals($this->systemUser->getDeletedAt(), $this->kuser->getDeletedAt(), 'deleted_at ' . $this->getParams());
     $partnerData = unserialize($this->kuser->getPartnerData());
     var_dump($partnerData);
     $this->assertTrue(get_class($partnerData) === 'Kaltura_AdminConsoleUserPartnerData', 'PartnerData is not of type Kaltura_AdminConsoleUserPartnerData');
     $this->assertEquals($this->systemUser->getIsPrimary(), $partnerData->isPrimary, 'is_primary ' . $this->getParams());
     $this->assertEquals($this->systemUser->getRole(), $partnerData->role, 'role ' . $this->getParams());
     // check new values
     $this->assertEquals(true, $this->kuser->getIsAdmin(), 'is_admin for ' . $this->getParams());
     $this->assertEquals($this->kuser->getLoginDataId(), $this->loginData->getId());
 }
Ejemplo n.º 2
0
 /**
  * Adds a new kuser and user_login_data records as needed
  * @param kuser $user
  * @param string $password
  * @param bool $checkPasswordStructure
  * @throws kUserException::USER_NOT_FOUND
  * @throws kUserException::USER_ALREADY_EXISTS
  * @throws kUserException::INVALID_EMAIL
  * @throws kUserException::INVALID_PARTNER
  * @throws kUserException::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED
  * @throws kUserException::LOGIN_ID_ALREADY_USED
  * @throws kUserException::PASSWORD_STRUCTURE_INVALID
  * @throws kPermissionException::ROLE_ID_MISSING
  * @throws kPermissionException::ONLY_ONE_ROLE_PER_USER_ALLOWED
  */
 public static function addUser(kuser $user, $password = null, $checkPasswordStructure = true, $sendEmail = null)
 {
     if (!$user->getPuserId()) {
         throw new kUserException('', kUserException::USER_ID_MISSING);
     }
     // check if user with the same partner and puserId already exists
     $existingUser = kuserPeer::getKuserByPartnerAndUid($user->getPartnerId(), $user->getPuserId());
     if ($existingUser) {
         throw new kUserException('', kUserException::USER_ALREADY_EXISTS);
     }
     // check if roles are valid - may throw exceptions
     if (!$user->getRoleIds() && $user->getIsAdmin()) {
         // assign default role according to user type admin / normal
         $userRoleId = $user->getPartner()->getAdminSessionRoleId();
         $user->setRoleIds($userRoleId);
     }
     UserRolePeer::testValidRolesForUser($user->getRoleIds(), $user->getPartnerId());
     if ($user->getScreenName() === null) {
         $user->setScreenName($user->getPuserId());
     }
     if ($user->getFullName() === null) {
         $user->setFirstName($user->getPuserId());
     }
     if (is_null($user->getStatus())) {
         $user->setStatus(KuserStatus::ACTIVE);
     }
     // if password is set, user should be able to login to the system - add a user_login_data record
     if ($password || $user->getIsAdmin()) {
         // throws an action on error
         $user->enableLogin($user->getEmail(), $password, $checkPasswordStructure, $sendEmail);
     }
     $user->save();
     return $user;
 }