mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-28 04:30:08 +02:00
Use anonymous user permissions, if nobody is logged in.
This commit is contained in:
parent
9d0dde3df3
commit
4d39d5cfb7
3 changed files with 108 additions and 14 deletions
|
@ -47,6 +47,9 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
*/
|
||||
class User extends NamedDBElement implements UserInterface, HasPermissionsInterface
|
||||
{
|
||||
/** The User id of the anonymous user */
|
||||
const ID_ANONYMOUS = 1;
|
||||
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
|
@ -128,6 +131,15 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
protected $permissions;
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the current user, is the user which represents the not logged in (anonymous) users.
|
||||
* @return bool True if this user is the anonymous user.
|
||||
*/
|
||||
public function isAnonymousUser() : bool
|
||||
{
|
||||
return $this->id === static::ID_ANONYMOUS && $this->name === 'anonymous';
|
||||
}
|
||||
|
||||
/**
|
||||
* A visual identifier that represents this user.
|
||||
*
|
||||
|
@ -216,6 +228,16 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
* Getters
|
||||
************************************************/
|
||||
|
||||
public function setName(string $new_name) : NamedDBElement
|
||||
{
|
||||
// Anonymous user is not allowed to change its username
|
||||
if(!$this->isAnonymousUser()) {
|
||||
$this->name = $new_name;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue