Fixing LDAP issue with Postgres (#3033)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
d2b556aa77
Коммит
123bfad69c
@@ -3499,6 +3499,10 @@
|
||||
"id": "store.sql_user.save.email_exists.app_error",
|
||||
"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"
|
||||
@@ -3515,6 +3519,10 @@
|
||||
"id": "store.sql_user.save.username_exists.app_error",
|
||||
"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"
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
Ссылка в новой задаче
Block a user