mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-08 18:44:30 +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->insertOneAggregateToken($this->container['EM'], $DI);
|
||||||
$this->insertLazaretFiles($this->container['EM'], $DI);
|
$this->insertLazaretFiles($this->container['EM'], $DI);
|
||||||
$this->insertAuthFailures($this->container['EM'], $DI);
|
$this->insertAuthFailures($this->container['EM'], $DI);
|
||||||
$this->insertOneRegistration($this->container['EM'],$DI['user_alt1'], $DI['coll']);
|
$this->insertOneRegistration($DI, $this->container['EM'], $DI['user_alt1'], $DI['coll'], 'now', 'registration_1');
|
||||||
$this->insertOneRegistration($this->container['EM'],$DI['user_alt2'], $DI['coll'], '-3 months');
|
$this->insertOneRegistration($DI, $this->container['EM'], $DI['user_alt2'], $DI['coll'], '-3 months', 'registration_2');
|
||||||
$this->insertOneRegistration($this->container['EM'],$DI['user_alt2'], $DI['coll']);
|
$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'] = $DI['user']->getId();
|
||||||
$fixtures['user']['test_phpunit_not_admin'] = $DI['user_notAdmin']->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_6'] = $DI['record_6']->get_record_id();
|
||||||
$fixtures['record']['record_7'] = $DI['record_7']->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['lazaret']['lazaret_1'] = $DI['lazaret_1']->getId();
|
||||||
|
|
||||||
$fixtures['user']['user_1'] = $DI['user_1']->getId();
|
$fixtures['user']['user_1'] = $DI['user_1']->getId();
|
||||||
@@ -644,16 +647,18 @@ class RegenerateSqliteDb extends Command
|
|||||||
$em->persist($entry);
|
$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());
|
$em->getEventManager()->removeEventSubscriber(new TimestampableListener());
|
||||||
$registration = new Registration();
|
$registration = new Registration();
|
||||||
$registration->setBaseId($collection->get_base_id());
|
$registration->setCollection($collection);
|
||||||
$registration->setUser($user->get_id());
|
$registration->setUser($user);
|
||||||
$registration->setUpdated(new \DateTime($when));
|
$registration->setUpdated(new \DateTime($when));
|
||||||
$registration->setCreated(new \DateTime($when));
|
$registration->setCreated(new \DateTime($when));
|
||||||
$em->persist($registration);
|
$em->persist($registration);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
$em->getEventManager()->addEventSubscriber(new TimestampableListener());
|
$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\Helper\User as UserHelper;
|
||||||
use Alchemy\Phrasea\Model\Entities\FtpCredential;
|
use Alchemy\Phrasea\Model\Entities\FtpCredential;
|
||||||
use Alchemy\Phrasea\Model\Entities\User;
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
use igorw;
|
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ControllerProviderInterface;
|
use Silex\ControllerProviderInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@@ -354,42 +353,39 @@ class Users implements ControllerProviderInterface
|
|||||||
return $response;
|
return $response;
|
||||||
})->bind('admin_users_export_csv');
|
})->bind('admin_users_export_csv');
|
||||||
|
|
||||||
$controllers->get('/demands/', function (Application $app) {
|
$controllers->get('/registrations/', function (Application $app) {
|
||||||
$app['manipulator.registration']->deleteOldRegistrations();
|
$app['manipulator.registration']->deleteOldRegistrations();
|
||||||
|
|
||||||
$models = $app['manipulator.user']->getRepository()->findModelOf($app['authentication']->getUser());
|
$models = $app['manipulator.user']->getRepository()->findModelOf($app['authentication']->getUser());
|
||||||
|
|
||||||
$users = $registrations = [];
|
$userRegistrations = [];
|
||||||
foreach ($app['manipulator.registration']->getRepository()->getDemandsForUser(
|
foreach ($app['manipulator.registration']->getRepository()->getUserRegistrations(
|
||||||
$app['authentication']->getUser(),
|
$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) {
|
) as $registration) {
|
||||||
$user = $registration->getUser();
|
$user = $registration->getUser();
|
||||||
$users[$user->getId()] = $user;
|
$userRegistrations[$user->getId()]['user'] = $user;
|
||||||
|
$userRegistrations[$user->getId()]['registrations'][$registration->getBaseid()] = $registration;
|
||||||
|
|
||||||
if (null !== igorw::get_in($registrations, [$user->getId(), $registration->getBaseId()])) {
|
|
||||||
$registrations[$user->getId()][$registration->getBaseId()] = $registration;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $app['twig']->render('admin/user/demand.html.twig', [
|
return $app['twig']->render('admin/user/registrations.html.twig', [
|
||||||
'users' => $users,
|
'user_registrations' => $userRegistrations,
|
||||||
'registrations' => $registrations,
|
|
||||||
'models' => $models,
|
'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 = [];
|
$templates = $deny = $accept = $options = [];
|
||||||
|
|
||||||
foreach ($request->request->get('template', []) as $tmp) {
|
foreach ($request->request->get('template', []) as $tmp) {
|
||||||
if (trim($tmp) != '') {
|
if ('' === trim($tmp)) {
|
||||||
$tmp = explode('_', $tmp);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (count($tmp) == 2) {
|
$tmp = explode('_', $tmp);
|
||||||
$templates[$tmp[0]] = $tmp[1];
|
|
||||||
}
|
if (count($tmp) == 2) {
|
||||||
|
$templates[$tmp[0]] = $tmp[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,92 +419,102 @@ class Users implements ControllerProviderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($templates) > 0 || count($deny) > 0 || count($accept) > 0) {
|
if (count($templates) > 0 || count($deny) > 0 || count($accept) > 0) {
|
||||||
$done = [];
|
$cacheToUpdate = $done = [];
|
||||||
$cache_to_update = [];
|
|
||||||
|
|
||||||
foreach ($templates as $usr => $template_id) {
|
foreach ($templates as $usr => $template_id) {
|
||||||
$user = $app['manipulator.user']->getRepository()->find($usr);
|
if (null === $user = $app['manipulator.user']->getRepository()->find($usr)) {
|
||||||
$cache_to_update[$usr] = true;
|
$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);
|
$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) {
|
foreach ($collections as $collection) {
|
||||||
$done[$usr][$base_id] = true;
|
$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) {
|
foreach ($deny as $usr => $bases) {
|
||||||
$cache_to_update[$usr] = true;
|
if (null === $user = $app['manipulator.user']->getRepository()->find($usr)) {
|
||||||
foreach ($bases as $bas) {
|
$app->abort(400, srpintf("User with id % in provided in 'deny' request variable could not be found", $usr));
|
||||||
if (null !== $registration = $app['manipulator.registration']->getRepository()->findOneBy([
|
}
|
||||||
'user' => $usr,
|
$cacheToUpdate[$usr] = $user;
|
||||||
'baseId' => $bas
|
foreach ($app['manipulator.registration']->getRepository()->getUserRegistrations(
|
||||||
])) {
|
$user,
|
||||||
$app['manipulator.registration']->rejectDemand($registration);
|
array_map(function ($baseId) use ($app) {
|
||||||
$done[$usr][$bas] = false;
|
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) {
|
foreach ($accept as $usr => $bases) {
|
||||||
$user = $app['manipulator.user']->getRepository()->find($usr);
|
if (null === $user = $app['manipulator.user']->getRepository()->find($usr)) {
|
||||||
$cache_to_update[$usr] = true;
|
$app->abort(400, srpintf("User with id % in provided in 'accept' request variable could not be found", $usr));
|
||||||
|
}
|
||||||
foreach ($bases as $bas) {
|
$cacheToUpdate[$usr] = $user;
|
||||||
$collection = \collection::get_from_base_id($app, $bas);
|
foreach ($app['manipulator.registration']->getRepository()->getUserRegistrations(
|
||||||
if (null !== $registration = $app['manipulator.registration']->getRepository()->findOneBy([
|
$user,
|
||||||
'user' => $user->get_id(),
|
array_map(function ($baseId) use ($app) {
|
||||||
'baseId' => $collection->get_base_id()
|
return \collection::get_from_base_id($app, $baseId);
|
||||||
])) {
|
}, $bases)
|
||||||
$done[$usr][$bas] = true;
|
) as $registration) {
|
||||||
$app['manipulator.registration']->acceptRegistration($registration, $user, $collection, $options[$usr][$bas]['HD'], $options[$usr][$bas]['WM']);
|
$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) {
|
array_walk($cacheToUpdate, function (User $user) use ($app) {
|
||||||
$user = $app['manipulator.user']->getRepository()->find($usr_id);
|
|
||||||
$app['acl']->get($user)->delete_data_from_cache();
|
$app['acl']->get($user)->delete_data_from_cache();
|
||||||
unset($user);
|
});
|
||||||
}
|
unset ($cacheToUpdate);
|
||||||
|
|
||||||
foreach ($done as $usr => $bases) {
|
foreach ($done as $usr => $bases) {
|
||||||
|
$user = $app['manipulator.user']->getRepository()->find($usr);
|
||||||
$acceptColl = $denyColl = [];
|
$acceptColl = $denyColl = [];
|
||||||
if (null !== $user = $app['manipulator.user']->getRepository()->find($usr)) {
|
|
||||||
if (\Swift_Validate::email($user->getEmail())) {
|
|
||||||
foreach ($bases as $bas => $isok) {
|
|
||||||
if ($isok) {
|
|
||||||
$acceptColl[] = \phrasea::bas_labels($bas, $app);
|
|
||||||
} else {
|
|
||||||
$denyColl[] = \phrasea::bas_labels($bas, $app);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (0 !== count($acceptColl) || 0 !== count($denyColl)) {
|
|
||||||
$message = '';
|
|
||||||
if (0 !== count($acceptColl)) {
|
|
||||||
$message .= "\n" . $app->trans('login::register:email: Vous avez ete accepte sur les collections suivantes : ') . implode(', ', $acceptColl). "\n";
|
|
||||||
}
|
|
||||||
if (0 !== count($denyColl)) {
|
|
||||||
$message .= "\n" . $app->trans('login::register:email: Vous avez ete refuse sur les collections suivantes : ') . implode(', ', $denyColl) . "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$receiver = new Receiver(null, $user->getEmail());
|
foreach ($bases as $bas => $isok) {
|
||||||
$mail = MailSuccessEmailUpdate::create($app, $receiver, null, $message);
|
$collection = \collection::get_from_base_id($app, $bas);
|
||||||
|
|
||||||
$app['notification.deliverer']->deliver($mail);
|
if ($isok) {
|
||||||
}
|
$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)) {
|
||||||
|
$message .= "\n" . $app->trans('login::register:email: Vous avez ete accepte sur les collections suivantes : ') . implode(', ', $acceptColl). "\n";
|
||||||
|
}
|
||||||
|
if (0 !== count($denyColl)) {
|
||||||
|
$message .= "\n" . $app->trans('login::register:email: Vous avez ete refuse sur les collections suivantes : ') . implode(', ', $denyColl) . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$receiver = new Receiver(null, $user->getEmail());
|
||||||
|
$mail = MailSuccessEmailUpdate::create($app, $receiver, null, $message);
|
||||||
|
|
||||||
|
$app['notification.deliverer']->deliver($mail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $app->redirectPath('users_display_demands', ['success' => 1]);
|
return $app->redirectPath('users_display_registrations', ['success' => 1]);
|
||||||
})->bind('users_submit_demands');
|
})->bind('users_submit_registrations');
|
||||||
|
|
||||||
$controllers->get('/import/file/', function (Application $app, Request $request) {
|
$controllers->get('/import/file/', function (Application $app, Request $request) {
|
||||||
return $app['twig']->render('admin/user/import/file.html.twig');
|
return $app['twig']->render('admin/user/import/file.html.twig');
|
||||||
|
@@ -92,11 +92,11 @@ class Lazaret implements ControllerProviderInterface
|
|||||||
$lazaretFiles = $lazaretRepository->findPerPage($baseIds, $offset, $perPage);
|
$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,
|
'lazaretFiles' => $lazaretFiles,
|
||||||
'currentPage' => $page,
|
'currentPage' => $page,
|
||||||
'perPage' => $perPage,
|
'perPage' => $perPage,
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -232,7 +232,7 @@ class Account implements ControllerProviderInterface
|
|||||||
public function accountAccess(Application $app, Request $request)
|
public function accountAccess(Application $app, Request $request)
|
||||||
{
|
{
|
||||||
return $app['twig']->render('account/access.html.twig', [
|
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)
|
public function updateAccount(PhraseaApplication $app, Request $request)
|
||||||
{
|
{
|
||||||
$demands = $request->request->get('demand');
|
$registrations = $request->request->get('registrations');
|
||||||
if (false === is_array($demands)) {
|
if (false === is_array($registrations)) {
|
||||||
$app->abort(400, '"demand" parameter must be an array of base id ');
|
$app->abort(400, '"registrations" parameter must be an array of base ids.');
|
||||||
}
|
}
|
||||||
if (0 !== count($demands)) {
|
if (0 !== count($registrations)) {
|
||||||
foreach ($demands as $baseId) {
|
foreach ($registrations as $baseId) {
|
||||||
$app['registration-manager']->createRegistration($app['authentication']->getUser()->get_id(), $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.'));
|
$app->addFlash('success', $app->trans('Your registration requests have been taken into account.'));
|
||||||
}
|
}
|
||||||
|
@@ -267,7 +267,7 @@ class Login implements ControllerProviderInterface
|
|||||||
|
|
||||||
public function doRegistration(PhraseaApplication $app, Request $request)
|
public function doRegistration(PhraseaApplication $app, Request $request)
|
||||||
{
|
{
|
||||||
if (! $app['registration.manager']->isRegistrationEnabled()) {
|
if (!$app['registration.manager']->isRegistrationEnabled()) {
|
||||||
$app->abort(404, 'Registration is disabled');
|
$app->abort(404, 'Registration is disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,7 +335,7 @@ class Login implements ControllerProviderInterface
|
|||||||
} else {
|
} else {
|
||||||
$selected = isset($data['collections']) ? $data['collections'] : null;
|
$selected = isset($data['collections']) ? $data['collections'] : null;
|
||||||
}
|
}
|
||||||
$inscriptions = $app['manipulator.registration']->getRegistrationSummary();
|
$inscriptions = $app['registration.manager']->getRegistrationSummary();
|
||||||
$inscOK = [];
|
$inscOK = [];
|
||||||
|
|
||||||
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
|
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||||
@@ -385,33 +385,25 @@ class Login implements ControllerProviderInterface
|
|||||||
$app['EM']->flush();
|
$app['EM']->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
$demandOK = [];
|
$registrationsOK = [];
|
||||||
|
|
||||||
if ($app['conf']->get(['registry', 'registration', 'auto-register-enabled'])) {
|
if ($app['conf']->get(['registry', 'registration', 'auto-register-enabled'])) {
|
||||||
$template_user = $app['manipulator.user']->getRepository()->findByLogin(User::USER_AUTOREGISTER);
|
$template_user = $app['manipulator.user']->getRepository()->findByLogin(User::USER_AUTOREGISTER);
|
||||||
|
$app['acl']->get($user)->apply_model($template_user, array_keys($inscOK));
|
||||||
$base_ids = [];
|
|
||||||
|
|
||||||
foreach (array_keys($inscOK) as $base_id) {
|
|
||||||
$base_ids[] = $base_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$app['acl']->get($user)->apply_model($template_user, $base_ids);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$autoReg = $app['acl']->get($user)->get_granted_base();
|
$autoReg = $app['acl']->get($user)->get_granted_base();
|
||||||
|
|
||||||
foreach ($inscOK as $base_id => $autorisation) {
|
foreach ($inscOK as $baseId => $authorization) {
|
||||||
if (false === $autorisation || $app['acl']->get($user)->has_access_to_base($base_id)) {
|
if (false === $authorization || $app['acl']->get($user)->has_access_to_base($baseId)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$app['manipulator.registration']->createRegistration($user->getId(), $base_id);
|
$app['manipulator.registration']->createRegistration($user, \collection::get_from_base_id($app, $baseId));
|
||||||
$demandOK[$base_id] = true;
|
$registrationsOK[$baseId] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'demand' => $demandOK,
|
'registrations'=> $registrationsOK,
|
||||||
'autoregister' => $autoReg,
|
'autoregister' => $autoReg,
|
||||||
'usr_id' => $user->getId()
|
'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) {
|
$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;
|
namespace Alchemy\Phrasea\Core\Provider;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Form\Constraint\NewLogin;
|
use Alchemy\Phrasea\Form\Constraint\NewLogin;
|
||||||
use Alchemy\Phrasea\Model\Manipulator\RegistrationManipulator;
|
|
||||||
use Alchemy\Phrasea\Model\Entities\User;
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
|
use Alchemy\Phrasea\Core\Configuration\RegistrationManager;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ServiceProviderInterface;
|
use Silex\ServiceProviderInterface;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
@@ -27,7 +27,7 @@ class RegistrationServiceProvider implements ServiceProviderInterface
|
|||||||
});
|
});
|
||||||
|
|
||||||
$app['registration.manager'] = $app->share(function (Application $app) {
|
$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) {
|
$app['registration.optional-fields'] = $app->share(function (Application $app) {
|
||||||
|
@@ -13,7 +13,7 @@ namespace Alchemy\Phrasea\Core;
|
|||||||
|
|
||||||
class Version
|
class Version
|
||||||
{
|
{
|
||||||
protected static $number = '3.9.0-alpha.12';
|
protected static $number = '3.9.0-alpha.13';
|
||||||
protected static $name = 'Epanterias';
|
protected static $name = 'Epanterias';
|
||||||
|
|
||||||
public static function getNumber()
|
public static function getNumber()
|
||||||
|
@@ -72,16 +72,15 @@ class PhraseaRegisterForm extends AbstractType
|
|||||||
|
|
||||||
$builder->add('provider-id', 'hidden');
|
$builder->add('provider-id', 'hidden');
|
||||||
|
|
||||||
$choices = [];
|
$choices = $baseIds = [];
|
||||||
$baseIds = [];
|
|
||||||
|
|
||||||
foreach ($this->app['manipulator.registration']->getRegistrationSummary() as $baseInfo) {
|
foreach ($this->app['registration.manager']->getRegistrationSummary() as $baseInfo) {
|
||||||
$dbName = $baseInfo['config']['db-name'];
|
$dbName = $baseInfo['config']['db-name'];
|
||||||
foreach ($baseInfo['config']['collections'] as $baseId => $collInfo) {
|
foreach ($baseInfo['config']['collections'] as $baseId => $collInfo) {
|
||||||
if (false === $collInfo['can-register']) {
|
if (false === $collInfo['can-register']) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$choices[$dbName][$baseId] = \phrasea::bas_labels($baseId, $this->app);
|
$choices[$dbName][$baseId] = $collInfo['coll-name'];
|
||||||
$baseIds[] = $baseId;
|
$baseIds[] = $baseId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,11 +11,14 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Model\Entities;
|
namespace Alchemy\Phrasea\Model\Entities;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Gedmo\Mapping\Annotation as Gedmo;
|
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")
|
* @ORM\Entity(repositoryClass="Alchemy\Phrasea\Model\Repositories\RegistrationRepository")
|
||||||
*/
|
*/
|
||||||
class Registration
|
class Registration
|
||||||
@@ -28,8 +31,11 @@ class Registration
|
|||||||
private $id;
|
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;
|
private $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,25 +116,45 @@ class Registration
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $user
|
|
||||||
*
|
|
||||||
* @return Registration
|
* @return Registration
|
||||||
*/
|
*/
|
||||||
public function setUser($user)
|
public function setUser(User $user)
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function getUser()
|
public function getUser()
|
||||||
{
|
{
|
||||||
return $this->user;
|
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
|
* @param mixed $baseId
|
||||||
*
|
*
|
||||||
|
@@ -11,40 +11,43 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Model\Manipulator;
|
namespace Alchemy\Phrasea\Model\Manipulator;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application;
|
||||||
use Alchemy\Phrasea\Authentication\ACLProvider;
|
use Alchemy\Phrasea\Authentication\ACLProvider;
|
||||||
use Alchemy\Phrasea\Model\Entities\Registration;
|
use Alchemy\Phrasea\Model\Entities\Registration;
|
||||||
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
use Alchemy\Phrasea\Model\Repositories\RegistrationRepository;
|
use Alchemy\Phrasea\Model\Repositories\RegistrationRepository;
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
use igorw;
|
|
||||||
|
|
||||||
class RegistrationManipulator implements ManipulatorInterface
|
class RegistrationManipulator implements ManipulatorInterface
|
||||||
{
|
{
|
||||||
private $em;
|
private $em;
|
||||||
|
private $app;
|
||||||
private $appbox;
|
private $appbox;
|
||||||
private $repository;
|
private $repository;
|
||||||
private $aclProvider;
|
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->em = $em;
|
||||||
$this->appbox = $appbox;
|
$this->appbox = $appbox;
|
||||||
$this->repository = $this->em->getRepository('Alchemy\Phrasea\Model\Entities\Registration');
|
|
||||||
$this->aclProvider = $aclProvider;
|
$this->aclProvider = $aclProvider;
|
||||||
|
$this->repository = $this->em->getRepository('Phraseanet:Registration');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new registration.
|
* Creates a new registration.
|
||||||
*
|
*
|
||||||
* @param $userId
|
* @param User $user
|
||||||
* @param $baseId
|
* @param \collection $collection
|
||||||
*
|
*
|
||||||
* @return Registration
|
* @return Registration
|
||||||
*/
|
*/
|
||||||
public function createRegistration($userId, $baseId)
|
public function createRegistration(User $user, \collection $collection)
|
||||||
{
|
{
|
||||||
$registration = new Registration();
|
$registration = new Registration();
|
||||||
$registration->setUser($userId);
|
$registration->setUser($user);
|
||||||
$registration->setBaseId($baseId);
|
$registration->setCollection($collection);
|
||||||
$this->em->persist($registration);
|
$this->em->persist($registration);
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
|
||||||
@@ -67,14 +70,15 @@ class RegistrationManipulator implements ManipulatorInterface
|
|||||||
/**
|
/**
|
||||||
* Accepts a registration.
|
* Accepts a registration.
|
||||||
*
|
*
|
||||||
* @param Registration $registration
|
* @param Registration $registration
|
||||||
* @param \User_Adapter $user
|
* @param bool $grantHd
|
||||||
* @param \Collection $collection
|
* @param bool $grantWatermark
|
||||||
* @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_sbas([$collection->get_sbas_id()]);
|
||||||
$this->aclProvider->get($user)->give_access_to_base([$collection->get_base_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(), [
|
$this->aclProvider->get($user)->update_rights_to_base($collection->get_base_id(), [
|
||||||
@@ -88,117 +92,6 @@ class RegistrationManipulator implements ManipulatorInterface
|
|||||||
$this->em->flush();
|
$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.
|
* Gets Registration Repository.
|
||||||
*
|
*
|
||||||
@@ -212,21 +105,23 @@ class RegistrationManipulator implements ManipulatorInterface
|
|||||||
/**
|
/**
|
||||||
* Deletes registration for given user.
|
* Deletes registration for given user.
|
||||||
*
|
*
|
||||||
* @param $userId
|
* @param User $user
|
||||||
* @param array $baseList
|
* @param \collection[] $collections
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function deleteRegistrationsForUser($userId, array $baseList)
|
public function deleteUserRegistrations(User $user, array $collections)
|
||||||
{
|
{
|
||||||
$qb = $this->getRepository()->createQueryBuilder('d');
|
$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->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->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();
|
return $qb->getQuery()->execute();
|
||||||
@@ -238,7 +133,7 @@ class RegistrationManipulator implements ManipulatorInterface
|
|||||||
public function deleteOldRegistrations()
|
public function deleteOldRegistrations()
|
||||||
{
|
{
|
||||||
$qb = $this->getRepository()->createQueryBuilder('d');
|
$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->where($qb->expr()->lt('d.created', ':date'));
|
||||||
$qb->setParameter(':date', new \DateTime('-1 month'));
|
$qb->setParameter(':date', new \DateTime('-1 month'));
|
||||||
$qb->getQuery()->execute();
|
$qb->getQuery()->execute();
|
||||||
@@ -249,12 +144,12 @@ class RegistrationManipulator implements ManipulatorInterface
|
|||||||
*
|
*
|
||||||
* @param $baseId
|
* @param $baseId
|
||||||
*/
|
*/
|
||||||
public function deleteRegistrationsOnCollection($baseId)
|
public function deleteRegistrationsOnCollection(\collection $collection)
|
||||||
{
|
{
|
||||||
$qb = $this->getRepository()->createQueryBuilder('d');
|
$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->where($qb->expr()->eq('d.baseId', ':base'));
|
||||||
$qb->setParameter(':base', $baseId);
|
$qb->setParameter(':base', $collection->get_base_id());
|
||||||
$qb->getQuery()->execute();
|
$qb->getQuery()->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -82,6 +82,6 @@ class NativeQueryProvider
|
|||||||
AND u.deleted="0"', $rsm
|
AND u.deleted="0"', $rsm
|
||||||
);
|
);
|
||||||
|
|
||||||
return $query->getResults();
|
return $query->getResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
namespace Alchemy\Phrasea\Model\Repositories;
|
namespace Alchemy\Phrasea\Model\Repositories;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RegistrationRepository
|
* RegistrationRepository
|
||||||
@@ -24,20 +25,22 @@ class RegistrationRepository extends EntityRepository
|
|||||||
/**
|
/**
|
||||||
* Displays registrations for user on provided collection.
|
* Displays registrations for user on provided collection.
|
||||||
*
|
*
|
||||||
* @param \User_Adapter $user
|
* @param User $user
|
||||||
* @param array $baseList
|
* @param \collection[] $collections
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getRegistrationsForUser(\User_Adapter $user, array $baseList)
|
public function getUserRegistrations(User $user, array $collections)
|
||||||
{
|
{
|
||||||
$qb = $this->createQueryBuilder('d');
|
$qb = $this->createQueryBuilder('d');
|
||||||
$qb->where($qb->expr()->eq('d.user', ':user'));
|
$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->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');
|
$qb->orderBy('d.created', 'DESC');
|
||||||
@@ -48,11 +51,11 @@ class RegistrationRepository extends EntityRepository
|
|||||||
/**
|
/**
|
||||||
* Gets registration registrations for a user.
|
* Gets registration registrations for a user.
|
||||||
*
|
*
|
||||||
* @param $usrId
|
* @param User $user
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getRegistrationsSummaryForUser($usrId)
|
public function getRegistrationsSummaryForUser(User $user)
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
$rsm = $this->createResultSetMappingBuilder('d');
|
$rsm = $this->createResultSetMappingBuilder('d');
|
||||||
@@ -78,7 +81,7 @@ class RegistrationRepository extends EntityRepository
|
|||||||
AND model_of = 0";
|
AND model_of = 0";
|
||||||
|
|
||||||
$query = $this->_em->createNativeQuery($sql, $rsm);
|
$query = $this->_em->createNativeQuery($sql, $rsm);
|
||||||
$query->setParameter(1, $usrId);
|
$query->setParameter(1, $user->getId());
|
||||||
|
|
||||||
foreach ($query->getResult() as $row) {
|
foreach ($query->getResult() as $row) {
|
||||||
$registrationEntity = $row[0];
|
$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;
|
namespace Alchemy\Phrasea\Setup\DoctrineMigrations;
|
||||||
|
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
use Doctrine\ORM\Query\ResultSetMapping;
|
|
||||||
|
|
||||||
class RegistrationMigration extends AbstractMigration
|
class RegistrationMigration extends AbstractMigration
|
||||||
{
|
{
|
||||||
public function doUpSql(Schema $schema)
|
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)
|
public function doDownSql(Schema $schema)
|
@@ -1089,7 +1089,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
$record->set_metadatas($metadatas);
|
$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) {
|
} catch (\Exception $e) {
|
||||||
$result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('An error occured'));
|
$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->execute([':base_id' => $this->get_base_id()]);
|
||||||
$stmt->closeCursor();
|
$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);
|
$this->get_databox()->delete_data_from_cache(databox::CACHE_COLLECTIONS);
|
||||||
|
|
||||||
@@ -534,7 +534,7 @@ class collection implements cache_cacheableInterface
|
|||||||
$stmt->execute($params);
|
$stmt->execute($params);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this->get_base_id());
|
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this);
|
||||||
|
|
||||||
phrasea::reset_baseDatas($app['phraseanet.appbox']);
|
phrasea::reset_baseDatas($app['phraseanet.appbox']);
|
||||||
|
|
||||||
@@ -748,17 +748,19 @@ class collection implements cache_cacheableInterface
|
|||||||
*/
|
*/
|
||||||
public function isRegistrationEnabled()
|
public function isRegistrationEnabled()
|
||||||
{
|
{
|
||||||
if ($xml = simplexml_load_string($this->get_prefs())) {
|
if (false === $xml = simplexml_load_string($this->get_prefs())) {
|
||||||
$element = $xml->xpath('/baseprefs/caninscript');
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (count($element) === 0) {
|
$element = $xml->xpath('/baseprefs/caninscript');
|
||||||
return $this->databox->isRegistrationEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($element as $caninscript) {
|
if (count($element) === 0) {
|
||||||
if (false !== (Boolean) (string) $caninscript) {
|
return $this->databox->isRegistrationEnabled();
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
foreach ($element as $caninscript) {
|
||||||
|
if (false !== (Boolean) (string) $caninscript) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -774,12 +776,12 @@ class collection implements cache_cacheableInterface
|
|||||||
*/
|
*/
|
||||||
public function getTermsOfUse()
|
public function getTermsOfUse()
|
||||||
{
|
{
|
||||||
if ($xml = simplexml_load_string($this->get_prefs())) {
|
if (false === $xml = simplexml_load_string($this->get_prefs())) {
|
||||||
foreach ($xml->xpath('/baseprefs/cgu') as $sbpcgu) {
|
return;
|
||||||
return $sbpcgu->saveXML();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
foreach ($xml->xpath('/baseprefs/cgu') as $sbpcgu) {
|
||||||
|
return $sbpcgu->saveXML();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ class databox_cgu
|
|||||||
if (trim($term['terms']) == '') {
|
if (trim($term['terms']) == '') {
|
||||||
continue;
|
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 .= '<blockquote>' . $term['terms'] . '</blockquote>';
|
||||||
$out .= '<div>' . $app->trans('cgus:: Pour continuer a utiliser lapplication, vous devez accepter les conditions precedentes') . '
|
$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)
|
public function fire($event, $params, &$object)
|
||||||
{
|
{
|
||||||
$default = [
|
$default = ['usr_id' => '', 'registrations' => []];
|
||||||
'usr_id' => ''
|
|
||||||
, 'demand' => []
|
|
||||||
];
|
|
||||||
|
|
||||||
$params = array_merge($default, $params);
|
$params = array_merge($default, $params);
|
||||||
$base_ids = $params['demand'];
|
$base_ids = $params['registrations'];
|
||||||
|
|
||||||
if (count($base_ids) == 0) {
|
if (count($base_ids) == 0) {
|
||||||
return;
|
return;
|
||||||
@@ -79,7 +76,7 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract
|
|||||||
|
|
||||||
$usr_id->appendChild($dom_xml->createTextNode($params['usr_id']));
|
$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 = $dom_xml->createElement('base_id');
|
||||||
$base_id_node->appendChild($dom_xml->createTextNode($base_id));
|
$base_id_node->appendChild($dom_xml->createTextNode($base_id));
|
||||||
$base_ids->appendChild($base_id_node);
|
$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' => []
|
'final' => []
|
||||||
, 'comment' => []
|
, '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
|
version: user-auth-provider
|
||||||
class: Alchemy\Phrasea\Setup\DoctrineMigrations\UserAuthProviderMigration
|
class: Alchemy\Phrasea\Setup\DoctrineMigrations\UserAuthProviderMigration
|
||||||
migration18:
|
migration18:
|
||||||
version: registration-request
|
version: registration
|
||||||
class: Alchemy\Phrasea\Setup\DoctrineMigrations\RegistrationMigration
|
class: Alchemy\Phrasea\Setup\DoctrineMigrations\RegistrationMigration
|
||||||
|
@@ -140,7 +140,7 @@
|
|||||||
<td style="text-align: right;">{{ collInfo["coll-name"] }}</td>
|
<td style="text-align: right;">{{ collInfo["coll-name"] }}</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td class="TD_R" style="width: 200px;">
|
<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>
|
<span>{{ "login::register: Faire une demande d\'acces" | trans }}</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@@ -44,7 +44,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="{% if feature == 'registrations' %}selected{% endif %}">
|
<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" />
|
<img src="/skins/admin/Demandes.png" />
|
||||||
<span>{{ 'admin::utilisateurs: demandes en cours' | trans }}</span>
|
<span>{{ 'admin::utilisateurs: demandes en cours' | trans }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
resize();
|
resize();
|
||||||
});
|
});
|
||||||
|
|
||||||
var $form = $("form#accept-demand");
|
var $form = $("form#accept-registration");
|
||||||
var $mainBtnAction = $(".btn-all-action", $form);
|
var $mainBtnAction = $(".btn-all-action", $form);
|
||||||
var $basesBtnAction = $(".btn-single-action", $form);
|
var $basesBtnAction = $(".btn-single-action", $form);
|
||||||
|
|
||||||
@@ -172,8 +172,8 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if users | length > 0 %}
|
{% if user_registrations | length > 0 %}
|
||||||
<form id="accept-demand" action="{{ path('users_submit_demands') }}" method="post">
|
<form id="accept-registration" action="{{ path('users_submit_registrations') }}" method="post">
|
||||||
<div class="btn-group btn-all-action">
|
<div class="btn-group btn-all-action">
|
||||||
<button data-event="deny" class="btn deny-checker" type="button">
|
<button data-event="deny" class="btn deny-checker" type="button">
|
||||||
<img title="{{ 'admin:: refuser l\'acces' | trans }}" src="/skins/icons/delete.gif"/>
|
<img title="{{ 'admin:: refuser l\'acces' | trans }}" src="/skins/icons/delete.gif"/>
|
||||||
@@ -200,9 +200,9 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="registration-wrapper PNB" style="top:160px;bottom: 50px;overflow: auto">
|
<div class="registration-wrapper PNB" style="top:160px;bottom: 50px;overflow: auto">
|
||||||
<div id="tab_demandes">
|
<div id="registrations">
|
||||||
{% for user in users %}
|
{% for user_registration in user_registrations %}
|
||||||
{% set userRegistrations = registrations[user.getId()] %}
|
{% set user = user_registration['user'] %}
|
||||||
<div class="well well-small">
|
<div class="well well-small">
|
||||||
<table class="table" style="table-layout: fixed;">
|
<table class="table" style="table-layout: fixed;">
|
||||||
<tr>
|
<tr>
|
||||||
@@ -230,9 +230,9 @@
|
|||||||
</dl>
|
</dl>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% for baseId, demand in userRegistrations %}
|
{% for basId, registration in user_registration['registrations'] %}
|
||||||
<div>
|
<div>
|
||||||
{{ app['date-formatter'].getPrettyString(demand.getUpdated()) }}
|
{{ app['date-formatter'].getPrettyString(registration.getUpdated()) }}
|
||||||
</div>
|
</div>
|
||||||
<span style="font-weight:bold;font-size:14px;word-wrap: break-word;">
|
<span style="font-weight:bold;font-size:14px;word-wrap: break-word;">
|
||||||
{{ basId| bas_labels(app) }}
|
{{ basId| bas_labels(app) }}
|
@@ -366,20 +366,18 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
self::$DI['app']['manipulator.user']->delete($user);
|
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());
|
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPostDemands()
|
public function testPostRegistrations()
|
||||||
{
|
{
|
||||||
$id = self::$DI['user_alt1']->getId();
|
$id = self::$DI['user_alt1']->getId();
|
||||||
$baseId = self::$DI['collection']->get_base_id();
|
$baseId = self::$DI['collection']->get_base_id();
|
||||||
$param = sprintf('%s_%s', $id, $baseId);
|
$param = sprintf('%s_%s', $id, $baseId);
|
||||||
|
|
||||||
$appbox = self::$DI['app']['phraseanet.appbox'];
|
|
||||||
|
|
||||||
$stmt = $this->getMock('PDOStatement');
|
$stmt = $this->getMock('PDOStatement');
|
||||||
|
|
||||||
$stmt->expects($this->any())
|
$stmt->expects($this->any())
|
||||||
@@ -408,7 +406,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate');
|
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate');
|
||||||
|
|
||||||
self::$DI['client']->request('POST', '/admin/users/demands/', [
|
self::$DI['client']->request('POST', '/admin/users/registrations/', [
|
||||||
'template' => [],
|
'template' => [],
|
||||||
'accept' => [$param],
|
'accept' => [$param],
|
||||||
'accept_hd' => [$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::upload
|
||||||
* @covers Alchemy\Phrasea\Controller\Prod\Upload::getJsonResponse
|
* @covers Alchemy\Phrasea\Controller\Prod\Upload::getJsonResponse
|
||||||
*/
|
*/
|
||||||
public function testUploadingTwiceTheSameRecordShouldSendToQuantantine()
|
public function testUploadingTwiceTheSameRecordShouldSendToQuarantine()
|
||||||
{
|
{
|
||||||
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoRecordQuarantined');
|
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoRecordQuarantined');
|
||||||
$this->mockUserNotificationSettings('eventsmanager_notify_uploadquarantine');
|
$this->mockUserNotificationSettings('eventsmanager_notify_uploadquarantine');
|
||||||
|
@@ -168,7 +168,7 @@ class UsrListsTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
{
|
{
|
||||||
$entry = self::$DI['app']['EM']->find('Phraseanet:UsrListEntry', 2);
|
$entry = self::$DI['app']['EM']->find('Phraseanet:UsrListEntry', 2);
|
||||||
$list_id = $entry->getList()->getId();
|
$list_id = $entry->getList()->getId();
|
||||||
$usr_id = $entry->getUser(self::$DI['app'])->getId();
|
$usr_id = $entry->getUser()->getId();
|
||||||
$entry_id = $entry->getId();
|
$entry_id = $entry->getId();
|
||||||
|
|
||||||
$route = '/prod/lists/list/' . $list_id . '/remove/' . $usr_id . '/';
|
$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')
|
$service = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\RegistrationManager')
|
||||||
->setConstructorArgs([self::$DI['app']['EM'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['acl']])
|
->setConstructorArgs([self::$DI['app']['phraseanet.appbox'], self::$DI['app']['manipulator.registration']->getRepository(), self::$DI['app']['locale']])
|
||||||
->setMethods(['getRegistrationSummary'])
|
->setMethods(['getRegistrationSummary'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$service->expects($this->once())->method('getRegistrationSummary')->will($this->returnValue($data));
|
$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/');
|
self::$DI['client']->request('GET', '/account/access/');
|
||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
@@ -320,7 +320,7 @@ class AccountTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
array_shift($notifs);
|
array_shift($notifs);
|
||||||
|
|
||||||
self::$DI['client']->request('POST', '/account/', [
|
self::$DI['client']->request('POST', '/account/', [
|
||||||
'demand' => $bases,
|
'registrations' => $bases,
|
||||||
'form_gender' => User::GENDER_MR,
|
'form_gender' => User::GENDER_MR,
|
||||||
'form_firstname' => 'gros',
|
'form_firstname' => 'gros',
|
||||||
'form_lastname' => 'minet',
|
'form_lastname' => 'minet',
|
||||||
@@ -347,7 +347,7 @@ class AccountTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
$this->assertTrue($response->isRedirect());
|
$this->assertTrue($response->isRedirect());
|
||||||
$this->assertEquals('minet', self::$DI['app']['authentication']->getUser()->getLastName());
|
$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(),
|
'user' => self::$DI['app']['authentication']->getUser()->getId(),
|
||||||
'pending' => true
|
'pending' => true
|
||||||
]);
|
]);
|
||||||
|
@@ -17,7 +17,7 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
|
|
||||||
class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||||
{
|
{
|
||||||
public static $demands;
|
public static $registrationCollections;
|
||||||
public static $collections;
|
public static $collections;
|
||||||
public static $login;
|
public static $login;
|
||||||
public static $email;
|
public static $email;
|
||||||
@@ -27,8 +27,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
if (null === self::$demands) {
|
if (null === self::$registrationCollections) {
|
||||||
self::$demands = [self::$DI['collection']->get_coll_id()];
|
self::$registrationCollections = [self::$DI['collection']->get_coll_id()];
|
||||||
}
|
}
|
||||||
if (null === self::$collections) {
|
if (null === self::$collections) {
|
||||||
self::$collections = [self::$DI['collection']->get_base_id()];
|
self::$collections = [self::$DI['collection']->get_base_id()];
|
||||||
@@ -45,7 +45,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
if (null === self::$email) {
|
if (null === self::$email) {
|
||||||
self::$email = self::$DI['user']->getEmail();
|
self::$email = self::$DI['user']->getEmail();
|
||||||
}
|
}
|
||||||
self::$DI['app']['registration.enabled'] = true;
|
|
||||||
|
$this->enableRegistration();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
@@ -56,7 +57,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
public static function tearDownAfterClass()
|
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();
|
parent::tearDownAfterClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,11 +210,11 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
self::$DI['user']->setMailLocked(true);
|
self::$DI['user']->setMailLocked(true);
|
||||||
$this->deleteRequest();
|
$this->deleteRequest();
|
||||||
$demand = new Registration();
|
$registration = new Registration();
|
||||||
$demand->setUser(self::$DI['user']);
|
$registration->setUser(self::$DI['user']);
|
||||||
$demand->setBaseId(self::$DI['collection']->get_base_id());
|
$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['app']['EM']->flush();
|
||||||
|
|
||||||
self::$DI['client']->request('GET', '/login/register-confirm/', ['code' => $token]);
|
self::$DI['client']->request('GET', '/login/register-confirm/', ['code' => $token]);
|
||||||
@@ -534,7 +535,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetPostRegisterWhenRegistrationDisabled($method, $route)
|
public function testGetPostRegisterWhenRegistrationDisabled($method, $route)
|
||||||
{
|
{
|
||||||
self::$DI['app']['registration.enabled'] = false;
|
$this->disableRegistration();
|
||||||
$this->logout(self::$DI['app']);
|
$this->logout(self::$DI['app']);
|
||||||
self::$DI['client']->request($method, $route);
|
self::$DI['client']->request($method, $route);
|
||||||
$this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode());
|
$this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode());
|
||||||
@@ -543,7 +544,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider provideInvalidRegistrationData
|
* @dataProvider provideInvalidRegistrationData
|
||||||
*/
|
*/
|
||||||
public function testPostRegisterbadArguments($parameters, $extraParameters, $errors)
|
public function testPostRegisterBadArguments($parameters, $extraParameters, $errors)
|
||||||
{
|
{
|
||||||
$this->enableTOU();
|
$this->enableTOU();
|
||||||
self::$DI['app']['registration.enabled'] = true;
|
self::$DI['app']['registration.enabled'] = true;
|
||||||
@@ -554,7 +555,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
$parameters = array_merge(['_token' => 'token'], $parameters);
|
$parameters = array_merge(['_token' => 'token'], $parameters);
|
||||||
foreach ($parameters as $key => $parameter) {
|
foreach ($parameters as $key => $parameter) {
|
||||||
if ('collections' === $key && null === $parameter) {
|
if ('collections' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$demands;
|
$parameters[$key] = self::$registrationCollections;
|
||||||
}
|
}
|
||||||
if ('login' === $key && null === $parameter) {
|
if ('login' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$login;
|
$parameters[$key] = self::$login;
|
||||||
@@ -577,6 +578,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
public function testPostRegisterWithoutParams()
|
public function testPostRegisterWithoutParams()
|
||||||
{
|
{
|
||||||
$this->logout(self::$DI['app']);
|
$this->logout(self::$DI['app']);
|
||||||
|
$this->disableTOU();
|
||||||
$crawler = self::$DI['client']->request('POST', '/login/register-classic/');
|
$crawler = self::$DI['client']->request('POST', '/login/register-classic/');
|
||||||
|
|
||||||
$this->assertFalse(self::$DI['client']->getResponse()->isRedirect());
|
$this->assertFalse(self::$DI['client']->getResponse()->isRedirect());
|
||||||
@@ -592,6 +594,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
'confirm' => 'password'
|
'confirm' => 'password'
|
||||||
],
|
],
|
||||||
"collections" => null,
|
"collections" => null,
|
||||||
|
"accept-tou" => '1'
|
||||||
], [], 1],
|
], [], 1],
|
||||||
[[//required extra-field missing
|
[[//required extra-field missing
|
||||||
"password" => [
|
"password" => [
|
||||||
@@ -599,7 +602,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
'confirm' => 'password'
|
'confirm' => 'password'
|
||||||
],
|
],
|
||||||
"email" => $this->generateEmail(),
|
"email" => $this->generateEmail(),
|
||||||
"collections" => null
|
"collections" => null,
|
||||||
|
"accept-tou" => '1'
|
||||||
], [
|
], [
|
||||||
[
|
[
|
||||||
'name' => 'login',
|
'name' => 'login',
|
||||||
@@ -612,7 +616,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
'confirm' => 'passwordMismatch'
|
'confirm' => 'passwordMismatch'
|
||||||
],
|
],
|
||||||
"email" => $this->generateEmail(),
|
"email" => $this->generateEmail(),
|
||||||
"collections" => null
|
"collections" => null,
|
||||||
|
"accept-tou" => '1'
|
||||||
], [], 1],
|
], [], 1],
|
||||||
[[//password tooshort
|
[[//password tooshort
|
||||||
"password" => [
|
"password" => [
|
||||||
@@ -620,7 +625,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
'confirm' => 'min'
|
'confirm' => 'min'
|
||||||
],
|
],
|
||||||
"email" => $this->generateEmail(),
|
"email" => $this->generateEmail(),
|
||||||
"collections" => null
|
"collections" => null,
|
||||||
|
"accept-tou" => '1'
|
||||||
], [], 1],
|
], [], 1],
|
||||||
[[//email invalid
|
[[//email invalid
|
||||||
"password" => [
|
"password" => [
|
||||||
@@ -628,7 +634,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
'confirm' => 'password'
|
'confirm' => 'password'
|
||||||
],
|
],
|
||||||
"email" => 'invalid.email',
|
"email" => 'invalid.email',
|
||||||
"collections" => null
|
"collections" => null,
|
||||||
|
"accept-tou" => '1'
|
||||||
], [], 1],
|
], [], 1],
|
||||||
[[//login exists
|
[[//login exists
|
||||||
"login" => null,
|
"login" => null,
|
||||||
@@ -637,7 +644,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
'confirm' => 'password'
|
'confirm' => 'password'
|
||||||
],
|
],
|
||||||
"email" => $this->generateEmail(),
|
"email" => $this->generateEmail(),
|
||||||
"collections" => null
|
"collections" => null,
|
||||||
|
"accept-tou" => '1'
|
||||||
], [
|
], [
|
||||||
[
|
[
|
||||||
'name' => 'login',
|
'name' => 'login',
|
||||||
@@ -650,7 +658,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
'confirm' => 'password'
|
'confirm' => 'password'
|
||||||
],
|
],
|
||||||
"email" => null,
|
"email" => null,
|
||||||
"collections" => null
|
"collections" => null,
|
||||||
|
"accept-tou" => '1'
|
||||||
], [], 1],
|
], [], 1],
|
||||||
[[//tou declined
|
[[//tou declined
|
||||||
"password" => [
|
"password" => [
|
||||||
@@ -658,8 +667,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
'confirm' => 'password'
|
'confirm' => 'password'
|
||||||
],
|
],
|
||||||
"email" => $this->generateEmail(),
|
"email" => $this->generateEmail(),
|
||||||
"collections" => null,
|
"collections" => null
|
||||||
"accept-tou" => '1'
|
|
||||||
], [], 1]
|
], [], 1]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -822,13 +830,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
self::$DI['app']['registration.fields'] = [];
|
self::$DI['app']['registration.fields'] = [];
|
||||||
$this->logout(self::$DI['app']);
|
$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');
|
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
||||||
$this->addProvider('provider-test', $provider);
|
$this->addProvider('provider-test', $provider);
|
||||||
|
|
||||||
@@ -856,7 +857,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
foreach ($parameters as $key => $parameter) {
|
foreach ($parameters as $key => $parameter) {
|
||||||
if ('collections' === $key && null === $parameter) {
|
if ('collections' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$demands;
|
$parameters[$key] = self::$registrationCollections;
|
||||||
}
|
}
|
||||||
if ('login' === $key && null === $parameter) {
|
if ('login' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$login;
|
$parameters[$key] = self::$login;
|
||||||
@@ -889,7 +890,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
foreach ($parameters as $key => $parameter) {
|
foreach ($parameters as $key => $parameter) {
|
||||||
if ('collections' === $key && null === $parameter) {
|
if ('collections' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$demands;
|
$parameters[$key] = self::$registrationCollections;
|
||||||
}
|
}
|
||||||
if ('login' === $key && null === $parameter) {
|
if ('login' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$login;
|
$parameters[$key] = self::$login;
|
||||||
@@ -931,7 +932,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
foreach ($parameters as $key => $parameter) {
|
foreach ($parameters as $key => $parameter) {
|
||||||
if ('collections' === $key && null === $parameter) {
|
if ('collections' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$demands;
|
$parameters[$key] = self::$registrationCollections;
|
||||||
}
|
}
|
||||||
if ('login' === $key && null === $parameter) {
|
if ('login' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$login;
|
$parameters[$key] = self::$login;
|
||||||
@@ -952,6 +953,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
{
|
{
|
||||||
self::$DI['app']['registration.fields'] = [];
|
self::$DI['app']['registration.fields'] = [];
|
||||||
$this->logout(self::$DI['app']);
|
$this->logout(self::$DI['app']);
|
||||||
|
$this->disableTOU();
|
||||||
|
|
||||||
$emails = [
|
$emails = [
|
||||||
'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0,
|
'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0,
|
||||||
@@ -1007,7 +1009,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
foreach ($parameters as $key => $parameter) {
|
foreach ($parameters as $key => $parameter) {
|
||||||
if ('collections' === $key && null === $parameter) {
|
if ('collections' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$demands;
|
$parameters[$key] = self::$registrationCollections;
|
||||||
}
|
}
|
||||||
if ('login' === $key && null === $parameter) {
|
if ('login' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$login;
|
$parameters[$key] = self::$login;
|
||||||
@@ -1059,6 +1061,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
self::$DI['app']['registration.fields'] = $extraParameters;
|
self::$DI['app']['registration.fields'] = $extraParameters;
|
||||||
|
|
||||||
$this->logout(self::$DI['app']);
|
$this->logout(self::$DI['app']);
|
||||||
|
$this->disableTOU();
|
||||||
|
|
||||||
$emails = [
|
$emails = [
|
||||||
'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0,
|
'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0,
|
||||||
@@ -1072,7 +1075,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
$parameters = array_merge(['_token' => 'token'], $parameters);
|
$parameters = array_merge(['_token' => 'token'], $parameters);
|
||||||
foreach ($parameters as $key => $parameter) {
|
foreach ($parameters as $key => $parameter) {
|
||||||
if ('collections' === $key && null === $parameter) {
|
if ('collections' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$demands;
|
$parameters[$key] = self::$registrationCollections;
|
||||||
}
|
}
|
||||||
if ('login' === $key && null === $parameter) {
|
if ('login' === $key && null === $parameter) {
|
||||||
$parameters[$key] = self::$login;
|
$parameters[$key] = self::$login;
|
||||||
@@ -1468,13 +1471,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
public function testAuthenticateProviderCallbackAlreadyBound()
|
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');
|
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
||||||
$this->addProvider('provider-test', $provider);
|
$this->addProvider('provider-test', $provider);
|
||||||
|
|
||||||
@@ -1620,8 +1616,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
||||||
$this->addProvider('provider-test', $provider);
|
$this->addProvider('provider-test', $provider);
|
||||||
|
|
||||||
$provider->expects($this->once())
|
$provider->expects($this->once())->method('onCallback');
|
||||||
->method('onCallback');
|
|
||||||
|
|
||||||
$token = new Token($provider, 42);
|
$token = new Token($provider, 42);
|
||||||
|
|
||||||
@@ -1660,10 +1655,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
{
|
{
|
||||||
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
||||||
$this->addProvider('provider-test', $provider);
|
$this->addProvider('provider-test', $provider);
|
||||||
|
$provider->expects($this->once())->method('onCallback');
|
||||||
$provider->expects($this->once())
|
|
||||||
->method('onCallback');
|
|
||||||
|
|
||||||
$token = new Token($provider, 42);
|
$token = new Token($provider, 42);
|
||||||
|
|
||||||
$provider->expects($this->any())
|
$provider->expects($this->any())
|
||||||
@@ -1688,16 +1680,15 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
->method('isEnabled')
|
->method('isEnabled')
|
||||||
->will($this->returnValue(false));
|
->will($this->returnValue(false));
|
||||||
|
|
||||||
self::$DI['app']['registration.enabled'] = false;
|
$this->disableRegistration();
|
||||||
|
|
||||||
$this->logout(self::$DI['app']);
|
$this->logout(self::$DI['app']);
|
||||||
self::$DI['client']->request('GET', '/login/provider/provider-test/callback/');
|
self::$DI['client']->request('GET', '/login/provider/provider-test/callback/');
|
||||||
|
|
||||||
$this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode());
|
$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->assertFalse(self::$DI['app']['authentication']->isAuthenticated());
|
||||||
$this->assertFlashMessagePopulated(self::$DI['app'], 'error', 1);
|
$this->assertFlashMessagePopulated(self::$DI['app'], 'error', 1);
|
||||||
|
$this->assertSame('/login/', self::$DI['client']->getResponse()->headers->get('location'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRegistrationFields()
|
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
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function deleteRequest()
|
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->setParameter(1, self::$DI['user']->getId());
|
||||||
$query->execute();
|
$query->execute();
|
||||||
}
|
}
|
||||||
@@ -1827,14 +1818,15 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
private function enableTOU()
|
private function enableTOU()
|
||||||
{
|
{
|
||||||
if (null === self::$termsOfUse) {
|
if (null !== self::$termsOfUse) {
|
||||||
self::$termsOfUse = [];
|
return;
|
||||||
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
|
}
|
||||||
self::$termsOfUse[$databox->get_sbas_id()] = $databox->get_cgus();
|
self::$termsOfUse = [];
|
||||||
|
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||||
|
self::$termsOfUse[$databox->get_sbas_id()] = $databox->get_cgus();
|
||||||
|
|
||||||
foreach ( self::$termsOfUse[$databox->get_sbas_id()]as $lng => $tou) {
|
foreach ( self::$termsOfUse[$databox->get_sbas_id()]as $lng => $tou) {
|
||||||
$databox->update_cgus($lng, 'something', false);
|
$databox->update_cgus($lng, 'something', false);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1856,4 +1848,65 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
self::$termsOfUse = null;
|
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()
|
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']);
|
$this->XMLHTTPRequest('POST', '/user/preferences/', ['prop' => 'prop_test', 'value' => 'val_test']);
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isOk());
|
$this->assertTrue($response->isOk());
|
||||||
$datas = (array) json_decode($response->getContent());
|
$this->assertTrue(json_decode($response->getContent())->success);
|
||||||
$this->assertArrayHasKey('success', $datas);
|
$this->assertEquals('val_test', self::$DI['app']['settings']->getUserSetting(self::$DI['user'], 'prop_test'));
|
||||||
$this->assertTrue($datas['success']);
|
|
||||||
$this->assertArrayHasKey('message', $datas);
|
|
||||||
unset($response, $datas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,11 +46,8 @@ class PreferencesTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
$this->XMLHTTPRequest('POST', "/user/preferences/temporary/", ['prop' => 'prop_test', 'value' => 'val_test']);
|
$this->XMLHTTPRequest('POST', "/user/preferences/temporary/", ['prop' => 'prop_test', 'value' => 'val_test']);
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isOk());
|
$this->assertTrue($response->isOk());
|
||||||
$datas = (array) json_decode($response->getContent());
|
$this->assertTrue(json_decode($response->getContent())->success);
|
||||||
$this->assertArrayHasKey('success', $datas);
|
|
||||||
$this->assertTrue($datas['success']);
|
|
||||||
$this->assertEquals('val_test', self::$DI['app']['session']->get('phraseanet.prop_test'));
|
$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
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@@ -7,7 +7,7 @@ use Alchemy\Phrasea\Core\Provider\RegistrationServiceProvider;
|
|||||||
/**
|
/**
|
||||||
* @covers Alchemy\Phrasea\Core\Provider\RegistrationServiceProvider
|
* @covers Alchemy\Phrasea\Core\Provider\RegistrationServiceProvider
|
||||||
*/
|
*/
|
||||||
class RegistrationServiceProviderTest extends ServiceProviderTestCase
|
class RegistrationServiceProviderTest extends ServiceProviderTestCase
|
||||||
{
|
{
|
||||||
private $fields;
|
private $fields;
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class RegistrationServiceProviderTest extends ServiceProviderTestCase
|
|||||||
public function provideServiceDescription()
|
public function provideServiceDescription()
|
||||||
{
|
{
|
||||||
return [
|
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;
|
namespace Alchemy\Tests\Phrasea\Registration;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application;
|
|
||||||
use Alchemy\Phrasea\Model\Entities\Registration;
|
use Alchemy\Phrasea\Model\Entities\Registration;
|
||||||
use Alchemy\Phrasea\Model\Manipulator\RegistrationManipulator;
|
use Alchemy\Phrasea\Model\Manipulator\RegistrationManipulator;
|
||||||
|
|
||||||
@@ -10,51 +9,30 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
|
|||||||
{
|
{
|
||||||
public function testCreateRegistration()
|
public function testCreateRegistration()
|
||||||
{
|
{
|
||||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']);
|
||||||
->disableOriginalConstructor()
|
$registration = $service->createRegistration(self::$DI['user'], self::$DI['collection']);
|
||||||
->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());
|
|
||||||
|
|
||||||
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\Registration', $registration);
|
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\Registration', $registration);
|
||||||
$this->assertEquals(self::$DI['collection']->get_base_id(), $registration->getBaseId());
|
$this->assertEquals(self::$DI['collection']->get_base_id(), $registration->getBaseId());
|
||||||
$this->assertEquals(self::$DI['user']->get_id(), $registration->getUser());
|
$this->assertEquals(self::$DI['user']->getId(), $registration->getUser()->getId());
|
||||||
|
|
||||||
return $registration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testRejectRegistration()
|
||||||
* @depends testCreateRegistration
|
|
||||||
*/
|
|
||||||
public function testRejectRegistration($registration)
|
|
||||||
{
|
{
|
||||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
$registration = self::$DI['registration_1'];
|
||||||
->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']);
|
|
||||||
|
|
||||||
|
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']);
|
||||||
$service->rejectRegistration($registration);
|
$service->rejectRegistration($registration);
|
||||||
|
|
||||||
$this->assertFalse($registration->isPending());
|
$this->assertFalse($registration->isPending());
|
||||||
$this->assertTrue($registration->isRejected());
|
$this->assertTrue($registration->isRejected());
|
||||||
|
|
||||||
return $registration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testAcceptRegistration()
|
||||||
* @depends testCreateRegistration
|
|
||||||
*/
|
|
||||||
public function testAcceptRegistration($registration)
|
|
||||||
{
|
{
|
||||||
$aclMock = $this->getMockBuilder('ACL')
|
$registration = self::$DI['registration_1'];
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
$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_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('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([
|
$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',
|
'candwnldpreview' => '1',
|
||||||
'actif' => '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);
|
$aclProviderMock = $this->getMockBuilder('Alchemy\Phrasea\Authentication\ACLProvider')->disableOriginalConstructor()->getMock();
|
||||||
$service->acceptRegistration($registration, self::$DI['user'], self::$DI['collection'], true, false);
|
$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()
|
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');
|
$qb = $service->getRepository()->createQueryBuilder('r');
|
||||||
$nbRegistrationBefore = $qb->select('COUNT(r)')
|
$nbRegistrationBefore = $qb->select('COUNT(r)')
|
||||||
->where($qb->expr()->eq('r.user', ':user'))
|
->where($qb->expr()->eq('r.user', ':user'))
|
||||||
->setParameter(':user', self::$DI['user_alt1']->get_id())
|
->setParameter(':user', self::$DI['user_alt1']->getId())
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getSingleScalarResult();
|
->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();
|
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
|
||||||
$this->assertGreaterThan($nbRegistrationAfter, $nbRegistrationBefore);
|
$this->assertGreaterThan($nbRegistrationAfter, $nbRegistrationBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeleteOldRegistrations()
|
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');
|
$qb = $service->getRepository()->createQueryBuilder('r');
|
||||||
$nbRegistrationBefore = $qb->select('COUNT(r)')
|
$nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult();
|
||||||
->getQuery()
|
|
||||||
->getSingleScalarResult();
|
|
||||||
$service->deleteOldRegistrations();
|
$service->deleteOldRegistrations();
|
||||||
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
|
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
|
||||||
$this->assertGreaterThan($nbRegistrationAfter, $nbRegistrationBefore);
|
$this->assertGreaterThan($nbRegistrationAfter, $nbRegistrationBefore);
|
||||||
@@ -106,151 +78,11 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
|
|||||||
|
|
||||||
public function testDeleteRegistrationOnCollection()
|
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');
|
$qb = $service->getRepository()->createQueryBuilder('r');
|
||||||
$nbRegistrationBefore = $qb->select('COUNT(r)')
|
$nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult();
|
||||||
->getQuery()
|
$service->deleteRegistrationsOnCollection(self::$DI['collection']);
|
||||||
->getSingleScalarResult();
|
|
||||||
$service->deleteRegistrationsOnCollection(self::$DI['collection']->get_base_id());
|
|
||||||
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
|
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
|
||||||
$this->assertGreaterThan($nbRegistrationAfter, $nbRegistrationBefore);
|
$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 = new FeedItem();
|
||||||
$item->setEntry($entry)
|
$item->setEntry($entry)
|
||||||
->setOrd(4)
|
->setOrd(4)
|
||||||
->setRecordId(self::$DI['record_1']->get_record_id())
|
->setRecordId(123456789)
|
||||||
->setSbasId(self::$DI['record_1']->get_record_id());
|
->setSbasId(123456789);
|
||||||
$entry->addItem($item);
|
$entry->addItem($item);
|
||||||
self::$DI['app']['EM']->persist($item);
|
self::$DI['app']['EM']->persist($item);
|
||||||
|
|
||||||
self::$DI['app']['EM']->persist($entry);
|
self::$DI['app']['EM']->persist($entry);
|
||||||
self::$DI['app']['EM']->flush();
|
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']);
|
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) {
|
self::$DI['oauth2-app-user'] = self::$DI->share(function ($DI) {
|
||||||
return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user']);
|
return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user']);
|
||||||
});
|
});
|
||||||
|
@@ -284,12 +284,12 @@ div.switch_right.unchecked {
|
|||||||
line-height: 22px;
|
line-height: 22px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#tab_demandes .dl-horizontal dd {
|
#tab-registrations .dl-horizontal dd {
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
margin-left: 140px;
|
margin-left: 140px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#tab_demandes .dl-horizontal dt {
|
#tab-registrations .dl-horizontal dt {
|
||||||
width: 130px;
|
width: 130px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user