コード例 #1
0
 /**
  * @param  DownloadTokenModel $downloadToken
  * @return DownloadTokenModel
  */
 public function create(models\ModelAbstract $downloadToken)
 {
     if (!$downloadToken instanceof DownloadTokenModel) {
         throw new InvalidArgumentException('Supplied data must be a download token model');
     }
     $downloadToken->token = UserService::getInstance()->generatePassword(60);
     $brandService = BrandService::getInstance();
     $brand = $brandService->loadByOrganization(\App::getOrgUserLogged());
     $router = \Zend_Controller_Front::getInstance()->getRouter();
     $downloadToken->url = $brand->endPoint . $router->assemble(array('controller' => $downloadToken->controller, 'action' => $downloadToken->action, 'token' => $downloadToken->token), 'downloadToken');
     $downloadToken->orgId = \App::getOrgUserLogged()->getId();
     $downloadToken->expireDatetime = \App::config('downloadTokenLifeTime', "+1 day");
     $ident = \Zend_Auth::getInstance()->getIdentity();
     if (isset($ident['username'])) {
         $downloadToken->username = $ident['username'];
     }
     if (isset($ident['authType'])) {
         $downloadToken->authType = $ident['authType'];
     }
     if (isset($ident['apiId'])) {
         $downloadToken->apiId = $ident['apiId'];
     }
     if (isset($ident['impersonation'])) {
         $downloadToken->impersonation = $ident['impersonation'];
     }
     return parent::create($downloadToken);
 }
コード例 #2
0
 public function isValid($value, $context = null)
 {
     if (!parent::isValid($value, $context)) {
         return false;
     }
     $cg = $this->_getCommercialGroup($value, 'id');
     if ($cg === false) {
         return false;
     }
     if ($cg === NULL) {
         $this->_error(self::ERROR_COMMERCIAL_GROUP_NOT_EXISTS, $value);
         return false;
     }
     if ($this->getCheckRestrictions()) {
         $restricted = $cg->restricted;
         switch (\App::getOrgUserLogged()->getType()) {
             case OrgCustomerModel::ORG_TYPE:
                 if ($restricted) {
                     $this->_error(self::ERROR_COMMERCIAL_GROUP_RESTRICTED, $value);
                     return false;
                 }
         }
     }
     return true;
 }
コード例 #3
0
 /**
  * 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);
 }
コード例 #4
0
 public function isValid($value, $context = null)
 {
     if (!parent::isValid($value, $context)) {
         return false;
     }
     if ($value == BusinessRule::CHANGE_COMMERCIAL_GROUP) {
         $type = App_Util_Array::getItem($context, '__parent.__parent.universeType');
         if ($type == AlarmRuleModel::UNIVERSE_SUBSCRIPTIONS_OF_COMMERCIAL_GROUP || $type == AlarmRuleModel::UNIVERSE_COMMERCIAL_GROUP) {
             $universeId = App_Util_Array::getItem($context, '__parent.__parent.universeId');
             $cg = $this->_getCommercialGroup($universeId, 'id');
             if ($cg === NULL) {
                 $this->_error(self::ERROR_COMMERCIAL_GROUP_NOT_EXISTS, $universeId);
                 return false;
             }
             $restricted = $cg->restricted;
             switch (\App::getOrgUserLogged()->getType()) {
                 case OrgCustomerModel::ORG_TYPE:
                     if ($restricted) {
                         $mss = "{$type} with commercial group id {$universeId}";
                         $this->_error(self::ERROR_UNIVERSE_TYPE_COMMERCIAL_GROUP_RESTRICTED, $mss);
                         return false;
                     }
             }
         }
     }
     return true;
 }
コード例 #5
0
 public function postAction()
 {
     $data = $this->_helper->requestData(true);
     if (isset($data['endCustomerData'])) {
         $data = $data['endCustomerData'];
     }
     // Filter data
     $data = $this->_helper->filter($data)->blacklist($this->_getCreateBlackList());
     //TODO filter should provide a fluent iface to apply these methods
     $data = $this->_helper->filter($data)->removeEmpty();
     $data = $this->_mapToModel($data);
     $org = new OrgAggregatorModel($data);
     $org->parentId = \App::getOrgUserLogged()->id;
     $org->description = "Organization made by API";
     // Check if it's allowed
     $this->_helper->allowed('create', $org);
     // Check mandatory fields
     //         $this->_preValidate($org->exportData(), new \Application\Model\Validate\Organization\OrgAggregatorValidate());
     // Create the organization via its service
     $this->_orgSrv->create($org);
     // Response with the organization id
     $this->view->endCustomerID = $org->getId();
     $url = $this->getFrontController()->getRouter()->assemble(array('controller' => $this->getRequest()->getControllerName(), 'action' => $this->getRequest()->getActionName(), 'id' => $org->getId()));
     $this->getResponse()->setHeader('Location', $url);
     $this->getResponse()->setHttpResponseCode(201);
 }
コード例 #6
0
 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));
 }
コード例 #7
0
 protected function _findByServiceType($serviceType)
 {
     $filters = array("_parents" => 1, "organizationId" => \App::getOrgUserLogged()->id);
     $result = $this->_getPybeService()->callMethod($this::LIST_METHOD, $filters);
     $httpResponse = $this->_getPybeService()->getLastResult();
     $this->_checkResponseResult($httpResponse, 'Pybe error looking for contracts by service type');
     $valid_service_ids = array();
     $services = \App_Util_Array::getItem($result, $this::SERVICE_KEY . '.items');
     if ($services) {
         foreach ($services as $service) {
             if (isset($service['type']) && $service['type'] == $serviceType) {
                 $valid_service_ids[] = $service['id'];
             }
         }
     }
     if (!$valid_service_ids) {
         return new ListResultModel(array('items' => array(), 'count' => 0));
     }
     $entries = array();
     $candidateContracts = array();
     $contracts = \App_Util_Array::getItem($result, $this::LIST_KEY . '.items');
     if ($contracts) {
         foreach ($contracts as $contract) {
             if (isset($contract['serviceId'])) {
                 if (in_array($contract['serviceId'], $valid_service_ids)) {
                     $entries[] = $contract;
                 }
             } elseif (isset($contract['parentContractId'])) {
                 if (isset($candidateContracts[$contract['parentContractId']])) {
                     $candidateContracts[$contract['parentContractId']][] = $contract;
                 } else {
                     $candidateContracts[$contract['parentContractId']] = array($contract);
                 }
             }
         }
     }
     if ($candidateContracts) {
         $parentContracts = \App_Util_Array::getItem($result, $this::PARENT_KEY . '.items');
         if ($parentContracts) {
             foreach ($parentContracts as $contract) {
                 if (isset($contract['serviceId'])) {
                     if (in_array($contract['serviceId'], $valid_service_ids) and isset($candidateContracts[$contract['id']])) {
                         $entries = array_merge($entries, $candidateContracts[$contract['id']]);
                     }
                 }
             }
         }
     }
     if (!$entries) {
         return new ListResultModel(array('items' => array(), 'count' => 0));
     }
     $outputItems = array();
     foreach ($entries as $entry) {
         $data = $this->_mapPybeModelToModel($entry);
         $outputItems[] = !is_null($this->_modelClassResult) ? new $this->_modelClassResult($data) : $data;
     }
     return new ListResultModel(array('items' => $outputItems, 'count' => count($outputItems)));
 }
コード例 #8
0
ファイル: IpType.php プロジェクト: SandeepUmredkar/PortalSMIP
 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;
 }
コード例 #9
0
 /**
  * Return all the roles of a given organization or an
  * associative list of all organizations and their roles.
  */
 public function indexAction()
 {
     $orgClass = get_class(\App::getOrgUserLogged());
     $orgType = $this->_getParam('orgType');
     if (!$orgType || $orgClass::ORG_TYPE !== $orgType && $orgClass::CHILDREN_ORG_TYPE !== $orgType) {
         throw new InvalidArgumentException("Invalid organization type.");
     }
     $this->view->roles = $this->_roleSrv->getRoles($orgType);
 }
コード例 #10
0
 /**
  */
 public function postAction()
 {
     // Filter data
     $data = $this->_helper->requestData(true);
     $data = $this->_helper->filter($data)->blacklist(array('id', 'organizationId'));
     $template = new TemplateModel($data);
     // Check if it's allowed
     $this->_helper->allowed('create', $template);
     $this->_templateSrv->create($template, \App::getOrgUserLogged());
     // Response with the user id
     $this->view->data = $template->getId();
 }
コード例 #11
0
 public function setUp()
 {
     if (App::getEnv() !== 'testing-ericsson') {
         $this->markTestSkipped();
     }
     $this->simMapper = SimMapper::getInstance();
     // Hack: Override the logged user organization
     $org = new \Application\Model\Organization\OrgMasterModel();
     $org->setId(self::ORG_ID);
     \App::getOrgUserLogged($org);
     $this->_user = $this->_createAuthUser(array('userName' => 'SimUserTest', 'organizationId' => self::ORG_ID));
 }
コード例 #12
0
 /**
  * Create a new service group
  */
 public function postAction()
 {
     // Create model
     $data = $this->_helper->requestData(true);
     $sg = new SupervisionGroupModel($data);
     $org = \App::getOrgUserLogged();
     $sg->setCustomerId($org->getId());
     // Check permissions
     $this->_helper->allowed('create', $sg);
     $sg = SupervisionGroupService::getInstance()->create($sg);
     // Response with the id
     $this->view->data = $sg->getId();
 }
コード例 #13
0
 protected function consumptionAction()
 {
     // get the organization ID
     $orgId = \App::getOrgUserLogged()->getId();
     $start = $this->_getParam('start');
     $end = $this->_getParam('end');
     // get target params (comma delimited targets)
     $target = $this->_getParam('target');
     if (!empty($target)) {
         $params = explode(',', $target);
     }
     $this->_reportSrv->getConsumptionData($orgId, $params, $start, $end);
 }
コード例 #14
0
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
     $auth = Zend_Auth::getInstance();
     $identity = $auth->getIdentity();
     $byPassMethods = array(App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD, App_Controller_Plugin_Auth::AUTH_TYPE_ASYNC, App_Controller_Plugin_Auth::AUTH_TYPE_EXTERNAL, App_Controller_Plugin_Auth::AUTH_TYPE_THIRD_PARTY);
     //Bypass some auth methods
     if ($identity['authType'] && in_array($identity['authType'], $byPassMethods)) {
         return;
     }
     $user = App::getUserLogged();
     $org = App::getOrgUserLogged();
     App_ListFilter::addDefaultExtraData('user', $user->getUserName());
 }
コード例 #15
0
 /**
  * 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;
 }
コード例 #16
0
 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);
 }
コード例 #17
0
ファイル: Msisdn.php プロジェクト: SandeepUmredkar/PortalSMIP
 /**
  * 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;
 }
コード例 #18
0
 protected function _getSummary(\App_ListFilter $filterList = NULL)
 {
     $org = \App::getOrgUserLogged();
     $result = new GroupListModel();
     $dumbAlarm = new Application\Model\AlarmModel();
     $dumbAlarm->condition = AlarmRuleCondition::CONDITION_LIFE_CYCLE_STATUS_CHANGE;
     $this->_helper->filterNotAllowedFilters()->setThrowExOnNotAllowed(true);
     $this->_addGroup($result, $filterList, array(array('fieldName' => AlarmFilterFields::STATE, 'value' => AlarmModel::STATE_CLOSED, 'inverted' => true)), 'ALL');
     $this->_addGroup($result, $filterList, array(array('fieldName' => AlarmFilterFields::SEVERITY, 'value' => AlarmRuleModel::SEVERITY_CRITICAL, 'inverted' => false)), AlarmRuleModel::SEVERITY_CRITICAL, true);
     $this->_addGroup($result, $filterList, array(array('fieldName' => AlarmFilterFields::SEVERITY, 'value' => AlarmRuleModel::SEVERITY_URGENT, 'inverted' => false)), AlarmRuleModel::SEVERITY_URGENT, true);
     $this->_addGroup($result, $filterList, array(array('fieldName' => AlarmFilterFields::SEVERITY, 'value' => AlarmRuleModel::SEVERITY_INFORMATIVE, 'inverted' => false)), AlarmRuleModel::SEVERITY_INFORMATIVE, true);
     $this->_addGroup($result, $filterList, array(array('fieldName' => AlarmFilterFields::STATE, 'value' => AlarmModel::STATE_ATTENDED, 'inverted' => false)), AlarmModel::STATE_ATTENDED);
     $this->_addGroup($result, $filterList, array(array('fieldName' => AlarmFilterFields::STATE, 'value' => AlarmModel::STATE_OPENED, 'inverted' => false)), AlarmModel::STATE_OPENED);
     $this->_addGroup($result, $filterList, array(array('fieldName' => AlarmFilterFields::STATE, 'value' => AlarmModel::STATE_CLOSED, 'inverted' => false)), AlarmModel::STATE_CLOSED);
     if ($org instanceof OrgCustomerModel) {
         $alarmType = $filterList->getOneFilterByFieldName(AlarmFilterFields::ALARM_TYPE);
         $isSupervision = $alarmType && $alarmType->getValue() == AlarmModel::TYPE_SUPERVISION && !$alarmType->getInverted();
         if (!$isSupervision) {
             try {
                 $dumbAlarm->importData(array('entity' => array('universeType' => AlarmRuleModel::UNIVERSE_SUBSCRIPTIONS_OF_COMMERCIAL_GROUP)));
                 $this->_helper->allowed('read', $dumbAlarm);
                 $this->_addGroup($result, $filterList, array(array('fieldName' => AlarmFilterFields::UNIVERSE_TYPE, 'value' => AlarmRuleModel::UNIVERSE_SUBSCRIPTIONS_OF_COMMERCIAL_GROUP, 'inverted' => false)), AlarmRuleModel::UNIVERSE_SUBSCRIPTIONS_OF_COMMERCIAL_GROUP, true);
             } catch (PermissionException $e) {
                 //Nothing to do
             } catch (NotAllowedException $e) {
                 //Nothing to do
             }
             try {
                 $dumbAlarm->importData(array('entity' => array('universeType' => AlarmRuleModel::UNIVERSE_COMMERCIAL_GROUP)));
                 $this->_helper->allowed('read', $dumbAlarm);
                 $this->_addGroup($result, $filterList, array(array('fieldName' => AlarmFilterFields::UNIVERSE_TYPE, 'value' => AlarmRuleModel::UNIVERSE_COMMERCIAL_GROUP, 'inverted' => false)), AlarmRuleModel::UNIVERSE_COMMERCIAL_GROUP, true);
             } catch (PermissionException $e) {
                 //Nothing to do
             } catch (NotAllowedException $e) {
                 //Nothing to do
             }
         }
     }
     return $result;
 }
コード例 #19
0
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $req)
 {
     try {
         // Avoid error override! :S
         if (count($this->getResponse()->getException())) {
             return;
         }
         $auth = Zend_Auth::getInstance();
         $identity = $auth->getIdentity();
         $byPassMethods = array(App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD, App_Controller_Plugin_Auth::AUTH_TYPE_ASYNC);
         //Bypass some auth methods
         if ($identity['authType'] && in_array($identity['authType'], $byPassMethods)) {
             return;
         }
         $log = $this->_getLogger();
         try {
             $org = App::getOrgUserLogged();
         } catch (UnexpectedValueException $ex) {
         }
         if (!$org) {
             $this->_forceLogout($req, "Unexpected fatal error: Impossible to retrieve organization", 500);
         }
         $log->setEventItem('organizationId', $org->id);
         $orgId = OrgService::getInstance()->getServiceProviderLevelId($org);
         // Construct dynamic log?
         if (!empty($orgId)) {
             $key = 'audit-' . $orgId;
             $log->setEventItem('serviceProviderId', $orgId);
             $writer = App::config('resources.multiplelog.audit');
             $writer['file']['writerParams']['stream'] = APPLICATION_PATH . "/../data/logs/{$key}.log";
             $log->addWriter($writer['file']);
         }
     } catch (Exception $exc) {
         $this->_forceLogout($req, "Unexpected fatal error: " . $exc->getMessage(), 500);
     }
 }
コード例 #20
0
 /**
  * User dependencies injection
  */
 public static function initUserAccount()
 {
     $ident = \Zend_Auth::getInstance()->getIdentity();
     // Transaction injection
     \App::get("trackingtoken");
     ProtoAbstractMapper::$accountingTransactionPrefix = 'Testing-';
     // User injection
     ProtoAbstractMapper::$accountingUserId = $ident['id'];
     ProtoAbstractMapper::$language = 'en';
     $user = \App::getUserLogged(null, true);
     $allowed = Zend_Controller_Action_HelperBroker::getStaticHelper('allowed');
     $allowed->setUser($user);
     AbstractMapper::$organizationId = $user->organizationId;
     // Org injection
     if (!empty($ident['orgId'])) {
         $org = OrgService::getInstance()->load($ident['orgId']);
         if (!$org) {
             $org = OrgModelFactory::factory(array('id' => $ident['orgId'], 'type' => OrganizationMapper::getTypeByOrgId($ident['orgId'])));
         }
         \App::getOrgUserLogged($org);
         AbstractMapper::$organizationId = $ident['orgId'];
     }
     WatcherMapper::getInstance()->destroySingleton();
 }
コード例 #21
0
 /**
  * Lists all prebills matching a criteria
  */
 public function indexAction()
 {
     // Check if the user is allowed to perform this action
     $dumbPreBill = new Application\Model\PreBillModel();
     $this->_helper->allowed('list', $dumbPreBill);
     $filters = $this->_getFilterParams();
     if (isset($filters['customerID'])) {
         $filters['customerId'] = $filters['customerID'];
         unset($filters['customerID']);
     }
     if (isset($filters['billingAccountID'])) {
         $orgUserLogged = App::getOrgUserLogged();
         if ($orgUserLogged instanceof \Application\Model\Organization\OrgCustomerModel) {
             $filters['customerId'] = $orgUserLogged->id;
         } else {
             if (!isset($filters['customerId'])) {
                 throw new InvalidArgumentException('Needed parameter was not found: customerID');
             }
         }
         $filters['billingAccountId'] = $filters['billingAccountID'];
         unset($filters['billingAccountID']);
     }
     if (isset($filters['startDate'])) {
         if (isset($filters['endDate']) && strtotime($filters['endDate']) < strtotime($filters['startDate'])) {
             throw new InvalidArgumentException("Invalid parameter value: The start date can't be after the end date");
         }
         $filters['creationPeriod'] = date('Y-m-d', strtotime($filters['startDate'])) . '<>';
         unset($filters['startDate']);
     }
     if (isset($filters['endDate'])) {
         if (!isset($filters['creationPeriod']) || !$filters['creationPeriod']) {
             $filters['creationPeriod'] = '<>';
         }
         $filters['creationPeriod'] .= date('Y-m-d', strtotime($filters['endDate']));
         unset($filters['endDate']);
     }
     $this->_checkFilterParams($filters, PreBillFilterFields::getWhiteList());
     try {
         $filterList = $this->_prebillSrv->buildFilterList($filters, true);
     } catch (\Application\Exceptions\ValidateException $e) {
         // HACK to override creationPeriod filter errors!
         $dataMap = array('startDate' => 'creationPeriod.min', 'endDate' => 'creationPeriod.max', 'billingAccountID' => 'billingAccountId', 'customerID' => 'customerId');
         $e = $this->_mapException($e, $dataMap, true);
         $messages = $e->getValidationErrors();
         $messageKeys = array_keys($messages);
         throw new Application\Exceptions\ValidateException("Invalid parameter value: '" . array_shift($messageKeys) . "'. " . array_shift($messages), array('validationErrors' => $messages, 'code' => $e->getCode()));
     }
     $this->_helper->filterNotAllowedFilters('filter_by', $filterList);
     $params = $this->_getPaginatorParams();
     $prebillList = $this->_prebillSrv->listAll($filterList, $params);
     $items = $prebillList->getItems();
     $this->view->prebill = array();
     $orgUserLogged = App::getOrgUserLogged();
     if ($orgUserLogged instanceof \Application\Model\Organization\OrgCustomerModel) {
         $items = array_slice($items, ($params['page'] - 1) * $params['count'], $params['count']);
     }
     foreach ($items as $item) {
         try {
             set_time_limit(30);
             $prebill = $this->_prebillSrv->load($item->getId());
             $this->_helper->allowed('read', $prebill);
             $this->view->prebill[] = $this->_mapToSdp($prebill->exportData());
         } catch (Exception $e) {
             \App::log()->warn($e);
         }
     }
     //         $this->view->prebill = $prebillList->getItems();
 }
コード例 #22
0
 /**
  * Deletes the given user
  */
 public function deleteAction()
 {
     throw new NotImplementedException('Prebill delete not implemented');
     // Try to load the chosen user
     $id = $this->getRequest()->getParam('id');
     $preBill = $this->_preBillSrv->load($id, \App::getOrgUserLogged());
     if (empty($preBill)) {
         throw new NotFoundException('PreBill ' . $id . ' not found', 404);
     }
     // Check permissions
     $this->_helper->allowed('delete', $preBill);
     // Remove the user
     try {
         $this->_preBillSrv->delete($id);
     } catch (Exception $e) {
         throw new InvalidArgumentException($e->getMessage(), null, $e);
     }
     $this->view->data = true;
 }
コード例 #23
0
 /**
  *
  * @param  string                      $id
  * @return \Application\Model\SimModel | null
  */
 public static function find($id)
 {
     $sim = SimMapper::getInstance()->findOneById($id, \App::getOrgUserLogged()->getId());
     return $sim;
 }
コード例 #24
0
 public function imsiAction()
 {
     if (!$this->getRequest()->isPost()) {
         throw new AppEx\ForbiddenException("Files action must be a post request.");
     }
     $this->_commercialGroupService = CommercialGroupService::getInstance();
     $data = $this->_helper->requestData(true);
     $imsiList = array();
     if (isset($data['IMSI'])) {
         foreach ($data['IMSI'] as $id) {
             try {
                 if (empty($id)) {
                     $imsiList[] = $this->_getNotSuccessCase($id, SteeringListService::RESULT_MISSING_PARAMETER_CODE, 'IMSI');
                     continue;
                 }
                 if (!is_numeric($id)) {
                     $imsiList[] = $this->_getNotSuccessCase($id, SteeringListService::RESULT_REQUEST_VALUES_INCORRECT_CODE, 'IMSI');
                     continue;
                 }
                 $sim = $this->_simService->load($id, \App::getOrgUserLogged(), 'imsi');
                 if (is_null($sim)) {
                     $imsiList[] = $this->_getNotSuccessCase($id, SteeringListService::RESULT_IMSI_NOT_FOUND_CODE, 'IMSI');
                     continue;
                 }
                 $simOrgId = $sim->getServiceProviderCommercialId();
                 $backupOrgId = Application\Model\Mapper\ProtoAbstractMapper::$organizationId;
                 $comGroupid = $sim->getCommercialGroupId();
                 Application\Model\Mapper\ProtoAbstractMapper::$organizationId = $simOrgId;
                 $comm = $this->_commercialGroupService->load($comGroupid);
                 Application\Model\Mapper\ProtoAbstractMapper::$organizationId = $backupOrgId;
                 $spId = $comm->getServicePackId();
                 if ($spId) {
                     $st = $this->_service->loadByServicePack($spId);
                     if ($st) {
                         $imsi = array('IMSI' => $id, 'RESULT' => SteeringListService::RESULT_SUCCESS_CODE, 'DESCRIPTION' => SteeringListService::RESULT_SUCCESS_DESC);
                         if (isset($st->resId)) {
                             $imsi['RSP_ID'] = $st->resId;
                         }
                         if (isset($st->steeringType)) {
                             $imsi['STEERING_TYPE'] = $this->_getSteeringType($st->steeringType);
                         }
                         $logistics = $sim->getLogistics();
                         if (isset($logistics)) {
                             $imsi['CARD_TYPE'] = $logistics;
                         }
                         $imsi['MSISDN'] = isset($sim->msisdn) ? $sim->msisdn : 'UNKNOWN';
                         $imsiList[] = $imsi;
                         continue;
                     } else {
                         $imsiList[] = $this->_getNotSuccessCase($id, SteeringListService::RESULT_REQUEST_VALUES_INCORRECT_CODE, 'IMSI');
                         continue;
                     }
                 } else {
                     $imsiList[] = $this->_getNotSuccessCase($id, SteeringListService::RESULT_INTERNAL_ERROR_CODE, 'IMSI');
                     continue;
                 }
             } catch (Exception $ex) {
                 $imsiList[] = $this->_getNotSuccessCase($id, SteeringListService::RESULT_INTERNAL_ERROR_CODE, 'IMSI');
                 continue;
             }
         }
     }
     $this->view->IMSI_RES = $imsiList;
 }
コード例 #25
0
 protected function __construct()
 {
     parent::__construct();
     $this->_defaultFilter = array("userId" => \App::getUserLogged()->id, "context" => \App::getOrgUserLogged()->id);
 }
コード例 #26
0
 /**
  * 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 instanceof RestrictionModel || $this->_acceptArrayAsModel && is_array($data))) {
         $this->_messages = array();
         $this->_messages[self::NOT_RESTRICTIONS] = $this->_messageTemplatesUser[self::NOT_RESTRICTIONS];
         return false;
     }
     if (!parent::isValid($data, $context, $removeNotPresentFields)) {
         return false;
     }
     if (!$data instanceof RestrictionModel) {
         $data = new RestrictionModel($data);
     }
     $contracts = ContractService::getInstance()->getContractsByServiceType('csrm')->getItems();
     if (!empty($contracts)) {
         $validator = new \Zend_Validate_NotEmpty();
     } else {
         $validator = new \App_Validate_Empty();
     }
     if (!$validator->isValid($data->steering)) {
         $this->_messages['steering'] = $validator->getMessages();
         return false;
     }
     // If Voice HOME = SMS HOME, roaming is linked
     if ($data->getVoice() && $data->getVoice()->getMo() && $data->getSms() && $data->getSms()->getMo() && $data->getVoice()->getMo()->getHome() === $data->getSms()->getMo()->getHome() && $data->getVoice()->getMo()->getRoaming() !== $data->getSms()->getMo()->getRoaming()) {
         $this->_messages = array();
         $this->_messages[self::NOT_SYNC_VOICE_SMS_ROAMING] = $this->_messageTemplatesUser[self::NOT_SYNC_VOICE_SMS_ROAMING];
         return false;
     }
     //      https://jira.tid.es/browse/GLOBALPORTAL-115352
     //         if ($data->getSms() && $data->getSms()->getMo() &&
     //             // If HOME is disabled and Roaming Enabled
     //             (($data->getSms()->getMo()->getHome() &&  !$data->getSms()->getMo()->getRoaming()) ||
     //                 // If HOME is enabled and Roaming !== International
     //                 (isset($data->getSms()->getMo()->roaming) &&
     //                     $data->getSms()->getMo()->getRoaming() !== $data->getSms()->getMo()->getInternational()))) {
     //             $this->_messages = array();
     //             $this->_messages[self::NOT_ROAMING_INTERNATIONAL_SAME_VALUE] =
     //                 $this->_messageTemplatesUser[self::NOT_ROAMING_INTERNATIONAL_SAME_VALUE];
     //             return false;
     //         }
     // Validate leading/commercial OB
     $org = \App::getOrgUserLogged();
     $orgProvider = OrgService::getInstance()->getParentByType($org->id, OrgServiceProviderModel::ORG_TYPE);
     if ($orgProvider && \Application\Service\OrgService::getInstance()->isCommercial($orgProvider)) {
         $validator = new RestrictionsCommercialValidate();
         if (!$validator->isValid($data, $context, $removeNotPresentFields)) {
             $this->_messages = $validator->getMessages();
             return false;
         }
     }
     return true;
 }
コード例 #27
0
 protected function _mapToModel(array $data, $usePreset = true)
 {
     $data = parent::_mapToModel($data, $usePreset);
     if (isset($data['billingCycleStart']) && !is_array($data['billingCycleStart'])) {
         $regex = '/^\\-\\-\\-(?P<dayOfMonth>\\d{2,2})(?P<timezone>.*)$/';
         if (preg_match($regex, $data['billingCycleStart'], $matches)) {
             $tz = App_Util_Date::getTimezoneValue($matches['timezone']);
             $matches['dayOfMonth'] = intval($matches['dayOfMonth']);
             $enumService = Application\Service\EnumeratedService::getInstance();
             $timezones = $enumService->getEnum(Application\Service\EnumeratedService::TIME_ZONE_ENUM_NAME);
             foreach ($timezones as $exmpl) {
                 if ($exmpl['offset'] == $matches['timezone']) {
                     $tz = $exmpl['id'];
                     break;
                 }
             }
             $matches['timezone'] = $tz;
             $data['billingCycleStart'] = $matches;
         } else {
             $data['billingCycleStart'] = array();
         }
     }
     if (isset($data['defaultBillingAccount']['contact'])) {
         $data['defaultBillingAccount']['contactIsPrimaryContact'] = false;
     }
     if (isset($data['defaultBillingAccount']['address'])) {
         $data['defaultBillingAccount']['addressIsCompanyAddress'] = false;
     }
     if (isset($data['shippingAddress'])) {
         $data['shippingAddressIsCompanyAddress'] = false;
     }
     if (isset($data['billingContact'])) {
         $data['billingContactIsPrimaryContact'] = false;
     }
     if (isset($data['billingContactAddress'])) {
         $data['billingContactAddressIsCompanyAddress'] = false;
     }
     if (isset($data['primaryContactAddress'])) {
         $data['primaryContactAddressIsCompanyAddress'] = false;
     }
     if ($usePreset && !isset($data['parentId'])) {
         $data['parentId'] = \App::getOrgUserLogged()->getId();
     }
     return $data;
 }
コード例 #28
0
 /**
  * Retrieve location information from a SIM
  */
 public function locationAction()
 {
     $sim = $this->_getSim();
     $this->_helper->filterNotAllowedFields('read_field', $sim);
     $filterList = $this->_simSrv->buildFilterList(array('icc' => $sim->getIcc()));
     $listResult = $this->_simSrv->listAll($filterList, array('count' => 1), null, \App::getOrgUserLogged());
     $items = $listResult->getItems();
     if (!empty($items)) {
         $item = array_shift($items);
         $sim->importData($item->exportData());
     }
     $this->view->locationDetailData = array();
     if ($sim->getLocationManual() && ($loc = $this->_mapLocationToSdp($sim->getLocationManual()->exportData()))) {
         $this->view->locationDetailData['manualLocation'] = $loc;
     }
     if ($sim->getLocationAuto() && ($loc = $this->_mapLocationToSdp($sim->getLocationAuto()->exportData()))) {
         $this->view->locationDetailData['automaticLocation'] = $loc;
     }
 }
コード例 #29
0
 /**
  * Get an specific user by its Id
  */
 public function getAction()
 {
     if (!$this->_hasParam('id')) {
         throw new InvalidArgumentException("Null Identifier recived");
     }
     $spId = $this->_getParam('id');
     $sp = $this->_spSrv->load($spId);
     if (empty($sp)) {
         throw new NotFoundException("ServicePack {$spId} not found", 404);
     }
     //        $this->_helper->allowed('read', $sp);
     $this->_spSrv->loadSubModels($sp);
     $modified = false;
     $tpModified = false;
     $lcModified = false;
     if (!empty($sp->tariffPlanServices)) {
         $tariffPlan = $sp->tariffPlanServices;
         // Check if there's any modified tariff
         $entries = array('defaultTermVoice', 'origVoice', 'defaultData', 'data', 'defaultOrigVoice', 'defaultSms', 'termVoice');
         $fields = array('q1Modified', 't2SModified', 't2QModified', 't4QModified', 't6QModified');
         foreach ($entries as $entry) {
             foreach ($fields as $field) {
                 if (!empty($tariffPlan->{$entry}->{$field})) {
                     $modified = true;
                     $tpModified = true;
                     break 2;
                 }
             }
         }
         if (isset($tariffPlan->zonePlan)) {
             $zoneGroups = $tariffPlan->zonePlan->zoneGroups;
             if (!empty($zoneGroups)) {
                 foreach ($zoneGroups as $zoneGroup) {
                     if (!empty($zoneGroup->zonesModified)) {
                         $modified = true;
                         $tpModified = true;
                         break;
                     }
                 }
             }
         }
     }
     if (!empty($sp->tariffPlanLifeCycle)) {
         $tariffPlan = $sp->tariffPlanLifeCycle;
         if (!empty($tariffPlan->status)) {
             foreach ($tariffPlan->status as $status) {
                 if (!empty($status->costModified)) {
                     $modified = true;
                     $lcModified = true;
                     break;
                 }
             }
         }
         if (!$lcModified && !empty($tariffPlan->transitions)) {
             foreach ($tariffPlan->transitions as $transition) {
                 if (!empty($transition->costModified)) {
                     $modified = true;
                     $lcModified = true;
                     break;
                 }
             }
         }
     }
     $this->view->data = $sp->exportData();
     try {
         $this->_helper->allowed('view_discounts', $sp);
         $discounts = $this->_spSrv->getDiscounts($sp);
     } catch (Exception $e) {
         $org = \App::getOrgUserLogged();
         try {
             $acl = \App::get('acl');
             if ($acl->existsPrivilege(\App::getUserLogged(), $org, 'read_field_discounts')) {
                 $this->_helper->allowed('read_field_discounts', $org);
             } else {
                 $this->_helper->allowed('read_field_default', $org);
             }
             $discounts = array();
             if ($org->getType() === \Application\Model\Organization\OrgCustomerModel::ORG_TYPE && $org->getServicepacksDiscounts() && $org->getServicepacksDiscounts()->customerServicepack) {
                 // Search current service pack
                 $spDisc = $org->getServicepacksDiscounts()->customerServicepack;
                 foreach ($spDisc as $disc) {
                     if ($disc->servicepackId == $sp->id) {
                         // See \Application\Model\ServicePack\Discount
                         $discounts[] = array('customerId' => $org->getId(), 'customerName' => $org->getName(), 'voice' => $disc->getVoiceDiscount(), 'sms' => $disc->getSmsDiscount(), 'data' => $disc->getDataDiscount());
                     }
                 }
             }
         } catch (Exception $e) {
             // Do nothing
         }
     }
     if (!empty($discounts)) {
         $this->view->data['discounts'] = $discounts;
     }
     try {
         $this->_helper->allowed('view_voucher_only_discounts', $sp);
         $voucherOnlyDiscounts = $this->_spSrv->getVoucherOnlyDiscounts($sp);
     } catch (Exception $e) {
         $org = \App::getOrgUserLogged();
         try {
             $acl = \App::get('acl');
             if ($acl->existsPrivilege(\App::getUserLogged(), $org, 'read_field_voucher_only_discounts')) {
                 $this->_helper->allowed('read_field_voucher_only_discounts', $org);
             } else {
                 $this->_helper->allowed('read_field_default', $org);
             }
             $voucherOnlyDiscounts = array();
             if ($org->getType() === \Application\Model\Organization\OrgCustomerModel::ORG_TYPE && $org->getServicepacksDiscounts() && $org->getServicepacksDiscounts()->customerServicepack) {
                 // Search current service pack
                 $spVoucherDisc = $org->getServicepacksDiscounts()->customerServicepack;
                 foreach ($spVoucherDisc as $disc) {
                     if ($disc->servicepackId == $sp->id) {
                         // See \Application\Model\ServicePack\Discount
                         $voucherOnlyDiscounts[] = array('customerId' => $org->getId(), 'customerName' => $org->getName(), 'voice' => $disc->getVoucherOnlyVoiceDiscount(), 'sms' => $disc->getVoucherOnlySmsDiscount(), 'data' => $disc->getVoucherOnlyDataDiscount());
                     }
                 }
             }
         } catch (Exception $e) {
             // Do nothing
         }
     }
     if (!empty($voucherOnlyDiscounts)) {
         $this->view->data['voucherOnlyDiscounts'] = $voucherOnlyDiscounts;
     }
     $this->view->data['tariffPlanServices']['modified'] = $tpModified;
     $this->view->data['tariffPlanLifeCycle']['modified'] = $lcModified;
     $this->view->modified = $modified;
 }
コード例 #30
0
 /**
  * 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 instanceof TemplateModel) {
         $this->_messages = array();
         $this->_messages[self::NOT_TEMPLATE] = $this->_messageTemplatesUser[self::NOT_TEMPLATE];
         return false;
     }
     if (!parent::isValid($data, $context, $removeNotPresentFields)) {
         return false;
     }
     if ($data instanceof TemplateModel) {
         $data = $data->exportData();
     }
     $type = $data['type'];
     $options = array('isTemplateValidation' => true);
     switch ($type) {
         case 'tariffPlanLifeCycle':
             $data = new Model\TariffPlanLifeCycleModel($data);
             $validator = new TariffPlanLifeCycleValidate($options);
             break;
         case 'tariffPlanService':
             $data = new Model\TariffPlanServicesModel($data);
             $validator = new TariffPlanServicesValidate($options);
             break;
         case 'lifeCycle':
             $data = new Model\LifeCycleModel($data);
             $validator = new LifeCycleValidate($options);
             break;
         case 'restrictions':
             $data = new Model\RestrictionModel($data);
             $validator = new RestrictionsValidate($options);
             break;
         case 'supplementaryServices':
             $data = new Model\SupplServicesModel($data);
             $validator = new SupplServicesValidate($options);
             break;
         case 'zonePlan':
             $data = new Model\ZonePlanModel($data);
             $validator = new ZonePlanValidate($options);
             break;
     }
     if (!$validator->isValid($data)) {
         $this->_messages = $validator->getMessages();
         return false;
     }
     //check if name exist
     $templateService = \Application\Service\TemplateService::getInstance();
     $filterList = array('name' => $data->getName(), 'type' => $type);
     $filterList = $templateService->buildFilterList($filterList, \App::getOrgUserLogged());
     $items = $templateService->listAll(array('filterList' => $filterList))->getItems();
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($item->getId() === $data->getId()) {
                 return true;
             }
         }
         $this->_messages[] = 'Template name already exist';
         return false;
     }
     return true;
 }