From 84bcd8d44c515c6ea66eb7dde4bd42db3a765a3b Mon Sep 17 00:00:00 2001 From: Misha Tomilov Date: Tue, 14 Jan 2025 14:58:21 +0100 Subject: [PATCH] Add user.pubid to the model --- h/models/user.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/h/models/user.py b/h/models/user.py index c8981242c58..f2bfc35230d 100644 --- a/h/models/user.py +++ b/h/models/user.py @@ -1,5 +1,6 @@ import datetime import re +from functools import partial from typing import TYPE_CHECKING import sqlalchemy as sa @@ -9,6 +10,7 @@ from h.db import Base from h.exceptions import InvalidUserId from h.models import helpers +from h.pubid import generate from h.util.user import format_userid, split_user if TYPE_CHECKING: @@ -20,6 +22,7 @@ USERNAME_PATTERN = "(?i)^[A-Z0-9._]+$" EMAIL_MAX_LENGTH = 100 DISPLAY_NAME_MAX_LENGTH = 30 +USER_PUBID_LENGTH = 12 def _normalise_username(username): @@ -158,6 +161,14 @@ def __table_args__(cls): # pylint:disable=no-self-argument id = sa.Column(sa.Integer, autoincrement=True, primary_key=True) + #: A publicly visible unique identifier for the user + pubid = sa.Column( + sa.Text(), + default=partial(generate, USER_PUBID_LENGTH), + unique=True, + nullable=True, + ) + #: Username as chosen by the user on registration _username = sa.Column("username", sa.UnicodeText(), nullable=False)