usernames: report reserved names as taken in the check paths too
account.checkUsername / channels.checkUsername / bots.checkUsername said a reserved name was available and only updateUsername rejected it. Add the blocklist check to peerUsernameAvailable (covers account + channel, both backends) and to bots.Service.CheckUsername, so the client shows "username is taken" immediately.
This commit is contained in:
parent
60537342d3
commit
f1c24e483c
7 changed files with 79 additions and 5 deletions
|
|
@ -67,8 +67,10 @@ func (s *CollectibleUsernameStore) WithReservedUsernames(reserved *ReservedUsern
|
|||
return s
|
||||
}
|
||||
|
||||
func (s *CollectibleUsernameStore) nameReservedLocked(usernameLower string) bool {
|
||||
if s.reserved == nil {
|
||||
// nameReserved reports whether a name is on the operator blocklist. It touches
|
||||
// only s.reserved (its own lock), so it is safe from any context.
|
||||
func (s *CollectibleUsernameStore) nameReserved(usernameLower string) bool {
|
||||
if s == nil || s.reserved == nil {
|
||||
return false
|
||||
}
|
||||
r, _ := s.reserved.IsReserved(context.Background(), usernameLower)
|
||||
|
|
@ -119,7 +121,7 @@ func (s *CollectibleUsernameStore) SetEditableUsername(_ context.Context, peer d
|
|||
return false, domain.ErrUsernameInvalid
|
||||
}
|
||||
key := strings.ToLower(username)
|
||||
if s.nameReservedLocked(key) {
|
||||
if s.nameReserved(key) {
|
||||
return false, domain.ErrUsernameOccupied
|
||||
}
|
||||
if existing, ok := s.registry[key]; ok {
|
||||
|
|
@ -334,7 +336,7 @@ func (s *CollectibleUsernameStore) MintCollectibleUsername(_ context.Context, re
|
|||
if _, ok := s.registry[key]; ok {
|
||||
return domain.CollectibleUsername{}, false, domain.ErrUsernameOccupied
|
||||
}
|
||||
if s.nameReservedLocked(key) {
|
||||
if s.nameReserved(key) {
|
||||
return domain.CollectibleUsername{}, false, domain.ErrUsernameOccupied
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue