/**
  * Returns true if and only if the assertion conditions are met
  *
  * This method is passed the ACL, Role, Resource, and privilege to which
  * the authorization query applies. If the $role, $resource, or $privilege
  * parameters are null, it means that the query applies to all Roles,
  * Resources, or privileges, respectively.
  *
  * @param  Zend_Acl                    $acl
  * @param  Zend_Acl_Role_Interface     $role
  * @param  Zend_Acl_Resource_Interface $resource
  * @param  string                      $privilege
  * @return boolean
  */
 public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
 {
     // We need specific objects to check against each other
     if (NULL === $role) {
         return false;
     }
     // Ensure we're handled User models
     if (!$role instanceof UserModel) {
         throw new Exception('Role must be an instance of UserModel');
     }
     // Get the organization
     $orgService = \Application\Service\OrgService::getInstance();
     $org = $orgService->load($role->getOrganizationId());
     if ($org->getType() != OrgCustomerModel::ORG_TYPE) {
         $org = $orgService->getParentByType($org, OrgCustomerModel::ORG_TYPE);
     }
     if ($org && !is_null($org->getSupplementaryServicesId())) {
         // Check if the customer has supplementary services configured
         // with application originated SMS option activated
         $supplSrv = \Application\Service\SupplServicesService::getInstance();
         $services = $supplSrv->load($org->getSupplementaryServicesId());
         if ($services && $services->getApplicationOriginatedSms() == SupplServicesModel::ST_ACTIVATED) {
             return true;
         }
     }
     throw new Exception('Role must have applicationOriginatedSms activated');
 }
 public function impersonateAction()
 {
     // Session user
     $user = $this->_getUser();
     if ($this->getRequest()->isPost()) {
         if (!$this->_hasParam('orgId')) {
             throw new InvalidArgumentException("Organization Id is required");
         }
         $orgId = $this->_getParam('orgId');
         $org = $this->_orgSrv->load($orgId);
         if (!isset($org)) {
             throw new InvalidArgumentException("Invalid organization: " . $orgId);
         }
         $this->_helper->allowed('impersonate', $org);
         $this->_userSrv->impersonate($org);
         $this->view->data = $orgId;
     } else {
         if ($this->getRequest()->isDelete()) {
             if (!$user->isImpersonating()) {
                 throw new InvalidArgumentException("User is not impersonating.");
             }
             $this->_userSrv->impersonate();
             $this->view->data = true;
         } else {
             throw new ForbiddenException("Impersonate must be a post or delete request");
         }
     }
 }
 public function isValid($value, $context = null)
 {
     $this->_messages = array();
     $field = $this->getOption('organizationIdField');
     if ($context instanceof App_ListFilter) {
         $orgId = $context->getOneFilterValueByFieldName($field);
         if (!is_null($orgId)) {
             $org = OrgService::getInstance()->load($orgId);
         } else {
             $this->_error(self::ERROR_ORGANIZATION_NOT_FOUND, $orgId);
             return false;
         }
     } else {
         if (empty($context) || empty($field) || empty($context[$field]) || !($org = OrgService::getInstance()->load($context[$field]))) {
             $this->_error(self::ERROR_ORGANIZATION_NOT_FOUND, $value);
             return false;
         }
     }
     if (!$org instanceof OrgCustomerModel) {
         $this->_error(self::ERROR_INVALID_ORG_TYPE, $value);
         return false;
     }
     if (!$org->hasBillingAccountId($value)) {
         $this->_error(self::ERROR_BILLING_NOT_FOUND, $value);
         return false;
     }
     return true;
 }
 public function isValid($value)
 {
     $this->_messages = array();
     try {
         $org = OrgService::getInstance()->load($value);
     } catch (Application\Exceptions\InvalidArgumentException $e) {
         \App::log()->info($e);
         $message = $this->_createMessage(self::ERROR_INVALID_ORG_TYPE, $value);
         $this->_messages[self::ERROR_INVALID_ORG_TYPE] = $message;
         return false;
     } catch (Application\Exceptions\GlobalServiceException $e) {
         \App::log()->info($e);
         $message = $this->_createMessage(self::ERROR_ON_CONNECTION, $value);
         $this->_messages[self::ERROR_ON_CONNECTION] = $message;
         return false;
     }
     if (!isset($org)) {
         $message = $this->_createMessage(self::ERROR_ORGANIZATION_NOT_FOUND, $value);
         $this->_messages[self::ERROR_ORGANIZATION_NOT_FOUND] = $message;
         return false;
     }
     if (!is_string($org->getType())) {
         $message = $this->_createMessage(self::ERROR_INVALID_TYPE, $value);
         $this->_messages[self::ERROR_INVALID_TYPE] = $message;
         return false;
     }
     if ($this->getOrganizationType() !== null && $this->getOrganizationType() !== $org->getType()) {
         $message = $this->_createMessage(self::ERROR_INVALID_ORG_TYPE, $value);
         $this->_messages[self::ERROR_INVALID_ORG_TYPE] = $message;
         return false;
     }
     return true;
 }
 /**
  * Route shutdown hook -- Check for router exceptions
  *
  * @param Zend_Controller_Request_Abstract $request
  */
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
     $auth = Zend_Auth::getInstance();
     $orgService = \Application\Service\OrgService::getInstance();
     $identity = $auth->getIdentity();
     //Bypass other auth methods
     if ($identity['authType'] != App_Controller_Plugin_Auth::AUTH_TYPE_AUTH_TOKEN) {
         return;
     }
     $front = Zend_Controller_Front::getInstance();
     $bs = $front->getParam('bootstrap');
     // Fetch logs and apply the token to them
     $multilog = $bs->getPluginResource('multiplelog');
     if (empty($identity['impersonation']) || empty($identity['impersonation']['orgId'])) {
         return;
     }
     $orgId = $identity['impersonation']['orgId'];
     $userSrv = UserService::getInstance();
     \App::log()->info($identity['username'] . " is running as " . $orgId . " admin");
     $user = $userSrv->loadByUsername($identity['username']);
     $userSrv->generateImpersonatedUser($user, $identity['impersonation']);
     foreach ($multilog->getLogs() as $log) {
         $log->setEventItem('impersonated', "as {$orgId} admin");
         $log->setEventItem('impersonatedOrgId', "{$orgId}");
         $log->setEventItem('username', $identity['username'] . " as {$orgId} admin");
     }
     //         Application\Model\Mapper\ProtoAbstractMapper::$accountingUserId .= "_impersonated";
     Application\Model\Mapper\ProtoAbstractMapper::$organizationId = $orgId;
     App_ListFilter::addDefaultExtraData('impersonated_org', $orgId);
     $org = OrgService::getInstance()->load($orgId);
     \App::getOrgUserLogged($org);
 }
 /**
  * Route shutdown hook
  *
  * @param  Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     // Setup Protobuf based mappers
     $ident = \Zend_Auth::getInstance()->getIdentity();
     $lang = null;
     if (!isset($ident['apiId'])) {
         $user = \Application\Model\Mapper\UserMapper::getInstance()->findOneByUserName($ident['username']);
         if ($user) {
             $lang = $user->language;
         } else {
             if (isset($ident['authType']) && $ident['authType'] !== App_Controller_Plugin_Auth::AUTH_TYPE_ASYNC) {
                 try {
                     if (isset($ident['orgId'])) {
                         $org = \Application\Service\OrgService::getInstance()->load($ident['orgId']);
                         if ($org) {
                             $lang = $org->defaultLanguage;
                         }
                     }
                 } catch (Exception $e) {
                     \App::log()->warn("No language defined. Using english.");
                     \App::log()->warn($e);
                 }
             }
         }
     }
     self::generateToken($ident['username'], $ident['orgId'], $lang);
 }
 /**
  *
  * @return type
  */
 public function getParent()
 {
     if (NULL === $this->_parent) {
         $this->_parent = OrgService::load($this->getParentId());
     }
     return $this->_parent;
 }
 public function testOrgConfigMaster()
 {
     $org = $this->_service->load(self::MASTER_ORG_ID);
     $config = $this->_service->getOrgConfig($org);
     $this->assertInstanceOf('Application\\Model\\Organization\\Types\\OrgConfigModel', $config);
     $this->assertEmpty($config->exportData());
 }
 public function __construct($options = null)
 {
     parent::__construct($options);
     if (isset($this->_spec['validators']['simType'])) {
         unset($this->_spec['validators']['simType']);
     }
     if (isset($this->_spec['validators']['simModel'])) {
         unset($this->_spec['validators']['simModel']);
     }
     if (isset($this->_spec['validators']['staticIpAddress']['Sim\\ApnSubnet'])) {
         unset($this->_spec['validators']['staticIpAddress']['Sim\\ApnSubnet']);
     }
     $org = \App::getOrgUserLogged();
     $orgConfig = \Application\Service\OrgService::getInstance()->getOrgConfig($org);
     // check that ipv6 is disabled
     if (isset($this->_spec['validators']['staticIpAddress']['Ip']) && $orgConfig->getConfig(OrgConfigModel::ORG_CONFIG_IPV6_DISABLED_KEY, OrgConfigModel::ORG_CONFIG_IPV6_DISABLED_DEFAULT)) {
         $this->_spec['validators']['staticIpAddress']['Ip']['allowipv6'] = false;
     }
     if (isset($this->_spec['validators']['staticIpAddress']['NotEmptyIfField'])) {
         unset($this->_spec['validators']['staticIpAddress']['NotEmptyIfField']);
     }
     if (isset($this->_spec['validators']['staticIpApnIndex'])) {
         $this->_spec['validators']['staticIpApnIndex'] = array('ApnIndex' => array('breakChainOnFailure' => true, 'min' => 1, 'max' => 10));
     }
     /**
      * @todo Move icc, imsi, msisdn to validators?
      * @see AbstractParser.php
      */
     $this->_spec['validators']['icc'] = array('regex' => array('pattern' => "/^[0-9]{2}[1-9][0-9]{0,2}[0-9]{1,4}[0-9]+\$/", 'breakChainOnFailure' => true), 'LuhnAlgorithm' => array('breakChainOnFailure' => true));
     $this->_spec['validators']['imsi'] = array('regex' => array('pattern' => "/^[0-9]{15}\$/", 'breakChainOnFailure' => true));
     $this->_spec['validators']['msisdn'] = array('regex' => array('pattern' => "/^[1-9][0-9]{0,2}[0-9]{1,15}\$/", 'breakChainOnFailure' => true));
     $this->_spec['validators']['apns'] = array('ApnList' => array('breakChainOnFailure' => true));
     $this->_spec['validators']['locationManual'] = array('LocationValidate' => array('breakChainOnFailure' => true, 'acceptArrayAsModel' => true));
 }
Exemple #10
0
 public function getList()
 {
     $options = array(Vpn::IP_TYPE_IPV4);
     $config = OrgService::getInstance()->getOrgConfig(\App::getOrgUserLogged());
     if (!$config->getConfig(OrgConfigModel::ORG_CONFIG_IPV6_DISABLED)) {
         $options[] = Vpn::IP_TYPE_IPV6;
     }
     return $options;
 }
 /**
  * Get an specific report by its Id
  */
 public function getAction()
 {
     $params = $this->getRequest()->getQuery();
     $params['id'] = $this->getRequest()->getParam('id');
     $params['reportType'] = $params['id'];
     // Mapping report name (a mistake on spec)
     if ($params['id'] === 'charges_detail_monthly') {
         $params['id'] = ReportModel::EXPENSE_DETAIL_MONTHLY;
         $params['reportType'] = ReportModel::EXPENSE_DETAIL_MONTHLY;
     } else {
         if ($params['id'] === 'charges_detail_daily') {
             $params['id'] = ReportModel::EXPENSE_DETAIL_DAILY;
             $params['reportType'] = ReportModel::EXPENSE_DETAIL_DAILY;
         }
     }
     // Check report permissions by type
     $dumpReport = new ReportModel();
     $dumpReport->setType($params['id']);
     try {
         $this->_helper->allowed('read', $dumpReport);
     } catch (ForbiddenException $ex) {
         \App::log()->crit($ex);
         if ($dumpReport->getResourceId() == 'report') {
             \App::log()->crit("Invalid report type: " . $params['id']);
         }
         throw new NotAllowedException('List report Operation is not allowed: Customer is not allowed');
     }
     // Check report params
     $this->_reportSrv->validateParams($params['id'], $params);
     // Check report organization
     if (isset($params['orgId'])) {
         try {
             $org = OrgService::getInstance()->load($params['orgId']);
         } catch (Exception $ex) {
             throw new \Application\Exceptions\InvalidArgumentException("Invalid parameter value: " . ReportFilterFields::ORGANIZATION . ". Supported values are customer-xxxxx");
         }
         if (empty($org)) {
             throw new NotFoundException("Resource " . ReportFilterFields::ORGANIZATION . " does not exists");
         }
         try {
             $this->_helper->allowed('read', $org);
         } catch (ForbiddenException $ex) {
             throw new NotAllowedException('List report Operation is not allowed: Customer is not allowed');
         }
     }
     // Check report exists
     if (!$this->_reportSrv->validateReportExists($params)) {
         throw new \Application\Exceptions\NotFoundException("Resource report does not exist");
     }
     // Prepare report download
     $downloadToken = new DownloadTokenModel();
     $downloadToken->params = $params;
     $downloadToken->controller = 'report';
     $downloadToken->action = 'get';
     $this->_downloadTokenSrv->create($downloadToken);
     $this->view->resultURL = $downloadToken->url;
 }
 /**
  * Retrive the list of enum by type
  *
  * @param string $type
  */
 public function getEnum($type, $filters = array())
 {
     /**
      * @var \Application\Model\Mapper\EnumeratedMapper
      */
     $enumMapper = \Application\Model\Mapper\EnumeratedMapper::getInstance();
     if (!$type) {
         throw new Exceptions\InvalidArgumentException("Enum type is mandatory");
     }
     if ($filters && !is_array($filters)) {
         throw new Exceptions\InvalidArgumentException("filters is not an array");
     }
     switch ($type) {
         case self::COUNTRY_ENUM_NAME:
             return $enumMapper->listCountry();
         case self::CURRENCY_ENUM_NAME:
             return $enumMapper->listCurrency();
         case self::LANGUAGE_ENUM_NAME:
             return $enumMapper->listLanguage();
         case self::SECTOR_ENUM_NAME:
             return $enumMapper->listSector();
         case self::STATUS_ENUM_NAME:
             return $enumMapper->listStatus();
         case self::COMPANY_TYPE_ENUM_NAME:
             return $enumMapper->listCompanyType();
         case self::TIME_ZONE_STATIC_ENUM_NAME:
             return $enumMapper->listStaticTimeZone();
         case self::MNO_ENUM_NAME:
             return $enumMapper->listMNO();
         default:
             // Get service provider id
             if (isset($filters['serviceProvider'])) {
                 $orgId = $filters['serviceProvider'];
             } else {
                 $org = \App::getOrgUserLogged();
                 $orgId = OrgService::getInstance()->getServiceProviderLevelId($org);
             }
             // Get enum by service provider
             switch ($type) {
                 case self::RAID_ENUM_NAME:
                     return $enumMapper->listRaid($orgId);
                 case self::SERVICE_PROVIDER_ZONE_ENUM_NAME:
                     $zones = $enumMapper->listServiceProviderZone($orgId);
                     return $this->_filterDefaultValues($zones);
                 case self::SERVICE_PROVIDER_DESTINATION_ENUM_NAME:
                     $destinations = $enumMapper->listServiceProviderDestination($orgId);
                     return $this->_filterDefaultValues($destinations);
                 case self::TIME_ZONE_ENUM_NAME:
                     return $enumMapper->listTimeZone($orgId);
                 case self::SERVICE_PROVIDER_REGION_ENUM_NAME:
                     $regions = $enumMapper->listServiceProviderRegion($orgId);
                     return $this->_filterDefaultValues($regions);
                 default:
                     throw new AppEx\InvalidArgumentException("Enumerated " . $type . " doesn't exist");
             }
     }
 }
 public function testActivate()
 {
     // Persist the org model
     $this->_org->save();
     $this->_service->deactivate($this->_org->getId());
     $org = $this->_service->load($this->_org->getId());
     $this->assertEquals($org->status, OrgAggregatorModel::ORG_STATUS_DEACTIVATED);
     $this->_service->activate($this->_org->getId());
     $org = $this->_service->load($this->_org->getId());
     $this->assertEquals($org->status, OrgAggregatorModel::ORG_STATUS_ACTIVATED);
 }
 public function changeBillingCycleStartDayAction()
 {
     if ($this->getRequest()->isPost()) {
         // Get params
         $id = $this->getRequest()->getParam('id');
         $org = $this->_orgSrv->load($id);
         // Check permissions
         $this->_helper->allowed('update_field_billingAccounts:*:billingCycleStartDay', $org);
         // Change billing day
         $data = $this->_helper->requestData();
         $this->_orgSrv->changeBillingCycleStartDay($id, @$data['billingAccountId'], @$data['billingCycleStartDay']);
     }
 }
 /**
  * Validate element value
  *
  * If a translation adapter is registered, any error messages will be
  * translated according to the current locale, using the given error code;
  * if no matching translation is found, the original message will be
  * utilized.
  *
  * Note: The *filtered* value is validated.
  *
  * @param  array   $data
  * @param  mixed   $context
  * @return boolean
  */
 public function isValid($data, $context = null, $removeNotPresentFields = false)
 {
     if ($data) {
         $org = \App::getOrgUserLogged();
         $orgConfig = \Application\Service\OrgService::getInstance()->getOrgConfig($org);
         $lteProvider = $orgConfig->getConfig(OrgConfigModel::ORG_CONFIG_LTE_ENABLED);
         if (!$lteProvider) {
             $this->_error(self::LTE_PROVIDER_DISABLED);
             return false;
         }
     }
     return true;
 }
 /**
  * Deletes the given organization
  */
 public function deleteAction()
 {
     // Try to load the chosen organization
     $id = $this->getRequest()->getParam('id');
     $org = $this->_orgSrv->load($id);
     if (empty($org)) {
         throw new NotFoundException('Organization ' . $id . ' not found', 404);
     }
     // Check permissions
     $this->_helper->allowed('delete', $org);
     $this->_orgSrv->delete($org);
     $this->view->data = true;
 }
 public function getSupplementaryService($context)
 {
     $user = \App::getUserLogged();
     $org = $user->getOrganization();
     if (!$org->supplementaryServicesId) {
         $orgService = OrgService::getInstance();
         $org = $orgService->getParentByType($org, OrgCustomerModel::ORG_TYPE);
     }
     if ($org) {
         $item = SupplServicesService::getInstance()->load($org->supplementaryServicesId);
         return $item;
     }
 }
 public function isValid($data, $context = null)
 {
     if (!parent::isValid($data, $context)) {
         return false;
     }
     $org = \Application\Service\OrgService::getInstance()->load($data['id']);
     if (isset($data['billingAccountId'])) {
         $billing = $org->getBillingAccount($data['billingAccountId']);
         if (!$billing->billingCycleModifiable) {
             $this->_billingAccountId = $data['billingAccountId'];
             $this->_error(self::BILLING_CYCLE_DAY_NOT_MODIFIABLE);
             return false;
         }
         $startingDay = $billing->billingCycleStartDay;
         if (!isset($startingDay) || !$startingDay) {
             $startingDay = $org->billingCycleStart->dayOfMonth;
         }
     } else {
         $billings = $org->getAllBillingAccounts();
         foreach ($billings as $billing) {
             // Basic info billing cycle start day is not modifiable if one of
             // billings is inheriting this value and it is not modifiable
             if (empty($billing->billingCycleStartDay) && !$billing->billingCycleModifiable) {
                 $this->_billingAccountId = $billing->billingAccountId . ' (inherited from default)';
                 $this->_error(self::BILLING_CYCLE_DAY_NOT_MODIFIABLE);
                 return false;
             }
         }
         $startingDay = $org->billingCycleStart->dayOfMonth;
     }
     $tz = $org->getBillingCycleStart()->getTimezone();
     $time = new DateTime("-1 day", new DateTimeZone($tz));
     $day = $time->format('d');
     if ($startingDay === $day) {
         $this->_error(self::NOT_ALLOWED_CHANGE_DAY_BEFORE);
         return false;
     }
     $time = new DateTime("now", new DateTimeZone($tz));
     $day = $time->format('d');
     if ($startingDay === $day) {
         $this->_error(self::NOT_ALLOWED_CHANGE_DAY_TODAY);
         return false;
     }
     $time = new DateTime("+1 day", new DateTimeZone($tz));
     $day = $time->format('d');
     if ($startingDay === $day) {
         $this->_error(self::NOT_ALLOWED_CHANGE_NEXT_DAY);
         return false;
     }
     return true;
 }
function findOrgsAndSendEvent($type, $params = array(), $sortFunction = NULL)
{
    $service = OrgService::getInstance();
    $orgs = $service->listAll($type, $params)->getItems();
    if ($sortFunction) {
        usort($orgs, $sortFunction);
    }
    foreach ($orgs as $org) {
        \Application\Model\Mapper\OrganizationMapper::$organizationId = $org->id;
        $org = $service->load($org->id);
        $service->sendEvent('update', $org);
        \App::log()->notice("Send event to " . $org::ORG_TYPE . " org: " . $org->id);
    }
    return $orgs;
}
 public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
 {
     if (NULL === $role) {
         return false;
     }
     // Ensure we're handled User models
     if (!$role instanceof \Application\Model\UserModel) {
         throw new Exception('Role must be an instance of UserModel');
     }
     $org = $role->getOrganization();
     $orgConfig = \Application\Service\OrgService::getInstance()->getOrgConfig($org);
     $keyConfig = $this->getKey();
     $valueConfig = $this->getValue();
     return $orgConfig->getConfig($keyConfig) == $valueConfig;
 }
 /**
  * Returns true if and only if the assertion conditions are met
  *
  * This method is passed the ACL, Role, Resource, and privilege to which
  * the authorization query applies. If the $role, $resource, or $privilege
  * parameters are null, it means that the query applies to all Roles,
  * Resources, or privileges, respectively.
  *
  * @param  Zend_Acl                    $acl
  * @param  Zend_Acl_Role_Interface     $role
  * @param  Zend_Acl_Resource_Interface $resource
  * @param  null                        $privilege
  * @return bool
  * @throws Exception
  */
 public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
 {
     if (NULL === $role || NULL === $resource) {
         return false;
     }
     // Ensure we're handled User models
     if (!$role instanceof \Application\Model\UserModel) {
         throw new Exception('Role must be an instance of UserModel');
     }
     $org = $role->getOrganization();
     if (!$org instanceof \Application\Model\Organization\OrgServiceProviderModel) {
         throw new Exception('Org must be an instance of OrgServiceProviderModel');
     }
     return \Application\Service\OrgService::getInstance()->isEnabler($org);
 }
 public function __construct($options = null)
 {
     $this->_spec = array('validators' => array('sms' => array('NotEmpty' => array('breakChainOnFailure' => true, 'type' => \Zend_Validate_NotEmpty::NULL), 'isBoolean' => array('breakChainOnFailure' => true)), 'msisdnList' => array('NotEmptyIfField' => array('breakChainOnFailure' => true, 'field' => 'sms', 'value' => true), 'Array' => array('breakChainOnFailure' => true, 'distinct' => true, 'validators' => array('NotEmpty' => array('breakChainOnFailure' => true), 'StringLength' => array('max' => 15, 'encoding' => "UTF-8", 'breakChainOnFailure' => true)))), 'email' => array('NotEmpty' => array('breakChainOnFailure' => true, 'type' => \Zend_Validate_NotEmpty::NULL), 'isBoolean' => array('breakChainOnFailure' => true)), 'emailList' => array('NotEmptyIfField' => array('breakChainOnFailure' => true, 'field' => 'email', 'value' => true, 'type' => \Zend_Validate_NotEmpty::EMPTY_ARRAY), 'Array' => array('breakChainOnFailure' => true, 'distinct' => true, 'validators' => array('EmailAddress' => array('mx' => false, 'breakChainOnFailure' => true)))), 'snmp' => array('NotEmpty' => array('breakChainOnFailure' => true, 'type' => \Zend_Validate_NotEmpty::NULL), 'isBoolean' => array('breakChainOnFailure' => true))));
     $org = \App::getOrgUserLogged();
     if ($org->getType() != OrgCustomerModel::ORG_TYPE) {
         $org = OrgService::getInstance()->getParentByType($org, OrgCustomerModel::ORG_TYPE);
     }
     if ($org && !is_null($org->getSupplementaryServicesId())) {
         $services = SupplServicesService::getInstance()->load($org->getSupplementaryServicesId());
         if (!$services || $services->getApplicationOriginatedSms() != SupplServicesModel::ST_ACTIVATED) {
             $this->_spec['validators']['sms']['Identical'] = array('token' => false, 'messageTemplates' => array(\Zend_Validate_Identical::NOT_SAME => "Application originated sms service not activated"));
         }
     }
     parent::__construct($options);
 }
 /**
  * @param  OrganizationModel|string      $org
  * @return \Application\Model\BrandModel
  */
 public function loadByOrganization($org)
 {
     $orgService = OrgService::getInstance();
     if (is_string($org)) {
         $org = $orgService->load($org);
     }
     if (!$org instanceof OrgModelAbstract) {
         throw new InvalidArgumentException("Organization must be an organization model or organization id");
     }
     $brand = BrandModel::DEFAULT_BRAND;
     $parentOrg = $orgService->getParentByType($org, OrgServiceProviderModel::ORG_TYPE);
     if ($parentOrg) {
         $brand = $parentOrg->getBrand();
     }
     return $this->loadByBrand($brand);
 }
 /**
  * isValid method
  *
  * @param (OrgModelAbstract) $org organization to validate if it has
  *                                aggregators or not
  *
  * @return null
  * @author Francisco Marcos <*****@*****.**>
  **/
 public function isValid($org)
 {
     if (!$org instanceof OrgModelAbstract) {
         throw new InvalidArgumentException('OrgModelAbstract class expected');
     }
     $service = OrgService::getInstance();
     $filters = $service->buildFilterList(array('type' => self::ORG_TYPE, 'parentId' => $org->id));
     $list = $service->listAll(self::ORG_TYPE, array('filterList' => $filters));
     $orgAggregatorCount = count($list);
     $valid = (bool) (!count($list));
     if (!$valid) {
         $this->setMessage(sprintf($this->_messageTemplates[self::MSG_HAS_AGGREGATORS], $org->id, $orgAggregatorCount), self::MSG_HAS_AGGREGATORS);
         $this->_error(self::MSG_HAS_AGGREGATORS);
     }
     return $valid;
 }
Exemple #25
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if no token has been found inside value.
  *
  * @param  mixed   $value
  * @param  array   $context
  * @return boolean
  */
 public function isValid($value, $context = null)
 {
     if (!is_string($value)) {
         $this->_error(self::INVALID_TYPE);
         return false;
     }
     $config = OrgService::getInstance()->getOrgConfig(\App::getOrgUserLogged());
     if ($value === '0' && $config->getConfig(OrgConfigModel::ORG_CONFIG_MSISDNLESS)) {
         return true;
     }
     if (!preg_match('/^[1-9][0-9]{0,17}$/', $value)) {
         $this->_error(self::INVALID_MSISDN, $value);
         return false;
     }
     return true;
 }
 public function isValid($value, $context = null)
 {
     $this->_messages = array();
     $id = isset($context['id']) ? $context['id'] : null;
     if ($id) {
         $org = OrgService::getInstance()->load($id);
         if ($org->crmId_1 == $value) {
             return true;
         }
     }
     $orgType = $this->getOrganizationType();
     if (!$orgType) {
         $message = $this->_createMessage(self::ERROR_INVALID_ORG_TYPE, $value);
         $this->_messages[self::ERROR_INVALID_ORG_TYPE] = $message;
         return false;
     }
     $found = false;
     try {
         $filter = OrgService::getInstance()->buildFilterList(array(CustomerFilterFields::CRM_ID1 => $value, 'type' => $orgType));
         $orgList = OrgService::getInstance()->listAll($orgType, array('filterList' => $filter));
         $orgs = $orgList->getItems();
         if (!isset($id) && !empty($orgs)) {
             $found = true;
         } else {
             if (isset($id)) {
                 foreach ($orgs as $item) {
                     //if organization have id, validate for update, else validate for create
                     if ($id !== $item->getId()) {
                         $found = true;
                         break;
                     }
                 }
             }
         }
         if (true === $found) {
             $message = $this->_createMessage(self::ERROR_ORGANIZATION_CRMID1_FOUND, $value);
             $this->_messages[self::ERROR_ORGANIZATION_CRMID1_FOUND] = $message;
             return false;
         }
         return true;
     } catch (Application\Exceptions\GlobalServiceException $e) {
         \App::log()->info($e);
         $message = $this->_createMessage(self::ERROR_ON_CONNECTION, $org);
         $this->_messages[self::ERROR_ON_CONNECTION] = $message;
         return false;
     }
 }
 /**
  * Lists all users matching a criteria
  */
 public function indexAction()
 {
     $cg = new CommercialGroupModel();
     $params = array();
     try {
         if ($this->_hasParam('customerId')) {
             $params = array('customerId' => $this->_getParam('customerId'));
         }
         // Normal case
         $this->_helper->allowed('list', $cg);
     } catch (ForbiddenException $e) {
         // HACK to allow commercial groups list for service providers
         $this->_helper->allowed('list_combo', $cg);
         if (!$this->_hasParam('customerId')) {
             throw new InvalidArgumentException("Missing customer parameter");
         }
     }
     if (isset($params['customerId'])) {
         $customer = \Application\Service\OrgService::getInstance()->load($params['customerId']);
         if (!$customer) {
             throw new NotFoundException("Customer not found");
         }
         $this->_helper->allowed('read', $customer);
     }
     $filterParams = $this->getRequest()->getQuery();
     $filterParams = $this->_mapToFilter($filterParams);
     $this->_checkFilterParams($filterParams, CommercialGroupFilterFields::getWhiteList());
     try {
         $filterList = $this->_cgSrv->buildFilterList($filterParams, true);
     } catch (ValidateException $e) {
         throw $this->_mapException($e, $this->_mapParamToFilter, true);
     }
     $this->_helper->filterNotAllowedFilters('filter_by', $filterList);
     $params['filterList'] = $filterList;
     $cgList = $this->_cgSrv->listAll($params);
     if ($cgList) {
         $items = $cgList->getItems();
         foreach ($items as $item) {
             foreach (array('whiteList', 'blackList', 'roamingList') as $field) {
                 if (isset($item->{$field})) {
                     unset($item->{$field});
                 }
             }
         }
         $this->view->commercialGroup = $items;
     }
 }
 /**
  * Returns true if and only if the assertion conditions are met
  * This method is passed the ACL, Role, Resource, and privilege to which
  * the authorization query applies. If the $role, $resource, or $privilege
  * parameters are null, it means that the query applies to all Roles,
  * Resources, or privileges, respectively.
  *
  * @param  Zend_Acl                    $acl
  * @param  Zend_Acl_Role_Interface     $role
  * @param  Zend_Acl_Resource_Interface $resource
  * @param  null                        $privilege
  * @return bool
  * @throws Exception
  */
 public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
 {
     // We need specific objects to check against each other
     if (NULL === $role || NULL === $resource) {
         return false;
     }
     // Ensure we're handled User models
     if (!$role instanceof UserModel) {
         throw new Exception('Role must be an instance of UserModel');
     }
     $orgId = $role->getOrganizationId();
     switch (true) {
         case $resource instanceof OrgModelAbstract:
             return $orgId === $resource->getParentId();
         case $resource instanceof Model\PreBillModel:
             return true;
             //TODO: we need serviceProviderId from ericsson
             return $orgId === $resource->getServiceProvider()->getId();
         case $resource instanceof UserModel:
             try {
                 $org = $resource->getOrganization();
                 if (NULL !== $org) {
                     return $orgId === $org->getParentId();
                 }
                 App::log()->err("User (" . $resource->getId() . ") organization (" . $resource->getOrganizationId() . ") doesn't exist");
                 return false;
             } catch (Exception $e) {
                 return false;
             }
         case $resource instanceof Model\CommercialGroupModel:
             // customerId is one of service provider customers?
             // TODO aggregatorId case?
             $org = OrgService::getInstance()->load($resource->getCustomerId());
             return $org && $orgId === $org->getParentId();
         case $resource instanceof Model\ReportModel:
             $params = $resource->getParams();
             if (isset($params['orgId']) && !empty($params['orgId'])) {
                 $org = OrgService::getInstance()->load($params['orgId']);
                 return $org && $orgId === $org->getParentId();
             } else {
                 return true;
             }
     }
     throw new Exception('Resource must be an instance of OrgModelAbstract or UserModel');
 }
 /**
  * Lists all users matching a criteria
  */
 public function indexAction()
 {
     $cg = new CommercialGroupModel();
     $params = array();
     try {
         if ($this->_hasParam('customer')) {
             $params = array('customerId' => $this->_getParam('customer'));
         }
         // Normal case
         $this->_helper->allowed('list', $cg);
     } catch (ForbiddenException $e) {
         // HACK to allow commercial groups list for service providers
         $this->_helper->allowed('list_combo', $cg);
         if (!$this->_hasParam('customer')) {
             throw new InvalidArgumentException("Missing customer parameter");
         }
     }
     if (isset($params['customerId'])) {
         $customer = \Application\Service\OrgService::getInstance()->load($params['customerId']);
         if (!$customer) {
             throw new NotFoundException("Customer not found");
         }
         $this->_helper->allowed('read', $customer);
     }
     $filterParams = $this->getRequest()->getQuery();
     $filterList = $this->_cgSrv->buildFilterList($filterParams);
     $this->_helper->filterNotAllowedFilters('filter_by', $filterList);
     $params['filterList'] = $filterList;
     $cgList = $this->_cgSrv->listAll($params);
     if ($cgList) {
         $count = $cgList->getCount();
         $list = array();
         foreach ($cgList->getItems() as $item) {
             try {
                 $this->_helper->allowed('read', $item);
                 $list[] = $item;
             } catch (Exception $e) {
                 $count--;
             }
         }
         $this->view->count = $count;
         $this->view->data = $list;
     }
 }
 /**
  * Returns true if and only if the assertion conditions are met
  *
  * This method is passed the ACL, Role, Resource, and privilege to which
  * the authorization query applies. If the $role, $resource, or $privilege
  * parameters are null, it means that the query applies to all Roles,
  * Resources, or privileges, respectively.
  *
  * @param  Zend_Acl                    $acl
  * @param  Zend_Acl_Role_Interface     $role
  * @param  Zend_Acl_Resource_Interface $resource
  * @param  string                      $privilege
  * @return boolean
  */
 public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
 {
     // We need specific objects to check against each other
     if (NULL === $role) {
         return false;
     }
     // Ensure we're handled User models
     if (!$role instanceof UserModel) {
         throw new Exception('Role must be an instance of UserModel');
     }
     if (!$resource instanceof SimModel) {
         throw new Exception('Resource must be an instance of SimModel');
     }
     // Get the organization
     $orgService = \Application\Service\OrgService::getInstance();
     if ($orgService->getTypeById($role->getOrganizationId()) == OrgServiceProviderModel::ORG_TYPE) {
         $org = $orgService->load($resource->customerId);
     } else {
         $org = $orgService->load($role->getOrganizationId());
     }
     if ($org->getType() != OrgCustomerModel::ORG_TYPE) {
         $org = $orgService->getParentByType($org, OrgCustomerModel::ORG_TYPE);
     }
     if ($org && !is_null($org->getSupplementaryServicesId())) {
         // Check if the customer has supplementary services configured
         // with application originated SMS option activated
         $supplSrv = \Application\Service\SupplServicesService::getInstance();
         try {
             if ($orgService->getTypeById($role->getOrganizationId()) == OrgAggregatorModel::ORG_TYPE) {
                 $services = $supplSrv->load($org->getSupplementaryServicesId(), $org);
             } else {
                 $services = $supplSrv->load($org->getSupplementaryServicesId());
             }
         } catch (\Exception $e) {
             \App::log()->warn($e);
             return False;
         }
         if ($services && $services->advancedSupervision == SupplServicesModel::ST_ACTIVATED) {
             return true;
         }
     }
     return false;
 }