[ENTITY] Add 'normalized_nickname' to GSActor, the result of Nickname::normalize, so we can make sure we don't have very similar nicknames duplicated

This commit is contained in:
Hugo Sales 2021-05-05 12:19:10 +00:00
parent f2727f9327
commit bd249b508b
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 44 additions and 25 deletions

View File

@ -92,7 +92,7 @@ class Security extends Controller
$valid_nickname = Nickname::normalize($data['nickname'], check_already_used: true);
try {
$actor = GSActor::create(['nickname' => $data['nickname']]);
$actor = GSActor::create(['nickname' => $data['nickname'], 'normalized_nickname' => Nickname::normalize($data['nickname'], check_already_used: true)]);
$user = LocalUser::create([
'nickname' => $data['nickname'],
'outgoing_email' => $data['email'],

View File

@ -48,6 +48,7 @@ class GSActor extends Entity
// {{{ Autocode
private int $id;
private string $nickname;
private string $normalized_nickname;
private ?string $fullname;
private int $roles = 4;
private ?string $homepage;
@ -82,6 +83,17 @@ class GSActor extends Entity
return $this->nickname;
}
public function setNormalizedNickname(string $normalized_nickname): self
{
$this->normalized_nickname = $normalized_nickname;
return $this;
}
public function getNormalizedNickname(): string
{
return $this->normalized_nickname;
}
public function setFullname(?string $fullname): self
{
$this->fullname = $fullname;
@ -181,29 +193,28 @@ class GSActor extends Entity
return $this->location_service;
}
public function setCreated(\DateTimeInterface $created): self
public function setCreated(DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getCreated(): \DateTimeInterface
public function getCreated(): DateTimeInterface
{
return $this->created;
}
public function setModified(\DateTimeInterface $modified): self
public function setModified(DateTimeInterface $modified): self
{
$this->modified = $modified;
return $this;
}
public function getModified(): \DateTimeInterface
public function getModified(): DateTimeInterface
{
return $this->modified;
}
// }}} Autocode
public function getAvatarUrl()
@ -284,6 +295,7 @@ class GSActor extends Entity
'fields' => [
'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'],
'nickname' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'nickname or username'],
'normalized_nickname' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'normalized (as per Nickanme::normalize) nickname or username'],
'fullname' => ['type' => 'text', 'description' => 'display name'],
'roles' => ['type' => 'int', 'not null' => true, 'default' => UserRoles::USER, 'description' => 'Bitmap of permissions this gsactor has'],
'homepage' => ['type' => 'text', 'description' => 'identifying URL'],
@ -299,6 +311,7 @@ class GSActor extends Entity
'primary key' => ['id'],
'indexes' => [
'gsactor_nickname_idx' => ['nickname'],
'gsactor_normalized_nickname_idx' => ['normalized_nickname'],
],
'fulltext indexes' => [
'gsactor_fulltext_idx' => ['nickname', 'fullname', 'location', 'bio', 'homepage'],

View File

@ -19,7 +19,9 @@
namespace App\Entity;
use App\Core\DB\DB;
use App\Core\Entity;
use DateTimeInterface;
/**
@ -66,31 +68,35 @@ class LocalGroup extends Entity
return $this->nickname;
}
public function setCreated(\DateTimeInterface $created): self
public function setCreated(DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getCreated(): \DateTimeInterface
public function getCreated(): DateTimeInterface
{
return $this->created;
}
public function setModified(\DateTimeInterface $modified): self
public function setModified(DateTimeInterface $modified): self
{
$this->modified = $modified;
return $this;
}
public function getModified(): \DateTimeInterface
public function getModified(): DateTimeInterface
{
return $this->modified;
}
// }}} Autocode
public function getActor()
{
return DB::find('gsactor', ['id' => $this->group_id]);
}
public static function schemaDef(): array
{
return [