Example #1
0
 public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
 {
     $mappings = $targetEntity->getAssociationMappings();
     if (!array_key_exists('journal', $mappings) || $mappings['journal']['targetEntity'] !== 'Ojs\\JournalBundle\\Entity\\Journal') {
         return '';
     }
     $selectedJournal = $this->journalService->getSelectedJournal();
     if (!$selectedJournal) {
         return '';
     }
     $journalJoinColumn = $mappings['journal']['joinColumns'][0]['name'];
     $addCondSql = $targetTableAlias . '.' . $journalJoinColumn . ' = ' . $selectedJournal->getId();
     return $addCondSql;
 }
Example #2
0
 /**
  * Check if user is selected journal publisher manager
  *
  * @return bool
  */
 public function isGrantedForPublisher()
 {
     $token = $this->tokenStorage->getToken();
     if ($token && method_exists($token, 'getUser')) {
         /** @var User $user */
         $user = $token->getUser();
     } else {
         return false;
     }
     $selectedJournal = $this->journalService->getSelectedJournal();
     if ($selectedJournal) {
         $publisher = $selectedJournal->getPublisher();
     } else {
         $publisherId = $this->requestStack->getCurrentRequest()->attributes->get('publisherId');
         if (!$publisherId) {
             return false;
         }
         $publisher = $this->em->getRepository('OjsJournalBundle:Publisher')->find($publisherId);
     }
     if ($user->isAdmin()) {
         return true;
     }
     foreach ($publisher->getPublisherManagers() as $manager) {
         if ($manager->getUser()->getId() == $user->getId()) {
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function getSecurityIdentities(Token\TokenInterface $token)
 {
     $sids = array();
     // add user security identity
     if (!$token instanceof Token\AnonymousToken) {
         try {
             $sids[] = UserSecurityIdentity::fromToken($token);
         } catch (\InvalidArgumentException $invalid) {
             // ignore, user has no user security identity
         }
     }
     // add all reachable roles
     foreach ($this->roleHierarchy->getReachableRoles($token->getRoles()) as $role) {
         $sids[] = new RoleSecurityIdentity($role);
     }
     // add journal roles
     $user = $token->getUser();
     try {
         $selectedJournal = $this->journalService->getSelectedJournal();
     } catch (\Exception $e) {
         $selectedJournal = false;
     }
     if ($user instanceof User && $selectedJournal instanceof Journal) {
         foreach ($user->getJournalRoles($selectedJournal) as $journalRoles) {
             $sids[] = new JournalRoleSecurityIdentity($journalRoles[0], $journalRoles[1]);
         }
     }
     // add built-in special roles
     if ($this->authenticationTrustResolver->isFullFledged($token)) {
         $sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_FULLY);
         $sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED);
         $sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
     } elseif ($this->authenticationTrustResolver->isRememberMe($token)) {
         $sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED);
         $sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
     } elseif ($this->authenticationTrustResolver->isAnonymous($token)) {
         $sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
     }
     return $sids;
 }
Example #4
0
 /**
  *
  * @param  Article $article
  * @return string
  */
 public function generateUrl(Article $article)
 {
     $journalUrl = $this->journalService->generateUrl($article->getJournal());
     return $journalUrl . '/' . $article->getSlug();
 }