[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); $valid_nickname = Nickname::normalize($data['nickname'], check_already_used: true);
try { 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([ $user = LocalUser::create([
'nickname' => $data['nickname'], 'nickname' => $data['nickname'],
'outgoing_email' => $data['email'], 'outgoing_email' => $data['email'],

View File

@ -48,6 +48,7 @@ class GSActor extends Entity
// {{{ Autocode // {{{ Autocode
private int $id; private int $id;
private string $nickname; private string $nickname;
private string $normalized_nickname;
private ?string $fullname; private ?string $fullname;
private int $roles = 4; private int $roles = 4;
private ?string $homepage; private ?string $homepage;
@ -82,6 +83,17 @@ class GSActor extends Entity
return $this->nickname; 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 public function setFullname(?string $fullname): self
{ {
$this->fullname = $fullname; $this->fullname = $fullname;
@ -181,29 +193,28 @@ class GSActor extends Entity
return $this->location_service; return $this->location_service;
} }
public function setCreated(\DateTimeInterface $created): self public function setCreated(DateTimeInterface $created): self
{ {
$this->created = $created; $this->created = $created;
return $this; return $this;
} }
public function getCreated(): \DateTimeInterface public function getCreated(): DateTimeInterface
{ {
return $this->created; return $this->created;
} }
public function setModified(\DateTimeInterface $modified): self public function setModified(DateTimeInterface $modified): self
{ {
$this->modified = $modified; $this->modified = $modified;
return $this; return $this;
} }
public function getModified(): \DateTimeInterface public function getModified(): DateTimeInterface
{ {
return $this->modified; return $this->modified;
} }
// }}} Autocode // }}} Autocode
public function getAvatarUrl() public function getAvatarUrl()
@ -282,23 +293,25 @@ class GSActor extends Entity
'name' => 'gsactor', 'name' => 'gsactor',
'description' => 'local and remote users, groups and bots are gsactors, for instance', 'description' => 'local and remote users, groups and bots are gsactors, for instance',
'fields' => [ 'fields' => [
'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'], 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'],
'nickname' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'nickname or username'], 'nickname' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'nickname or username'],
'fullname' => ['type' => 'text', 'description' => 'display name'], 'normalized_nickname' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'normalized (as per Nickanme::normalize) nickname or username'],
'roles' => ['type' => 'int', 'not null' => true, 'default' => UserRoles::USER, 'description' => 'Bitmap of permissions this gsactor has'], 'fullname' => ['type' => 'text', 'description' => 'display name'],
'homepage' => ['type' => 'text', 'description' => 'identifying URL'], 'roles' => ['type' => 'int', 'not null' => true, 'default' => UserRoles::USER, 'description' => 'Bitmap of permissions this gsactor has'],
'bio' => ['type' => 'text', 'description' => 'descriptive biography'], 'homepage' => ['type' => 'text', 'description' => 'identifying URL'],
'location' => ['type' => 'text', 'description' => 'physical location'], 'bio' => ['type' => 'text', 'description' => 'descriptive biography'],
'lat' => ['type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'], 'location' => ['type' => 'text', 'description' => 'physical location'],
'lon' => ['type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'], 'lat' => ['type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'],
'location_id' => ['type' => 'int', 'description' => 'location id if possible'], 'lon' => ['type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'],
'location_service' => ['type' => 'int', 'description' => 'service used to obtain location id'], 'location_id' => ['type' => 'int', 'description' => 'location id if possible'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], 'location_service' => ['type' => 'int', 'description' => 'service used to obtain location id'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
], ],
'primary key' => ['id'], 'primary key' => ['id'],
'indexes' => [ 'indexes' => [
'gsactor_nickname_idx' => ['nickname'], 'gsactor_nickname_idx' => ['nickname'],
'gsactor_normalized_nickname_idx' => ['normalized_nickname'],
], ],
'fulltext indexes' => [ 'fulltext indexes' => [
'gsactor_fulltext_idx' => ['nickname', 'fullname', 'location', 'bio', 'homepage'], 'gsactor_fulltext_idx' => ['nickname', 'fullname', 'location', 'bio', 'homepage'],

View File

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