示例#1
0
 /**
  * Adds a new user role object to the account.
  * 
  * @action add
  * @param KalturaUserRole $userRole A new role
  * @return KalturaUserRole The added user role object
  * 
  * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
  * @throws KalturaErrors::PROPERTY_VALIDATION_NOT_UPDATABLE
  * @throws KalturaErrors::PERMISSION_NOT_FOUND
  */
 public function addAction(KalturaUserRole $userRole)
 {
     $userRole->validatePropertyNotNull('name');
     if (!$userRole->status) {
         $userRole->status = KalturaUserRoleStatus::ACTIVE;
     }
     // cannot add a role with a name that already exists
     if (UserRolePeer::getByNameAndPartnerId($userRole->name, $this->getPartnerId())) {
         throw new KalturaAPIException(KalturaErrors::ROLE_NAME_ALREADY_EXISTS);
     }
     try {
         PermissionPeer::checkValidPermissionsForRole($userRole->permissionNames, $this->getPartnerId());
     } catch (kPermissionException $e) {
         $code = $e->getCode();
         if ($code == kPermissionException::PERMISSION_NOT_FOUND) {
             throw new KalturaAPIException(KalturaErrors::PERMISSION_NOT_FOUND, $e->getMessage());
         }
     }
     $dbUserRole = $userRole->toInsertableObject();
     $dbUserRole->setPartnerId($this->getPartnerId());
     $dbUserRole->save();
     $userRole = new KalturaUserRole();
     $userRole->fromObject($dbUserRole, $this->getResponseProfile());
     return $userRole;
 }