/**
  * @param array  $permissionArray
  * @param string $locale
  * @param null   $perm
  *
  * @return string
  */
 public function permission($permissionArray, $locale, $perm = null)
 {
     $permission = null;
     $permissions = isset($permissionArray[Permission::LOCALE_KEY]) ? $permissionArray[Permission::LOCALE_KEY] : array();
     if (isset($permissions[$locale])) {
         $permission = $permissions[$locale];
     } else {
         $permission = isset($permissions[Permission::WILD_KEY]) ? $permissions[Permission::WILD_KEY] : '';
     }
     return Permission::checkPermission($permission, $perm);
 }
Exemple #2
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getContainer();
     /** @var EntityManager $em */
     $em = $container->get('doctrine')->getManager();
     // Create first user
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setName('Admin Tradukoj');
     $user->setActive(true);
     $user->addRole(User::ROLE_ADMIN);
     $user->setPassword('Tradukoj$1234');
     /** @var EncoderFactory $encoderFactory */
     $encoderFactory = $container->get('security.encoder_factory');
     $encoder = $encoderFactory->getEncoder($user);
     $user->setPassword($encoder->encodePassword($user->getPassword(), $user->getSalt()));
     $em->persist($user);
     $em->flush();
     $usersColl = new ArrayCollection();
     $usersColl->add($user);
     // create first project
     $project = new Project();
     $project->setName('tradukoj');
     $project->setApiKey('tradukoj.com');
     $project->setApiSecret('Tradukoj$1234');
     $project->setManagedLocales('en,es');
     $project->setProject('tradukoj');
     //$project->setUsers($usersColl);
     $permission = new Permission();
     $permission->setUser($user);
     $permission->setProject($project);
     $permission->addPermission(Permission::OWNER);
     // Give permission to write in all languages
     $permission->addPermission(Permission::WRITE_PERM, '*');
     $em->persist($permission);
     $em->persist($project);
     $em->flush();
     $output->writeln(" done!");
 }
Exemple #3
0
 /**
  * @param $locale
  * @param $perm
  *
  * @return bool
  */
 protected function checkPermission($locale, $perm)
 {
     $permissionArray = $this->user->getPermission();
     $permission = null;
     $permissions = isset($permissionArray[Permission::LOCALE_KEY]) ? $permissionArray[Permission::LOCALE_KEY] : array();
     if (isset($permissions[$locale])) {
         $permission = $permissions[$locale];
     } else {
         $permission = isset($permissions[Permission::WILD_KEY]) ? $permissions[Permission::WILD_KEY] : '';
     }
     return Permission::checkPermission($permission, $perm);
 }
Exemple #4
0
 /**
  * @Route("/change-user-permissions/{projectId}", name="change_user_permission")
  * @ParamConverter("project", class="TranslationsBundle:Project", options={"id" = "projectId"})
  */
 public function changeUserPermissionsAction(Project $project, Request $request)
 {
     $session = $request->getSession();
     $this->init();
     /** @var Permission $permission */
     $permission = $this->translationsManager->getPermissionForUserAndProject($this->user, $project);
     if (!$permission || $permission->getPermissions(Permission::GENERAL_KEY) != Permission::OWNER) {
         return $this->exception('error.acl.not_enough_permissions_to_manage_this_project');
     }
     $managedLocales = explode(',', $project->getManagedLocales());
     $userId = $request->get('user');
     $locale = $request->get('locale');
     if (!in_array($locale, $managedLocales)) {
         return $this->exception(sprintf('the locale %s is not managed by this project', $locale));
     }
     $newPermission = $request->get('permission');
     if (!in_array($newPermission, Permission::getAllowedLocalePermissions())) {
         return $this->exception(sprintf('the permission %s is not recognized', $newPermission));
     }
     $user = $this->getUserRepository()->find($userId);
     if (!$user) {
         return $this->exception('error.permissions.no_user_found');
     }
     /** @var Permission $permission */
     $permission = $this->getPermissionRepository()->findPermissionForProjectAndUser($project, $user);
     if (!$permission) {
         return $this->exception('error.permissions.no_permissions_for_this_user');
     }
     $permission->addPermission($newPermission, $locale);
     $this->em->persist($permission);
     $this->em->flush($permission);
     return $this->resultOk(array('locale' => $locale, 'user' => $user->getId(), 'permission' => $newPermission));
 }