Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user.pubid to the model #9248

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions h/models/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import re
from functools import partial
from typing import TYPE_CHECKING

import sqlalchemy as sa
Expand All @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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),
mtomilov marked this conversation as resolved.
Show resolved Hide resolved
unique=True,
nullable=True,
)

#: Username as chosen by the user on registration
_username = sa.Column("username", sa.UnicodeText(), nullable=False)

Expand Down
Loading