mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Merge branch 'release-3.0'
This commit is contained in:
@@ -568,7 +568,7 @@ func GetSession(token string) *model.Session {
|
||||
} else {
|
||||
session = sessionResult.Data.(*model.Session)
|
||||
|
||||
if session.IsExpired() {
|
||||
if session.IsExpired() || session.Token != token {
|
||||
return nil
|
||||
} else {
|
||||
AddSessionToCache(session)
|
||||
|
||||
@@ -222,11 +222,6 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func CreateTeam(c *Context, team *model.Team) *model.Team {
|
||||
if !utils.Cfg.EmailSettings.EnableSignUpWithEmail {
|
||||
c.Err = model.NewLocAppError("createTeam", "api.team.create_team.email_disabled.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return nil
|
||||
}
|
||||
|
||||
if team == nil {
|
||||
c.SetInvalidParam("createTeam", "team")
|
||||
|
||||
@@ -22,19 +22,19 @@ const (
|
||||
type WebConn struct {
|
||||
WebSocket *websocket.Conn
|
||||
Send chan *model.Message
|
||||
SessionId string
|
||||
SessionToken string
|
||||
UserId string
|
||||
hasPermissionsToChannel map[string]bool
|
||||
hasPermissionsToTeam map[string]bool
|
||||
}
|
||||
|
||||
func NewWebConn(ws *websocket.Conn, userId string, sessionId string) *WebConn {
|
||||
func NewWebConn(ws *websocket.Conn, userId string, sessionToken string) *WebConn {
|
||||
go func() {
|
||||
achan := Srv.Store.User().UpdateUserAndSessionActivity(userId, sessionId, model.GetMillis())
|
||||
achan := Srv.Store.User().UpdateUserAndSessionActivity(userId, sessionToken, model.GetMillis())
|
||||
pchan := Srv.Store.User().UpdateLastPingAt(userId, model.GetMillis())
|
||||
|
||||
if result := <-achan; result.Err != nil {
|
||||
l4g.Error(utils.T("api.web_conn.new_web_conn.last_activity.error"), userId, sessionId, result.Err)
|
||||
l4g.Error(utils.T("api.web_conn.new_web_conn.last_activity.error"), userId, sessionToken, result.Err)
|
||||
}
|
||||
|
||||
if result := <-pchan; result.Err != nil {
|
||||
@@ -46,7 +46,7 @@ func NewWebConn(ws *websocket.Conn, userId string, sessionId string) *WebConn {
|
||||
Send: make(chan *model.Message, 64),
|
||||
WebSocket: ws,
|
||||
UserId: userId,
|
||||
SessionId: sessionId,
|
||||
SessionToken: sessionToken,
|
||||
hasPermissionsToChannel: make(map[string]bool),
|
||||
hasPermissionsToTeam: make(map[string]bool),
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func (c *WebConn) InvalidateCacheForChannel(channelId string) {
|
||||
func (c *WebConn) HasPermissionsToTeam(teamId string) bool {
|
||||
perm, ok := c.hasPermissionsToTeam[teamId]
|
||||
if !ok {
|
||||
session := GetSession(c.SessionId)
|
||||
session := GetSession(c.SessionToken)
|
||||
if session == nil {
|
||||
perm = false
|
||||
c.hasPermissionsToTeam[teamId] = perm
|
||||
|
||||
@@ -33,7 +33,7 @@ func connect(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
wc := NewWebConn(ws, c.Session.UserId, c.Session.Id)
|
||||
wc := NewWebConn(ws, c.Session.UserId, c.Session.Token)
|
||||
hub.Register(wc)
|
||||
go wc.writePump()
|
||||
wc.readPump()
|
||||
|
||||
@@ -3511,6 +3511,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"
|
||||
@@ -3527,6 +3531,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"
|
||||
|
||||
@@ -615,7 +615,7 @@ func (o *Config) GetSanitizeOptions() map[string]bool {
|
||||
}
|
||||
|
||||
func (o *Config) Sanitize() {
|
||||
if &o.LdapSettings != nil && len(*o.LdapSettings.BindPassword) > 0 {
|
||||
if o.LdapSettings.BindPassword != nil && len(*o.LdapSettings.BindPassword) > 0 {
|
||||
*o.LdapSettings.BindPassword = FAKE_SETTING
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -285,7 +285,7 @@ func ValidateLdapFilter(cfg *model.Config) *model.AppError {
|
||||
}
|
||||
|
||||
func Desanitize(cfg *model.Config) {
|
||||
if *cfg.LdapSettings.BindPassword == model.FAKE_SETTING {
|
||||
if cfg.LdapSettings.BindPassword != nil && *cfg.LdapSettings.BindPassword == model.FAKE_SETTING {
|
||||
*cfg.LdapSettings.BindPassword = *Cfg.LdapSettings.BindPassword
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user