/** * {@inheritdoc} */ public function checkPermissions($entity, ObjectManager $em) { $loggedUserId = $this->securityFacade->getLoggedUserId(); if ($loggedUserId && $loggedUserId == $entity->getId()) { throw new ForbiddenException('self delete'); } }
/** * 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; }
/** * @param bool $isOn */ protected function onMode($isOn) { $userId = $this->securityFacade->getLoggedUserId(); try { $this->publisher->send('oro/maintenance', array('isOn' => (bool) $isOn, 'userId' => $userId)); } catch (\Exception $e) { $this->logger->error($e->getMessage()); } }
/** * {@inheritdoc} */ protected function checkPermissions($entity, ObjectManager $em) { $loggedUserId = $this->securityFacade->getLoggedUserId(); if ($loggedUserId && $loggedUserId == $entity->getId()) { throw new ForbiddenException('self delete'); } if ($this->securityFacade->hasUserSidSharedRecords($entity)) { throw new ForbiddenException('user has shared records'); } parent::checkPermissions($entity, $em); }
/** * Gets a list of user's calendars for which it is granted to add events * * @return array of [id, name] */ public function getUserCalendars() { /** @var CalendarRepository $repo */ $repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:Calendar'); $calendars = $repo->getUserCalendarsQueryBuilder($this->securityFacade->getOrganizationId(), $this->securityFacade->getLoggedUserId())->select('c.id, c.name')->getQuery()->getArrayResult(); foreach ($calendars as &$calendar) { if (empty($calendar['name'])) { $calendar['name'] = $this->entityNameResolver->getName($this->securityFacade->getLoggedUser()); } } return $calendars; }
/** * @param BuildAfter $event */ public function onBuildAfter(BuildAfter $event) { $datagrid = $event->getDatagrid(); $datasource = $datagrid->getDatasource(); if ($datasource instanceof OrmDatasource) { $parameters = $datagrid->getParameters(); $userId = $parameters->get('userId'); if (!$userId) { $userId = $this->securityFacade->getLoggedUserId(); } $datasource->getQueryBuilder()->andWhere(sprintf('task.owner = %d', $userId)); } }
/** * {@inheritdoc} */ protected function searchIds($search, $firstResult, $maxResults) { $userIds = parent::searchIds($search, $firstResult, $maxResults + 1); $excludedKey = null; $currentUserId = $this->securityFacade->getLoggedUserId(); if ($currentUserId) { $excludedKey = array_search($currentUserId, $userIds); } if (false !== $excludedKey) { unset($userIds[$excludedKey]); $userIds = array_values($userIds); } else { $userIds = array_slice($userIds, 0, $maxResults); } return $userIds; }
/** * Process form * * @param CalendarEvent $entity * * @throws \LogicException * * @return bool True on successful processing, false otherwise */ public function process(CalendarEvent $entity) { $this->form->setData($entity); if (in_array($this->request->getMethod(), array('POST', 'PUT'))) { $originalChildren = new ArrayCollection(); foreach ($entity->getChildEvents() as $childEvent) { $originalChildren->add($childEvent); } $this->form->submit($this->request); if ($this->form->isValid()) { $this->ensureCalendarSet($entity); $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, $originalChildren, $this->form->get('notifyInvitedUsers')->getData()); return true; } } return false; }
public function onModeOff() { $userId = $this->securityFacade->getLoggedUserId(); $this->publisher->send('oro/maintenance', array('isOn' => false, 'userId' => $userId)); }
/** * Returns query builder that uses to build query for search bu id or by search string. * Result data limit by users that was have access to the current organization and excluding current user. * * @return QueryBuilder */ protected function getBasicQueryBuilder() { $queryBuilder = $this->entityRepository->createQueryBuilder('u'); $queryBuilder->join('u.organizations', 'org')->andWhere('org.id = :org')->andWhere('u.id != :currentUser')->setParameter('org', $this->securityFacade->getOrganizationId())->setParameter('currentUser', $this->securityFacade->getLoggedUserId()); return $queryBuilder; }