/**
  * @param string $queryType
  * @param string $query
  *
  * @return array[]
  */
 public function suggest($queryType, $query)
 {
     if ('user' == $queryType) {
         $dql = $this->em->createQuery(sprintf('SELECT u FROM %s u WHERE u.firstName LIKE ?0 OR u.lastName LIKE ?0 OR u.username LIKE ?0 OR u.email LIKE ?0', User::clazz()));
         $dql->setParameter(0, '%' . $query . '%');
         $rawResult = [];
         foreach ($dql->getResult() as $user) {
             /* @var User $user */
             $value = $this->stringifyUser($user);
             $rawResult[] = array('id' => $user->getId(), 'value' => $value);
         }
         return $rawResult;
     } elseif ('exact-user' == $queryType) {
         // find by ID
         $user = $this->em->find(User::clazz(), $query);
         if (!$user) {
             throw new \DomainException(T::trans('Unable to find a user "%username%"', array('%username%' => $query)));
         }
         return [array('id' => $user->getId(), 'value' => $this->stringifyUser($user))];
     } elseif ('eventType' == $queryType) {
         $activities = $this->activityManager->query(array('filter' => [array('property' => 'type', 'value' => 'like:%' . $query . '%')]));
         $rawResult = [];
         foreach ($activities['items'] as $activity) {
             /* @var ActivityInterface $activity */
             $rawResult[] = $activity->getType();
         }
         $rawResult = array_values(array_unique($rawResult));
         $result = [];
         foreach ($rawResult as $item) {
             $result[] = array('id' => $item, 'value' => $item);
         }
         return $result;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     if (!$this->items) {
         $this->items = [new Permission(T::trans('Access users and groups manager'), ModeraBackendSecurityBundle::ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION, 'user-management'), new Permission(T::trans('Manage user profiles'), ModeraBackendSecurityBundle::ROLE_MANAGE_USER_PROFILES, 'user-management'), new Permission(T::trans('Manage permissions'), ModeraBackendSecurityBundle::ROLE_MANAGE_PERMISSIONS, 'user-management')];
     }
     return $this->items;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     if (!$this->items) {
         $this->items = [new Permission(T::trans('Access administration interface'), ModeraMJRSecurityIntegrationBundle::ROLE_BACKEND_USER, 'site')];
     }
     return $this->items;
 }
예제 #4
0
 public function boot()
 {
     $reflClass = new \ReflectionClass(T::clazz());
     $reflProp = $reflClass->getProperty('container');
     $reflProp->setAccessible(true);
     $reflProp->setValue(null, $this->container);
 }
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     if (!$this->items) {
         $this->items = [new PermissionCategory(T::trans('User management'), 'user-management')];
     }
     return $this->items;
 }
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     if (!$this->items) {
         $this->items = [new PermissionCategory(T::trans('Site'), 'site')];
     }
     return $this->items;
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     if (!$this->items) {
         $this->items = [new Permission(T::trans('Access modules manager'), ModeraBackendModuleBundle::ROLE_ACCESS_BACKEND_TOOLS_MODULES_SECTION, 'site')];
     }
     return $this->items;
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     if (!$this->items) {
         $this->items = [new Permission(T::trans('Access Tools section'), ModeraBackendToolsBundle::ROLE_ACCESS_TOOLS_SECTION, 'site')];
     }
     return $this->items;
 }
예제 #9
0
 /**
  * @throws \RuntimeException If given used is root user and cannot be deleted
  *
  * @param User $user
  */
 public function remove(User $user)
 {
     if ($this->rootUserHandler->isRootUser($user)) {
         throw new \RuntimeException(T::trans('Super admin user never can be deleted.'));
     }
     $this->em->remove($user);
     $this->em->flush();
 }
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     if (!$this->items) {
         $this->items = array();
         if ($this->authorizationChecker->isGranted(ModeraBackendSecurityBundle::ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION)) {
             $this->items[] = new Section(T::trans('Security permissions'), 'tools.security', T::trans('Control permissions of users/groups.'), '', '', 'modera-backend-security-tools-icon');
         }
     }
     return $this->items;
 }
예제 #11
0
 public function method1()
 {
     $barDomain = 'bardomain';
     T::trans('Some simple token');
     $message = 'hello ';
     $message .= 'world';
     T::trans('We got something for ya, %s!', array('name' => 'Vassily', 'xxx' => $fn()), 'foodomain');
     T::trans('Another token', null, $barDomain);
     T::trans($message);
     T::trans('Broken translation', null, rand(100));
     T::transChoice('This is "transChoice token"', null, null, 'tcdomain');
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     // "client" configuration configs are not that much important when standard foundation is used because
     // "general" category relies on "Modera.backend.dcmjr.view.GeneralSettingsPanel" to display
     // and edit configuration properties which defines all required configuration right in JS file
     $yes = T::trans('yes');
     $no = T::trans('no');
     $kernelDebugServer = array('handler' => 'modera_config.boolean_handler', 'update_handler' => 'modera_dynamically_configurable_app.value_handling.kernel_config_writer', 'true_text' => $yes, 'false_text' => $no);
     $kernelDebugClient = array('xtype' => 'combo', 'store' => [['prod', 'yes'], ['dev', 'no']]);
     $kernelEnvServer = array('handler' => 'modera_config.dictionary_handler', 'update_handler' => 'modera_dynamically_configurable_app.value_handling.kernel_config_writer', 'dictionary' => array('prod' => $yes, 'dev' => $no));
     $kernelEnvClient = array('xtype' => 'combo', 'store' => [[true, 'yes'], [false, 'no']]);
     return array(new CED(Bundle::CONFIG_KERNEL_ENV, T::trans('Production mode'), 'prod', 'general', $kernelEnvServer, $kernelEnvClient), new CED(Bundle::CONFIG_KERNEL_DEBUG, T::trans('Maintenance mode'), false, 'general', $kernelDebugServer, $kernelDebugClient));
 }
예제 #13
0
 /**
  * @param ActivityInterface $activity
  *
  * @return array
  */
 public function resolve(ActivityInterface $activity)
 {
     $isId = preg_match('/^[0-9]+$/', $activity->getAuthor());
     if ($isId) {
         /* @var User $user */
         $user = $this->om->find(User::clazz(), $activity->getAuthor());
         if ($user) {
             return array('id' => $user->getId(), 'isUser' => true, 'fullName' => $user->getFullName(), 'username' => $user->getUsername());
         } else {
             return array('isUser' => false, 'identity' => $activity->getAuthor());
         }
     } else {
         return array('isUser' => false, 'identity' => $activity->getAuthor() ? $activity->getAuthor() : T::trans('Unknown'));
     }
 }
 /**
  * @param GetResponseForExceptionEvent $event
  *
  * @return string
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getRequest()->isXmlHttpRequest()) {
         return self::RESULT_NOT_AJAX;
     }
     if (substr($event->getRequest()->getPathInfo(), 0, strlen($this->backendRoutesPrefix)) != $this->backendRoutesPrefix) {
         return self::RESULT_NOT_BACKEND_REQUEST;
     }
     $e = $event->getException();
     $response = null;
     if ($e instanceof AccessDeniedException) {
         $msg = "Your session has expired and you need to re-login or you don't have privileges to perform given action.";
         $response = new JsonResponse(array('success' => false, 'message' => T::trans($msg)), 403);
         $event->setResponse($response);
     }
 }
 /**
  * @param User $user
  * @param $plainPassword
  *
  * @return array|bool
  */
 public function sendPassword(User $user, $plainPassword)
 {
     /* @var \Swift_Message $message */
     $message = $this->mailer->createMessage();
     $locale = $this->getLocale($user);
     $subject = T::trans('Your password', array(), 'mail', $locale);
     $body = T::trans('Your new password is: %plainPassword%', array('%plainPassword%' => $plainPassword), 'mail', $locale);
     $message->setFrom($this->mailSender);
     $message->setTo($user->getEmail());
     $message->setSubject($subject);
     $message->setBody($body);
     $failedRecipients = array();
     if (!$this->mailer->send($message, $failedRecipients)) {
         return $failedRecipients;
     }
     return true;
 }
 /**
  * @Route("%modera_file_uploader.uploader_url%", name="modera_file_uploader", options={"expose"=true})
  *
  * @param Request $request
  */
 public function uploadAction(Request $request)
 {
     if (!$this->container->getParameter('modera_file_uploader.is_enabled')) {
         throw $this->createNotFoundException(T::trans('Uploader is not enabled.'));
     }
     /* @var WebUploader $webUploader */
     $webUploader = $this->get('modera_file_uploader.uploading.web_uploader');
     $result = null;
     try {
         $result = $webUploader->upload($request);
     } catch (FileValidationException $e) {
         return new JsonResponse(array('success' => false, 'error' => implode(', ', $e->getErrors()), 'errors' => $e->getErrors()));
     }
     if (false === $result) {
         return new JsonResponse(array('success' => false, 'error' => T::trans('Unable to find an upload gateway that is able to process this file upload.')));
     }
     return new JsonResponse($result);
 }
예제 #17
0
 /**
  * @return array
  */
 public function getConfig()
 {
     $em = $this->getDoctrine();
     $groupEntityValidator = function (array $params, Group $group, DefaultEntityValidator $defaultValidator, array $config, ContainerInterface $container) use($em) {
         $validationResult = $defaultValidator->validate($group, $config);
         if (!$group->getRefName()) {
             return $validationResult;
         }
         /** @var Group[] $groupWithSuchRefNameList */
         $groupWithSuchRefNameList = $em->getRepository(Group::clazz())->findByRefName($group->getRefName());
         if (count($groupWithSuchRefNameList) > 0) {
             $groupWithSuchRefName = $groupWithSuchRefNameList[0];
             if ($groupWithSuchRefName->getId() != $group->getId()) {
                 $validationResult->addFieldError('refName', T::trans('This refName is taken. Consider use \'%groupName%\' group or change current reference name.', array('%groupName%' => $groupWithSuchRefName->getName())));
             }
         }
         return $validationResult;
     };
     $mapEntity = function (array $params, Group $group, DataMapperInterface $defaultMapper, ContainerInterface $container) {
         $defaultMapper->mapData($params, $group);
         /*
          * Because of unique constrain we cannot save '' value as refName.
          * Only one time can, actually. :) So, to allow user use groups without
          * refName we have to set null by force because of ExtJs empty form value
          * is ''.
          */
         $refName = $group->getRefName();
         if ($refName === '') {
             $group->setRefName(null);
         } else {
             /*
              * To help users avoid duplicates group we use normalizing for refName
              */
             $group->setRefName(Group::normalizeRefNameString($refName));
         }
     };
     return array('entity' => Group::clazz(), 'security' => array('role' => ModeraBackendSecurityBundle::ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION, 'actions' => array('create' => ModeraBackendSecurityBundle::ROLE_MANAGE_PERMISSIONS, 'update' => ModeraBackendSecurityBundle::ROLE_MANAGE_PERMISSIONS, 'remove' => ModeraBackendSecurityBundle::ROLE_MANAGE_PERMISSIONS)), 'hydration' => array('groups' => array('list' => function (Group $group) {
         return array('id' => $group->getId(), 'name' => $group->getName(), 'usersCount' => count($group->getUsers()));
     }, 'delete-group' => ['name'], 'main-form' => ['id', 'name', 'refName'], 'compact-list' => ['id', 'name']), 'profiles' => array('list', 'compact-list', 'delete-group', 'edit-group' => array('main-form'))), 'format_new_entity_values' => function (array $params, array $config, NewValuesFactoryInterface $defaultImpl, ContainerInterface $container) {
         return array('refName' => null);
     }, 'new_entity_validator' => $groupEntityValidator, 'updated_entity_validator' => $groupEntityValidator, 'map_data_on_create' => $mapEntity, 'map_data_on_update' => $mapEntity);
 }
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     $serverConfig = array('id' => 'modera_config.as_is_handler');
     return [new CED(ModeraBackendGoogleAnalyticsBundle::TRACKING_CODE_CONFIG_KEY, T::trans('Backend tracking code'), '', 'google-analytics', $serverConfig, array())];
 }
예제 #19
0
파일: Dummy.php 프로젝트: modera/foundation
 public function test()
 {
     return T::trans('Test token');
 }
예제 #20
0
 /**
  * @return array
  */
 public function getConfig()
 {
     $self = $this;
     return array('entity' => User::clazz(), 'create_default_data_mapper' => function (ContainerInterface $container) {
         return $this->container->get('modera_backend_security.data_mapper.user_data_mapper');
     }, 'security' => array('actions' => array('create' => ModeraBackendSecurityBundle::ROLE_MANAGE_USER_PROFILES, 'update' => function (AuthorizationCheckerInterface $ac, array $params) use($self) {
         /* @var TokenStorageInterface $ts */
         $ts = $self->get('security.token_storage');
         /* @var User $user */
         $user = $ts->getToken()->getUser();
         if ($ac->isGranted(ModeraBackendSecurityBundle::ROLE_MANAGE_USER_PROFILES)) {
             return true;
         } else {
             // irrespectively of what privileges user has we will always allow him to edit his
             // own profile data
             return $user instanceof User && isset($params['record']['id']) && $user->getId() == $params['record']['id'];
         }
     }, 'remove' => ModeraBackendSecurityBundle::ROLE_MANAGE_USER_PROFILES, 'list' => ModeraBackendSecurityBundle::ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION)), 'hydration' => array('groups' => array('main-form' => ['id', 'username', 'email', 'firstName', 'lastName', 'middleName', 'meta'], 'list' => function (User $user) {
         $groups = array();
         foreach ($user->getGroups() as $group) {
             $groups[] = $group->getName();
         }
         return array('id' => $user->getId(), 'username' => $user->getUsername(), 'email' => $user->getEmail(), 'firstName' => $user->getFirstName(), 'lastName' => $user->getLastName(), 'middleName' => $user->getMiddleName(), 'state' => $user->getState(), 'groups' => $groups, 'meta' => $user->getMeta());
     }, 'compact-list' => ['id', 'username', 'fullname'], 'delete-user' => ['username']), 'profiles' => array('list', 'delete-user', 'main-form', 'compact-list', 'modera-backend-security-group-groupusers' => HydrationProfile::create(false)->useGroups(array('compact-list')))), 'map_data_on_create' => function (array $params, User $entity, DataMapperInterface $defaultMapper, ContainerInterface $container) use($self) {
         $defaultMapper->mapData($params, $entity);
         if (isset($params['plainPassword']) && $params['plainPassword']) {
             $plainPassword = $params['plainPassword'];
         } else {
             $plainPassword = $self->generatePassword();
         }
         $self->setPassword($entity, $plainPassword);
         if (isset($params['sendPassword']) && $params['sendPassword'] != '') {
             /* @var MailService $mailService */
             $mailService = $container->get('modera_backend_security.service.mail_service');
             $mailService->sendPassword($entity, $plainPassword);
         }
     }, 'map_data_on_update' => function (array $params, User $entity, DataMapperInterface $defaultMapper, ContainerInterface $container) use($self) {
         $defaultMapper->mapData($params, $entity);
         /* @var LoggerInterface $activityMgr */
         $activityMgr = $container->get('modera_activity_logger.manager.activity_manager');
         /* @var TokenStorageInterface $ts */
         $ts = $container->get('security.token_storage');
         if (isset($params['plainPassword']) && $params['plainPassword']) {
             $self->setPassword($entity, $params['plainPassword']);
             if (isset($params['sendPassword']) && $params['sendPassword'] != '') {
                 /* @var MailService $mailService */
                 $mailService = $container->get('modera_backend_security.service.mail_service');
                 $mailService->sendPassword($entity, $params['plainPassword']);
             }
             $activityMsg = T::trans('Password has been changed for user "%user%".', array('%user%' => $entity->getUsername()));
             $activityContext = array('type' => 'user.password_changed', 'author' => $ts->getToken()->getUser()->getId());
             $activityMgr->info($activityMsg, $activityContext);
         } else {
             $activityMsg = T::trans('Profile data is changed for user "%user%".', array('%user%' => $entity->getUsername()));
             $activityContext = array('type' => 'user.profile_updated', 'author' => $ts->getToken()->getUser()->getId());
             $activityMgr->info($activityMsg, $activityContext);
         }
     }, 'remove_entities_handler' => function ($entities, $params, $defaultHandler, ContainerInterface $container) {
         /* @var UserService $userService */
         $userService = $container->get('modera_security.service.user_service');
         $operationResult = new OperationResult();
         foreach ($entities as $entity) {
             /* @var User $entity*/
             $userService->remove($entity);
             $operationResult->reportEntity(User::clazz(), $entity->getId(), OperationResult::TYPE_ENTITY_REMOVED);
         }
         return $operationResult;
     });
 }
 public function testBoot()
 {
     $reflProp = new \ReflectionProperty(T::clazz(), 'container');
     $reflProp->setAccessible(true);
     $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\ContainerInterface', $reflProp->getValue());
 }
예제 #22
0
파일: TTest.php 프로젝트: modera/foundation
 public function testTransChoice()
 {
     $expectedOutput = array('foo id', 'foo number', array('params'), 'foo domain', 'foo locale');
     $this->assertSame($expectedOutput, T::transChoice('foo id', 'foo number', array('params'), 'foo domain', 'foo locale'));
 }
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     return [new StandardSection('google-analytics', T::trans('Google analytics'), 'Modera.backend.configutils.runtime.SettingsListActivity', 'pie-chart', array('activationParams' => array('category' => 'google-analytics')))];
 }
예제 #24
0
 public function __construct()
 {
     $this->items = array(new Section(T::trans('Settings'), 'tools.settings', T::trans('Configure the current site.'), '', '', 'modera-backend-tools-settings-icon'));
 }