diff options
-rw-r--r-- | i18n/en.json | 8 | ||||
-rw-r--r-- | store/sql_channel_store.go | 6 | ||||
-rw-r--r-- | store/sql_preference_store.go | 2 | ||||
-rw-r--r-- | store/sql_store.go | 11 | ||||
-rw-r--r-- | store/sql_team_store.go | 4 | ||||
-rw-r--r-- | store/sql_user_store.go | 8 |
6 files changed, 27 insertions, 12 deletions
diff --git a/i18n/en.json b/i18n/en.json index cfa8eaf56..eaf2fcf49 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3500,6 +3500,10 @@ "translation": "An account with that email already exists." }, { + "id": "store.sql_user.save.email_exists.ldap_app_error", + "translation": "This account does not use LDAP authentication. Please sign in using email and password." + }, + { "id": "store.sql_user.save.existing.app_error", "translation": "Must call update for exisiting user" }, @@ -3516,6 +3520,10 @@ "translation": "An account with that username already exists." }, { + "id": "store.sql_user.save.username_exists.ldap_app_error", + "translation": "An account with that username already exists. Please contact your Administrator." + }, + { "id": "store.sql_user.update.app_error", "translation": "We couldn't update the account" }, diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index 9f9d86454..0a8873b57 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -165,7 +165,7 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo } if err := transaction.Insert(channel); err != nil { - if IsUniqueConstraintError(err.Error(), "Name", "channels_name_teamid_key") { + if IsUniqueConstraintError(err.Error(), []string{"Name", "channels_name_teamid_key"}) { dupChannel := model.Channel{} s.GetMaster().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name}) if dupChannel.DeleteAt > 0 { @@ -200,7 +200,7 @@ func (s SqlChannelStore) Update(channel *model.Channel) StoreChannel { } if count, err := s.GetMaster().Update(channel); err != nil { - if IsUniqueConstraintError(err.Error(), "Name", "channels_name_teamid_key") { + if IsUniqueConstraintError(err.Error(), []string{"Name", "channels_name_teamid_key"}) { dupChannel := model.Channel{} s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name= :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name}) if dupChannel.DeleteAt > 0 { @@ -508,7 +508,7 @@ func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *mode } if err := transaction.Insert(member); err != nil { - if IsUniqueConstraintError(err.Error(), "ChannelId", "channelmembers_pkey") { + if IsUniqueConstraintError(err.Error(), []string{"ChannelId", "channelmembers_pkey"}) { result.Err = model.NewLocAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.exists.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error()) } else { result.Err = model.NewLocAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.save.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error()) diff --git a/store/sql_preference_store.go b/store/sql_preference_store.go index bb3fca3e3..83bf92ead 100644 --- a/store/sql_preference_store.go +++ b/store/sql_preference_store.go @@ -155,7 +155,7 @@ func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *mo result := StoreResult{} if err := transaction.Insert(preference); err != nil { - if IsUniqueConstraintError(err.Error(), "UserId", "preferences_pkey") { + if IsUniqueConstraintError(err.Error(), []string{"UserId", "preferences_pkey"}) { result.Err = model.NewLocAppError("SqlPreferenceStore.insert", "store.sql_preference.insert.exists.app_error", nil, "user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error()) } else { diff --git a/store/sql_store.go b/store/sql_store.go index 688e1b116..0979579df 100644 --- a/store/sql_store.go +++ b/store/sql_store.go @@ -582,9 +582,16 @@ func (ss SqlStore) RemoveIndexIfExists(indexName string, tableName string) { } } -func IsUniqueConstraintError(err string, mysql string, postgres string) bool { +func IsUniqueConstraintError(err string, indexName []string) bool { unique := strings.Contains(err, "unique constraint") || strings.Contains(err, "Duplicate entry") - field := strings.Contains(err, mysql) || strings.Contains(err, postgres) + field := false + for _, contain := range indexName { + if strings.Contains(err, contain) { + field = true + break + } + } + return unique && field } diff --git a/store/sql_team_store.go b/store/sql_team_store.go index c17a45d97..4692ecd3e 100644 --- a/store/sql_team_store.go +++ b/store/sql_team_store.go @@ -68,7 +68,7 @@ func (s SqlTeamStore) Save(team *model.Team) StoreChannel { } if err := s.GetMaster().Insert(team); err != nil { - if IsUniqueConstraintError(err.Error(), "Name", "teams_name_key") { + if IsUniqueConstraintError(err.Error(), []string{"Name", "teams_name_key"}) { result.Err = model.NewLocAppError("SqlTeamStore.Save", "store.sql_team.save.domain_exists.app_error", nil, "id="+team.Id+", "+err.Error()) } else { result.Err = model.NewLocAppError("SqlTeamStore.Save", "store.sql_team.save.app_error", nil, "id="+team.Id+", "+err.Error()) @@ -370,7 +370,7 @@ func (s SqlTeamStore) SaveMember(member *model.TeamMember) StoreChannel { } if err := s.GetMaster().Insert(member); err != nil { - if IsUniqueConstraintError(err.Error(), "TeamId", "teammembers_pkey") { + if IsUniqueConstraintError(err.Error(), []string{"TeamId", "teammembers_pkey"}) { result.Err = model.NewLocAppError("SqlTeamStore.SaveMember", "store.sql_team.save_member.exists.app_error", nil, "team_id="+member.TeamId+", user_id="+member.UserId+", "+err.Error()) } else { result.Err = model.NewLocAppError("SqlTeamStore.SaveMember", "store.sql_team.save_member.save.app_error", nil, "team_id="+member.TeamId+", user_id="+member.UserId+", "+err.Error()) diff --git a/store/sql_user_store.go b/store/sql_user_store.go index a6b706380..11a915055 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -77,9 +77,9 @@ func (us SqlUserStore) Save(user *model.User) StoreChannel { } if err := us.GetMaster().Insert(user); err != nil { - if IsUniqueConstraintError(err.Error(), "Email", "users_email_key") { + if IsUniqueConstraintError(err.Error(), []string{"Email", "users_email_key", "idx_users_email_unique"}) { result.Err = model.NewLocAppError("SqlUserStore.Save", "store.sql_user.save.email_exists.app_error", nil, "user_id="+user.Id+", "+err.Error()) - } else if IsUniqueConstraintError(err.Error(), "Username", "users_username_key") { + } else if IsUniqueConstraintError(err.Error(), []string{"Username", "users_username_key", "idx_users_username_unique"}) { result.Err = model.NewLocAppError("SqlUserStore.Save", "store.sql_user.save.username_exists.app_error", nil, "user_id="+user.Id+", "+err.Error()) } else { result.Err = model.NewLocAppError("SqlUserStore.Save", "store.sql_user.save.app_error", nil, "user_id="+user.Id+", "+err.Error()) @@ -155,9 +155,9 @@ func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) StoreCha } if count, err := us.GetMaster().Update(user); err != nil { - if IsUniqueConstraintError(err.Error(), "Email", "users_email_teamid_key") { + if IsUniqueConstraintError(err.Error(), []string{"Email", "users_email_key", "idx_users_email_unique"}) { result.Err = model.NewLocAppError("SqlUserStore.Update", "store.sql_user.update.email_taken.app_error", nil, "user_id="+user.Id+", "+err.Error()) - } else if IsUniqueConstraintError(err.Error(), "Username", "users_username_teamid_key") { + } else if IsUniqueConstraintError(err.Error(), []string{"Username", "users_username_key", "idx_users_username_unique"}) { result.Err = model.NewLocAppError("SqlUserStore.Update", "store.sql_user.update.username_taken.app_error", nil, "user_id="+user.Id+", "+err.Error()) } else { result.Err = model.NewLocAppError("SqlUserStore.Update", "store.sql_user.update.updating.app_error", nil, "user_id="+user.Id+", "+err.Error()) |