mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 21:43:18 +00:00
Add ACL & helper methods
This commit is contained in:
@@ -218,6 +218,11 @@ class User
|
|||||||
*/
|
*/
|
||||||
private $updated;
|
private $updated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \ACL
|
||||||
|
*/
|
||||||
|
private $acl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
@@ -792,4 +797,54 @@ class User
|
|||||||
|
|
||||||
$this->updated = $updated;
|
$this->updated = $updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Application $app
|
||||||
|
*
|
||||||
|
* @return \ACL
|
||||||
|
*/
|
||||||
|
public function ACL(Application $app)
|
||||||
|
{
|
||||||
|
if (!$this->acl instanceof \ACL) {
|
||||||
|
$this->acl = new \ACL($this, $app);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->acl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isTemplate()
|
||||||
|
{
|
||||||
|
return null !== $this->modelOf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isSpecial()
|
||||||
|
{
|
||||||
|
return in_array($this->login, array('invite', 'autoregister'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDisplayName()
|
||||||
|
{
|
||||||
|
if ($this->isTemplate()) {
|
||||||
|
return sprintf(_('modele %s'), $this->getLogin());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trim($this->lastName) !== '' || trim($this->firstName) !== '') {
|
||||||
|
return $this->firstName . ('' !== $this->firstName && '' !== $this->lastName ? ' ' : '') . $this->lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trim($this->email) !== '') {
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _('Unnamed user');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -81,6 +81,42 @@ class UserTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->user->setGeonameId(-1);
|
$this->user->setGeonameId(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetDisplayName()
|
||||||
|
{
|
||||||
|
$this->user->setLogin('login');
|
||||||
|
$this->user->setFirstName('firstname');
|
||||||
|
$this->user->setLastName('lastname');
|
||||||
|
$this->user->setEmail('email@email.com');
|
||||||
|
$this->assertEquals($this->user->getDisplayName(), 'firstname lastname');
|
||||||
|
$this->user->setLastName('');
|
||||||
|
$this->assertEquals($this->user->getDisplayName(), 'firstname');
|
||||||
|
$this->user->setFirstName('');
|
||||||
|
$this->assertEquals($this->user->getDisplayName(), 'email@email.com');
|
||||||
|
$this->user->setEmail(null);
|
||||||
|
$this->assertEquals($this->user->getDisplayName(), 'Unnamed user');
|
||||||
|
$this->user->setLastName('lastname');
|
||||||
|
$this->assertEquals($this->user->getDisplayName(), 'lastname');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsTemplate()
|
||||||
|
{
|
||||||
|
$this->assertFalse($this->user->isTemplate());
|
||||||
|
$this->user->setModelOf(1);
|
||||||
|
$this->assertTrue($this->user->isTemplate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsSpecial()
|
||||||
|
{
|
||||||
|
$this->user->setLogin('login');
|
||||||
|
$this->assertFalse($this->user->isSpecial());
|
||||||
|
$this->user->setLogin('invite');
|
||||||
|
$this->assertTrue($this->user->isSpecial());
|
||||||
|
$this->user->setLogin('login');
|
||||||
|
$this->assertFalse($this->user->isSpecial());
|
||||||
|
$this->user->setLogin('autoregister');
|
||||||
|
$this->assertTrue($this->user->isSpecial());
|
||||||
|
}
|
||||||
|
|
||||||
public function genderProvider()
|
public function genderProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
Reference in New Issue
Block a user