summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/channel.go33
-rw-r--r--api/channel_test.go26
-rw-r--r--i18n/en.json12
-rw-r--r--model/post.go3
-rw-r--r--webapp/components/rename_channel_modal.jsx2
5 files changed, 74 insertions, 2 deletions
diff --git a/api/channel.go b/api/channel.go
index b8a52747d..e4786c616 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -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"]
diff --git a/api/channel_test.go b/api/channel_test.go
index 11914414b..25e7b6a28 100644
--- a/api/channel_test.go
+++ b/api/channel_test.go
@@ -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
diff --git a/i18n/en.json b/i18n/en.json
index 856a24693..2467be4bd 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -320,6 +320,18 @@
"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"
},
diff --git a/model/post.go b/model/post.go
index cffe8e342..43b4ad977 100644
--- a/model/post.go
+++ b/model/post.go
@@ -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)
}
diff --git a/webapp/components/rename_channel_modal.jsx b/webapp/components/rename_channel_modal.jsx
index 3eaab834f..5253b1c80 100644
--- a/webapp/components/rename_channel_modal.jsx
+++ b/webapp/components/rename_channel_modal.jsx
@@ -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;