<commit_before><?php

/**
 * UserRole service lets you create and manage user permissions
 * @service userRole
 * @package api
 * @subpackage services
 */
class UserRoleService extends KalturaBaseService
{
	public function initService($serviceName, $actionName)
	{
		parent::initService($serviceName, $actionName);
		
		myPartnerUtils::addPartnerToCriteria(new UserRolePeer(), $this->getPartnerId(), $this->private_partner_data, $this->partnerGroup());
		myPartnerUtils::addPartnerToCriteria(new PermissionPeer(), $this->getPartnerId(), $this->private_partner_data, $this->partnerGroup());
	}	

	
	/**
	 * Allows you to add a new KalturaUserRole object
	 * 
	 * @action add
	 * @param KalturaUserRole $permissionItem
	 * @return KalturaUserRole
	 * 
	 * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
	 * @throws KalturaErrors::PROPERTY_VALIDATION_NOT_UPDATABLE
	 * @throws KalturaErrors::PERMISSION_NOT_FOUND
	 */
	public function addAction(KalturaUserRole $userRole)
	{
		$userRole->validateForInsert();
		$userRole->validatePropertyNotNull('name');
		
		if (!$userRole->status) {
			$userRole->status = KalturaUserRoleStatus::ACTIVE;
		}
		
		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);
		
		return $userRole;
	}
	
	/**
	 * Retrieve a KalturaUserRole object by ID
	 * 
	 * @action get
	 * @param int $userRoleId 
	 * @return KalturaUserRole
	 * 
	 * @throws KalturaErrors::INVALID_OBJECT_ID
	 */		
	public function getAction($userRoleId)
	{
		$c = new Criteria();
		$allowedPartnerIds = explode(',', $this->partnerGroup());
		$allowedPartnerIds[] = PartnerPeer::GLOBAL_PARTNER;
		$c->addAnd(UserRolePeer::PARTNER_ID, $allowedPartnerIds, Criteria::IN);
		$c->addAnd(UserRolePeer::ID, $userRoleId);
		$c->addAnd(UserRolePeer::STATUS, KalturaUserRoleStatus::DELETED, Criteria::NOT_EQUAL);
		
		UserRolePeer::setUseCriteriaFilter(false);
		$dbUserRole = UserRolePeer::doSelectOne($c);
		UserRolePeer::setUseCriteriaFilter(true);
		
		if (!$dbUserRole) {
			throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $userRoleId);
		}
			
		$userRole = new KalturaUserRole();
		$userRole->fromObject($dbUserRole);
		
		return $userRole;
	}


	/**
	 * Update an existing KalturaUserRole object
	 * 
	 * @action update
	 * @param int $userRoleId
	 * @param KalturaUserRole $userRole
	 * @return KalturaUserRole
	 *
	 * @throws KalturaErrors::INVALID_OBJECT_ID
	 * @throws KalturaErrors::PERMISSION_NOT_FOUND
	 */	
	public function updateAction($userRoleId, KalturaUserRole $userRole)
	{
		$dbUserRole = UserRolePeer::retrieveByPK($userRoleId);
	
		if (!$dbUserRole) {
			throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $userRoleId);
		}
		
		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->toUpdatableObject($dbUserRole);
		$dbUserRole->save();
	
		$userRole = new KalturaUserRole();
		$userRole->fromObject($dbUserRole);
		
		return $userRole;
	}

	/**
	 * Mark the KalturaUserRole object as deleted
	 * 
	 * @action delete
	 * @param int $userRoleId 
	 * @return KalturaUserRole
	 *
	 * @throws KalturaErrors::INVALID_OBJECT_ID
	 * @throws KalturaErrors::ROLE_IS_BEING_USED
	 */		
	public function deleteAction($userRoleId)
	{
		$dbUserRole = UserRolePeer::retrieveByPK($userRoleId);
	
		if (!$dbUserRole) {
			throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $userRoleId);
		}

		try {
			$dbUserRole->setAsDeleted();
		}
		catch (kPermissionException $e) {
			$code = $e->getCode();
			if ($code == kPermissionException::ROLE_IS_BEING_USED) {
				throw new KalturaAPIException(KalturaErrors::ROLE_IS_BEING_USED);
			}
			throw $e;			
		}	
		$dbUserRole->save();
			
		$userRole = new KalturaUserRole();
		$userRole->fromObject($dbUserRole);
		
		return $userRole;
	}
	
	/**
	 * List permission items
	 * 
	 * @action list
	 * @param KalturaUserRoleFilter $filter
	 * @param KalturaFilterPager $pager
	 * @return KalturaUserRoleListResponse
	 */
	public function listAction(KalturaUserRoleFilter  $filter = null, KalturaFilterPager $pager = null)
	{
		if (!$filter)
			$filter = new KalturaUserRoleFilter();
			
		$userRoleFilter = $filter->toObject();
		
		UserRolePeer::setUseCriteriaFilter(false);

		$c = new Criteria();
		$c->addAnd(UserRolePeer::PARTNER_ID, array (0, $this->getPartnerId()), Criteria::IN);
		$c->addAnd(UserRolePeer::STATUS, KalturaUserRoleStatus::DELETED, Criteria::NOT_EQUAL);
		$userRoleFilter->attachToCriteria($c);
		$count = UserRolePeer::doCount($c);
		
		if ($pager)
			$pager->attachToCriteria($c);
		$list = UserRolePeer::doSelect($c);
		
		UserRolePeer::setUseCriteriaFilter(true);
		
		$response = new KalturaUserRoleListResponse();
		$response->objects = KalturaUserRoleArray::fromDbArray($list);
		$response->totalCount = $count;<commit_msg>Partner group fixes<commit_after><?php

/**
 * UserRole service lets you create and manage user permissions
 * @service userRole
 * @package api
 * @subpackage services
 */
class UserRoleService extends KalturaBaseService
{
	public function initService($serviceName, $actionName)
	{
		parent::initService($serviceName, $actionName);
		
		myPartnerUtils::addPartnerToCriteria(new UserRolePeer(), $this->getPartnerId(), $this->private_partner_data, $this->partnerGroup());
		myPartnerUtils::addPartnerToCriteria(new PermissionPeer(), $this->getPartnerId(), $this->private_partner_data, $this->partnerGroup());
	}
	
	protected function globalPartnerAllowed($actionName)
	{
		if ($actionName === 'get') {
			return true;
		}
		if ($actionName === 'list') {
			return true;
		}
		return parent::globalPartnerAllowed($actionName);
	}

	
	/**
	 * Allows you to add a new KalturaUserRole object
	 * 
	 * @action add
	 * @param KalturaUserRole $permissionItem
	 * @return KalturaUserRole
	 * 
	 * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
	 * @throws KalturaErrors::PROPERTY_VALIDATION_NOT_UPDATABLE
	 * @throws KalturaErrors::PERMISSION_NOT_FOUND
	 */
	public function addAction(KalturaUserRole $userRole)
	{
		$userRole->validateForInsert();
		$userRole->validatePropertyNotNull('name');
		
		if (!$userRole->status) {
			$userRole->status = KalturaUserRoleStatus::ACTIVE;
		}
		
		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);
		
		return $userRole;
	}
	
	/**
	 * Retrieve a KalturaUserRole object by ID
	 * 
	 * @action get
	 * @param int $userRoleId 
	 * @return KalturaUserRole
	 * 
	 * @throws KalturaErrors::INVALID_OBJECT_ID
	 */		
	public function getAction($userRoleId)
	{
		$dbUserRole = UserRolePeer::retrieveByPK($userRoleId);
		
		if (!$dbUserRole) {
			throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $userRoleId);
		}
			
		$userRole = new KalturaUserRole();
		$userRole->fromObject($dbUserRole);
		
		return $userRole;
	}
	

	/**
	 * Update an existing KalturaUserRole object
	 * 
	 * @action update
	 * @param int $userRoleId
	 * @param KalturaUserRole $userRole
	 * @return KalturaUserRole
	 *
	 * @throws KalturaErrors::INVALID_OBJECT_ID
	 * @throws KalturaErrors::PERMISSION_NOT_FOUND
	 */	
	public function updateAction($userRoleId, KalturaUserRole $userRole)
	{
		$dbUserRole = UserRolePeer::retrieveByPK($userRoleId);
	
		if (!$dbUserRole) {
			throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $userRoleId);
		}
		
		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->toUpdatableObject($dbUserRole);
		$dbUserRole->save();
	
		$userRole = new KalturaUserRole();
		$userRole->fromObject($dbUserRole);
		
		return $userRole;
	}

	/**
	 * Mark the KalturaUserRole object as deleted
	 * 
	 * @action delete
	 * @param int $userRoleId 
	 * @return KalturaUserRole
	 *
	 * @throws KalturaErrors::INVALID_OBJECT_ID
	 * @throws KalturaErrors::ROLE_IS_BEING_USED
	 */		
	public function deleteAction($userRoleId)
	{
		$dbUserRole = UserRolePeer::retrieveByPK($userRoleId);
	
		if (!$dbUserRole) {
			throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $userRoleId);
		}

		try {
			$dbUserRole->setAsDeleted();
		}
		catch (kPermissionException $e) {
			$code = $e->getCode();
			if ($code == kPermissionException::ROLE_IS_BEING_USED) {
				throw new KalturaAPIException(KalturaErrors::ROLE_IS_BEING_USED);
			}
			throw $e;			
		}	
		$dbUserRole->save();
			
		$userRole = new KalturaUserRole();
		$userRole->fromObject($dbUserRole);
		
		return $userRole;
	}
	
	/**
	 * List permission items
	 * 
	 * @action list
	 * @param KalturaUserRoleFilter $filter
	 * @param KalturaFilterPager $pager
	 * @return KalturaUserRoleListResponse
	 */
	public function listAction(KalturaUserRoleFilter  $filter = null, KalturaFilterPager $pager = null)
	{
		if (!$filter)
			$filter = new KalturaUserRoleFilter();
			
		$userRoleFilter = $filter->toObject();

		$c = new Criteria();
		$userRoleFilter->attachToCriteria($c);
		$count = UserRolePeer::doCount($c);
		
		if ($pager)
			$pager->attachToCriteria($c);
		$list = UserRolePeer::doSelect($c);
		
		$response = new KalturaUserRoleListResponse();
		$response->objects = KalturaUserRoleArray::fromDbArray($list);
		$response->totalCount = $count;
{'fraction_non_alphanumeric': 0.1325141776937618, 'fraction_numerical': 9.45179584120983e-05, 'mean_word_length': 4.977966101694915, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7468146', 'n_tokens_mistral': 3954, 'n_tokens_neox': 3500, 'n_words': 596}