Fix users modelOf and lastModel wording

This commit is contained in:
Romain Neutron
2014-02-27 16:34:40 +01:00
parent 2df0f9d659
commit 9536aacab7
16 changed files with 42 additions and 44 deletions

View File

@@ -231,7 +231,7 @@ class RegenerateSqliteDb extends Command
$user3Deleted->setDeleted(true);
$template = $this->insertOneUser('template', null, true);
$template->setModelOf($user1);
$template->setTemplateOwner($user1);
$DI['user_1'] = $user1;
$DI['user_2'] = $user2;

View File

@@ -356,7 +356,7 @@ class Users implements ControllerProviderInterface
$controllers->get('/registrations/', function (Application $app) {
$app['manipulator.registration']->deleteOldRegistrations();
$models = $app['manipulator.user']->getRepository()->findModelOf($app['authentication']->getUser());
$models = $app['manipulator.user']->getRepository()->findTemplateOwner($app['authentication']->getUser());
$userRegistrations = [];
foreach ($app['manipulator.registration']->getRepository()->getUserRegistrations(

View File

@@ -11,11 +11,9 @@
namespace Alchemy\Phrasea\Core\Configuration;
use Alchemy\Phrasea\Cache\ArrayCache;
use Alchemy\Phrasea\Cache\Cache;
use Alchemy\Phrasea\Model\Entities\Collection;
use Alchemy\Phrasea\Model\Entities\Databox;
use Doctrine\ORM\EntityManager;
use Psr\Log\LoggerInterface;
class AccessRestriction

View File

@@ -644,7 +644,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
{
$template = $this->app['manipulator.user']->getRepository()->find($this->request->get('template'));
if (null === $template->getModelOf() || $template->getModelOf()->getId() !== $this->app['authentication']->getUser()->getId()) {
if (null === $template->getTemplateOwner() || $template->getTemplateOwner()->getId() !== $this->app['authentication']->getUser()->getId()) {
throw new AccessDeniedHttpException('You are not the owner of the template');
}
@@ -736,7 +736,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
if ($user->isTemplate()) {
$template = $user;
if ($template->getModelOf()->getId() !== $this->app['authentication']->getUser()->getId()) {
if ($template->getTemplateOwner()->getId() !== $this->app['authentication']->getUser()->getId()) {
continue;
}
}

View File

@@ -198,7 +198,7 @@ class Manage extends Helper
}
$created_user = $this->app['manipulator.user']->getRepository()->find($name, \random::generatePassword(16));
$created_user->setModelOf($this->app['authentication']->getUser());
$created_user->setTemplateOwner($this->app['authentication']->getUser());
$this->usr_id = $this->app['authentication']->getUser()->getId();
return $created_user;

View File

@@ -179,7 +179,7 @@ class User
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="last_model", referencedColumnName="id")
**/
private $lastModel;
private $lastAppliedTemplate;
/**
* @ORM\Column(type="text", name="push_list")
@@ -229,7 +229,7 @@ class User
*
* @var User
**/
private $modelOf;
private $templateOwner;
/**
* @ORM\OneToOne(targetEntity="FtpCredential", mappedBy="user", cascade={"all"})
@@ -752,17 +752,17 @@ class User
/**
* @return User
*/
public function getModelOf()
public function getTemplateOwner()
{
return $this->modelOf;
return $this->templateOwner;
}
/**
* @param User $owner
*/
public function setModelOf(User $owner)
public function setTemplateOwner(User $owner)
{
$this->modelOf = $owner;
$this->templateOwner = $owner;
return $this;
}
@@ -770,17 +770,17 @@ class User
/**
* @return User
*/
public function getLastModel()
public function getLastAppliedTemplate()
{
return $this->lastModel;
return $this->lastAppliedTemplate;
}
/**
* @param User $lastModel
* @param User $lastAppliedTemplate
*/
public function setLastModel(User $lastModel)
public function setLastAppliedTemplate(User $lastAppliedTemplate)
{
$this->lastModel = $lastModel;
$this->lastAppliedTemplate = $lastAppliedTemplate;
return $this;
}
@@ -1016,7 +1016,7 @@ class User
*/
public function isTemplate()
{
return null !== $this->modelOf;
return null !== $this->templateOwner;
}
/**

View File

@@ -104,7 +104,7 @@ class UserManipulator implements ManipulatorInterface
{
$user = $this->manager->create();
$this->doSetLogin($user, $login);
$user->setModelOf($owner);
$user->setTemplateOwner($owner);
$this->manager->update($user);
return $user;

View File

@@ -32,7 +32,7 @@ class UserRepository extends EntityRepository
$qb = $this->createQueryBuilder('u');
$qb->where($qb->expr()->eq('u.admin', $qb->expr()->literal(true)))
->andWhere($qb->expr()->isNull('u.modelOf'))
->andWhere($qb->expr()->isNull('u.templateOwner'))
->andWhere($qb->expr()->eq('u.deleted', $qb->expr()->literal(false)));
return $qb->getQuery()->getResult();
@@ -80,7 +80,7 @@ class UserRepository extends EntityRepository
$qb = $this->createQueryBuilder('u');
$qb->where($qb->expr()->eq('u.login', $qb->expr()->literal($login)))
->andWhere($qb->expr()->isNotNull('u.email'))
->andWhere($qb->expr()->isNull('u.modelOf'))
->andWhere($qb->expr()->isNull('u.templateOwner'))
->andWhere($qb->expr()->eq('u.guest', $qb->expr()->literal(false)))
->andWhere($qb->expr()->eq('u.deleted', $qb->expr()->literal(false)));
@@ -88,14 +88,14 @@ class UserRepository extends EntityRepository
}
/**
* Finds model of given user.
* Finds templates owned by a given user.
*
* @param User $user
*
* @return array
*/
public function findModelOf(User $user)
public function findTemplateOwner(User $user)
{
return $this->findBy(['modelOf' => $user->getId()]);
return $this->findBy(['templateOwner' => $user->getId()]);
}
}

View File

@@ -386,7 +386,7 @@ class ACL implements cache_cacheableInterface
$this->apply_template_time_limits($template_user, $base_ids);
$this->user->setLastModel($template_user);
$this->user->setLastAppliedTemplate($template_user);
return $this;
}

View File

@@ -258,7 +258,7 @@ class User_Query implements User_QueryInterface
}
if ($this->templates) {
$sql .= $this->generate_field_constraints('lastModel', $this->templates);
$sql .= $this->generate_field_constraints('last_model', $this->templates);
}
if (count($this->base_ids) == 0) {
@@ -316,7 +316,7 @@ class User_Query implements User_QueryInterface
}
if ($this->last_model) {
$sql .= ' AND Users.lastModel = ' . $this->app['phraseanet.appbox']->get_connection()->quote($this->last_model) . ' ';
$sql .= ' AND Users.last_model = ' . $this->app['phraseanet.appbox']->get_connection()->quote($this->last_model) . ' ';
}
$sql_like = [];

View File

@@ -147,9 +147,9 @@
<td>
{{usr.getCountry()}}
</td>
{% if usr.getLastModel() is not none %}
{% if usr.getLastAppliedTemplate() is not none %}
<td>
{{ usr.getLastModel().getLogin() }}
{{ usr.getLastAppliedTemplate().getLogin() }}
</td>
{% endif %}
<td>

View File

@@ -232,7 +232,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
{
$this->authenticate(self::$DI['app']);
$template = self::$DI['app']['manipulator.user']->createUser(uniqid('template_'), "test");
$template->setModelOf(self::$DI['user']);
$template->setTemplateOwner(self::$DI['user']);
$user = self::$DI['app']['manipulator.user']->createUser(uniqid('user_'), "test");
self::$DI['client']->request('POST', '/admin/users/apply_template/', [
'template' => $template->getId(),

View File

@@ -102,7 +102,7 @@ class UserTest extends \PhraseanetTestCase
{
$this->assertFalse($this->user->isTemplate());
$template = new User();
$this->user->setModelOf($template);
$this->user->setTemplateOwner($template);
$this->assertTrue($this->user->isTemplate());
}
@@ -118,12 +118,12 @@ class UserTest extends \PhraseanetTestCase
$this->assertTrue($this->user->isSpecial());
}
public function testSetModelOf()
public function testSetTemplateOwner()
{
$template = new User();
$user = new User();
$template->setModelOf($user);
$this->assertSame($user, $template->getModelOf());
$template->setTemplateOwner($user);
$this->assertSame($user, $template->getTemplateOwner());
}
public function genderProvider()

View File

@@ -28,9 +28,9 @@ class UserManagerTest extends \PhraseanetTestCase
$template = self::$DI['app']['manipulator.user']->createUser('template'.uniqid(), 'password');
self::$DI['app']['model.user-manager']->update($template);
$user = self::$DI['app']['manipulator.user']->createUser('login'.uniqid(), 'password');
$user->setModelOf($template);
$user->setTemplateOwner($template);
self::$DI['app']['model.user-manager']->update($user);
$this->assertNotNull($user->getPassword());
$this->assertNotNull($user->getModelOf());
$this->assertNotNull($user->getTemplateOwner());
}
}

View File

@@ -159,7 +159,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
self::$DI['app']['manipulator.user']->setEmail($user, 'testtest.fr');
}
public function testInvalidSetModelOf()
public function testInvalidSetTemplateOwner()
{
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
$this->setExpectedException(

View File

@@ -41,25 +41,25 @@ class Upgrade39UsersTest extends \PhraseanetTestCase
private function assertLastAppliedModelAreOk(EntityManager $em)
{
// check update
$this->assertEquals(176, $this->loadUser($em, 188)->getLastModel()->getId());
$this->assertEquals(176, $this->loadUser($em, 188)->getLastAppliedTemplate()->getId());
// last_model does not exist
$this->assertNull($this->loadUser($em, 105)->getLastModel());
$this->assertNull($this->loadUser($em, 105)->getLastAppliedTemplate());
// last_model is a deleted user
$this->assertNull($this->loadUser($em, 36)->getLastModel());
$this->assertNull($this->loadUser($em, 36)->getLastAppliedTemplate());
// no last_model
$this->assertNull($this->loadUser($em, 4)->getLastModel());
$this->assertNull($this->loadUser($em, 4)->getLastAppliedTemplate());
}
private function assertTemplateAreOwnedByValidUser(EntityManager $em)
{
// check update
$this->assertEquals(109, $this->loadUser($em, 160)->getModelOf()->getId());
$this->assertEquals(109, $this->loadUser($em, 160)->getTemplateOwner()->getId());
// owner does not exist
$this->assertNull($this->loadUser($em, 12));
// owner has been deleted
$this->assertNull($this->loadUser($em, 31));
// no owner
$this->assertNull($this->loadUser($em, 11)->getModelOf());
$this->assertNull($this->loadUser($em, 11)->getTemplateOwner());
}
/**