admin: allow shorter operator-assigned usernames, add reference docs

Lower the username floor to 3 characters on the admin-only write path
(account/channel set-username), separate from the 5-character self-service
minimum, since a deliberately short operator handle isn't the squatting the
higher floor guards against. Channel admin username assignment previously
had no length/format validation at all; this adds it.

Also adds three reference docs: the client's deep-link (tg://, owpg://)
surface, an OpenAPI 3.1 spec for both admin HTTP APIs (built from source,
not the stale docs/admin-panel-api.en.md), and a starter reserved-username
blocklist.
This commit is contained in:
Astra 2026-09-17 15:24:31 +01:00
parent 6af4576fed
commit c39011e542
5 changed files with 3861 additions and 5 deletions

View file

@ -635,11 +635,19 @@ func (s *Service) AdminSetSettings(ctx context.Context, channelID int64, patch d
return s.channels.SetChannelAdminSettings(ctx, channelID, patch)
}
// AdminSetUsername force-sets or clears a channel username through the admin path.
// AdminSetUsername force-sets or clears a channel username through the admin
// path. Unlike UpdateUsername it does not consult config.ReservedUsernames --
// an operator who deliberately reserved a word still needs to be able to hand
// it to a specific channel -- but format/length validity is still enforced,
// just against the lower minChannelUsernameLenAdmin floor.
func (s *Service) AdminSetUsername(ctx context.Context, channelID int64, username string) (domain.Channel, error) {
if s == nil || s.channels == nil || channelID == 0 {
return domain.Channel{}, domain.ErrChannelInvalid
}
username = normalizeChannelUsername(username)
if username != "" && !validChannelUsernameMinLen(username, minChannelUsernameLenAdmin) {
return domain.Channel{}, domain.ErrUsernameInvalid
}
return s.channels.SetChannelUsernameAdmin(ctx, channelID, username)
}
@ -2520,8 +2528,20 @@ func normalizeChannelUsername(username string) string {
return strings.TrimSpace(username)
}
// minChannelUsernameLenAdmin is the floor for an operator-assigned channel
// username via AdminSetUsername (the admin API/panel) -- shorter than what
// self-service channels.updateUsername allows, mirroring
// users.minUsernameLenAdmin: a deliberate short handle assigned by an
// operator is not the squatting the higher self-service minimum guards
// against.
const minChannelUsernameLenAdmin = 3
func validChannelUsername(username string) bool {
if len(username) < 5 || len(username) > 32 {
return validChannelUsernameMinLen(username, 5)
}
func validChannelUsernameMinLen(username string, minLen int) bool {
if len(username) < minLen || len(username) > 32 {
return false
}
for i := 0; i < len(username); i++ {