public function setUp() { $this->_watcherService = WatcherService::getInstance(); $this->_txId = uniqid('test-', true); $user = \App::getUserLogged(); $this->_watcher = new WatcherModel(); $this->_watcher->scope = 'user'; $this->_watcher->scopeId = $user->id; $this->_watcher->owner = $user->id; $this->_watcher->namespace = 'connectivity'; $this->_watcher->entityType = 'transaction'; $this->_watcher->entityIds = array($this->_txId); $this->_watcher->transport = 'popbox'; $this->_watcher->priority = WatcherModel::PRIORITY_LOW; $this->_watcher->status = WatcherModel::STATUS_ACTIVE; $this->_watcher->expire = strtotime(\App::config('watchers.expire', "+1 day")); $this->_watcher->remove = strtotime(\App::config('watchers.autoremove', "+6 months")); $this->_watcher->tags = array('context_' . $user->getOrganizationId()); $this->_watcher->maxEvents = 1; $this->_watcher->maxEventStackSize = 1; $this->_watcher->params = new StructConfigModel(); $this->_watcher->hiddenParams = new StructConfigModel(); $this->_event = new EventModel(); $this->_event->namespace = 'connectivity'; $this->_event->entityType = 'transaction'; $this->_event->entityId = $this->_txId; $this->_event->created = time(); $this->_event->modified = time(); $this->_event->pushEventData = true; }
public function setUp() { $this->_asyncService = AsyncService::getInstance(); $this->_transactionIds = array('eeruqw2131saw222sawdd1', 'shduah892189hwhsaskjdh', 'shdshausd21271hudias12'); $this->_data = array('data' => '{tested}'); $this->_user = array('user' => \App::getUserLogged()->getId(), 'organization' => \App::getUserLogged()->getOrganizationId(), 'authType' => \App_Controller_Plugin_Auth::AUTH_TYPE_AUTH_TOKEN); }
protected function _checkValue($value, $comparedValue) { switch ($comparedValue) { case self::IS_NULL: $comparedValue = NULL; break; case self::USER_ID: $comparedValue = \App::getUserLogged()->id; break; case self::USER_ORG_ID: $comparedValue = \App::getUserLogged()->organizationId; break; } switch ($this->getOperator()) { case self::EQUAL: $result = $value == $comparedValue; break; case self::STRICT_EQUAL: $result = $value === $comparedValue; break; case self::GREATER_THAN: $result = $value > $comparedValue; break; case self::LESS_THAN: $result = $value < $comparedValue; break; case self::CONTAINS: if (is_array($value)) { $result = in_array($comparedValue, $value); } else { if (is_string($value) && is_string($comparedValue)) { $result = !(strpos($value, $comparedValue) === false); } else { throw new App_ListFilter_Rule_Condition_Exception('Values are no possible to compare with CONTAINS operator.'); } } break; case self::IN: if (is_array($comparedValue)) { $result = in_array($value, $comparedValue); } else { if (is_string($value) && is_string($comparedValue)) { $result = !(strpos($comparedValue, $value) === false); } else { throw new App_ListFilter_Rule_Condition_Exception('Values are no possible to compare with IN operator.'); } } break; } /* * Logic table * | Inv | res | * | 1 | 1 | 0 * | 1 | 0 | 1 * | 0 | 1 | 1 * | 0 | 0 | 0 */ return $this->getInverted() != $result; }
/** * Validate element value * * @param array $data * @param mixed $context * @return boolean */ public function isValid($value, $context = array()) { $currentUser = \App::getUserLogged(); if (isset($context['id']) && $currentUser->getId() === $context['id'] && $currentUser->monetaryDataAccess !== $value) { $this->_messages = array(self::NOT_ALLOWED_CHANGE_MONETARY_ACCESS_ITSELF => $this->_templateMessages[self::NOT_ALLOWED_CHANGE_MONETARY_ACCESS_ITSELF]); return false; } return true; }
/** * Lists all permissions */ public function indexAction() { if (($namespace = $this->_getParam('namespace')) || ($namespace = $this->getRequest()->getHeader('Realm'))) { } if (!($roleId = $this->_getParam('roleId'))) { $roleId = \App::getUserLogged()->getRoleId(); } $this->view->permissions = \Core\Service\PermissionService::getInstance()->load($roleId, $namespace); }
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()); }
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; } }
protected function _preCreate($item) { if (!$item instanceof WatcherModel) { throw new InvalidArgumentException("Watcher model expected"); } if ($item->scope === 'token' && Zend_Auth::getInstance()->hasIdentity()) { $ident = Zend_Auth::getInstance()->getIdentity(); $item->scopeId = $ident['token']; if (!isset($item->remove)) { $item->remove = strtotime('+1 day'); if (!isset($item->expire)) { $item->expire = $item->remove; } } } $item->owner = \App::getUserLogged()->id; }
public function testWhitelist() { //TODO: If execute only this test class, the test pass successfull, //We have to investigate why it doesn't pass when it is executed in group $this->markTestSkipped("Execution in test group doesn't work."); $boot = $this->_helper->getFrontController()->getParam('bootstrap'); $acl = $boot->getResource('acl'); $acl->allow(\App::getUserLogged()->getRoleId(), $this->_sim->getResourceId(), 'test2_field_default', new App_Acl_Assert_NotAllowed()); $acl->allow(\App::getUserLogged()->getRoleId(), $this->_sim->getResourceId(), 'test2_field_icc'); $acl->allow(\App::getUserLogged()->getRoleId(), $this->_sim->getResourceId(), 'test2_field_locationManual'); $acl->allow(\App::getUserLogged()->getRoleId(), $this->_sim->getResourceId(), 'test2_field_locationManual:longitude'); $this->_helper->direct('test2_field', $this->_sim); $this->assertNotNull($this->_sim->locationManual, "locationManual not null"); $this->assertNotNull($this->_sim->icc, "Icc not null"); $this->assertNotNull($this->_sim->locationManual->longitude, "Latitude not null"); $this->assertNull($this->_sim->id, "Id is null"); $this->assertNull($this->_sim->locationManual->latitude, "locationManual.longitude is null"); }
public function setupHttpClient(Zend_Http_Client $httpClient) { $httpClient->setHeaders('M2M-ApiKey', $this->getApiKey()); if ($this->_useSession) { $user = \App::getUserLogged(); if (in_array($user->authType, array(App_Controller_Plugin_Auth::AUTH_TYPE_AUTH_TOKEN, App_Controller_Plugin_Auth::AUTH_TYPE_REGULAR))) { \App::log()->debug("M2M-Session: " . $user->authToken); \App::log()->debug("M2M-Organization: " . $user->organizationId); $httpClient->setHeaders('M2M-Session', $user->authToken); $httpClient->setHeaders('M2M-Organization', $user->organizationId); } elseif ($user->authType == App_Controller_Plugin_Auth::AUTH_TYPE_EXTERNAL) { \App::log()->debug("M2M-UGW-Certificate: " . $user->id); \App::log()->debug("M2M-Organization: " . $user->organizationId); $httpClient->setHeaders('M2M-UGW-Certificate', $user->id); $httpClient->setHeaders('M2M-Organization', $user->organizationId); } } }
/** * 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 UserModel) { $this->_messages = array(); $this->_messages[self::NOT_USER] = $this->_messageTemplatesUser[self::NOT_USER]; return false; } if (!parent::isValid($data, $context, $removeNotPresentFields)) { return false; } //Check if a user organization status is actived /** * @var $data \Application\Model\UserModel */ $org = $data->getOrganization(); if (!is_null($org) && $org->getStatus() === \Application\Model\OrgModelAbstract::ORG_STATUS_DEACTIVATED) { $this->_messages[] = "Organization disabled"; return false; } if (null !== $data->getId()) { /** * @var $user \Application\Model\UserModel */ $user = UserMapper::getInstance()->findOneById($data->getId()); // Validate if user try to change non-editable values. $fields = array('userName', 'organizationId'); if ($data->getId() === \App::getUserLogged()->getId()) { $fields[] = 'role'; } $fixedFieldsValidator = new \App_Validate_NotEditableFields($fields); if (!$fixedFieldsValidator->isValid($data->exportData(), $user->exportData())) { $this->_messages = $fixedFieldsValidator->getMessages(); return false; } } return true; }
public function meAction() { $this->view->user = \App::getUserLogged(); $this->_helper->filterNotAllowedFields('read_field', $this->view->user); if ($this->getRequest()->getParam('organization', false)) { $this->view->organization = $this->view->user->getOrganization(); $this->_helper->filterNotAllowedFields('read_field', $this->view->organization); $orgService = OrgService::getInstance(); $orgService->getOrgConfig($this->view->organization); $sp = $orgService->getParentByType($this->view->organization, OrgServiceProviderModel::ORG_TYPE); if ($sp && isset($sp->isEnabler)) { $this->view->organization->alwaysOnRoaming = !$sp->isEnabler; } if ($this->view->organization instanceof OrgCustomerModel && isset($this->view->organization->supplementaryServicesId)) { try { $supplService = SupplServicesService::getInstance()->load($this->view->organization->supplementaryServicesId); if ($supplService) { try { $this->_helper->allowed('read', $supplService); $this->_helper->filterNotAllowedFields('read_field', $supplService); $this->view->supplService = $supplService; } catch (PermissionException $e) { } } } catch (\Exception $e) { \App::log()->warn($e); } } } if (($namespace = $this->_getParam('permissions')) || ($namespace = $this->getRequest()->getHeader('Realm'))) { if ($namespace == 1) { $namespace = null; } $this->view->permissions = \Core\Service\PermissionService::getInstance()->load(\App::getUserLogged()->getRoleId(), $namespace); } }
/** * 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(); }
public function direct(SimModel $sim) { $allowed = Zend_Controller_Action_HelperBroker::getStaticHelper("allowed"); $allowed->direct('read', $sim); /* * TODO Needs refactor. It should be done by filterNotAllowedFields */ $user = \App::getUserLogged(); if (!$user->monetaryDataAccess) { $sim->setExpenseMonthly(null); $sim->setExpenseDetail(null); } /* * TODO Needs refactor. It should be done by filterNotAllowedFields */ try { $allowed->direct('read_time_and_consumption', $sim); } catch (\Application\Exceptions\ForbiddenException $e) { $sim->setTimeAndConsumption(null); } $filter = Zend_Controller_Action_HelperBroker::getStaticHelper("filterNotAllowedFields"); $filter->direct("read_field", $sim); return $this; }
/** * Create a new user */ public function postAction() { // Avoid setting custom id $data = $this->_helper->requestData(true); $data = $this->_helper->filter($data)->blacklist(array('id')); if (empty($data['customerId'])) { $data['customerId'] = \App::getUserLogged()->getOrganizationId(); } $commercialGroup = new CommercialGroupModel($data); // Check if it's allowed $this->_helper->allowed('create', $commercialGroup); // Create the organization via its service $this->_cgSrv->create($commercialGroup); // Response with the organization id $this->view->data = $commercialGroup->getId(); }
protected function _constructWatcherToTransaction() { $user = \App::getUserLogged(); $watcher = new WatcherModel(); if ($user->isRegularAuthUser()) { $watcher->scope = 'user'; $watcher->scopeId = $user->id; $watcher->owner = $user->id; } else { $watcher->scope = 'apiId'; $watcher->scopeId = $user->apiId; $watcher->owner = $user->apiId; } $watcher->namespace = 'connectivity'; $watcher->entityType = 'transaction'; $watcher->entityIds = array(); $watcher->transport = 'popbox'; $watcher->priority = WatcherModel::PRIORITY_LOW; $watcher->status = WatcherModel::STATUS_ACTIVE; $watcher->expire = strtotime(\App::config('watchers.expire', "+1 day")); $watcher->remove = strtotime(\App::config('watchers.autoremove', "+6 months")); $watcher->tags = array('context_' . \App::getUserLogged()->getOrganizationId()); $watcher->maxEvents = 1; $watcher->maxEventStackSize = 1; $watcher->params = new StructConfigModel(); $watcher->hiddenParams = new StructConfigModel(); if ($request = \Zend_Controller_Front::getInstance()->getRequest()) { $watcher->params->method = $request->getMethod(); if ($request->getQuery()) { $watcher->params->query = $request->getQuery(); } $watcher->params->url = $request->getRequestUri(); } return $watcher; }
/** * Check asserts WITHOUT resource or privilege dependency */ public function assertAction() { // Check request params if (!$this->_hasParam('name')) { throw new InvalidArgumentException('Param name is required'); } $class = '\\App_Acl_Assert_' . $this->_getParam('name'); if (!class_exists($class)) { throw new NotFoundException('Assert not found'); } try { // Get ACL object $boot = $this->getFrontController()->getParam('bootstrap'); $acl = $boot->getResource('acl'); // Execute assert $obj = new $class(); $this->view->data = $obj->assert($acl, \App::getUserLogged()); } catch (Exception $e) { \App::log()->err("[ASSERT] " . $e->getMessage()); $this->view->data = false; } }
public function update(ModelAbstract $model) { $model->userId = \App::getUserLogged()->id; return parent::update($model); }
protected function _getPrivilegeByPrefix($privilege, $resource) { $boot = $this->getFrontController()->getParam('bootstrap'); $acl = $boot->getResource('acl'); return $acl->getPrivilegesByPrefix(App::getUserLogged(), $resource, $privilege); }
public function getDefaultTags() { $tags = parent::getDefaultTags(); $tags[] = \App::getUserLogged()->id; return $tags; }
public function deleteAction() { $itemId = $this->getRequest()->getParam('id'); if ($itemId !== 'all') { return parent::deleteAction(); } $dumpItem = new $this->_modelClass(); $this->_helper->allowed('list', $dumpItem); $filterList = $this->_service->buildFilterList(array('tags' => 'context_' . \App::getUserLogged()->organizationId)); $this->_service->deleteAll($filterList); $this->view->data = true; }
public function findAll(array $data = array()) { if (!isset($data['filterList']) || !$data['filterList'] instanceof \App_ListFilter || !$data['filterList']->isValid()) { throw new InvalidArgumentException("Filter is not valid."); } $itemData = $this->_findAllEricsson($data); $items = array(); if (!empty($itemData['items'])) { foreach ($itemData['items'] as $data) { $report = new ReportModel($data); if ($report->type === ReportModel::CHARGES_DETAIL && isset($report->hasMoneyInfo) && ($report->hasMoneyInfo && !\App::getUserLogged()->monetaryDataAccess || !$report->hasMoneyInfo && \App::getUserLogged()->monetaryDataAccess)) { continue; } $items[] = new ReportModel($data); } } else { \App::log()->info("Report without items (Ericsson empty list)"); } $result = new ListResultModel(); $result->setItems($items); if (isset($itemData['count'])) { $result->setCount(count($items)); } return $result; }
/** * Create a new user */ public function postAction() { $data = $this->_helper->requestData(true); // Avoid setting custom id $data = $this->_helper->filter($data)->blacklist(array('id')); if (empty($data['customerId'])) { $data['customerId'] = \App::getUserLogged()->getOrganizationId(); } $commercialGroup = new CommercialGroupModel($data); // Check if it's allowed $this->_helper->allowed('create', $commercialGroup); $data = $this->_mapToModel($data); // Check mandatory fields // $this->_preValidate($data, new CommercialGroupValidate()); $commercialGroup = new CommercialGroupModel($data); // Create the organization via its service try { $this->_cgSrv->create($commercialGroup); } catch (ValidateException $ex) { throw $this->_mapException($ex); } $url = $this->getFrontController()->getRouter()->assemble(array('controller' => $this->getRequest()->getControllerName(), 'action' => $this->getRequest()->getActionName(), 'id' => $commercialGroup->getId())); $this->getResponse()->setHeader('Location', $url); $this->getResponse()->setHttpResponseCode(201); }
/** * 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; }
public function setUser($user = null) { // Dependency with application at lib? :O $this->_user = $user === null ? \App::getUserLogged() : $user; }