new users now join off-topic defaultly
Этот коммит содержится в:
@@ -320,7 +320,7 @@ func joinChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
channelId := params["id"]
|
||||
|
||||
JoinChannel(c, channelId)
|
||||
JoinChannel(c, channelId, "")
|
||||
|
||||
if c.Err != nil {
|
||||
return
|
||||
@@ -331,7 +331,7 @@ func joinChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(model.MapToJson(result)))
|
||||
}
|
||||
|
||||
func JoinChannel(c *Context, channelId string) {
|
||||
func JoinChannel(c *Context, channelId string, role string) {
|
||||
|
||||
sc := Srv.Store.Channel().Get(channelId)
|
||||
uc := Srv.Store.User().Get(c.Session.UserId)
|
||||
@@ -357,7 +357,7 @@ func JoinChannel(c *Context, channelId string) {
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN {
|
||||
cm := &model.ChannelMember{ChannelId: channel.Id, UserId: c.Session.UserId, NotifyLevel: model.CHANNEL_NOTIFY_ALL}
|
||||
cm := &model.ChannelMember{ChannelId: channel.Id, UserId: c.Session.UserId, NotifyLevel: model.CHANNEL_NOTIFY_ALL, Roles: role}
|
||||
|
||||
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
|
||||
c.Err = cmresult.Err
|
||||
@@ -380,6 +380,32 @@ func JoinChannel(c *Context, channelId string) {
|
||||
}
|
||||
}
|
||||
|
||||
func JoinDefaultChannels(c *Context, user *model.User, channelRole string) *model.AppError {
|
||||
// We don't call JoinChannel here since c.Session is not populated on user creation
|
||||
|
||||
var err *model.AppError = nil
|
||||
|
||||
if result := <-Srv.Store.Channel().GetByName(user.TeamId, "town-square"); result.Err != nil {
|
||||
err = result.Err
|
||||
} else {
|
||||
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id, NotifyLevel: model.CHANNEL_NOTIFY_ALL, Roles: channelRole}
|
||||
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
|
||||
err = cmResult.Err
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Channel().GetByName(user.TeamId, "off-topic"); result.Err != nil {
|
||||
err = result.Err
|
||||
} else {
|
||||
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id, NotifyLevel: model.CHANNEL_NOTIFY_ALL, Roles: channelRole}
|
||||
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
|
||||
err = cmResult.Err
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func leaveChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
params := mux.Vars(r)
|
||||
|
||||
@@ -197,7 +197,7 @@ func joinCommand(c *Context, command *model.Command) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
JoinChannel(c, v.Id)
|
||||
JoinChannel(c, v.Id, "")
|
||||
|
||||
if c.Err != nil {
|
||||
return false
|
||||
|
||||
10
api/team.go
10
api/team.go
@@ -146,7 +146,10 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
rteam := result.Data.(*model.Team)
|
||||
|
||||
CreateDefaultChannels(c, rteam.Id)
|
||||
if _, err := CreateDefaultChannels(c, rteam.Id); err != nil {
|
||||
c.Err = nil
|
||||
return
|
||||
}
|
||||
|
||||
teamSignup.User.TeamId = rteam.Id
|
||||
teamSignup.User.EmailVerified = true
|
||||
@@ -192,7 +195,10 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
rteam := result.Data.(*model.Team)
|
||||
|
||||
CreateDefaultChannels(c, rteam.Id)
|
||||
if _, err := CreateDefaultChannels(c, rteam.Id); err != nil {
|
||||
c.Err = nil
|
||||
return
|
||||
}
|
||||
|
||||
if rteam.AllowValet {
|
||||
CreateValet(c, rteam)
|
||||
|
||||
15
api/user.go
15
api/user.go
@@ -176,21 +176,16 @@ func CreateUser(c *Context, team *model.Team, user *model.User) *model.User {
|
||||
} else {
|
||||
ruser := result.Data.(*model.User)
|
||||
|
||||
// Do not error if user cannot be added to the town-square channel
|
||||
if cresult := <-Srv.Store.Channel().GetByName(team.Id, "town-square"); cresult.Err != nil {
|
||||
l4g.Error("Failed to get town-square err=%v", cresult.Err)
|
||||
} else {
|
||||
cm := &model.ChannelMember{ChannelId: cresult.Data.(*model.Channel).Id, UserId: ruser.Id, NotifyLevel: model.CHANNEL_NOTIFY_ALL, Roles: channelRole}
|
||||
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
|
||||
l4g.Error("Failed to add member town-square err=%v", cmresult.Err)
|
||||
}
|
||||
// Soft error if there is an issue joining the default channels
|
||||
if err := JoinDefaultChannels(c, ruser, channelRole); err != nil {
|
||||
l4g.Error("Encountered an issue joining default channels user_id=%s, team_id=%s, err=%v", ruser.Id, ruser.TeamId, err)
|
||||
}
|
||||
|
||||
//fireAndForgetWelcomeEmail(strings.Split(ruser.FullName, " ")[0], ruser.Email, team.Name, c.TeamUrl+"/channels/town-square")
|
||||
|
||||
if user.EmailVerified {
|
||||
if cresult := <-Srv.Store.User().VerifyEmail(ruser.Id); cresult.Err != nil {
|
||||
l4g.Error("Failed to get town-square err=%v", cresult.Err)
|
||||
l4g.Error("Failed to set email verified err=%v", cresult.Err)
|
||||
}
|
||||
} else {
|
||||
FireAndForgetVerifyEmail(result.Data.(*model.User).Id, strings.Split(ruser.FullName, " ")[0], ruser.Email, team.Name, c.TeamUrl)
|
||||
@@ -198,7 +193,7 @@ func CreateUser(c *Context, team *model.Team, user *model.User) *model.User {
|
||||
|
||||
ruser.Sanitize(map[string]bool{})
|
||||
|
||||
//This message goes to every channel, so the channelId is irrelevant
|
||||
// This message goes to every channel, so the channelId is irrelevant
|
||||
message := model.NewMessage(team.Id, "", ruser.Id, model.ACTION_NEW_USER)
|
||||
|
||||
store.PublishAndForget(message)
|
||||
|
||||
Ссылка в новой задаче
Block a user