Fixed creating of new users

This commit is contained in:
konrad 2018-09-04 19:39:31 +02:00 committed by kolaente
parent 906aee8b7d
commit 245259216f
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
3 changed files with 8 additions and 7 deletions

View file

@ -81,6 +81,6 @@ func TestTeamList(t *testing.T) {
// Delete with a nonexistant list // Delete with a nonexistant list
err = tl4.Delete() err = tl4.Delete()
assert.Error(t, err) assert.Error(t, err)
assert.True(t, IsErrListDoesNotExist(err)) assert.True(t, IsErrTeamDoesNotHaveAccessToList(err))
} }

View file

@ -79,6 +79,6 @@ func TestTeamNamespace(t *testing.T) {
// Try deleting with a nonexistant namespace // Try deleting with a nonexistant namespace
err = tn4.Delete() err = tn4.Delete()
assert.Error(t, err) assert.Error(t, err)
assert.True(t, IsErrNamespaceDoesNotExist(err)) assert.True(t, IsErrTeamDoesNotHaveAccessToNamespace(err))
} }

View file

@ -15,24 +15,25 @@ func CreateUser(user User) (newUser User, err error) {
} }
// Check if the user already existst with that username // Check if the user already existst with that username
var exists bool exists := true
existingUser, err := GetUser(User{Username: newUser.Username}) existingUser, err := GetUser(User{Username: newUser.Username})
if err != nil { if err != nil {
if IsErrUserDoesNotExist(err) { if IsErrUserDoesNotExist(err) {
exists = true exists = false
} else { } else {
return User{}, err return User{}, err
} }
} }
if exists { if exists {
return User{}, ErrUsernameExists{existingUser.ID, existingUser.Username} return User{}, ErrUsernameExists{newUser.ID, newUser.Username}
} }
// Check if the user already existst with that email // Check if the user already existst with that email
exists = true
existingUser, err = GetUser(User{Email: newUser.Email}) existingUser, err = GetUser(User{Email: newUser.Email})
if err != nil && !IsErrUserDoesNotExist(err) { if err != nil {
if IsErrUserDoesNotExist(err) { if IsErrUserDoesNotExist(err) {
exists = true exists = false
} else { } else {
return User{}, err return User{}, err
} }