mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
GH-4685 Post a System Message when channel is renamed (#4762)
* test changes * added system message when displayname changed * added test * gofmt
This commit is contained in:
committed by
Christopher Speller
parent
fad14e6624
commit
e9a1a8d3d9
@@ -251,6 +251,8 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
oldChannel.Header = channel.Header
|
||||
oldChannel.Purpose = channel.Purpose
|
||||
|
||||
oldChannelDisplayName := oldChannel.DisplayName
|
||||
|
||||
if len(channel.DisplayName) > 0 {
|
||||
oldChannel.DisplayName = channel.DisplayName
|
||||
}
|
||||
@@ -267,6 +269,9 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = ucresult.Err
|
||||
return
|
||||
} else {
|
||||
if oldChannelDisplayName != channel.DisplayName {
|
||||
go PostUpdateChannelDisplayNameMessage(c, channel.Id, oldChannelDisplayName, channel.DisplayName)
|
||||
}
|
||||
c.LogAudit("name=" + channel.Name)
|
||||
w.Write([]byte(oldChannel.ToJson()))
|
||||
}
|
||||
@@ -354,6 +359,34 @@ func PostUpdateChannelHeaderMessage(c *Context, channelId string, oldChannelHead
|
||||
}
|
||||
}
|
||||
|
||||
func PostUpdateChannelDisplayNameMessage(c *Context, channelId string, oldChannelDisplayName, newChannelDisplayName string) {
|
||||
uc := Srv.Store.User().Get(c.Session.UserId)
|
||||
|
||||
if uresult := <-uc; uresult.Err != nil {
|
||||
l4g.Error(utils.T("api.channel.post_update_channel_displayname_message_and_forget.retrieve_user.error"), uresult.Err)
|
||||
return
|
||||
} else {
|
||||
user := uresult.Data.(*model.User)
|
||||
|
||||
message := fmt.Sprintf(utils.T("api.channel.post_update_channel_displayname_message_and_forget.updated_from"), user.Username, oldChannelDisplayName, newChannelDisplayName)
|
||||
|
||||
post := &model.Post{
|
||||
ChannelId: channelId,
|
||||
Message: message,
|
||||
Type: model.POST_DISPLAYNAME_CHANGE,
|
||||
UserId: c.Session.UserId,
|
||||
Props: model.StringInterface{
|
||||
"old_displayname": oldChannelDisplayName,
|
||||
"new_displayname": newChannelDisplayName,
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := CreatePost(c, post, false); err != nil {
|
||||
l4g.Error(utils.T("api.channel.post_update_channel_displayname_message_and_forget.create_post.error"), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
channelId := props["channel_id"]
|
||||
|
||||
@@ -370,6 +370,32 @@ func TestUpdateChannel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateChannelDisplayName(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
Client := th.SystemAdminClient
|
||||
team := th.SystemAdminTeam
|
||||
user := th.CreateUser(Client)
|
||||
LinkUserToTeam(user, team)
|
||||
|
||||
Client.Login(user.Email, user.Password)
|
||||
|
||||
channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
||||
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
|
||||
|
||||
Client.AddChannelMember(channel1.Id, user.Id)
|
||||
|
||||
newDisplayName := "a" + channel1.DisplayName + "a"
|
||||
channel1.DisplayName = newDisplayName
|
||||
channel1 = Client.Must(Client.UpdateChannel(channel1)).Data.(*model.Channel)
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
r1 := Client.Must(Client.GetPosts(channel1.Id, 0, 1, "")).Data.(*model.PostList)
|
||||
if len(r1.Order) != 1 {
|
||||
t.Fatal("Displayname update system message was not found")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateChannelHeader(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
Client := th.BasicClient
|
||||
|
||||
12
i18n/en.json
12
i18n/en.json
@@ -319,6 +319,18 @@
|
||||
"id": "api.channel.post_update_channel_header_message_and_forget.updated_to",
|
||||
"translation": "%s updated the channel header to: %s"
|
||||
},
|
||||
{
|
||||
"id": "api.channel.post_update_channel_displayname_message_and_forget.create_post.error",
|
||||
"translation": "Failed to post displayname update message %v"
|
||||
},
|
||||
{
|
||||
"id": "api.channel.post_update_channel_displayname_message_and_forget.retrieve_user.error",
|
||||
"translation": "Failed to retrieve user while trying to save update channel displayname message %v"
|
||||
},
|
||||
{
|
||||
"id": "api.channel.post_update_channel_displayname_message_and_forget.updated_from",
|
||||
"translation": "%s updated the channel display name from: %s to: %s"
|
||||
},
|
||||
{
|
||||
"id": "api.channel.post_user_add_remove_message_and_forget.error",
|
||||
"translation": "Failed to post join/leave message %v"
|
||||
|
||||
@@ -17,6 +17,7 @@ const (
|
||||
POST_JOIN_LEAVE = "system_join_leave"
|
||||
POST_ADD_REMOVE = "system_add_remove"
|
||||
POST_HEADER_CHANGE = "system_header_change"
|
||||
POST_DISPLAYNAME_CHANGE = "system_displayname_change"
|
||||
POST_CHANNEL_DELETED = "system_channel_deleted"
|
||||
POST_EPHEMERAL = "system_ephemeral"
|
||||
POST_FILEIDS_MAX_RUNES = 150
|
||||
@@ -117,7 +118,7 @@ func (o *Post) IsValid() *AppError {
|
||||
}
|
||||
|
||||
// should be removed once more message types are supported
|
||||
if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_ADD_REMOVE || o.Type == POST_SLACK_ATTACHMENT || o.Type == POST_HEADER_CHANGE) {
|
||||
if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_ADD_REMOVE || o.Type == POST_SLACK_ATTACHMENT || o.Type == POST_HEADER_CHANGE || o.Type == POST_DISPLAYNAME_CHANGE) {
|
||||
return NewLocAppError("Post.IsValid", "model.post.is_valid.type.app_error", nil, "id="+o.Type)
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ export class RenameChannelModal extends React.Component {
|
||||
|
||||
const channel = Object.assign({}, this.props.channel);
|
||||
const oldName = channel.name;
|
||||
const oldDisplayName = channel.displayName;
|
||||
const oldDisplayName = channel.display_name;
|
||||
const state = {serverError: ''};
|
||||
const {formatMessage} = this.props.intl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user