Merge pull request #98 from mattermost/mm-1199
fixes mm-1199 adds off-topic as a default channel
Этот коммит содержится в:
@@ -57,7 +57,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if sc, err := CreateChannel(c, channel, r.URL.Path, true); err != nil {
|
if sc, err := CreateChannel(c, channel, true); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@@ -65,7 +65,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateChannel(c *Context, channel *model.Channel, path string, addMember bool) (*model.Channel, *model.AppError) {
|
func CreateChannel(c *Context, channel *model.Channel, addMember bool) (*model.Channel, *model.AppError) {
|
||||||
if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
|
if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
} else {
|
||||||
@@ -100,7 +100,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if sc, err := CreateDirectChannel(c, userId, r.URL.Path); err != nil {
|
if sc, err := CreateDirectChannel(c, userId); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@@ -108,7 +108,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateDirectChannel(c *Context, otherUserId string, path string) (*model.Channel, *model.AppError) {
|
func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model.AppError) {
|
||||||
if len(otherUserId) != 26 {
|
if len(otherUserId) != 26 {
|
||||||
return nil, model.NewAppError("CreateDirectChannel", "Invalid other user id ", otherUserId)
|
return nil, model.NewAppError("CreateDirectChannel", "Invalid other user id ", otherUserId)
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ func CreateDirectChannel(c *Context, otherUserId string, path string) (*model.Ch
|
|||||||
return nil, model.NewAppError("CreateDirectChannel", "Invalid other user id ", otherUserId)
|
return nil, model.NewAppError("CreateDirectChannel", "Invalid other user id ", otherUserId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if sc, err := CreateChannel(c, channel, path, true); err != nil {
|
if sc, err := CreateChannel(c, channel, true); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: otherUserId,
|
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: otherUserId,
|
||||||
@@ -146,6 +146,23 @@ func CreateDirectChannel(c *Context, otherUserId string, path string) (*model.Ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateDefaultChannels(c *Context, teamId string) ([]*model.Channel, *model.AppError) {
|
||||||
|
townSquare := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: teamId}
|
||||||
|
|
||||||
|
if _, err := CreateChannel(c, townSquare, false); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
offTopic := &model.Channel{DisplayName: "Off-Topic", Name: "off-topic", Type: model.CHANNEL_OPEN, TeamId: teamId}
|
||||||
|
|
||||||
|
if _, err := CreateChannel(c, offTopic, false); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
channels := []*model.Channel{townSquare, offTopic}
|
||||||
|
return channels, nil
|
||||||
|
}
|
||||||
|
|
||||||
func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
channel := model.ChannelFromJson(r.Body)
|
channel := model.ChannelFromJson(r.Body)
|
||||||
@@ -303,7 +320,7 @@ func joinChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
params := mux.Vars(r)
|
params := mux.Vars(r)
|
||||||
channelId := params["id"]
|
channelId := params["id"]
|
||||||
|
|
||||||
JoinChannel(c, channelId, r.URL.Path)
|
JoinChannel(c, channelId, "")
|
||||||
|
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
return
|
return
|
||||||
@@ -314,7 +331,7 @@ func joinChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write([]byte(model.MapToJson(result)))
|
w.Write([]byte(model.MapToJson(result)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func JoinChannel(c *Context, channelId string, path string) {
|
func JoinChannel(c *Context, channelId string, role string) {
|
||||||
|
|
||||||
sc := Srv.Store.Channel().Get(channelId)
|
sc := Srv.Store.Channel().Get(channelId)
|
||||||
uc := Srv.Store.User().Get(c.Session.UserId)
|
uc := Srv.Store.User().Get(c.Session.UserId)
|
||||||
@@ -340,7 +357,7 @@ func JoinChannel(c *Context, channelId string, path string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if channel.Type == model.CHANNEL_OPEN {
|
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 {
|
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
|
||||||
c.Err = cmresult.Err
|
c.Err = cmresult.Err
|
||||||
@@ -363,6 +380,32 @@ func JoinChannel(c *Context, channelId string, path 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) {
|
func leaveChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
params := mux.Vars(r)
|
params := mux.Vars(r)
|
||||||
|
|||||||
@@ -35,8 +35,15 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rget := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
|
rget := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
|
||||||
if rget.Channels[0].Name != channel.Name {
|
nameMatch := false
|
||||||
t.Fatal("full name didn't match")
|
for _, c := range rget.Channels {
|
||||||
|
if c.Name == channel.Name {
|
||||||
|
nameMatch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !nameMatch {
|
||||||
|
t.Fatal("Did not create channel with correct name")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := Client.CreateChannel(rchannel.Data.(*model.Channel)); err == nil {
|
if _, err := Client.CreateChannel(rchannel.Data.(*model.Channel)); err == nil {
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ func joinCommand(c *Context, command *model.Command) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
JoinChannel(c, v.Id, "/command")
|
JoinChannel(c, v.Id, "")
|
||||||
|
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ func TestJoinCommands(t *testing.T) {
|
|||||||
|
|
||||||
c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
|
c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
|
||||||
|
|
||||||
if len(c1.Channels) != 3 { // 3 because of town-square and direct
|
if len(c1.Channels) != 4 { // 4 because of town-square, off-topic and direct
|
||||||
t.Fatal("didn't join channel")
|
t.Fatal("didn't join channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
api/team.go
12
api/team.go
@@ -146,10 +146,8 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
} else {
|
} else {
|
||||||
rteam := result.Data.(*model.Team)
|
rteam := result.Data.(*model.Team)
|
||||||
|
|
||||||
channel := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: rteam.Id}
|
if _, err := CreateDefaultChannels(c, rteam.Id); err != nil {
|
||||||
|
c.Err = nil
|
||||||
if _, err := CreateChannel(c, channel, r.URL.Path, false); err != nil {
|
|
||||||
c.Err = err
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,10 +195,8 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
} else {
|
} else {
|
||||||
rteam := result.Data.(*model.Team)
|
rteam := result.Data.(*model.Team)
|
||||||
|
|
||||||
channel := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: rteam.Id}
|
if _, err := CreateDefaultChannels(c, rteam.Id); err != nil {
|
||||||
|
c.Err = nil
|
||||||
if _, err := CreateChannel(c, channel, r.URL.Path, false); err != nil {
|
|
||||||
c.Err = err
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ func TestCreateFromSignupTeam(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
|
||||||
|
if len(c1.Channels) != 2 {
|
||||||
|
t.Fatal("default channels not created")
|
||||||
|
}
|
||||||
|
|
||||||
ts.Data = "garbage"
|
ts.Data = "garbage"
|
||||||
_, err = Client.CreateTeamFromSignup(&ts)
|
_, err = Client.CreateTeamFromSignup(&ts)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -71,6 +76,17 @@ func TestCreateTeam(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user := &model.User{TeamId: rteam.Data.(*model.Team).Id, Email: model.NewId() + "corey@test.com", FullName: "Corey Hulen", Password: "pwd"}
|
||||||
|
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||||
|
Srv.Store.User().VerifyEmail(user.Id)
|
||||||
|
|
||||||
|
Client.LoginByEmail(team.Domain, user.Email, "pwd")
|
||||||
|
|
||||||
|
c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
|
||||||
|
if len(c1.Channels) != 2 {
|
||||||
|
t.Fatal("default channels not created")
|
||||||
|
}
|
||||||
|
|
||||||
if rteam.Data.(*model.Team).Name != team.Name {
|
if rteam.Data.(*model.Team).Name != team.Name {
|
||||||
t.Fatal("full name didn't match")
|
t.Fatal("full name didn't match")
|
||||||
}
|
}
|
||||||
|
|||||||
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 {
|
} else {
|
||||||
ruser := result.Data.(*model.User)
|
ruser := result.Data.(*model.User)
|
||||||
|
|
||||||
// Do not error if user cannot be added to the town-square channel
|
// Soft error if there is an issue joining the default channels
|
||||||
if cresult := <-Srv.Store.Channel().GetByName(team.Id, "town-square"); cresult.Err != nil {
|
if err := JoinDefaultChannels(c, ruser, channelRole); err != nil {
|
||||||
l4g.Error("Failed to get town-square err=%v", cresult.Err)
|
l4g.Error("Encountered an issue joining default channels user_id=%s, team_id=%s, err=%v", ruser.Id, ruser.TeamId, 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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//fireAndForgetWelcomeEmail(strings.Split(ruser.FullName, " ")[0], ruser.Email, team.Name, c.TeamUrl+"/channels/town-square")
|
//fireAndForgetWelcomeEmail(strings.Split(ruser.FullName, " ")[0], ruser.Email, team.Name, c.TeamUrl+"/channels/town-square")
|
||||||
|
|
||||||
if user.EmailVerified {
|
if user.EmailVerified {
|
||||||
if cresult := <-Srv.Store.User().VerifyEmail(ruser.Id); cresult.Err != nil {
|
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 {
|
} else {
|
||||||
FireAndForgetVerifyEmail(result.Data.(*model.User).Id, strings.Split(ruser.FullName, " ")[0], ruser.Email, team.Name, c.TeamUrl)
|
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{})
|
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)
|
message := model.NewMessage(team.Id, "", ruser.Id, model.ACTION_NEW_USER)
|
||||||
|
|
||||||
store.PublishAndForget(message)
|
store.PublishAndForget(message)
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func manualTest(c *api.Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
createdTeam := result.Data.(*model.Team)
|
createdTeam := result.Data.(*model.Team)
|
||||||
|
|
||||||
channel := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: createdTeam.Id}
|
channel := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: createdTeam.Id}
|
||||||
if _, err := api.CreateChannel(c, channel, r.URL.Path, false); err != nil {
|
if _, err := api.CreateChannel(c, channel, false); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -356,6 +356,7 @@ module.exports = React.createClass({
|
|||||||
var ui_name = channel.display_name
|
var ui_name = channel.display_name
|
||||||
var members = ChannelStore.getCurrentExtraInfo().members;
|
var members = ChannelStore.getCurrentExtraInfo().members;
|
||||||
var creator_name = "";
|
var creator_name = "";
|
||||||
|
var userStyle = { color: UserStore.getCurrentUser().props.theme }
|
||||||
|
|
||||||
for (var i = 0; i < members.length; i++) {
|
for (var i = 0; i < members.length; i++) {
|
||||||
if (members[i].roles.indexOf('admin') > -1) {
|
if (members[i].roles.indexOf('admin') > -1) {
|
||||||
@@ -382,8 +383,18 @@ module.exports = React.createClass({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
} else if (channel.name === Constants.OFFTOPIC_CHANNEL) {
|
||||||
|
more_messages = (
|
||||||
|
<div className="channel-intro">
|
||||||
|
<h4 className="channel-intro-title">Welcome</h4>
|
||||||
|
<p>
|
||||||
|
{"This is the start of " + ui_name + ", a channel for conversations you’d prefer out of more focused channels."}
|
||||||
|
<br/>
|
||||||
|
<a className="intro-links" href="#" style={userStyle} data-toggle="modal" data-target="#edit_channel" data-desc={channel.description} data-title={ui_name} data-channelid={channel.id}><i className="fa fa-pencil"></i>Set a description</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
var userStyle = { color: UserStore.getCurrentUser().props.theme }
|
|
||||||
var ui_type = channel.type === 'P' ? "private group" : "channel";
|
var ui_type = channel.type === 'P' ? "private group" : "channel";
|
||||||
more_messages = (
|
more_messages = (
|
||||||
<div className="channel-intro">
|
<div className="channel-intro">
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ module.exports = {
|
|||||||
MAX_UPLOAD_FILES: 5,
|
MAX_UPLOAD_FILES: 5,
|
||||||
MAX_FILE_SIZE: 50000000, // 50 MB
|
MAX_FILE_SIZE: 50000000, // 50 MB
|
||||||
DEFAULT_CHANNEL: 'town-square',
|
DEFAULT_CHANNEL: 'town-square',
|
||||||
|
OFFTOPIC_CHANNEL: 'off-topic',
|
||||||
POST_CHUNK_SIZE: 60,
|
POST_CHUNK_SIZE: 60,
|
||||||
RESERVED_DOMAINS: [
|
RESERVED_DOMAINS: [
|
||||||
"www",
|
"www",
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ func getChannel(c *api.Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
otherUserId = ids[0]
|
otherUserId = ids[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if sc, err := api.CreateDirectChannel(c, otherUserId, r.URL.Path); err != nil {
|
if sc, err := api.CreateDirectChannel(c, otherUserId); err != nil {
|
||||||
api.Handle404(w, r)
|
api.Handle404(w, r)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user