private function doDeliverPermalink(Request $request, $sbas_id, $record_id, $token, $subdef) { $databox = $this->getDatabox($sbas_id); $record = $this->retrieveRecord($databox, $token, $record_id, $subdef); $watermark = $stamp = false; if ($this->authentication->isAuthenticated()) { $watermark = !$this->acl->get($this->authentication->getUser())->has_right_on_base($record->get_base_id(), 'nowatermark'); if ($watermark) { /** @var BasketElementRepository $repository */ $repository = $this->app['repo.basket-elements']; if (count($repository->findReceivedValidationElementsByRecord($record, $this->authentication->getUser())) > 0) { $watermark = false; } elseif (count($repository->findReceivedElementsByRecord($record, $this->authentication->getUser())) > 0) { $watermark = false; } } return $this->deliverContentWithCaptionLink($request, $record, $subdef, $watermark, $stamp, $token); } $collection = \collection::get_from_base_id($this->app, $record->get_base_id()); switch ($collection->get_pub_wm()) { default: case 'none': $watermark = false; break; case 'stamp': $stamp = true; break; case 'wm': $watermark = true; break; } return $this->deliverContentWithCaptionLink($request, $record, $subdef, $watermark, $stamp, $token); }
/** * @param string $login * @return User */ private function getUserOrCurrentUser($login = null) { if ($login !== null) { $user = $this->userRepository->findByLogin($login); if (!$user) { throw new AccountException('User not found'); } } else { $user = $this->authenticationService->getUser(); } return $user; }
public function getAction(Request $request, $sbas_id, $record_id, $subdef) { $databox = $this->appbox->get_databox((int) $sbas_id); $record = new \record_adapter($this->app, $sbas_id, $record_id); $stamp = $watermark = false; if ($subdef != 'thumbnail') { $all_access = false; $subdefStruct = $databox->get_subdef_structure(); if ($subdefStruct->getSubdefGroup($record->get_type())) { foreach ($subdefStruct->getSubdefGroup($record->get_type()) as $subdefObj) { /** @var \databox_subdef $subdefObj */ if ($subdefObj->get_name() == $subdef) { if ($subdefObj->get_class() == 'thumbnail') { $all_access = true; } break; } } } if (!$record->has_subdef($subdef) || !$record->get_subdef($subdef)->is_physically_present()) { throw new NotFoundHttpException(); } if (!$this->acl->get($this->authentication->getUser())->has_access_to_subdef($record, $subdef)) { throw new AccessDeniedHttpException(sprintf('User has not access to subdef %s', $subdef)); } $stamp = false; $watermark = !$this->acl->get($this->authentication->getUser())->has_right_on_base($record->get_base_id(), 'nowatermark'); if ($watermark && !$all_access) { $subdef_class = null; try { $subdef_class = $databox->get_subdef_structure()->get_subdef($record->get_type(), $subdef)->get_class(); } catch (\Exception_Databox_SubdefNotFound $e) { } if ($subdef_class == \databox_subdef::CLASS_PREVIEW && $this->acl->get($this->authentication->getUser())->has_preview_grant($record)) { $watermark = false; } elseif ($subdef_class == \databox_subdef::CLASS_DOCUMENT && $this->acl->get($this->authentication->getUser())->has_hd_grant($record)) { $watermark = false; } } if ($watermark && !$all_access) { $repository = $this->app['repo.basket-elements']; $ValidationByRecord = $repository->findReceivedValidationElementsByRecord($record, $this->authentication->getUser()); $ReceptionByRecord = $repository->findReceivedElementsByRecord($record, $this->authentication->getUser()); if ($ValidationByRecord && count($ValidationByRecord) > 0) { $watermark = false; } elseif ($ReceptionByRecord && count($ReceptionByRecord) > 0) { $watermark = false; } } } return $this->deliverContent($request, $record, $subdef, $watermark, $stamp); }
/** * @covers Alchemy\Phrasea\Authentication\Authenticator::isAuthenticated */ public function testIsAuthenticated() { $app = $this->loadApp(); $sessionEntity = new Session(); $sessionEntity->setUser(self::$DI['user']); $sessionEntity->setUserAgent(''); $app['browser'] = $browser = $this->getBrowserMock(); $app['session'] = $session = $this->getSessionMock(); $app['EM'] = $em = $this->getEntityManagerMock(); $app['EM']->expects($this->any())->method('find')->with($this->equalTo('Phraseanet:Session'), $this->equalTo(1))->will($this->returnValue($sessionEntity)); $userRepository = $this->getMockBuilder('Alchemy\\Phrasea\\Model\\Repositories\\UserRepository')->disableOriginalConstructor()->getMock(); $userRepository->expects($this->once())->method('find')->with($this->equalTo(self::$DI['user']->getId()))->will($this->returnValue(self::$DI['user'])); $app['manipulator.user'] = $this->getMockBuilder('Alchemy\\Phrasea\\Model\\Manipulator\\UserManipulator')->disableOriginalConstructor()->getMock(); $app['manipulator.user']->expects($this->once())->method('getRepository')->will($this->returnValue($userRepository)); $session->set('usr_id', self::$DI['user']->getId()); $session->set('session_id', 1); $authenticator = new Authenticator($app, $browser, $session, $app['EM']); $this->assertTrue($authenticator->isAuthenticated()); $this->assertEquals(self::$DI['user'], $authenticator->getUser()); }