/**
  * @param EmailTemplate $template
  *
  * @return Closure
  */
 protected function createExistingEntityQueryBuilder(EmailTemplate $template)
 {
     return function (EmailTemplateRepository $repository) use($template) {
         $qb = $repository->createQueryBuilder('e');
         return $qb->orderBy('e.name', 'ASC')->andWhere('e.entityName = :entityName OR e.entityName IS NULL')->andWhere("e.organization = :organization")->andWhere($qb->expr()->orX($qb->expr()->eq('e.visible', ':visible'), $qb->expr()->eq('e.id', ':id')))->setParameter('entityName', Email::ENTITY_CLASS)->setParameter('organization', $this->securityFacade->getOrganization())->setParameter('id', $template->getId())->setParameter('visible', true);
     };
 }
Esempio n. 2
0
 /**
  * Process form
  *
  * @param  CalendarEvent $entity
  * @throws \LogicException
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     if (!$entity->getCalendar()) {
         if ($this->securityFacade->getLoggedUser() && $this->securityFacade->getOrganization()) {
             /** @var Calendar $defaultCalendar */
             $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($this->securityFacade->getLoggedUser()->getId(), $this->securityFacade->getOrganization()->getId());
             $entity->setCalendar($defaultCalendar);
         } else {
             throw new \LogicException('Current user did not define');
         }
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
             if ($targetEntityClass) {
                 $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
                 $targetEntity = $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId);
                 $action = $this->entityRoutingHelper->getAction($this->request);
                 if ($action === 'activity') {
                     $this->activityManager->addActivityTarget($entity, $targetEntity);
                 }
                 if ($action === 'assign' && $targetEntity instanceof User && $targetEntityId !== $this->securityFacade->getLoggedUserId()) {
                     /** @var Calendar $defaultCalendar */
                     $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($targetEntity->getId(), $targetEntity->getOrganization()->getId());
                     $entity->setCalendar($defaultCalendar);
                 }
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
Esempio n. 3
0
 /**
  * @return array
  */
 protected function createChoices()
 {
     $user = $this->securityFacade->getLoggedUser();
     if (!$user instanceof User) {
         return [];
     }
     $emails = array_merge(array_values($this->relatedEmailsProvider->getEmails($user, 1, true)), $this->mailboxManager->findAvailableMailboxEmails($user, $this->securityFacade->getOrganization()));
     return array_combine($emails, $emails);
 }
Esempio n. 4
0
 /**
  * Set email seen status for current user for single email or thread
  *
  * @param Email $entity
  * @param bool  $isSeen
  * @param bool  $checkThread - if false it will be applied for single email instead of thread
  */
 public function setSeenStatus(Email $entity, $isSeen = true, $checkThread = false)
 {
     $user = $this->securityFacade->getLoggedUser();
     $organization = $this->securityFacade->getOrganization();
     $emailUsers = $this->getEmailUserRepository()->getAllEmailUsersByEmail($entity, $user, $organization, $checkThread);
     foreach ($emailUsers as $emailUser) {
         $this->setEmailUserSeen($emailUser, $isSeen);
     }
     $this->em->flush();
 }
Esempio n. 5
0
 /**
  * @param string       $key
  * @param Organization $entity
  */
 public function fillEntityData($key, $entity)
 {
     switch ($key) {
         case 'default':
             $organization = $this->securityFacade->getOrganization();
             if ($organization) {
                 $entity->setName($organization->getName());
             }
             return;
     }
     parent::fillEntityData($key, $entity);
 }
 /**
  * @param bool $addValue FALSE for variable definitions; TRUE for variable values
  *
  * @return array
  */
 protected function getVariables($addValue)
 {
     $result = [];
     $organization = $this->securityFacade->getOrganization();
     $user = $this->securityFacade->getLoggedUser();
     $this->addOrganizationName($result, $organization, $addValue);
     $this->addUserName($result, $user, $addValue);
     $this->addUserFirstName($result, $user, $addValue);
     $this->addUserLastName($result, $user, $addValue);
     $this->addUserFullName($result, $user, $addValue);
     return $result;
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function process(User $user)
 {
     if ($this->securityFacade !== null && $user->getCurrentOrganization() === null) {
         $user->setCurrentOrganization($this->securityFacade->getOrganization());
     }
     $this->form->setData($user);
     if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->onSuccess($user);
             return true;
         }
     }
     return false;
 }
Esempio n. 8
0
 /**
  * Apply custom ACL checks
  *
  * @param QueryBuilder $qb
  */
 public function applyAcl(QueryBuilder $qb)
 {
     $user = $this->securityFacade->getLoggedUser();
     $organization = $this->securityFacade->getOrganization();
     $mailboxIds = $this->doctrine->getRepository('OroEmailBundle:Mailbox')->findAvailableMailboxIds($user, $organization);
     $uoCheck = $qb->expr()->andX($qb->expr()->eq('eu.owner', ':owner'), $qb->expr()->eq('eu.organization ', ':organization'));
     if (!empty($mailboxIds)) {
         $qb->andWhere($qb->expr()->orX($uoCheck, $qb->expr()->in('eu.mailboxOwner', ':mailboxIds')));
         $qb->setParameter('mailboxIds', $mailboxIds);
     } else {
         $qb->andWhere($uoCheck);
     }
     $qb->setParameter('owner', $user->getId());
     $qb->setParameter('organization', $organization->getId());
 }
Esempio n. 9
0
 /**
  * @param string $search
  * @param int    $firstResult
  * @param int    $maxResults
  *
  * @return array
  */
 protected function searchIds($search, $firstResult, $maxResults)
 {
     $ids = parent::searchIds($search, $firstResult, $maxResults);
     // Need to make additional query cause of Mysql Full-Text Search limitation and databases stop words.
     // http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_ft_min_word_len
     // http://dev.mysql.com/doc/refman/5.0/en/fulltext-stopwords.html
     // http://www.postgresql.org/docs/9.1/static/textsearch-dictionaries.html
     $object = $this->entityRepository->findOneBy(['name' => $search, 'organization' => $this->securityFacade->getOrganization()]);
     if ($object !== null) {
         $id = $object->getId();
         if (!in_array($id, $ids, true)) {
             $ids[] = $id;
         }
     }
     return $ids;
 }
Esempio n. 10
0
 /**
  * Find EmilUser User logged in system
  *
  * @param Email $entity - entity Email
  *
  * @return null|EmailUser
  */
 protected function getCurrentEmailUser(Email $entity)
 {
     $user = $this->securityFacade->getToken()->getUser();
     $currentOrganization = $this->securityFacade->getOrganization();
     $emailUser = $this->em->getRepository('OroEmailBundle:EmailUser')->findByEmailAndOwner($entity, $user, $currentOrganization);
     return $emailUser;
 }
Esempio n. 11
0
 /**
  * @param FormBuilderInterface $builder
  */
 protected function addOwnerOrganizationEventListener(FormBuilderInterface $builder)
 {
     $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
         /** @var ImapEmailOrigin $data */
         $data = $event->getData();
         if ($data !== null) {
             if ($data->getOwner() === null) {
                 $data->setOwner($this->securityFacade->getLoggedUser());
             }
             if ($data->getOrganization() === null) {
                 $organization = $this->securityFacade->getOrganization() ? $this->securityFacade->getOrganization() : $this->securityFacade->getLoggedUser()->getOrganization();
                 $data->setOrganization($organization);
             }
             $event->setData($data);
         }
     });
 }
Esempio n. 12
0
 /**
  * @return bool|Organization
  */
 protected function getCurrentOrganization()
 {
     $businessUnit = $this->getCurrentBusinessUnit($this->securityFacade->getOrganization());
     if (!$businessUnit) {
         return true;
     }
     return $businessUnit->getOrganization();
 }
Esempio n. 13
0
 /**
  * Return array of numbers unread emails per folder
  *
  * @return array
  */
 public function getUnreadEmailsCount()
 {
     $currentOrganization = $this->securityFacade->getOrganization();
     $currentUser = $this->securityFacade->getLoggedUser();
     $result = $this->em->getRepository("OroEmailBundle:Email")->getCountNewEmailsPerFolders($currentUser, $currentOrganization);
     $total = $this->em->getRepository("OroEmailBundle:Email")->getCountNewEmails($currentUser, $currentOrganization);
     $result[] = array('num' => $total, 'id' => 0);
     return $result;
 }
Esempio n. 14
0
 /**
  * Returns array of mailbox choices.
  *
  * @return array
  */
 public function getChoiceList()
 {
     $repo = $this->doctrine->getRepository('OroEmailBundle:Mailbox');
     /** @var Mailbox[] $systemMailboxes */
     $systemMailboxes = $repo->findAvailableMailboxes($this->securityFacade->getLoggedUser(), $this->securityFacade->getOrganization());
     $origins = $this->getOriginsList();
     $choiceList = [];
     foreach ($origins as $origin) {
         $mailbox = $origin->getMailboxName();
         if (count($origin->getFolders()) > 0) {
             $choiceList[$origin->getId()] = str_replace('@', '\\@', $mailbox);
         }
     }
     foreach ($systemMailboxes as $mailbox) {
         $choiceList[$mailbox->getOrigin()->getId()] = $mailbox->getLabel();
     }
     return $choiceList;
 }
 /**
  * @param CalendarEvent $entity
  *
  * @throws \LogicException
  */
 protected function ensureCalendarSet(CalendarEvent $entity)
 {
     if ($entity->getCalendar() || $entity->getSystemCalendar()) {
         return;
     }
     if (!$this->securityFacade->getLoggedUser() || !$this->securityFacade->getOrganization()) {
         throw new \LogicException('Both logged in user and organization must be defined.');
     }
     /** @var Calendar $defaultCalendar */
     $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($this->securityFacade->getLoggedUser()->getId(), $this->securityFacade->getOrganization()->getId());
     $entity->setCalendar($defaultCalendar);
 }
Esempio n. 16
0
 /**
  * Find existing email origin entity by email string or create and persist new one.
  *
  * @param string                $email
  * @param OrganizationInterface $organization
  * @param string                $originName
  * @param boolean               $enableUseUserEmailOrigin
  *
  * @return EmailOrigin
  */
 public function getEmailOrigin($email, OrganizationInterface $organization = null, $originName = InternalEmailOrigin::BAP, $enableUseUserEmailOrigin = true)
 {
     $originKey = $originName . $email;
     if (!$organization && $this->securityFacade !== null && $this->securityFacade->getOrganization()) {
         $organization = $this->securityFacade->getOrganization();
     }
     if (!array_key_exists($originKey, $this->origins)) {
         $emailOwner = $this->emailOwnerProvider->findEmailOwner($this->getEntityManager(), $this->emailAddressHelper->extractPureEmailAddress($email));
         $origin = $this->emailOriginHelper->findEmailOrigin($emailOwner, $organization, $originName, $enableUseUserEmailOrigin);
         $this->origins[$originKey] = $origin;
     }
     return $this->origins[$originKey];
 }
Esempio n. 17
0
 /**
  * @return EmailOrigin
  */
 protected function getEmailOrigin()
 {
     if (!$this->emailOrigin) {
         /** @var User $originOwner */
         $originOwner = $this->securityFacade->getLoggedUser();
         $organization = $this->securityFacade->getOrganization();
         $originName = 'API_User_' . $originOwner->getId();
         $origins = $originOwner->getEmailOrigins()->filter(function ($item) use($originName, $organization) {
             return $item instanceof InternalEmailOrigin && $item->getName() === $originName && $item->getOrganization() === $organization;
         });
         $this->emailOrigin = !$origins->isEmpty() ? $origins->first() : $this->createEmailOrigin($originOwner, $organization, $originName);
     }
     return $this->emailOrigin;
 }
Esempio n. 18
0
 /**
  * Find existing email origin entity by email string or create and persist new one.
  *
  * @param string $email
  * @param string $originName
  * @param boolean $enableUseUserEmailOrigin
  *
  * @return EmailOrigin
  */
 public function getEmailOrigin($email, $originName = InternalEmailOrigin::BAP, $enableUseUserEmailOrigin = true)
 {
     $originKey = $originName . $email;
     $organization = $this->securityFacade !== null && $this->securityFacade->getOrganization() ? $this->securityFacade->getOrganization() : null;
     if (!array_key_exists($originKey, $this->origins)) {
         $emailOwner = $this->emailOwnerProvider->findEmailOwner($this->getEntityManager(), $this->emailAddressHelper->extractPureEmailAddress($email));
         if ($emailOwner instanceof User) {
             $origin = $this->getPreferedOrigin($enableUseUserEmailOrigin, $emailOwner, $organization);
         } else {
             $origin = $this->getEntityManager()->getRepository('OroEmailBundle:InternalEmailOrigin')->findOneBy(['internalName' => $originName]);
         }
         $this->origins[$originKey] = $origin;
     }
     return $this->origins[$originKey];
 }
Esempio n. 19
0
 /**
  * Find existing email origin entity by email string or create and persist new one.
  *
  * @param string $email
  * @param string $originName
  *
  * @return EmailOrigin
  */
 public function getEmailOrigin($email, $originName = InternalEmailOrigin::BAP)
 {
     $originKey = $originName . $email;
     $organization = $this->securityFacade !== null && $this->securityFacade->getOrganization() ? $this->securityFacade->getOrganization() : null;
     if (!array_key_exists($originKey, $this->origins)) {
         $emailOwner = $this->emailOwnerProvider->findEmailOwner($this->getEntityManager(), $this->emailAddressHelper->extractPureEmailAddress($email));
         if ($emailOwner instanceof User) {
             $origins = $emailOwner->getEmailOrigins()->filter(function ($item) use($organization) {
                 return $item instanceof InternalEmailOrigin && (!$organization || $item->getOrganization() === $organization);
             });
             $origin = $origins->isEmpty() ? null : $origins->first();
             if ($origin === null) {
                 $origin = $this->createUserInternalOrigin($emailOwner, $organization);
             }
         } else {
             $origin = $this->getEntityManager()->getRepository('OroEmailBundle:InternalEmailOrigin')->findOneBy(['internalName' => $originName]);
         }
         $this->origins[$originKey] = $origin;
     }
     return $this->origins[$originKey];
 }
 /**
  * Get current organization
  *
  * @return Organization
  */
 public function getOrganization()
 {
     return $this->securityFacade->getOrganization();
 }
Esempio n. 21
0
 /**
  * Find EmilUser User logged in system
  *
  * @param Email $entity - entity Email
  *
  * @return EmailUser[]
  */
 protected function getCurrentEmailUser(Email $entity)
 {
     $user = $this->securityFacade->getToken()->getUser();
     $currentOrganization = $this->securityFacade->getOrganization();
     return array_merge($this->getEmailUserRepository()->findByEmailAndOwner($entity, $user, $currentOrganization), $this->getEmailUserRepository()->findByEmailForMailbox($entity));
 }
Esempio n. 22
0
 /**
  * @return Organization|null
  */
 protected function getOrganization()
 {
     return $this->securityFacade->getOrganization();
 }
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(['selectedEntity' => Email::ENTITY_CLASS, 'query_builder' => function (EmailTemplateRepository $repository) {
         return $repository->getEntityTemplatesQueryBuilder(Email::ENTITY_CLASS, $this->securityFacade->getOrganization(), true);
     }, 'configs' => ['allowClear' => true, 'placeholder' => 'oro.form.custom_value']]);
 }
 /**
  * @return Mailbox[]
  */
 protected function getMailboxes()
 {
     $repo = $this->doctrine->getRepository(self::EMAIL_MAILBOX);
     /** @var Mailbox[] $systemMailboxes */
     return $repo->findAvailableMailboxes($this->securityFacade->getLoggedUser(), $this->securityFacade->getOrganization());
 }
 /**
  * Create Ticket
  * @param CreateTicketCommand $command
  * @return \Diamante\DeskBundle\Model\Ticket\Ticket
  * @throws \RuntimeException if unable to load required branch, reporter, assignee
  */
 public function createTicket(CreateTicketCommand $command)
 {
     $this->isGranted('CREATE', 'Entity:DiamanteDeskBundle:Ticket');
     \Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput');
     $this->ticketBuilder->setSubject($command->subject)->setDescription($command->description)->setBranchId($command->branch)->setReporter($command->reporter)->setAssigneeId($command->assignee)->setPriority($command->priority)->setSource($command->source)->setStatus($command->status)->setTags($command->tags);
     $ticket = $this->ticketBuilder->build();
     if (is_array($command->attachmentsInput) && false === empty($command->attachmentsInput)) {
         foreach ($command->attachmentsInput as $each) {
             $this->attachmentManager->createNewAttachment($each->getFilename(), $each->getContent(), $ticket);
         }
     }
     $this->ticketRepository->store($ticket);
     if ($this->securityFacade->getOrganization()) {
         $this->tagManager->saveTagging($ticket);
     }
     $this->em->detach($ticket);
     $this->dispatchEvents($ticket);
     return $ticket;
 }