mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-08 10:34:34 +00:00
Refactor && Typo && Use plain objects as function parameters instead of ids
This commit is contained in:
@@ -96,10 +96,9 @@ class RegenerateSqliteDb extends Command
|
||||
$this->insertOneAggregateToken($this->container['EM'], $DI);
|
||||
$this->insertLazaretFiles($this->container['EM'], $DI);
|
||||
$this->insertAuthFailures($this->container['EM'], $DI);
|
||||
$this->insertOneRegistration($this->container['EM'],$DI['user_alt1'], $DI['coll']);
|
||||
$this->insertOneRegistration($this->container['EM'],$DI['user_alt2'], $DI['coll'], '-3 months');
|
||||
$this->insertOneRegistration($this->container['EM'],$DI['user_alt2'], $DI['coll']);
|
||||
|
||||
$this->insertOneRegistration($DI, $this->container['EM'], $DI['user_alt1'], $DI['coll'], 'now', 'registration_1');
|
||||
$this->insertOneRegistration($DI, $this->container['EM'], $DI['user_alt2'], $DI['coll'], '-3 months', 'registration_2');
|
||||
$this->insertOneRegistration($DI, $this->container['EM'], $DI['user_notAdmin'], $DI['coll'], 'now', 'registration_3');
|
||||
|
||||
$fixtures['user']['test_phpunit'] = $DI['user']->getId();
|
||||
$fixtures['user']['test_phpunit_not_admin'] = $DI['user_notAdmin']->getId();
|
||||
@@ -127,6 +126,10 @@ class RegenerateSqliteDb extends Command
|
||||
$fixtures['record']['record_6'] = $DI['record_6']->get_record_id();
|
||||
$fixtures['record']['record_7'] = $DI['record_7']->get_record_id();
|
||||
|
||||
$fixtures['registrations']['registration_1'] = $DI['registration_1']->getId();
|
||||
$fixtures['registrations']['registration_2'] = $DI['registration_2']->getId();
|
||||
$fixtures['registrations']['registration_3'] = $DI['registration_3']->getId();
|
||||
|
||||
$fixtures['lazaret']['lazaret_1'] = $DI['lazaret_1']->getId();
|
||||
|
||||
$fixtures['user']['user_1'] = $DI['user_1']->getId();
|
||||
@@ -644,16 +647,18 @@ class RegenerateSqliteDb extends Command
|
||||
$em->persist($entry);
|
||||
}
|
||||
|
||||
private function insertOneRegistration(EntityManager $em, \User_Adapter $user, \collection $collection, $when = 'now')
|
||||
private function insertOneRegistration(\Pimple $DI, EntityManager $em, User $user, \collection $collection, $when, $name)
|
||||
{
|
||||
$em->getEventManager()->removeEventSubscriber(new TimestampableListener());
|
||||
$registration = new Registration();
|
||||
$registration->setBaseId($collection->get_base_id());
|
||||
$registration->setUser($user->get_id());
|
||||
$registration->setCollection($collection);
|
||||
$registration->setUser($user);
|
||||
$registration->setUpdated(new \DateTime($when));
|
||||
$registration->setCreated(new \DateTime($when));
|
||||
$em->persist($registration);
|
||||
$em->flush();
|
||||
$em->getEventManager()->addEventSubscriber(new TimestampableListener());
|
||||
|
||||
$DI[$name] = $registration;
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,6 @@ namespace Alchemy\Phrasea\Controller\Admin;
|
||||
use Alchemy\Phrasea\Helper\User as UserHelper;
|
||||
use Alchemy\Phrasea\Model\Entities\FtpCredential;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use igorw;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -354,44 +353,41 @@ class Users implements ControllerProviderInterface
|
||||
return $response;
|
||||
})->bind('admin_users_export_csv');
|
||||
|
||||
$controllers->get('/demands/', function (Application $app) {
|
||||
$controllers->get('/registrations/', function (Application $app) {
|
||||
$app['manipulator.registration']->deleteOldRegistrations();
|
||||
|
||||
$models = $app['manipulator.user']->getRepository()->findModelOf($app['authentication']->getUser());
|
||||
|
||||
$users = $registrations = [];
|
||||
foreach ($app['manipulator.registration']->getRepository()->getDemandsForUser(
|
||||
$userRegistrations = [];
|
||||
foreach ($app['manipulator.registration']->getRepository()->getUserRegistrations(
|
||||
$app['authentication']->getUser(),
|
||||
array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_base(['canadmin']))
|
||||
$app['acl']->get($app['authentication']->getUser())->get_granted_base(['canadmin'])
|
||||
) as $registration) {
|
||||
$user = $registration->getUser();
|
||||
$users[$user->getId()] = $user;
|
||||
|
||||
|
||||
if (null !== igorw::get_in($registrations, [$user->getId(), $registration->getBaseId()])) {
|
||||
$registrations[$user->getId()][$registration->getBaseId()] = $registration;
|
||||
}
|
||||
$userRegistrations[$user->getId()]['user'] = $user;
|
||||
$userRegistrations[$user->getId()]['registrations'][$registration->getBaseid()] = $registration;
|
||||
}
|
||||
|
||||
return $app['twig']->render('admin/user/demand.html.twig', [
|
||||
'users' => $users,
|
||||
'registrations' => $registrations,
|
||||
return $app['twig']->render('admin/user/registrations.html.twig', [
|
||||
'user_registrations' => $userRegistrations,
|
||||
'models' => $models,
|
||||
]);
|
||||
})->bind('users_display_demands');
|
||||
})->bind('users_display_registrations');
|
||||
|
||||
$controllers->post('/demands/', function (Application $app, Request $request) {
|
||||
$controllers->post('/registrations/', function (Application $app, Request $request) {
|
||||
$templates = $deny = $accept = $options = [];
|
||||
|
||||
foreach ($request->request->get('template', []) as $tmp) {
|
||||
if (trim($tmp) != '') {
|
||||
if ('' === trim($tmp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tmp = explode('_', $tmp);
|
||||
|
||||
if (count($tmp) == 2) {
|
||||
$templates[$tmp[0]] = $tmp[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($request->request->get('deny', []) as $den) {
|
||||
$den = explode('_', $den);
|
||||
@@ -423,71 +419,83 @@ class Users implements ControllerProviderInterface
|
||||
}
|
||||
|
||||
if (count($templates) > 0 || count($deny) > 0 || count($accept) > 0) {
|
||||
$done = [];
|
||||
$cache_to_update = [];
|
||||
$cacheToUpdate = $done = [];
|
||||
|
||||
foreach ($templates as $usr => $template_id) {
|
||||
$user = $app['manipulator.user']->getRepository()->find($usr);
|
||||
$cache_to_update[$usr] = true;
|
||||
if (null === $user = $app['manipulator.user']->getRepository()->find($usr)) {
|
||||
$app->abort(400, srpintf("User with id % in provided in 'template' request variable could not be found", $usr));
|
||||
}
|
||||
$cacheToUpdate[$usr] = $user;
|
||||
|
||||
$user_template = $app['manipulator.user']->getRepository()->find($template_id);
|
||||
$base_ids = array_keys($app['acl']->get($user_template)->get_granted_base());
|
||||
$collections = $app['acl']->get($user_template)->get_granted_base();
|
||||
$baseIds = array_keys($collections);
|
||||
|
||||
$app['acl']->get($user)->apply_model($user_template, $base_ids);
|
||||
$app['acl']->get($user)->apply_model($user_template, $baseIds);
|
||||
|
||||
foreach ($base_ids as $base_id) {
|
||||
$done[$usr][$base_id] = true;
|
||||
foreach ($collections as $collection) {
|
||||
$done[$usr][$collection->get_base_id()] = true;
|
||||
}
|
||||
|
||||
$app['manipulator.registration']->deleteRegistrationsForUser($user->get_id(), $base_ids);
|
||||
$app['manipulator.registration']->deleteUserRegistrations($user, $collections);
|
||||
}
|
||||
|
||||
foreach ($deny as $usr => $bases) {
|
||||
$cache_to_update[$usr] = true;
|
||||
foreach ($bases as $bas) {
|
||||
if (null !== $registration = $app['manipulator.registration']->getRepository()->findOneBy([
|
||||
'user' => $usr,
|
||||
'baseId' => $bas
|
||||
])) {
|
||||
$app['manipulator.registration']->rejectDemand($registration);
|
||||
$done[$usr][$bas] = false;
|
||||
if (null === $user = $app['manipulator.user']->getRepository()->find($usr)) {
|
||||
$app->abort(400, srpintf("User with id % in provided in 'deny' request variable could not be found", $usr));
|
||||
}
|
||||
$cacheToUpdate[$usr] = $user;
|
||||
foreach ($app['manipulator.registration']->getRepository()->getUserRegistrations(
|
||||
$user,
|
||||
array_map(function ($baseId) use ($app) {
|
||||
return \collection::get_from_base_id($app, $baseId);
|
||||
}, $bases)
|
||||
) as $registration) {
|
||||
$app['manipulator.registration']->rejectRegistration($registration);
|
||||
$done[$usr][$registration->getBaseId()] = false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($accept as $usr => $bases) {
|
||||
$user = $app['manipulator.user']->getRepository()->find($usr);
|
||||
$cache_to_update[$usr] = true;
|
||||
|
||||
foreach ($bases as $bas) {
|
||||
$collection = \collection::get_from_base_id($app, $bas);
|
||||
if (null !== $registration = $app['manipulator.registration']->getRepository()->findOneBy([
|
||||
'user' => $user->get_id(),
|
||||
'baseId' => $collection->get_base_id()
|
||||
])) {
|
||||
$done[$usr][$bas] = true;
|
||||
$app['manipulator.registration']->acceptRegistration($registration, $user, $collection, $options[$usr][$bas]['HD'], $options[$usr][$bas]['WM']);
|
||||
if (null === $user = $app['manipulator.user']->getRepository()->find($usr)) {
|
||||
$app->abort(400, srpintf("User with id % in provided in 'accept' request variable could not be found", $usr));
|
||||
}
|
||||
$cacheToUpdate[$usr] = $user;
|
||||
foreach ($app['manipulator.registration']->getRepository()->getUserRegistrations(
|
||||
$user,
|
||||
array_map(function ($baseId) use ($app) {
|
||||
return \collection::get_from_base_id($app, $baseId);
|
||||
}, $bases)
|
||||
) as $registration) {
|
||||
$done[$usr][$registration->getBaseId()] = true;
|
||||
$app['manipulator.registration']->acceptRegistration(
|
||||
$registration,
|
||||
$options[$usr][$registration->getBaseId()]['HD'],
|
||||
$options[$usr][$registration->getBaseId()]['WM']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array_keys($cache_to_update) as $usr_id) {
|
||||
$user = $app['manipulator.user']->getRepository()->find($usr_id);
|
||||
array_walk($cacheToUpdate, function (User $user) use ($app) {
|
||||
$app['acl']->get($user)->delete_data_from_cache();
|
||||
unset($user);
|
||||
}
|
||||
});
|
||||
unset ($cacheToUpdate);
|
||||
|
||||
foreach ($done as $usr => $bases) {
|
||||
$user = $app['manipulator.user']->getRepository()->find($usr);
|
||||
$acceptColl = $denyColl = [];
|
||||
if (null !== $user = $app['manipulator.user']->getRepository()->find($usr)) {
|
||||
if (\Swift_Validate::email($user->getEmail())) {
|
||||
|
||||
foreach ($bases as $bas => $isok) {
|
||||
$collection = \collection::get_from_base_id($app, $bas);
|
||||
|
||||
if ($isok) {
|
||||
$acceptColl[] = \phrasea::bas_labels($bas, $app);
|
||||
} else {
|
||||
$denyColl[] = \phrasea::bas_labels($bas, $app);
|
||||
$acceptColl[] = $collection->get_label($app['locale']);
|
||||
continue;
|
||||
}
|
||||
|
||||
$denyColl[] = $collection->get_label($app['locale']);
|
||||
}
|
||||
|
||||
if (0 !== count($acceptColl) || 0 !== count($denyColl)) {
|
||||
$message = '';
|
||||
if (0 !== count($acceptColl)) {
|
||||
@@ -504,11 +512,9 @@ class Users implements ControllerProviderInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $app->redirectPath('users_display_demands', ['success' => 1]);
|
||||
})->bind('users_submit_demands');
|
||||
return $app->redirectPath('users_display_registrations', ['success' => 1]);
|
||||
})->bind('users_submit_registrations');
|
||||
|
||||
$controllers->get('/import/file/', function (Application $app, Request $request) {
|
||||
return $app['twig']->render('admin/user/import/file.html.twig');
|
||||
|
@@ -92,11 +92,11 @@ class Lazaret implements ControllerProviderInterface
|
||||
$lazaretFiles = $lazaretRepository->findPerPage($baseIds, $offset, $perPage);
|
||||
}
|
||||
|
||||
return $app['twig']->render('prod/upload/lazaret.html.twig', array(
|
||||
return $app['twig']->render('prod/upload/lazaret.html.twig', [
|
||||
'lazaretFiles' => $lazaretFiles,
|
||||
'currentPage' => $page,
|
||||
'perPage' => $perPage,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -232,7 +232,7 @@ class Account implements ControllerProviderInterface
|
||||
public function accountAccess(Application $app, Request $request)
|
||||
{
|
||||
return $app['twig']->render('account/access.html.twig', [
|
||||
'inscriptions' => $app['manipulator.registration']->getRegistrationSummary($app['authentication']->getUser()->getId())
|
||||
'inscriptions' => $app['registration.manager']->getRegistrationSummary($app['authentication']->getUser())
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -326,13 +326,13 @@ class Account implements ControllerProviderInterface
|
||||
*/
|
||||
public function updateAccount(PhraseaApplication $app, Request $request)
|
||||
{
|
||||
$demands = $request->request->get('demand');
|
||||
if (false === is_array($demands)) {
|
||||
$app->abort(400, '"demand" parameter must be an array of base id ');
|
||||
$registrations = $request->request->get('registrations');
|
||||
if (false === is_array($registrations)) {
|
||||
$app->abort(400, '"registrations" parameter must be an array of base ids.');
|
||||
}
|
||||
if (0 !== count($demands)) {
|
||||
foreach ($demands as $baseId) {
|
||||
$app['registration-manager']->createRegistration($app['authentication']->getUser()->get_id(), $baseId);
|
||||
if (0 !== count($registrations)) {
|
||||
foreach ($registrations as $baseId) {
|
||||
$app['manipulator.registration']->createRegistration($app['authentication']->getUser(), \collection::get_from_base_id($app, $baseId));
|
||||
}
|
||||
$app->addFlash('success', $app->trans('Your registration requests have been taken into account.'));
|
||||
}
|
||||
|
@@ -335,7 +335,7 @@ class Login implements ControllerProviderInterface
|
||||
} else {
|
||||
$selected = isset($data['collections']) ? $data['collections'] : null;
|
||||
}
|
||||
$inscriptions = $app['manipulator.registration']->getRegistrationSummary();
|
||||
$inscriptions = $app['registration.manager']->getRegistrationSummary();
|
||||
$inscOK = [];
|
||||
|
||||
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
@@ -385,33 +385,25 @@ class Login implements ControllerProviderInterface
|
||||
$app['EM']->flush();
|
||||
}
|
||||
|
||||
$demandOK = [];
|
||||
|
||||
$registrationsOK = [];
|
||||
if ($app['conf']->get(['registry', 'registration', 'auto-register-enabled'])) {
|
||||
$template_user = $app['manipulator.user']->getRepository()->findByLogin(User::USER_AUTOREGISTER);
|
||||
|
||||
$base_ids = [];
|
||||
|
||||
foreach (array_keys($inscOK) as $base_id) {
|
||||
$base_ids[] = $base_id;
|
||||
}
|
||||
|
||||
$app['acl']->get($user)->apply_model($template_user, $base_ids);
|
||||
$app['acl']->get($user)->apply_model($template_user, array_keys($inscOK));
|
||||
}
|
||||
|
||||
$autoReg = $app['acl']->get($user)->get_granted_base();
|
||||
|
||||
foreach ($inscOK as $base_id => $autorisation) {
|
||||
if (false === $autorisation || $app['acl']->get($user)->has_access_to_base($base_id)) {
|
||||
foreach ($inscOK as $baseId => $authorization) {
|
||||
if (false === $authorization || $app['acl']->get($user)->has_access_to_base($baseId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$app['manipulator.registration']->createRegistration($user->getId(), $base_id);
|
||||
$demandOK[$base_id] = true;
|
||||
$app['manipulator.registration']->createRegistration($user, \collection::get_from_base_id($app, $baseId));
|
||||
$registrationsOK[$baseId] = true;
|
||||
}
|
||||
|
||||
$params = [
|
||||
'demand' => $demandOK,
|
||||
'registrations'=> $registrationsOK,
|
||||
'autoregister' => $autoReg,
|
||||
'usr_id' => $user->getId()
|
||||
];
|
||||
|
204
lib/Alchemy/Phrasea/Core/Configuration/RegistrationManager.php
Normal file
204
lib/Alchemy/Phrasea/Core/Configuration/RegistrationManager.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Configuration;
|
||||
|
||||
use Alchemy\Phrasea\Model\Repositories\RegistrationRepository;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use igorw;
|
||||
|
||||
class RegistrationManager
|
||||
{
|
||||
/** @var \appbox */
|
||||
private $appbox;
|
||||
private $repository;
|
||||
|
||||
public function __construct(\appbox $appbox, RegistrationRepository $repository, $locale)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->repository = $repository;
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether registration is enabled or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isRegistrationEnabled()
|
||||
{
|
||||
foreach ($this->appbox->get_databoxes() as $databox) {
|
||||
foreach ($databox->get_collections() as $collection) {
|
||||
if ($collection->isRegistrationEnabled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about registration configuration and registration status if a user id is provided.
|
||||
*
|
||||
* @param null|user $user
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRegistrationSummary(User $user = null)
|
||||
{
|
||||
$data = $userData = [];
|
||||
|
||||
// Gets user data
|
||||
if (null !== $user) {
|
||||
$userData = $this->repository->getRegistrationsSummaryForUser($user);
|
||||
}
|
||||
|
||||
foreach ($this->appbox->get_databoxes() as $databox) {
|
||||
$data[$databox->get_sbas_id()] = [
|
||||
// Registrations on databox by type
|
||||
'registrations' => [
|
||||
'by-type' => [
|
||||
'inactive' => [],
|
||||
'accepted' => [],
|
||||
'in-time' => [],
|
||||
'out-dated' => [],
|
||||
'pending' => [],
|
||||
'rejected' => [],
|
||||
]
|
||||
],
|
||||
// Registration configuration on databox and collections that belong to the databox
|
||||
'config' => [
|
||||
'db-name' => $databox->get_dbname(),
|
||||
'cgu' => $databox->get_cgus(),
|
||||
'can-register' => $databox->isRegistrationEnabled(),
|
||||
// Configuration on collection
|
||||
'collections' => [],
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($databox->get_collections() as $collection) {
|
||||
// Sets collection info
|
||||
$data[$databox->get_sbas_id()]['config']['collections'][$collection->get_base_id()] = $this->getCollectionSummary($collection, $userData);
|
||||
// Sets registration by type
|
||||
if (null !== $registration = $this->getUserCollectionRegistration($collection, $userData)) {
|
||||
$data[$databox->get_sbas_id()]['registrations']['by-type'][$registration['type']][] = $registration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether user has ever requested a registration on collection or not.
|
||||
*
|
||||
* @param \collection $collection
|
||||
* @param $userData
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function userHasRequestedARegistrationOnCollection(\collection $collection, $userData)
|
||||
{
|
||||
if (null === $userRegistration = igorw\get_in($userData, [$collection->get_sbas_id(), $collection->get_base_id()])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !is_null($userRegistration['active']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a user registration for given collection or null if no registration were requested.
|
||||
*
|
||||
* @param \collection $collection
|
||||
* @param $userData
|
||||
*
|
||||
* @return null|array
|
||||
*/
|
||||
private function getUserCollectionRegistration(\collection $collection, $userData)
|
||||
{
|
||||
if (false === $this->userHasRequestedARegistrationOnCollection($collection, $userData)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$userRegistration = igorw\get_in($userData, [$collection->get_sbas_id(), $collection->get_base_id()]);
|
||||
|
||||
// sets collection name
|
||||
$userRegistration['coll-name'] = $collection->get_label($this->locale);
|
||||
// sets default type
|
||||
$userRegistration['type'] = 'active';
|
||||
|
||||
// gets registration entity
|
||||
$registration = $userRegistration['registration'];
|
||||
|
||||
// set registration type & return user registration
|
||||
$registrationStillExists = !is_null($registration);
|
||||
$registrationNoMoreExists = !$registrationStillExists;
|
||||
$isPending = $registrationStillExists && $registration->isPending() && !$registration->isRejected();
|
||||
$isRejected = $registrationStillExists && $registration->isRejected();
|
||||
$isDone = ($registrationNoMoreExists) || (!$isPending && !$isRejected);
|
||||
$isActive = (Boolean) $userRegistration['active'];
|
||||
$isTimeLimited = (Boolean) $userRegistration['time-limited'];
|
||||
$isNotTimeLimited = !$isTimeLimited;
|
||||
$isOnTime = (Boolean) $userRegistration['in-time'];
|
||||
$isOutDated = !$isOnTime;
|
||||
|
||||
if (!$isActive) {
|
||||
$userRegistration['type'] = 'inactive';
|
||||
|
||||
return $userRegistration;
|
||||
}
|
||||
|
||||
if ($isDone) {
|
||||
$userRegistration['type'] = 'accepted';
|
||||
|
||||
return $userRegistration;
|
||||
}
|
||||
|
||||
if ($isRejected) {
|
||||
$userRegistration['type'] = 'rejected';
|
||||
|
||||
return $userRegistration;
|
||||
}
|
||||
|
||||
if ($isTimeLimited && $isOnTime && $isPending) {
|
||||
$userRegistration['type'] = 'in-time';
|
||||
|
||||
return $userRegistration;
|
||||
}
|
||||
|
||||
if ($isTimeLimited && $isOutDated && $isPending) {
|
||||
$userRegistration['type'] = 'out-time';
|
||||
|
||||
return $userRegistration;
|
||||
}
|
||||
|
||||
if ($isNotTimeLimited && $isPending) {
|
||||
$userRegistration['type'] = 'pending';
|
||||
|
||||
return $userRegistration;
|
||||
}
|
||||
|
||||
return $userRegistration;
|
||||
}
|
||||
|
||||
private function getCollectionSummary(\collection $collection, $userData)
|
||||
{
|
||||
return [
|
||||
'coll-name' => $collection->get_label($this->locale),
|
||||
// gets collection registration or fallback to databox configuration
|
||||
'can-register' => $collection->isRegistrationEnabled(),
|
||||
'cgu' => $collection->getTermsOfUse(),
|
||||
// boolean to tell whether user has already requested an access to the collection
|
||||
'registration' => $this->userHasRequestedARegistrationOnCollection($collection, $userData)
|
||||
];
|
||||
}
|
||||
}
|
@@ -40,7 +40,7 @@ class ManipulatorServiceProvider implements ServiceProviderInterface
|
||||
});
|
||||
|
||||
$app['manipulator.registration'] = $app->share(function ($app) {
|
||||
return new RegistrationManipulator($app['EM'], $app['phraseanet.appbox'], $app['acl']);
|
||||
return new RegistrationManipulator($app, $app['EM'], $app['acl'], $app['phraseanet.appbox']);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -12,8 +12,8 @@
|
||||
namespace Alchemy\Phrasea\Core\Provider;
|
||||
|
||||
use Alchemy\Phrasea\Form\Constraint\NewLogin;
|
||||
use Alchemy\Phrasea\Model\Manipulator\RegistrationManipulator;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\Phrasea\Core\Configuration\RegistrationManager;
|
||||
use Silex\Application;
|
||||
use Silex\ServiceProviderInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
@@ -27,7 +27,7 @@ class RegistrationServiceProvider implements ServiceProviderInterface
|
||||
});
|
||||
|
||||
$app['registration.manager'] = $app->share(function (Application $app) {
|
||||
return new RegistrationManager($app['phraseanet.appbox']);
|
||||
return new RegistrationManager($app['phraseanet.appbox'], $app['manipulator.registration']->getRepository(), $app['locale']);
|
||||
});
|
||||
|
||||
$app['registration.optional-fields'] = $app->share(function (Application $app) {
|
||||
|
@@ -13,7 +13,7 @@ namespace Alchemy\Phrasea\Core;
|
||||
|
||||
class Version
|
||||
{
|
||||
protected static $number = '3.9.0-alpha.12';
|
||||
protected static $number = '3.9.0-alpha.13';
|
||||
protected static $name = 'Epanterias';
|
||||
|
||||
public static function getNumber()
|
||||
|
@@ -72,16 +72,15 @@ class PhraseaRegisterForm extends AbstractType
|
||||
|
||||
$builder->add('provider-id', 'hidden');
|
||||
|
||||
$choices = [];
|
||||
$baseIds = [];
|
||||
$choices = $baseIds = [];
|
||||
|
||||
foreach ($this->app['manipulator.registration']->getRegistrationSummary() as $baseInfo) {
|
||||
foreach ($this->app['registration.manager']->getRegistrationSummary() as $baseInfo) {
|
||||
$dbName = $baseInfo['config']['db-name'];
|
||||
foreach ($baseInfo['config']['collections'] as $baseId => $collInfo) {
|
||||
if (false === $collInfo['can-register']) {
|
||||
continue;
|
||||
}
|
||||
$choices[$dbName][$baseId] = \phrasea::bas_labels($baseId, $this->app);
|
||||
$choices[$dbName][$baseId] = $collInfo['coll-name'];
|
||||
$baseIds[] = $baseId;
|
||||
}
|
||||
}
|
||||
|
@@ -11,11 +11,14 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Model\Entities;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
|
||||
/**
|
||||
* @ORM\Table(name="Registration")
|
||||
* @ORM\Table(name="Registration",uniqueConstraints={
|
||||
* @ORM\UniqueConstraint(name="unique_registration", columns={"user_id","base_id","pending"})
|
||||
* })
|
||||
* @ORM\Entity(repositoryClass="Alchemy\Phrasea\Model\Repositories\RegistrationRepository")
|
||||
*/
|
||||
class Registration
|
||||
@@ -28,8 +31,11 @@ class Registration
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", name="user_id")
|
||||
*/
|
||||
* @ORM\ManyToOne(targetEntity="User")
|
||||
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
|
||||
*
|
||||
* @return User
|
||||
**/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
@@ -110,11 +116,9 @@ class Registration
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $user
|
||||
*
|
||||
* @return Registration
|
||||
*/
|
||||
public function setUser($user)
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
@@ -122,13 +126,35 @@ class Registration
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return integer
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
*
|
||||
* @return \collection
|
||||
*/
|
||||
public function getCollection(Application $app)
|
||||
{
|
||||
return \collection::get_from_base_id($app, $this->baseId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \collection $collection
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCollection(\collection $collection)
|
||||
{
|
||||
$this->baseId = $collection->get_base_id();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $baseId
|
||||
*
|
||||
|
@@ -11,40 +11,43 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Model\Manipulator;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Authentication\ACLProvider;
|
||||
use Alchemy\Phrasea\Model\Entities\Registration;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\Phrasea\Model\Repositories\RegistrationRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use igorw;
|
||||
|
||||
class RegistrationManipulator implements ManipulatorInterface
|
||||
{
|
||||
private $em;
|
||||
private $app;
|
||||
private $appbox;
|
||||
private $repository;
|
||||
private $aclProvider;
|
||||
|
||||
public function __construct(EntityManager $em, \appbox $appbox, ACLProvider $aclProvider)
|
||||
public function __construct(Application $app, EntityManager $em, ACLProvider $aclProvider, \appbox $appbox)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->em = $em;
|
||||
$this->appbox = $appbox;
|
||||
$this->repository = $this->em->getRepository('Alchemy\Phrasea\Model\Entities\Registration');
|
||||
$this->aclProvider = $aclProvider;
|
||||
$this->repository = $this->em->getRepository('Phraseanet:Registration');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new registration.
|
||||
*
|
||||
* @param $userId
|
||||
* @param $baseId
|
||||
* @param User $user
|
||||
* @param \collection $collection
|
||||
*
|
||||
* @return Registration
|
||||
*/
|
||||
public function createRegistration($userId, $baseId)
|
||||
public function createRegistration(User $user, \collection $collection)
|
||||
{
|
||||
$registration = new Registration();
|
||||
$registration->setUser($userId);
|
||||
$registration->setBaseId($baseId);
|
||||
$registration->setUser($user);
|
||||
$registration->setCollection($collection);
|
||||
$this->em->persist($registration);
|
||||
$this->em->flush();
|
||||
|
||||
@@ -68,13 +71,14 @@ class RegistrationManipulator implements ManipulatorInterface
|
||||
* Accepts a registration.
|
||||
*
|
||||
* @param Registration $registration
|
||||
* @param \User_Adapter $user
|
||||
* @param \Collection $collection
|
||||
* @param bool $grantHd
|
||||
* @param bool $grantWatermark
|
||||
*/
|
||||
public function acceptRegistration(Registration $registration, \User_Adapter $user, \Collection $collection, $grantHd = false, $grantWatermark = false)
|
||||
public function acceptRegistration(Registration $registration, $grantHd = false, $grantWatermark = false)
|
||||
{
|
||||
$user = $registration->getUser();
|
||||
$collection = $registration->getCollection($this->app);
|
||||
|
||||
$this->aclProvider->get($user)->give_access_to_sbas([$collection->get_sbas_id()]);
|
||||
$this->aclProvider->get($user)->give_access_to_base([$collection->get_base_id()]);
|
||||
$this->aclProvider->get($user)->update_rights_to_base($collection->get_base_id(), [
|
||||
@@ -88,117 +92,6 @@ class RegistrationManipulator implements ManipulatorInterface
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about registration configuration and registration status if a user id is provided.
|
||||
*
|
||||
* @param null|integer $userId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRegistrationSummary($userId = null)
|
||||
{
|
||||
$data = $userData = [];
|
||||
|
||||
if (null !== $userId) {
|
||||
$userData = $this->getRepository()->getRegistrationsSummaryForUser($userId);
|
||||
}
|
||||
|
||||
foreach ($this->appbox->get_databoxes() as $databox) {
|
||||
$ddata = [
|
||||
'registrations' => [
|
||||
'by-type' => [
|
||||
'inactive' => [],
|
||||
'accepted' => [],
|
||||
'in-time' => [],
|
||||
'out-dated' => [],
|
||||
'pending' => [],
|
||||
'rejected' => [],
|
||||
],
|
||||
'by-collection' => []
|
||||
],
|
||||
'config' => [
|
||||
'db-name' => $databox->get_dbname(),
|
||||
'cgu' => $databox->get_cgus(),
|
||||
'can-register' => $databox->isRegistrationEnabled(),
|
||||
'collections' => [],
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($databox->get_collections() as $collection) {
|
||||
// sets collection info
|
||||
$ddata['config']['collections'][$collection->get_base_id()] = [
|
||||
'coll-name' => $collection->get_name(),
|
||||
// gets collection registration or fallback to databox configuration
|
||||
'can-register' => $collection->isRegistrationEnabled(),
|
||||
'cgu' => $collection->getTermsOfUse(),
|
||||
'registration' => null
|
||||
];
|
||||
|
||||
if (null === $userRegistration = igorw\get_in($userData, [$databox->get_sbas_id(), $collection->get_base_id()])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// sets collection name
|
||||
$userRegistration['coll-name'] = $collection->get_name();
|
||||
// gets registration entity
|
||||
$registration = $userRegistration['registration'];
|
||||
|
||||
$noRegistrationMade = is_null($userRegistration['active']);
|
||||
$registrationMade = !$noRegistrationMade;
|
||||
$registrationStillExists = !is_null($registration);
|
||||
$registrationNoMoreExists = !$registrationStillExists;
|
||||
$isPending = $registrationStillExists && $registration->isPending() && !$registration->isRejected();
|
||||
$isRejected = $registrationStillExists && $registration->isRejected();
|
||||
$isDone = ($registrationNoMoreExists && $registrationMade) || (!$isPending && !$isRejected);
|
||||
$isActive = (Boolean) $userRegistration['active'];
|
||||
$isTimeLimited = (Boolean) $userRegistration['time-limited'];
|
||||
$isNotTimeLimited = !$isTimeLimited;
|
||||
$isOnTime = (Boolean) $userRegistration['in-time'];
|
||||
$isOutDated = !$isOnTime;
|
||||
|
||||
if ($noRegistrationMade) {
|
||||
continue;
|
||||
}
|
||||
// sets registrations
|
||||
$ddata['config']['collections'][$collection->get_base_id()]['registration'] = $userRegistration;
|
||||
$ddata['registrations']['by-collection'][$collection->get_base_id()] = $userRegistration;
|
||||
|
||||
if (!$isActive) {
|
||||
$ddata['registrations']['by-type']['inactive'][] = $userRegistration;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($isDone) {
|
||||
$ddata['registrations']['by-type']['accepted'][] = $userRegistration;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($isRejected) {
|
||||
$ddata['registrations']['by-type']['rejected'][] = $userRegistration;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($isTimeLimited && $isOnTime && $isPending) {
|
||||
$ddata['registrations']['by-type']['in-time'][] = $userRegistration;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($isTimeLimited && $isOutDated && $isPending) {
|
||||
$ddata['registrations']['by-type']['out-time'][] = $userRegistration;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($isNotTimeLimited && $isPending) {
|
||||
$ddata['registrations']['by-type']['pending'][] = $userRegistration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data[$databox->get_sbas_id()] = $ddata;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Registration Repository.
|
||||
*
|
||||
@@ -212,21 +105,23 @@ class RegistrationManipulator implements ManipulatorInterface
|
||||
/**
|
||||
* Deletes registration for given user.
|
||||
*
|
||||
* @param $userId
|
||||
* @param array $baseList
|
||||
* @param User $user
|
||||
* @param \collection[] $collections
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteRegistrationsForUser($userId, array $baseList)
|
||||
public function deleteUserRegistrations(User $user, array $collections)
|
||||
{
|
||||
$qb = $this->getRepository()->createQueryBuilder('d');
|
||||
$qb->delete('Alchemy\Phrasea\Model\Entities\Registration', 'd');
|
||||
$qb->delete('Phraseanet:Registration', 'd');
|
||||
$qb->where($qb->expr()->eq('d.user', ':user'));
|
||||
$qb->setParameter(':user', $userId);
|
||||
$qb->setParameter(':user', $user->getId());
|
||||
|
||||
if (count($baseList) > 0) {
|
||||
if (count($collections) > 0) {
|
||||
$qb->andWhere('d.baseId IN (:bases)');
|
||||
$qb->setParameter(':bases', $baseList);
|
||||
$qb->setParameter(':bases', array_map(function ($collection) {
|
||||
return $collection->get_base_id();
|
||||
}, $collections));
|
||||
}
|
||||
|
||||
return $qb->getQuery()->execute();
|
||||
@@ -238,7 +133,7 @@ class RegistrationManipulator implements ManipulatorInterface
|
||||
public function deleteOldRegistrations()
|
||||
{
|
||||
$qb = $this->getRepository()->createQueryBuilder('d');
|
||||
$qb->delete('Alchemy\Phrasea\Model\Entities\Registration', 'd');
|
||||
$qb->delete('Phraseanet:Registration', 'd');
|
||||
$qb->where($qb->expr()->lt('d.created', ':date'));
|
||||
$qb->setParameter(':date', new \DateTime('-1 month'));
|
||||
$qb->getQuery()->execute();
|
||||
@@ -249,12 +144,12 @@ class RegistrationManipulator implements ManipulatorInterface
|
||||
*
|
||||
* @param $baseId
|
||||
*/
|
||||
public function deleteRegistrationsOnCollection($baseId)
|
||||
public function deleteRegistrationsOnCollection(\collection $collection)
|
||||
{
|
||||
$qb = $this->getRepository()->createQueryBuilder('d');
|
||||
$qb->delete('Alchemy\Phrasea\Model\Entities\Registration', 'd');
|
||||
$qb->delete('Phraseanet:Registration', 'd');
|
||||
$qb->where($qb->expr()->eq('d.baseId', ':base'));
|
||||
$qb->setParameter(':base', $baseId);
|
||||
$qb->setParameter(':base', $collection->get_base_id());
|
||||
$qb->getQuery()->execute();
|
||||
}
|
||||
}
|
||||
|
@@ -82,6 +82,6 @@ class NativeQueryProvider
|
||||
AND u.deleted="0"', $rsm
|
||||
);
|
||||
|
||||
return $query->getResults();
|
||||
return $query->getResult();
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@
|
||||
namespace Alchemy\Phrasea\Model\Repositories;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
|
||||
/**
|
||||
* RegistrationRepository
|
||||
@@ -24,20 +25,22 @@ class RegistrationRepository extends EntityRepository
|
||||
/**
|
||||
* Displays registrations for user on provided collection.
|
||||
*
|
||||
* @param \User_Adapter $user
|
||||
* @param array $baseList
|
||||
* @param User $user
|
||||
* @param \collection[] $collections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRegistrationsForUser(\User_Adapter $user, array $baseList)
|
||||
public function getUserRegistrations(User $user, array $collections)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('d');
|
||||
$qb->where($qb->expr()->eq('d.user', ':user'));
|
||||
$qb->setParameter(':user', $user->get_id());
|
||||
$qb->setParameter(':user', $user->getId());
|
||||
|
||||
if (count($baseList) > 0) {
|
||||
if (count($collections) > 0) {
|
||||
$qb->andWhere('d.baseId IN (:bases)');
|
||||
$qb->setParameter(':bases', $baseList);
|
||||
$qb->setParameter(':bases', array_map(function ($collection) {
|
||||
return $collection->get_base_id();
|
||||
}, $collections));
|
||||
}
|
||||
|
||||
$qb->orderBy('d.created', 'DESC');
|
||||
@@ -48,11 +51,11 @@ class RegistrationRepository extends EntityRepository
|
||||
/**
|
||||
* Gets registration registrations for a user.
|
||||
*
|
||||
* @param $usrId
|
||||
* @param User $user
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRegistrationsSummaryForUser($usrId)
|
||||
public function getRegistrationsSummaryForUser(User $user)
|
||||
{
|
||||
$data = [];
|
||||
$rsm = $this->createResultSetMappingBuilder('d');
|
||||
@@ -78,7 +81,7 @@ class RegistrationRepository extends EntityRepository
|
||||
AND model_of = 0";
|
||||
|
||||
$query = $this->_em->createNativeQuery($sql, $rsm);
|
||||
$query->setParameter(1, $usrId);
|
||||
$query->setParameter(1, $user->getId());
|
||||
|
||||
foreach ($query->getResult() as $row) {
|
||||
$registrationEntity = $row[0];
|
||||
|
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Registration;
|
||||
|
||||
class RegistrationManager
|
||||
{
|
||||
/** @var \appbox */
|
||||
private $appbox;
|
||||
|
||||
public function __construct(\appbox $appbox)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether registration is enabled or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isRegistrationEnabled()
|
||||
{
|
||||
foreach ($this->appbox->get_databoxes() as $databox) {
|
||||
foreach($databox->get_collections() as $collection) {
|
||||
if ($collection->isRegistrationEnabled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -12,13 +12,12 @@
|
||||
namespace Alchemy\Phrasea\Setup\DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
|
||||
class RegistrationMigration extends AbstractMigration
|
||||
{
|
||||
public function doUpSql(Schema $schema)
|
||||
{
|
||||
$this->addSql("CREATE TABLE Registration (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, base_id INT NOT NULL, pending TINYINT(1) NOT NULL, rejected TINYINT(1) NOT NULL, created DATETIME NOT NULL, updated DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
|
||||
$this->addSql("CREATE TABLE Registration (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, base_id INT NOT NULL, pending TINYINT(1) NOT NULL, rejected TINYINT(1) NOT NULL, created DATETIME NOT NULL, updated DATETIME NOT NULL, INDEX IDX_7A997C5FA76ED395 (user_id), UNIQUE INDEX unique_registration (user_id, base_id, pending), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
|
||||
}
|
||||
|
||||
public function doDownSql(Schema $schema)
|
@@ -1089,7 +1089,7 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
}
|
||||
|
||||
$record->set_metadatas($metadatas);
|
||||
$result->set_datas(array("record_metadatas" => $this->list_record_caption($record->get_caption())));
|
||||
$result->set_datas(["record_metadatas" => $this->list_record_caption($record->get_caption())]);
|
||||
} catch (\Exception $e) {
|
||||
$result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('An error occured'));
|
||||
}
|
||||
|
@@ -406,7 +406,7 @@ class collection implements cache_cacheableInterface
|
||||
$stmt->execute([':base_id' => $this->get_base_id()]);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this->get_base_id());
|
||||
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this);
|
||||
|
||||
$this->get_databox()->delete_data_from_cache(databox::CACHE_COLLECTIONS);
|
||||
|
||||
@@ -534,7 +534,7 @@ class collection implements cache_cacheableInterface
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this->get_base_id());
|
||||
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this);
|
||||
|
||||
phrasea::reset_baseDatas($app['phraseanet.appbox']);
|
||||
|
||||
@@ -748,7 +748,10 @@ class collection implements cache_cacheableInterface
|
||||
*/
|
||||
public function isRegistrationEnabled()
|
||||
{
|
||||
if ($xml = simplexml_load_string($this->get_prefs())) {
|
||||
if (false === $xml = simplexml_load_string($this->get_prefs())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$element = $xml->xpath('/baseprefs/caninscript');
|
||||
|
||||
if (count($element) === 0) {
|
||||
@@ -760,7 +763,6 @@ class collection implements cache_cacheableInterface
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -774,12 +776,12 @@ class collection implements cache_cacheableInterface
|
||||
*/
|
||||
public function getTermsOfUse()
|
||||
{
|
||||
if ($xml = simplexml_load_string($this->get_prefs())) {
|
||||
if (false === $xml = simplexml_load_string($this->get_prefs())) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($xml->xpath('/baseprefs/cgu') as $sbpcgu) {
|
||||
return $sbpcgu->saveXML();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ class databox_cgu
|
||||
if (trim($term['terms']) == '') {
|
||||
continue;
|
||||
}
|
||||
$out .= '<div style="display:none;" class="cgu-dialog" title="' . str_replace('"', '"', $app->trans('cgus:: CGUs de la base %s', $name)) . '">';
|
||||
$out .= '<div style="display:none;" class="cgu-dialog" title="' . str_replace('"', '"', $app->trans('cgus:: CGUs de la base %name%', ['%name%', $name])) . '">';
|
||||
|
||||
$out .= '<blockquote>' . $term['terms'] . '</blockquote>';
|
||||
$out .= '<div>' . $app->trans('cgus:: Pour continuer a utiliser lapplication, vous devez accepter les conditions precedentes') . '
|
||||
|
@@ -38,13 +38,10 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract
|
||||
*/
|
||||
public function fire($event, $params, &$object)
|
||||
{
|
||||
$default = [
|
||||
'usr_id' => ''
|
||||
, 'demand' => []
|
||||
];
|
||||
$default = ['usr_id' => '', 'registrations' => []];
|
||||
|
||||
$params = array_merge($default, $params);
|
||||
$base_ids = $params['demand'];
|
||||
$base_ids = $params['registrations'];
|
||||
|
||||
if (count($base_ids) == 0) {
|
||||
return;
|
||||
@@ -79,7 +76,7 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract
|
||||
|
||||
$usr_id->appendChild($dom_xml->createTextNode($params['usr_id']));
|
||||
|
||||
foreach ($params['demand'] as $base_id => $is_ok) {
|
||||
foreach ($params['registrations'] as $base_id => $is_ok) {
|
||||
$base_id_node = $dom_xml->createElement('base_id');
|
||||
$base_id_node->appendChild($dom_xml->createTextNode($base_id));
|
||||
$base_ids->appendChild($base_id_node);
|
||||
|
122
lib/classes/patch/390alpha13a.php
Normal file
122
lib/classes/patch/390alpha13a.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\Registration;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
|
||||
class patch_390alpha13a implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0-alpha.13';
|
||||
|
||||
/** @var array */
|
||||
private $concern = [base::APPLICATION_BOX];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDoctrineMigrations()
|
||||
{
|
||||
return ['registration'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(base $appbox, Application $app)
|
||||
{
|
||||
$em = $app['EM'];
|
||||
|
||||
$sql = "SELECT date_modif, usr_id, base_id, en_cours, refuser
|
||||
FROM demand";
|
||||
|
||||
$rsm = new ResultSetMapping();
|
||||
$rsm->addScalarResult('base_id','base_id');
|
||||
$rsm->addScalarResult('en_cours','en_cours');
|
||||
$rsm->addScalarResult('refuser','refuser');
|
||||
$rsm->addScalarResult('usr_id', 'usr_id');
|
||||
$rsm->addScalarResult('date_modif', 'date_modif');
|
||||
|
||||
$rs = $em->createNativeQuery($sql, $rsm)->getResult();
|
||||
$n = 0;
|
||||
|
||||
foreach ($rs as $row) {
|
||||
try {
|
||||
$user = $em->createQuery('SELECT PARTIAL u.{id} FROM Phraseanet:User s WHERE u.id = :id')
|
||||
->setParameters(['id' => $row['usr_id']])
|
||||
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
|
||||
->getSingleResult();
|
||||
} catch (NoResultException $e) {
|
||||
$app['monolog']->addInfo(sprintf(
|
||||
'Patch %s : Registration for user (%s) could not be turn into doctrine entity as user could not be found.',
|
||||
$this->get_release(),
|
||||
$row['usr_id']
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$collection = \collection::get_from_base_id($app, $row['base_id']);
|
||||
} catch (\Exception $e) {
|
||||
$app['monolog']->addInfo(sprintf(
|
||||
'Patch %s : Registration for user (%s) could not be turn into doctrine entity as base with id (%s) could not be found.',
|
||||
$this->get_release(),
|
||||
$row['usr_id'],
|
||||
$row['base_id']
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
$registration = new Registration();
|
||||
$registration->setCollection($collection);
|
||||
$registration->setUser($user);
|
||||
$registration->setPending($row['en_cours']);
|
||||
$registration->setCreated(new \DateTime($row['date_modif']));
|
||||
$registration->setRejected($row['refuser']);
|
||||
|
||||
if ($n % 100 === 0) {
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
$n++;
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
}
|
@@ -371,7 +371,7 @@ class record_preview extends record_adapter
|
||||
[
|
||||
'final' => []
|
||||
, 'comment' => []
|
||||
, 'user' => $this->app['manipulator.user']->getRepository()->find($row['usr_id'])
|
||||
, 'user' => $row['usr_id'] ? $this->app['manipulator.user']->getRepository()->find($row['usr_id']) : null
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -55,5 +55,5 @@ migrations:
|
||||
version: user-auth-provider
|
||||
class: Alchemy\Phrasea\Setup\DoctrineMigrations\UserAuthProviderMigration
|
||||
migration18:
|
||||
version: registration-request
|
||||
version: registration
|
||||
class: Alchemy\Phrasea\Setup\DoctrineMigrations\RegistrationMigration
|
@@ -140,7 +140,7 @@
|
||||
<td style="text-align: right;">{{ collInfo["coll-name"] }}</td>
|
||||
<td></td>
|
||||
<td class="TD_R" style="width: 200px;">
|
||||
<input style="width: 15px;" class="checkbox" type="checkbox" name="demand[]" value="{{ baseId }}" />
|
||||
<input style="width: 15px;" class="checkbox" type="checkbox" name="registrations[]" value="{{ baseId }}" />
|
||||
<span>{{ "login::register: Faire une demande d\'acces" | trans }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
@@ -44,7 +44,7 @@
|
||||
</a>
|
||||
</li>
|
||||
<li class="{% if feature == 'registrations' %}selected{% endif %}">
|
||||
<a target="right" href="{{ path('users_display_demands') }}" class="ajax">
|
||||
<a target="right" href="{{ path('users_display_registrations') }}" class="ajax">
|
||||
<img src="/skins/admin/Demandes.png" />
|
||||
<span>{{ 'admin::utilisateurs: demandes en cours' | trans }}</span>
|
||||
</a>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
resize();
|
||||
});
|
||||
|
||||
var $form = $("form#accept-demand");
|
||||
var $form = $("form#accept-registration");
|
||||
var $mainBtnAction = $(".btn-all-action", $form);
|
||||
var $basesBtnAction = $(".btn-single-action", $form);
|
||||
|
||||
@@ -172,8 +172,8 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if users | length > 0 %}
|
||||
<form id="accept-demand" action="{{ path('users_submit_demands') }}" method="post">
|
||||
{% if user_registrations | length > 0 %}
|
||||
<form id="accept-registration" action="{{ path('users_submit_registrations') }}" method="post">
|
||||
<div class="btn-group btn-all-action">
|
||||
<button data-event="deny" class="btn deny-checker" type="button">
|
||||
<img title="{{ 'admin:: refuser l\'acces' | trans }}" src="/skins/icons/delete.gif"/>
|
||||
@@ -200,9 +200,9 @@
|
||||
</table>
|
||||
|
||||
<div class="registration-wrapper PNB" style="top:160px;bottom: 50px;overflow: auto">
|
||||
<div id="tab_demandes">
|
||||
{% for user in users %}
|
||||
{% set userRegistrations = registrations[user.getId()] %}
|
||||
<div id="registrations">
|
||||
{% for user_registration in user_registrations %}
|
||||
{% set user = user_registration['user'] %}
|
||||
<div class="well well-small">
|
||||
<table class="table" style="table-layout: fixed;">
|
||||
<tr>
|
||||
@@ -230,9 +230,9 @@
|
||||
</dl>
|
||||
</td>
|
||||
<td>
|
||||
{% for baseId, demand in userRegistrations %}
|
||||
{% for basId, registration in user_registration['registrations'] %}
|
||||
<div>
|
||||
{{ app['date-formatter'].getPrettyString(demand.getUpdated()) }}
|
||||
{{ app['date-formatter'].getPrettyString(registration.getUpdated()) }}
|
||||
</div>
|
||||
<span style="font-weight:bold;font-size:14px;word-wrap: break-word;">
|
||||
{{ basId| bas_labels(app) }}
|
@@ -366,20 +366,18 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
self::$DI['app']['manipulator.user']->delete($user);
|
||||
}
|
||||
|
||||
public function testRenderDemands()
|
||||
public function testRenderRegistrations()
|
||||
{
|
||||
self::$DI['client']->request('GET', '/admin/users/demands/');
|
||||
self::$DI['client']->request('GET', '/admin/users/registrations/');
|
||||
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
||||
}
|
||||
|
||||
public function testPostDemands()
|
||||
public function testPostRegistrations()
|
||||
{
|
||||
$id = self::$DI['user_alt1']->getId();
|
||||
$baseId = self::$DI['collection']->get_base_id();
|
||||
$param = sprintf('%s_%s', $id, $baseId);
|
||||
|
||||
$appbox = self::$DI['app']['phraseanet.appbox'];
|
||||
|
||||
$stmt = $this->getMock('PDOStatement');
|
||||
|
||||
$stmt->expects($this->any())
|
||||
@@ -408,7 +406,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate');
|
||||
|
||||
self::$DI['client']->request('POST', '/admin/users/demands/', [
|
||||
self::$DI['client']->request('POST', '/admin/users/registrations/', [
|
||||
'template' => [],
|
||||
'accept' => [$param],
|
||||
'accept_hd' => [$param],
|
||||
|
@@ -140,7 +140,7 @@ class UploadTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
* @covers Alchemy\Phrasea\Controller\Prod\Upload::upload
|
||||
* @covers Alchemy\Phrasea\Controller\Prod\Upload::getJsonResponse
|
||||
*/
|
||||
public function testUploadingTwiceTheSameRecordShouldSendToQuantantine()
|
||||
public function testUploadingTwiceTheSameRecordShouldSendToQuarantine()
|
||||
{
|
||||
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoRecordQuarantined');
|
||||
$this->mockUserNotificationSettings('eventsmanager_notify_uploadquarantine');
|
||||
|
@@ -168,7 +168,7 @@ class UsrListsTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
{
|
||||
$entry = self::$DI['app']['EM']->find('Phraseanet:UsrListEntry', 2);
|
||||
$list_id = $entry->getList()->getId();
|
||||
$usr_id = $entry->getUser(self::$DI['app'])->getId();
|
||||
$usr_id = $entry->getUser()->getId();
|
||||
$entry_id = $entry->getId();
|
||||
|
||||
$route = '/prod/lists/list/' . $list_id . '/remove/' . $usr_id . '/';
|
||||
|
@@ -84,14 +84,14 @@ class AccountTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
]
|
||||
];
|
||||
|
||||
$service = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\RegistrationManipulator')
|
||||
->setConstructorArgs([self::$DI['app']['EM'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['acl']])
|
||||
$service = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\RegistrationManager')
|
||||
->setConstructorArgs([self::$DI['app']['phraseanet.appbox'], self::$DI['app']['manipulator.registration']->getRepository(), self::$DI['app']['locale']])
|
||||
->setMethods(['getRegistrationSummary'])
|
||||
->getMock();
|
||||
|
||||
$service->expects($this->once())->method('getRegistrationSummary')->will($this->returnValue($data));
|
||||
|
||||
self::$DI['app']['registration-manager'] = $service;
|
||||
self::$DI['app']['registration.manager'] = $service;
|
||||
self::$DI['client']->request('GET', '/account/access/');
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
@@ -320,7 +320,7 @@ class AccountTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
array_shift($notifs);
|
||||
|
||||
self::$DI['client']->request('POST', '/account/', [
|
||||
'demand' => $bases,
|
||||
'registrations' => $bases,
|
||||
'form_gender' => User::GENDER_MR,
|
||||
'form_firstname' => 'gros',
|
||||
'form_lastname' => 'minet',
|
||||
@@ -347,7 +347,7 @@ class AccountTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$this->assertEquals('minet', self::$DI['app']['authentication']->getUser()->getLastName());
|
||||
|
||||
$rs = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Registration')->findBy([
|
||||
$rs = self::$DI['app']['EM']->getRepository('Phraseanet:Registration')->findBy([
|
||||
'user' => self::$DI['app']['authentication']->getUser()->getId(),
|
||||
'pending' => true
|
||||
]);
|
||||
|
@@ -17,7 +17,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
{
|
||||
public static $demands;
|
||||
public static $registrationCollections;
|
||||
public static $collections;
|
||||
public static $login;
|
||||
public static $email;
|
||||
@@ -27,8 +27,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (null === self::$demands) {
|
||||
self::$demands = [self::$DI['collection']->get_coll_id()];
|
||||
if (null === self::$registrationCollections) {
|
||||
self::$registrationCollections = [self::$DI['collection']->get_coll_id()];
|
||||
}
|
||||
if (null === self::$collections) {
|
||||
self::$collections = [self::$DI['collection']->get_base_id()];
|
||||
@@ -45,7 +45,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
if (null === self::$email) {
|
||||
self::$email = self::$DI['user']->getEmail();
|
||||
}
|
||||
self::$DI['app']['registration.enabled'] = true;
|
||||
|
||||
$this->enableRegistration();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
@@ -56,7 +57,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::$demands = self::$collections = self::$login = self::$email = self::$termsOfUse = null;
|
||||
self::$registrationCollections = self::$collections = self::$login = self::$email = self::$termsOfUse = null;
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
@@ -209,11 +210,11 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
self::$DI['user']->setMailLocked(true);
|
||||
$this->deleteRequest();
|
||||
$demand = new Registration();
|
||||
$demand->setUser(self::$DI['user']);
|
||||
$demand->setBaseId(self::$DI['collection']->get_base_id());
|
||||
$registration = new Registration();
|
||||
$registration->setUser(self::$DI['user']);
|
||||
$registration->setBaseId(self::$DI['collection']->get_base_id());
|
||||
|
||||
self::$DI['app']['EM']->persist($demand);
|
||||
self::$DI['app']['EM']->persist($registration);
|
||||
self::$DI['app']['EM']->flush();
|
||||
|
||||
self::$DI['client']->request('GET', '/login/register-confirm/', ['code' => $token]);
|
||||
@@ -534,7 +535,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
public function testGetPostRegisterWhenRegistrationDisabled($method, $route)
|
||||
{
|
||||
self::$DI['app']['registration.enabled'] = false;
|
||||
$this->disableRegistration();
|
||||
$this->logout(self::$DI['app']);
|
||||
self::$DI['client']->request($method, $route);
|
||||
$this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode());
|
||||
@@ -543,7 +544,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
/**
|
||||
* @dataProvider provideInvalidRegistrationData
|
||||
*/
|
||||
public function testPostRegisterbadArguments($parameters, $extraParameters, $errors)
|
||||
public function testPostRegisterBadArguments($parameters, $extraParameters, $errors)
|
||||
{
|
||||
$this->enableTOU();
|
||||
self::$DI['app']['registration.enabled'] = true;
|
||||
@@ -554,7 +555,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$parameters = array_merge(['_token' => 'token'], $parameters);
|
||||
foreach ($parameters as $key => $parameter) {
|
||||
if ('collections' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$demands;
|
||||
$parameters[$key] = self::$registrationCollections;
|
||||
}
|
||||
if ('login' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$login;
|
||||
@@ -577,6 +578,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
public function testPostRegisterWithoutParams()
|
||||
{
|
||||
$this->logout(self::$DI['app']);
|
||||
$this->disableTOU();
|
||||
$crawler = self::$DI['client']->request('POST', '/login/register-classic/');
|
||||
|
||||
$this->assertFalse(self::$DI['client']->getResponse()->isRedirect());
|
||||
@@ -592,6 +594,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
'confirm' => 'password'
|
||||
],
|
||||
"collections" => null,
|
||||
"accept-tou" => '1'
|
||||
], [], 1],
|
||||
[[//required extra-field missing
|
||||
"password" => [
|
||||
@@ -599,7 +602,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
'confirm' => 'password'
|
||||
],
|
||||
"email" => $this->generateEmail(),
|
||||
"collections" => null
|
||||
"collections" => null,
|
||||
"accept-tou" => '1'
|
||||
], [
|
||||
[
|
||||
'name' => 'login',
|
||||
@@ -612,7 +616,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
'confirm' => 'passwordMismatch'
|
||||
],
|
||||
"email" => $this->generateEmail(),
|
||||
"collections" => null
|
||||
"collections" => null,
|
||||
"accept-tou" => '1'
|
||||
], [], 1],
|
||||
[[//password tooshort
|
||||
"password" => [
|
||||
@@ -620,7 +625,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
'confirm' => 'min'
|
||||
],
|
||||
"email" => $this->generateEmail(),
|
||||
"collections" => null
|
||||
"collections" => null,
|
||||
"accept-tou" => '1'
|
||||
], [], 1],
|
||||
[[//email invalid
|
||||
"password" => [
|
||||
@@ -628,7 +634,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
'confirm' => 'password'
|
||||
],
|
||||
"email" => 'invalid.email',
|
||||
"collections" => null
|
||||
"collections" => null,
|
||||
"accept-tou" => '1'
|
||||
], [], 1],
|
||||
[[//login exists
|
||||
"login" => null,
|
||||
@@ -637,7 +644,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
'confirm' => 'password'
|
||||
],
|
||||
"email" => $this->generateEmail(),
|
||||
"collections" => null
|
||||
"collections" => null,
|
||||
"accept-tou" => '1'
|
||||
], [
|
||||
[
|
||||
'name' => 'login',
|
||||
@@ -650,7 +658,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
'confirm' => 'password'
|
||||
],
|
||||
"email" => null,
|
||||
"collections" => null
|
||||
"collections" => null,
|
||||
"accept-tou" => '1'
|
||||
], [], 1],
|
||||
[[//tou declined
|
||||
"password" => [
|
||||
@@ -658,8 +667,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
'confirm' => 'password'
|
||||
],
|
||||
"email" => $this->generateEmail(),
|
||||
"collections" => null,
|
||||
"accept-tou" => '1'
|
||||
"collections" => null
|
||||
], [], 1]
|
||||
];
|
||||
}
|
||||
@@ -822,13 +830,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
self::$DI['app']['registration.fields'] = [];
|
||||
$this->logout(self::$DI['app']);
|
||||
|
||||
$managerMock = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\RegistrationManipulator')
|
||||
->setConstructorArgs([self::$DI['app']['EM'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['acl']])
|
||||
->setMethods(['getRepository'])
|
||||
->getMock();
|
||||
$managerMock->expects($this->any())->method('getRepository')->will($this->returnValue(self::$DI['app']['registration-manager']->getRepository()));
|
||||
self::$DI['app']['registration-manager'] = $managerMock;
|
||||
|
||||
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
||||
$this->addProvider('provider-test', $provider);
|
||||
|
||||
@@ -856,7 +857,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
foreach ($parameters as $key => $parameter) {
|
||||
if ('collections' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$demands;
|
||||
$parameters[$key] = self::$registrationCollections;
|
||||
}
|
||||
if ('login' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$login;
|
||||
@@ -889,7 +890,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
foreach ($parameters as $key => $parameter) {
|
||||
if ('collections' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$demands;
|
||||
$parameters[$key] = self::$registrationCollections;
|
||||
}
|
||||
if ('login' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$login;
|
||||
@@ -931,7 +932,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
foreach ($parameters as $key => $parameter) {
|
||||
if ('collections' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$demands;
|
||||
$parameters[$key] = self::$registrationCollections;
|
||||
}
|
||||
if ('login' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$login;
|
||||
@@ -952,6 +953,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
{
|
||||
self::$DI['app']['registration.fields'] = [];
|
||||
$this->logout(self::$DI['app']);
|
||||
$this->disableTOU();
|
||||
|
||||
$emails = [
|
||||
'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0,
|
||||
@@ -1007,7 +1009,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
foreach ($parameters as $key => $parameter) {
|
||||
if ('collections' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$demands;
|
||||
$parameters[$key] = self::$registrationCollections;
|
||||
}
|
||||
if ('login' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$login;
|
||||
@@ -1059,6 +1061,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
self::$DI['app']['registration.fields'] = $extraParameters;
|
||||
|
||||
$this->logout(self::$DI['app']);
|
||||
$this->disableTOU();
|
||||
|
||||
$emails = [
|
||||
'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0,
|
||||
@@ -1072,7 +1075,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$parameters = array_merge(['_token' => 'token'], $parameters);
|
||||
foreach ($parameters as $key => $parameter) {
|
||||
if ('collections' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$demands;
|
||||
$parameters[$key] = self::$registrationCollections;
|
||||
}
|
||||
if ('login' === $key && null === $parameter) {
|
||||
$parameters[$key] = self::$login;
|
||||
@@ -1468,13 +1471,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
public function testAuthenticateProviderCallbackAlreadyBound()
|
||||
{
|
||||
$managerMock = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\RegistrationManipulator')
|
||||
->setConstructorArgs([self::$DI['app']['EM'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['acl']])
|
||||
->setMethods(['getRepository'])
|
||||
->getMock();
|
||||
$managerMock->expects($this->any())->method('getRepository')->will($this->returnValue(self::$DI['app']['registration-manager']->getRepository()));
|
||||
self::$DI['app']['registration-manager'] = $managerMock;
|
||||
|
||||
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
||||
$this->addProvider('provider-test', $provider);
|
||||
|
||||
@@ -1620,8 +1616,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
||||
$this->addProvider('provider-test', $provider);
|
||||
|
||||
$provider->expects($this->once())
|
||||
->method('onCallback');
|
||||
$provider->expects($this->once())->method('onCallback');
|
||||
|
||||
$token = new Token($provider, 42);
|
||||
|
||||
@@ -1660,10 +1655,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
{
|
||||
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
||||
$this->addProvider('provider-test', $provider);
|
||||
|
||||
$provider->expects($this->once())
|
||||
->method('onCallback');
|
||||
|
||||
$provider->expects($this->once())->method('onCallback');
|
||||
$token = new Token($provider, 42);
|
||||
|
||||
$provider->expects($this->any())
|
||||
@@ -1688,16 +1680,15 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
->method('isEnabled')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
self::$DI['app']['registration.enabled'] = false;
|
||||
|
||||
$this->disableRegistration();
|
||||
$this->logout(self::$DI['app']);
|
||||
self::$DI['client']->request('GET', '/login/provider/provider-test/callback/');
|
||||
|
||||
$this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode());
|
||||
$this->assertSame('/login/', self::$DI['client']->getResponse()->headers->get('location'));
|
||||
|
||||
$this->assertFalse(self::$DI['app']['authentication']->isAuthenticated());
|
||||
$this->assertFlashMessagePopulated(self::$DI['app'], 'error', 1);
|
||||
$this->assertSame('/login/', self::$DI['client']->getResponse()->headers->get('location'));
|
||||
}
|
||||
|
||||
public function testGetRegistrationFields()
|
||||
@@ -1792,12 +1783,12 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete inscription demand made by the current authenticathed user
|
||||
* Delete inscription request made by the current authenticathed user
|
||||
* @return void
|
||||
*/
|
||||
private function deleteRequest()
|
||||
{
|
||||
$query = self::$DI['app']['EM']->createQuery('DELETE FROM Alchemy\Phrasea\Model\Entities\Registration d WHERE d.user=?1');
|
||||
$query = self::$DI['app']['EM']->createQuery('DELETE FROM Phraseanet:Registration d WHERE d.user=?1');
|
||||
$query->setParameter(1, self::$DI['user']->getId());
|
||||
$query->execute();
|
||||
}
|
||||
@@ -1827,7 +1818,9 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
private function enableTOU()
|
||||
{
|
||||
if (null === self::$termsOfUse) {
|
||||
if (null !== self::$termsOfUse) {
|
||||
return;
|
||||
}
|
||||
self::$termsOfUse = [];
|
||||
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
self::$termsOfUse[$databox->get_sbas_id()] = $databox->get_cgus();
|
||||
@@ -1837,7 +1830,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function resetTOU()
|
||||
{
|
||||
@@ -1856,4 +1848,65 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
self::$termsOfUse = null;
|
||||
}
|
||||
|
||||
private function getRegistrationSummary()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'registrations' => [
|
||||
'by-type' => [
|
||||
'inactive' => [new Registration()],
|
||||
'accepted' => [new Registration()],
|
||||
'in-time' => [new Registration()],
|
||||
'out-dated' => [new Registration()],
|
||||
'pending' => [new Registration()],
|
||||
'rejected' => [new Registration()],
|
||||
],
|
||||
'by-collection' => []
|
||||
],
|
||||
'config' => [
|
||||
'db-name' => 'a_db_name',
|
||||
'cgu' => null,
|
||||
'cgu-release' => null,
|
||||
'can-register' => false,
|
||||
'collections' => [
|
||||
[
|
||||
'coll-name' => 'a_coll_name',
|
||||
'can-register' => false,
|
||||
'cgu' => 'Some terms of use.',
|
||||
'registration' => null
|
||||
],
|
||||
[
|
||||
'coll-name' => 'an_other_coll_name',
|
||||
'can-register' => false,
|
||||
'cgu' => null,
|
||||
'registration' => null
|
||||
]
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function enableRegistration()
|
||||
{
|
||||
$managerMock = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\RegistrationManager')
|
||||
->setConstructorArgs([self::$DI['app']['phraseanet.appbox'], self::$DI['app']['manipulator.registration']->getRepository(), self::$DI['app']['locale']])
|
||||
->setMethods(['isRegistrationEnabled'])
|
||||
->getMock();
|
||||
|
||||
self::$DI['app']['registration.manager'] = $managerMock;
|
||||
self::$DI['app']['registration.manager']->expects($this->any())->method('isRegistrationEnabled')->will($this->returnValue(true));
|
||||
}
|
||||
|
||||
private function disableRegistration()
|
||||
{
|
||||
$managerMock = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\RegistrationManager')
|
||||
->setConstructorArgs([self::$DI['app']['phraseanet.appbox'], self::$DI['app']['manipulator.registration']->getRepository(), self::$DI['app']['locale']])
|
||||
->setMethods(['isRegistrationEnabled'])
|
||||
->getMock();
|
||||
|
||||
self::$DI['app']['registration.manager'] = $managerMock;
|
||||
self::$DI['app']['registration.manager']->expects($this->any())->method('isRegistrationEnabled')->will($this->returnValue(false));
|
||||
}
|
||||
}
|
||||
|
@@ -11,29 +11,11 @@ class PreferencesTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
public function testSaveUserPref()
|
||||
{
|
||||
self::$DI['app']['authentication']->setUser($this->getMockBuilder('Alchemy\Phrasea\Model\Entities\User')
|
||||
->setMethods(['addSetting'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock());
|
||||
|
||||
self::$DI['app']['manipulator.user'] = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\User')
|
||||
->setMethods(['setUserSetting'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
self::$DI['app']['manipulator.user']->expects($this->once())
|
||||
->method('setUserSetting')
|
||||
->with($this->isInstanceOf('Alchemy\Phrasea\Model\Entities\User'), $this->equalTo('prop_test'), $this->equalTo('val_test'))
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$this->XMLHTTPRequest('POST', '/user/preferences/', ['prop' => 'prop_test', 'value' => 'val_test']);
|
||||
$response = self::$DI['client']->getResponse();
|
||||
$this->assertTrue($response->isOk());
|
||||
$datas = (array) json_decode($response->getContent());
|
||||
$this->assertArrayHasKey('success', $datas);
|
||||
$this->assertTrue($datas['success']);
|
||||
$this->assertArrayHasKey('message', $datas);
|
||||
unset($response, $datas);
|
||||
$this->assertTrue(json_decode($response->getContent())->success);
|
||||
$this->assertEquals('val_test', self::$DI['app']['settings']->getUserSetting(self::$DI['user'], 'prop_test'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,11 +46,8 @@ class PreferencesTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->XMLHTTPRequest('POST', "/user/preferences/temporary/", ['prop' => 'prop_test', 'value' => 'val_test']);
|
||||
$response = self::$DI['client']->getResponse();
|
||||
$this->assertTrue($response->isOk());
|
||||
$datas = (array) json_decode($response->getContent());
|
||||
$this->assertArrayHasKey('success', $datas);
|
||||
$this->assertTrue($datas['success']);
|
||||
$this->assertTrue(json_decode($response->getContent())->success);
|
||||
$this->assertEquals('val_test', self::$DI['app']['session']->get('phraseanet.prop_test'));
|
||||
unset($response, $datas);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Core\Configuration;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\Registration;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\Phrasea\Core\Configuration\RegistrationManager;
|
||||
|
||||
class RegistrationManagerTest extends \PhraseanetTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getRegistrationProvider
|
||||
*/
|
||||
public function testRegistrationIsEnabled($enabledOnColl, $expected)
|
||||
{
|
||||
$mockColl = $this->getMockBuilder('\collection')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockColl->expects($this->once())->method('isRegistrationEnabled')->will($this->returnValue($enabledOnColl));
|
||||
|
||||
$mockDatabox = $this->getMockBuilder('\databox')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockAppbox = $this->getMockBuilder('\appbox')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockColl->expects($this->once())->method('isRegistrationEnabled')->will($this->returnValue(false));
|
||||
|
||||
$mockDatabox->expects($this->once())->method('get_collections')->will($this->returnValue([$mockColl]));
|
||||
$mockAppbox->expects($this->once())->method('get_databoxes')->will($this->returnValue([$mockDatabox]));
|
||||
|
||||
$service = new RegistrationManager($mockAppbox, self::$DI['app']['manipulator.registration']->getRepository(), self::$DI['app']['locale']);
|
||||
$this->assertEquals($expected, $service->isRegistrationEnabled());
|
||||
}
|
||||
|
||||
public function getRegistrationProvider()
|
||||
{
|
||||
return [
|
||||
[false, false],
|
||||
[true, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider userDataProvider
|
||||
*/
|
||||
public function testGetRegistrationSummaryWithUserData($data, $type, $value)
|
||||
{
|
||||
$repoMock = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\RegistrationRepository')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getRegistrationsSummaryForUser'])
|
||||
->getMock();
|
||||
$repoMock->expects($this->once())->method('getRegistrationsSummaryForUser')->will($this->returnValue($data));
|
||||
|
||||
$service = new RegistrationManager(self::$DI['app']['phraseanet.appbox'], $repoMock, self::$DI['app']['locale']);
|
||||
|
||||
$rs = $service->getRegistrationSummary(self::$DI['user']);
|
||||
|
||||
$databox = current(self::$DI['app']['phraseanet.appbox']->get_databoxes());
|
||||
$collection = current($databox->get_collections());
|
||||
|
||||
$this->assertEquals($value, count($rs[$databox->get_sbas_id()]['registrations']['by-type'][$type]));
|
||||
}
|
||||
|
||||
public function userDataProvider()
|
||||
{
|
||||
$pendingRegistration = new Registration();
|
||||
$pendingRegistration->setBaseId(1);
|
||||
$pendingRegistration->setUser(new User());
|
||||
$pendingRegistration->setPending(true);
|
||||
$pendingRegistration->setRejected(false);
|
||||
|
||||
$rejectedRegistration = new Registration();
|
||||
$rejectedRegistration->setBaseId(1);
|
||||
$rejectedRegistration->setUser(new User());
|
||||
$rejectedRegistration->setPending(true);
|
||||
$rejectedRegistration->setRejected(true);
|
||||
|
||||
$databox = current((new \appbox(new Application()))->get_databoxes());
|
||||
$collection = current($databox->get_collections());
|
||||
|
||||
$noLimitedPendingRegistration = [
|
||||
[
|
||||
$databox->get_sbas_id() => [
|
||||
$collection->get_base_id() => [
|
||||
'base-id' => $collection->get_base_id(),
|
||||
'db-name' => 'toto',
|
||||
'active' => true,
|
||||
'time-limited' => false,
|
||||
'in-time' => null,
|
||||
'registration' => $pendingRegistration
|
||||
]
|
||||
]
|
||||
],
|
||||
'pending',
|
||||
1
|
||||
];
|
||||
|
||||
$rejectedRegistration = [
|
||||
[
|
||||
$databox->get_sbas_id() => [
|
||||
$collection->get_base_id() => [
|
||||
'base-id' => $collection->get_base_id(),
|
||||
'db-name' => 'titi',
|
||||
'active' => true,
|
||||
'time-limited' => false,
|
||||
'in-time' => null,
|
||||
'registration' => $rejectedRegistration
|
||||
]
|
||||
]
|
||||
],
|
||||
'rejected',
|
||||
1
|
||||
];
|
||||
|
||||
$noActiveRegistration = [
|
||||
[
|
||||
$databox->get_sbas_id() => [
|
||||
$collection->get_base_id() => [
|
||||
'base-id' => 1,
|
||||
'db-name' => 'tutu',
|
||||
'active' => false,
|
||||
'time-limited' => false,
|
||||
'in-time' => null,
|
||||
'registration' => $pendingRegistration
|
||||
]
|
||||
]
|
||||
],
|
||||
'inactive',
|
||||
1
|
||||
];
|
||||
|
||||
$limitedActiveIntimePendingRegistration = [
|
||||
[
|
||||
$databox->get_sbas_id() => [
|
||||
$collection->get_base_id() => [
|
||||
'base-id' => $collection->get_base_id(),
|
||||
'db-name' => 'tata',
|
||||
'active' => true,
|
||||
'time-limited' => true,
|
||||
'in-time' => true,
|
||||
'registration' => $pendingRegistration
|
||||
]
|
||||
]
|
||||
],
|
||||
'in-time',
|
||||
1
|
||||
];
|
||||
|
||||
$limitedActiveOutdatedPendingRegistration = [
|
||||
[
|
||||
$databox->get_sbas_id() => [
|
||||
$collection->get_base_id() => [
|
||||
'base-id' => $collection->get_base_id(),
|
||||
'db-name' => 'toutou',
|
||||
'active' => true,
|
||||
'time-limited' => true,
|
||||
'in-time' => false,
|
||||
'registration' => $pendingRegistration
|
||||
]
|
||||
]
|
||||
],
|
||||
'out-time',
|
||||
1
|
||||
];
|
||||
|
||||
return [
|
||||
$noLimitedPendingRegistration,
|
||||
$noActiveRegistration,
|
||||
$limitedActiveIntimePendingRegistration,
|
||||
$limitedActiveOutdatedPendingRegistration,
|
||||
$rejectedRegistration
|
||||
];
|
||||
}
|
||||
}
|
@@ -37,7 +37,7 @@ class RegistrationServiceProviderTest extends ServiceProviderTestCase
|
||||
public function provideServiceDescription()
|
||||
{
|
||||
return [
|
||||
['Alchemy\Phrasea\Core\Provider\RegistrationServiceProvider', 'registration.manager', 'Alchemy\Phrasea\Registration\RegistrationManager'],
|
||||
['Alchemy\Phrasea\Core\Provider\RegistrationServiceProvider', 'registration.manager', 'Alchemy\Phrasea\Core\Configuration\RegistrationManager'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Registration;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\Registration;
|
||||
use Alchemy\Phrasea\Model\Manipulator\RegistrationManipulator;
|
||||
|
||||
@@ -10,51 +9,30 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
|
||||
{
|
||||
public function testCreateRegistration()
|
||||
{
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$em->expects($this->once())->method('persist')->with($this->isInstanceOf('Alchemy\Phrasea\Model\Entities\Registration'));
|
||||
$em->expects($this->once())->method('flush');
|
||||
|
||||
$service = new RegistrationManipulator($em, self::$DI['app']['phraseanet.appbox'], self::$DI['app']['acl']);
|
||||
|
||||
$registration = $service->createRegistration(self::$DI['user']->get_id(), self::$DI['collection']->get_base_id());
|
||||
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']);
|
||||
$registration = $service->createRegistration(self::$DI['user'], self::$DI['collection']);
|
||||
|
||||
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\Registration', $registration);
|
||||
$this->assertEquals(self::$DI['collection']->get_base_id(), $registration->getBaseId());
|
||||
$this->assertEquals(self::$DI['user']->get_id(), $registration->getUser());
|
||||
|
||||
return $registration;
|
||||
$this->assertEquals(self::$DI['user']->getId(), $registration->getUser()->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateRegistration
|
||||
*/
|
||||
public function testRejectRegistration($registration)
|
||||
public function testRejectRegistration()
|
||||
{
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$em->expects($this->once())->method('persist')->with($this->isInstanceOf('Alchemy\Phrasea\Model\Entities\Registration'));
|
||||
$em->expects($this->once())->method('flush');
|
||||
|
||||
$service = new RegistrationManipulator($em, self::$DI['app']['phraseanet.appbox'], self::$DI['app']['acl']);
|
||||
$registration = self::$DI['registration_1'];
|
||||
|
||||
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']);
|
||||
$service->rejectRegistration($registration);
|
||||
|
||||
$this->assertFalse($registration->isPending());
|
||||
$this->assertTrue($registration->isRejected());
|
||||
|
||||
return $registration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateRegistration
|
||||
*/
|
||||
public function testAcceptRegistration($registration)
|
||||
public function testAcceptRegistration()
|
||||
{
|
||||
$aclMock = $this->getMockBuilder('ACL')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$registration = self::$DI['registration_1'];
|
||||
|
||||
$aclMock = $this->getMockBuilder('ACL')->disableOriginalConstructor()->getMock();
|
||||
$aclMock->expects($this->once())->method('give_access_to_sbas')->with($this->equalTo([self::$DI['collection']->get_sbas_id()]));
|
||||
$aclMock->expects($this->once())->method('give_access_to_base')->with($this->equalTo([self::$DI['collection']->get_base_id()]));
|
||||
$aclMock->expects($this->once())->method('update_rights_to_base')->with($this->equalTo(self::$DI['collection']->get_base_id()), $this->equalTo([
|
||||
@@ -64,41 +42,35 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
|
||||
'candwnldpreview' => '1',
|
||||
'actif' => '1',
|
||||
]));
|
||||
$aclProviderMock = $this->getMockBuilder('Alchemy\Phrasea\Authentication\ACLProvider')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$aclProviderMock->expects($this->any())->method('get')->with($this->equalTo(self::$DI['user']))->will($this->returnvalue($aclMock));
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$em->expects($this->once())->method('remove')->with($this->isInstanceOf('Alchemy\Phrasea\Model\Entities\Registration'));
|
||||
$em->expects($this->once())->method('flush');
|
||||
|
||||
$service = new RegistrationManipulator($em, self::$DI['app']['phraseanet.appbox'], $aclProviderMock);
|
||||
$service->acceptRegistration($registration, self::$DI['user'], self::$DI['collection'], true, false);
|
||||
$aclProviderMock = $this->getMockBuilder('Alchemy\Phrasea\Authentication\ACLProvider')->disableOriginalConstructor()->getMock();
|
||||
$aclProviderMock->expects($this->any())->method('get')->with($this->isInstanceOf('Alchemy\Phrasea\Model\Entities\User'))->will($this->returnvalue($aclMock));
|
||||
|
||||
self::$DI['app']['acl'] = $aclProviderMock;
|
||||
|
||||
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']);
|
||||
$service->acceptRegistration($registration, true, false);
|
||||
}
|
||||
|
||||
public function testDeleteRegistrationForUser()
|
||||
{
|
||||
$service = new RegistrationManipulator(self::$DI['app']['EM'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['acl']);
|
||||
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']);
|
||||
$qb = $service->getRepository()->createQueryBuilder('r');
|
||||
$nbRegistrationBefore = $qb->select('COUNT(r)')
|
||||
->where($qb->expr()->eq('r.user', ':user'))
|
||||
->setParameter(':user', self::$DI['user_alt1']->get_id())
|
||||
->setParameter(':user', self::$DI['user_alt1']->getId())
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
$service->deleteRegistrationsForUser(self::$DI['user_alt1']->get_id(), [self::$DI['collection']->get_base_id()]);
|
||||
$service->deleteUserRegistrations(self::$DI['user_alt1'], [self::$DI['collection']]);
|
||||
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
|
||||
$this->assertGreaterThan($nbRegistrationAfter, $nbRegistrationBefore);
|
||||
}
|
||||
|
||||
public function testDeleteOldRegistrations()
|
||||
{
|
||||
$service = new RegistrationManipulator(self::$DI['app']['EM'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['acl']);
|
||||
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']);
|
||||
$qb = $service->getRepository()->createQueryBuilder('r');
|
||||
$nbRegistrationBefore = $qb->select('COUNT(r)')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
$nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult();
|
||||
$service->deleteOldRegistrations();
|
||||
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
|
||||
$this->assertGreaterThan($nbRegistrationAfter, $nbRegistrationBefore);
|
||||
@@ -106,151 +78,11 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
|
||||
|
||||
public function testDeleteRegistrationOnCollection()
|
||||
{
|
||||
$service = new RegistrationManipulator(self::$DI['app']['EM'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['acl']);
|
||||
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']);
|
||||
$qb = $service->getRepository()->createQueryBuilder('r');
|
||||
$nbRegistrationBefore = $qb->select('COUNT(r)')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
$service->deleteRegistrationsOnCollection(self::$DI['collection']->get_base_id());
|
||||
$nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult();
|
||||
$service->deleteRegistrationsOnCollection(self::$DI['collection']);
|
||||
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
|
||||
$this->assertGreaterThan($nbRegistrationAfter, $nbRegistrationBefore);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider userDataProvider
|
||||
*/
|
||||
public function testGetRegistrationSummaryWithUserData($data, $type, $value)
|
||||
{
|
||||
$repoMock = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\RegistrationRepository')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getRegistrationsSummaryForUser'])
|
||||
->getMock();
|
||||
$repoMock->expects($this->once())->method('getRegistrationsSummaryForUser')->will($this->returnValue($data));
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$em->expects($this->once())->method('getRepository')->will($this->returnValue($repoMock));
|
||||
|
||||
$service = new RegistrationManipulator($em, self::$DI['app']['phraseanet.appbox'], self::$DI['app']['acl']);
|
||||
|
||||
$rs = $service->getRegistrationSummary(4);
|
||||
|
||||
$databox = current(self::$DI['app']['phraseanet.appbox']->get_databoxes());
|
||||
$collection = current($databox->get_collections());
|
||||
|
||||
$this->assertEquals($value, count($rs[$databox->get_sbas_id()]['registrations']['by-type'][$type]));
|
||||
$this->assertNotNull($rs[$databox->get_sbas_id()]['registrations']['by-collection'][$collection->get_base_id()]);
|
||||
}
|
||||
|
||||
public function userDataProvider()
|
||||
{
|
||||
$pendingRegistration = new Registration();
|
||||
$pendingRegistration->setBaseId(1);
|
||||
$pendingRegistration->setUser(3);
|
||||
$pendingRegistration->setPending(true);
|
||||
$pendingRegistration->setRejected(false);
|
||||
|
||||
$rejectedRegistration = new Registration();
|
||||
$rejectedRegistration->setBaseId(1);
|
||||
$rejectedRegistration->setUser(3);
|
||||
$rejectedRegistration->setPending(true);
|
||||
$rejectedRegistration->setRejected(true);
|
||||
|
||||
$databox = current((new \appbox(new Application()))->get_databoxes());
|
||||
$collection = current($databox->get_collections());
|
||||
|
||||
$noLimitedPendingRegistration = [
|
||||
[
|
||||
$databox->get_sbas_id() => [
|
||||
$collection->get_base_id() => [
|
||||
'base-id' => $collection->get_base_id(),
|
||||
'db-name' => 'toto',
|
||||
'active' => true,
|
||||
'time-limited' => false,
|
||||
'in-time' => null,
|
||||
'registration' => $pendingRegistration
|
||||
]
|
||||
]
|
||||
],
|
||||
'pending',
|
||||
1
|
||||
];
|
||||
|
||||
|
||||
$rejectedRegistration = [
|
||||
[
|
||||
$databox->get_sbas_id() => [
|
||||
$collection->get_base_id() => [
|
||||
'base-id' => $collection->get_base_id(),
|
||||
'db-name' => 'titi',
|
||||
'active' => true,
|
||||
'time-limited' => false,
|
||||
'in-time' => null,
|
||||
'registration' => $rejectedRegistration
|
||||
]
|
||||
]
|
||||
],
|
||||
'rejected',
|
||||
1
|
||||
];
|
||||
|
||||
$noActiveRegistration = [
|
||||
[
|
||||
$databox->get_sbas_id() => [
|
||||
$collection->get_base_id() => [
|
||||
'base-id' => 1,
|
||||
'db-name' => 'tutu',
|
||||
'active' => false,
|
||||
'time-limited' => false,
|
||||
'in-time' => null,
|
||||
'registration' => $pendingRegistration
|
||||
]
|
||||
]
|
||||
],
|
||||
'inactive',
|
||||
1
|
||||
];
|
||||
|
||||
$limitedActiveIntimePendingRegistration = [
|
||||
[
|
||||
$databox->get_sbas_id() => [
|
||||
$collection->get_base_id() => [
|
||||
'base-id' => $collection->get_base_id(),
|
||||
'db-name' => 'tata',
|
||||
'active' => true,
|
||||
'time-limited' => true,
|
||||
'in-time' => true,
|
||||
'registration' => $pendingRegistration
|
||||
]
|
||||
]
|
||||
],
|
||||
'in-time',
|
||||
1
|
||||
];
|
||||
|
||||
$limitedActiveOutdatedPendingRegistration = [
|
||||
[
|
||||
$databox->get_sbas_id() => [
|
||||
$collection->get_base_id() => [
|
||||
'base-id' => $collection->get_base_id(),
|
||||
'db-name' => 'toutou',
|
||||
'active' => true,
|
||||
'time-limited' => true,
|
||||
'in-time' => false,
|
||||
'registration' => $pendingRegistration
|
||||
]
|
||||
]
|
||||
],
|
||||
'out-time',
|
||||
1
|
||||
];
|
||||
|
||||
return [
|
||||
$noLimitedPendingRegistration,
|
||||
$noActiveRegistration,
|
||||
$limitedActiveIntimePendingRegistration,
|
||||
$limitedActiveOutdatedPendingRegistration,
|
||||
$rejectedRegistration
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -53,14 +53,14 @@ class FeedItemRepositoryTest extends \PhraseanetTestCase
|
||||
$item = new FeedItem();
|
||||
$item->setEntry($entry)
|
||||
->setOrd(4)
|
||||
->setRecordId(self::$DI['record_1']->get_record_id())
|
||||
->setSbasId(self::$DI['record_1']->get_record_id());
|
||||
->setRecordId(123456789)
|
||||
->setSbasId(123456789);
|
||||
$entry->addItem($item);
|
||||
self::$DI['app']['EM']->persist($item);
|
||||
|
||||
self::$DI['app']['EM']->persist($entry);
|
||||
self::$DI['app']['EM']->flush();
|
||||
|
||||
$this->assertCount(4, self::$DI['app']['EM']->getRepository('Phraseanet:FeedItem')->loadLatest(self::$DI['app'], 20));
|
||||
$this->assertCount(3, self::$DI['app']['EM']->getRepository('Phraseanet:FeedItem')->loadLatest(self::$DI['app'], 20));
|
||||
}
|
||||
}
|
||||
|
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Registration;
|
||||
|
||||
use Alchemy\Phrasea\Registration\RegistrationManager;
|
||||
|
||||
class RegistrationManagerTest extends \PhraseanetTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getRegistrationProvider
|
||||
*/
|
||||
public function testRegistrationIsEnabled($enabledOnColl, $expected)
|
||||
{
|
||||
$mockColl = $this->getMockBuilder('\collection')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockColl->expects($this->once())->method('isRegistrationEnabled')->will($this->returnValue($enabledOnColl));
|
||||
|
||||
$mockDatabox = $this->getMockBuilder('\databox')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockAppbox = $this->getMockBuilder('\appbox')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockColl->expects($this->once())->method('isRegistrationEnabled')->will($this->returnValue(false));
|
||||
|
||||
$mockDatabox->expects($this->once())->method('get_collections')->will($this->returnValue([$mockColl]));
|
||||
$mockAppbox->expects($this->once())->method('get_databoxes')->will($this->returnValue([$mockDatabox]));
|
||||
|
||||
$service = new RegistrationManager($mockAppbox);
|
||||
$this->assertEquals($expected, $service->isRegistrationEnabled());
|
||||
}
|
||||
|
||||
public function getRegistrationProvider()
|
||||
{
|
||||
return [
|
||||
[false, false],
|
||||
[true, true],
|
||||
];
|
||||
}
|
||||
}
|
@@ -133,6 +133,16 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_template']);
|
||||
});
|
||||
|
||||
self::$DI['registration_1'] = self::$DI->share(function ($DI) {
|
||||
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_1']);
|
||||
});
|
||||
self::$DI['registration_2'] = self::$DI->share(function ($DI) {
|
||||
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_2']);
|
||||
});
|
||||
self::$DI['registration_3'] = self::$DI->share(function ($DI) {
|
||||
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_3']);
|
||||
});
|
||||
|
||||
self::$DI['oauth2-app-user'] = self::$DI->share(function ($DI) {
|
||||
return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user']);
|
||||
});
|
||||
|
@@ -284,12 +284,12 @@ div.switch_right.unchecked {
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
#tab_demandes .dl-horizontal dd {
|
||||
#tab-registrations .dl-horizontal dd {
|
||||
word-break: break-all;
|
||||
margin-left: 140px;
|
||||
}
|
||||
|
||||
#tab_demandes .dl-horizontal dt {
|
||||
#tab-registrations .dl-horizontal dt {
|
||||
width: 130px;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user