Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getRawValue(ResultRecordInterface $record)
 {
     $label = null;
     try {
         $label = $record->getValue($this->getOr(self::DATA_NAME_KEY, $this->get(self::NAME_KEY)));
     } catch (\LogicException $e) {
     }
     return $this->twig->loadTemplate(self::TEMPLATE)->render(['url' => parent::getRawValue($record), 'label' => $label]);
 }
 function it_prepares_an_author_value_with_context($userManager, ResultRecordInterface $record, User $user)
 {
     $record->getValue('author')->willReturn('julia');
     $record->getValue('context')->willReturn('my context');
     $userManager->findUserByUsername(Argument::any())->shouldBeCalled()->willReturn($user);
     $user->getFirstName()->willReturn('Julia');
     $user->getLastName()->willReturn('Doe');
     $user->getEmail()->willReturn('*****@*****.**');
     $this->getValue($record)->shouldReturn('Julia Doe - julia@zaro.com (my context)');
 }
 /**
  * @param array $inputData
  * @param array $expectedData
  *
  * @dataProvider getActionsProvider
  */
 public function testGetActions(array $inputData, array $expectedData)
 {
     $this->record->expects($this->any())->method('getValue')->with('id')->willReturn($inputData['record']['id']);
     $this->doctrine->expects($this->any())->method('getManagerForClass')->with($expectedData['class'])->willReturn($this->manager);
     $this->manager->expects($this->any())->method('getReference')->with($expectedData['class'], $expectedData['id'])->willReturn($inputData['object']);
     $this->securityFacade->expects($this->any())->method('isGranted')->willReturnCallback(function ($permission) use($inputData) {
         return $inputData['isGranted'][$permission];
     });
     $this->assertEquals($expectedData['actions'], $this->actionPermissionProvider->getActions($this->record, $inputData['config']));
 }
 /**
  * @param boolean $isRecordEnabled
  * @param array $expected
  * @dataProvider recordConditions
  */
 public function testGetRequestStatusDefinitionPermissions($isRecordEnabled, array $expected)
 {
     $this->record->expects($this->once())->method('getValue')->with('enabled')->willReturn($isRecordEnabled);
     $result = $this->actionPermissionProvider->getUserPermissions($this->record);
     $this->assertCount(count($this->actionsList), $result);
     foreach ($this->actionsList as $action) {
         $this->assertArrayHasKey($action, $result);
     }
     $this->assertEquals($expected, $result);
 }
 /**
  * {@inheritdoc}
  */
 protected function getRawValue(ResultRecordInterface $record)
 {
     try {
         $value = $record->getValue($this->getOr(self::DATA_NAME_KEY, $this->get(self::NAME_KEY)));
     } catch (\LogicException $e) {
         // default value
         $value = null;
     }
     return $value;
 }
 /**
  * @param ResultRecordInterface $record
  *
  * @return array
  */
 public function getAccountUserRolePermission(ResultRecordInterface $record)
 {
     $isGranted = true;
     $delete = true;
     if ($record->getValue('isRolePredefined')) {
         $isGranted = $this->securityFacade->isGranted('orob2b_account_frontend_account_user_role_create');
         $delete = false;
     }
     return ['view' => true, 'update' => $isGranted, 'delete' => $delete];
 }
 /**
  * @param boolean  $isRolePredefined
  * @param boolean  $isGranted
  * @param array    $expected
  *
  * @dataProvider getAccountUserRolePermissionProvider
  */
 public function testGetAccountUserRolePermission($isRolePredefined, $isGranted, array $expected)
 {
     $this->record->expects($this->any())->method('getValue')->with($this->isType('string'))->willReturn($isRolePredefined);
     $this->securityFacade->expects($isRolePredefined ? $this->once() : $this->never())->method('isGranted')->with($this->isType('string'))->willReturn($isGranted);
     $result = $this->actionPermissionProvider->getAccountUserRolePermission($this->record);
     $this->assertCount(count($this->accountUserRoleActionList), $result);
     foreach ($this->accountUserRoleActionList as $action) {
         $this->assertArrayHasKey($action, $result);
     }
     $this->assertEquals($expected, $result);
 }
 /**
  * @param ResultRecordInterface $record
  * @return array
  */
 public function getInvitationPermissions(ResultRecordInterface $record)
 {
     /** @var User $user */
     $user = $this->securityFacade->getLoggedUser();
     $invitationStatus = $record->getValue('invitationStatus');
     $parentId = $record->getValue('parentId');
     $ownerId = $record->getValue('ownerId');
     $childrenCount = $record->getValue('childrenCount');
     $isEditable = !$invitationStatus || $invitationStatus && !$parentId;
     return array('accept' => $this->isAvailableResponseButton($user, $parentId, $ownerId, $childrenCount, $invitationStatus, CalendarEvent::ACCEPTED), 'decline' => $this->isAvailableResponseButton($user, $parentId, $ownerId, $childrenCount, $invitationStatus, CalendarEvent::DECLINED), 'tentatively' => $this->isAvailableResponseButton($user, $parentId, $ownerId, $childrenCount, $invitationStatus, CalendarEvent::TENTATIVELY_ACCEPTED), 'view' => true, 'update' => $isEditable);
 }
 /**
  * {@inheritdoc}
  */
 public function getValue(ResultRecordInterface $record)
 {
     $entity = $record->getValue('entity');
     $entityClass = ClassUtils::getRealClass($entity);
     if ($this->mappingProvider->isClassSupported($entityClass)) {
         return parent::getValue($record);
     } else {
         $this->params[self::TEMPLATE_KEY] = $this->defaultTemplate;
         return $this->getTemplate()->render(['entityType' => $this->entityConfigProvider->getConfig($entityClass)->get('label'), 'entity' => $entity, 'indexer_item' => $record->getValue('indexer_item')]);
     }
 }
 /**
  * Get route parameters from record
  *
  * @param ResultRecordInterface $record
  *
  * @return array
  */
 protected function getParameters(ResultRecordInterface $record)
 {
     $result = [];
     foreach ($this->getOr(self::PARAMS_KEY, []) as $name => $dataKey) {
         if (is_numeric($name)) {
             $name = $dataKey;
         }
         $result[$name] = $record->getValue($dataKey);
     }
     return $result;
 }
Example #11
0
 /**
  * @param ResultRecordInterface $record
  * @param array                 $actions
  *
  * @return array
  */
 public function getMarketingListItemPermissions(ResultRecordInterface $record, array $actions)
 {
     $actions = array_keys($actions);
     $permissions = array();
     foreach ($actions as $action) {
         $permissions[$action] = true;
     }
     $isSubscribed = (bool) $record->getValue('subscribed');
     $permissions['subscribe'] = !$isSubscribed;
     $permissions['unsubscribe'] = $isSubscribed;
     return $permissions;
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 protected function getRawValue(ResultRecordInterface $record)
 {
     try {
         $value = $record->getValue($this->getOr(self::DATA_NAME_KEY) ?: $this->get(self::NAME_KEY));
         if ($this->getOr(self::FRONTEND_TYPE_KEY) === self::TYPE_MULTI_SELECT) {
             $value = explode(',', $value);
         }
     } catch (\LogicException $e) {
         // default value
         $value = null;
     }
     return $value;
 }
 /**
  * @param ResultRecordInterface $record
  * @param array $config
  * @return array
  */
 public function getActions(ResultRecordInterface $record, array $config)
 {
     $actions = [];
     foreach ($config as $action => $options) {
         $isGranted = true;
         if (isset($options['acl_permission']) && isset($options['acl_class'])) {
             $object = $this->findObject($options['acl_class'], $record->getValue('id'));
             $isGranted = $this->securityFacade->isGranted($options['acl_permission'], $object);
         }
         $actions[$action] = $isGranted;
     }
     return $actions;
 }
 /**
  * Test getRequestStatusDefinitionPermissions
  *
  * @dataProvider recordConditions
  * @param boolean $isRecordDeleted
  * @param string $name
  */
 public function testGetRequestStatusDefinitionPermissions($isRecordDeleted, $name)
 {
     $this->record->expects($this->at(0))->method('getValue')->with('deleted')->willReturn($isRecordDeleted);
     $this->record->expects($this->at(1))->method('getValue')->with('name')->willReturn($name);
     $result = $this->actionPermissionProvider->getRequestStatusDefinitionPermissions($this->record);
     $this->assertCount(count($this->actionsList), $result);
     foreach ($this->actionsList as $action) {
         $this->assertArrayHasKey($action, $result);
     }
     $isDefaultStatus = $name == self::CONFIG_DEFAULT_STATUS;
     $this->assertEquals($isRecordDeleted, $result['restore']);
     $this->assertEquals(!$isRecordDeleted && !$isDefaultStatus, $result['delete']);
     $this->assertTrue($result['view']);
 }
 /**
  * {@inheritdoc}
  */
 public function getValue(ResultRecordInterface $record)
 {
     $entity = $record->getValue('entity');
     $entityClass = ClassUtils::getRealClass($entity);
     if (empty($this->entitiesConfig[$entityClass])) {
         throw new InvalidConfigurationException(sprintf('Unknown entity type %s, unable to find search configuration', $entityClass));
     } else {
         $searchTemplate = $this->entitiesConfig[$entityClass]['search_template'];
     }
     if (!$this->params->offsetGetOr('template', false)) {
         $this->params->offsetSet('template', $searchTemplate);
     }
     return $this->getTemplate()->render(array('indexer_item' => $record->getValue('indexer_item'), 'entity' => $record->getValue('entity')));
 }
 /**
  * @param ResultRecordInterface $record
  * @param array $actions
  * @return array
  */
 public function getPermissions(ResultRecordInterface $record, array $actions)
 {
     $actions = array_keys($actions);
     $permissions = [];
     foreach ($actions as $action) {
         $permissions[$action] = true;
     }
     if (array_key_exists('default', $permissions)) {
         $permissions['default'] = !$record->getValue('default');
     }
     if (array_key_exists('delete', $permissions)) {
         $permissions['delete'] = !$record->getValue('default');
     }
     return $permissions;
 }
 /**
  * {@inheritdoc}
  */
 public function getRawValue(ResultRecordInterface $record)
 {
     $context = array_merge($this->getOr(self::CONTEXT_KEY, []), ['record' => $record, 'value' => $record->getValue($this->getOr(self::DATA_NAME_KEY, $this->get(self::NAME_KEY)))]);
     return $this->getTemplate()->render($context);
 }
 /**
  * Disables delete action for system attributes
  *
  * @param ResultRecordInterface $record
  * @return array
  */
 public static function getActionConfiguration(ResultRecordInterface $record)
 {
     $isSystem = $record->getValue('system');
     return ['delete' => empty($isSystem)];
 }
 /**
  * @param ResultRecordInterface $record
  *
  * @return mixed
  */
 protected function getRawValue(ResultRecordInterface $record)
 {
     return $this->translator->trans($this->manager->getLabelByType($record->getValue('formType')));
 }
 /**
  * @param ResultRecordInterface $record
  *
  * @return array
  */
 public function getUserPermissions(ResultRecordInterface $record)
 {
     $enabled = $record->getValue('enabled');
     return ['enable' => !$enabled, 'disable' => $enabled, 'view' => true, 'update' => true, 'delete' => true];
 }
 /**
  * @param ResultRecordInterface $record
  *
  * @return array
  */
 public function getRequestStatusDefinitionPermissions(ResultRecordInterface $record)
 {
     $isDeleted = $record->getValue('deleted');
     $isDefaultRequestStatus = $this->configManager->get('oro_b2b_rfp.default_request_status') === $record->getValue('name');
     return ['restore' => $isDeleted, 'delete' => !$isDeleted && !$isDefaultRequestStatus, 'view' => true, 'update' => true];
 }
 /**
  * @param ResultRecordInterface $record
  * @param bool $checkExtension
  *
  * @return bool
  */
 protected function isChannelApplicable(ResultRecordInterface $record, $checkExtension = true)
 {
     $channelId = $record->getValue(self::CHANNEL_KEY);
     return $this->channelSettingsProvider->isChannelApplicable($channelId, $checkExtension);
 }
 /**
  * @param ResultRecordInterface $record
  * @return array
  */
 public function getProcessDefinitionPermissions(ResultRecordInterface $record)
 {
     $isEnabled = $record->getValue('enabled');
     return array('activate' => !$isEnabled, 'deactivate' => $isEnabled, 'view' => true);
 }