PLT-2978: Add channel purpose change system message. (#5094)
Completes original patch by David Lu.
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
cdf91d8ee8
Коммит
0685afd1d1
@@ -262,6 +262,7 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
channelId := props["channel_id"]
|
||||
if len(channelId) != 26 {
|
||||
@@ -292,6 +293,7 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
oldChannelPurpose := channel.Purpose
|
||||
channel.Purpose = channelPurpose
|
||||
|
||||
app.InvalidateCacheForChannel(channel.Id)
|
||||
@@ -299,6 +301,9 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = ucresult.Err
|
||||
return
|
||||
} else {
|
||||
if err := app.PostUpdateChannelPurposeMessage(c.Session.UserId, channel.Id, c.TeamId, oldChannelPurpose, channelPurpose); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
c.LogAudit("name=" + channel.Name)
|
||||
w.Write([]byte(channel.ToJson()))
|
||||
}
|
||||
|
||||
@@ -630,6 +630,17 @@ func TestUpdateChannelPurpose(t *testing.T) {
|
||||
upChannel1 = result.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("Purpose update system message was not found")
|
||||
} else if val, ok := r1.Posts[r1.Order[0]].Props["old_purpose"]; !ok || val != "" {
|
||||
t.Fatal("Props should contain old_header with old purpose value")
|
||||
} else if val, ok := r1.Posts[r1.Order[0]].Props["new_purpose"]; !ok || val != "new purpose" {
|
||||
t.Fatal("Props should contain new_header with new purpose value")
|
||||
}
|
||||
|
||||
if upChannel1.Purpose != data["channel_purpose"] {
|
||||
t.Fatal("Failed to update purpose")
|
||||
}
|
||||
|
||||
@@ -316,6 +316,41 @@ func PostUpdateChannelHeaderMessage(userId string, channelId string, teamId stri
|
||||
return nil
|
||||
}
|
||||
|
||||
func PostUpdateChannelPurposeMessage(userId string, channelId string, teamId string, oldChannelPurpose string, newChannelPurpose string) *model.AppError {
|
||||
uc := Srv.Store.User().Get(userId)
|
||||
|
||||
if uresult := <-uc; uresult.Err != nil {
|
||||
return model.NewLocAppError("PostUpdateChannelPurposeMessage", "app.channel.post_update_channel_purpose_message.retrieve_user.error", nil, uresult.Err.Error())
|
||||
} else {
|
||||
user := uresult.Data.(*model.User)
|
||||
|
||||
var message string
|
||||
if oldChannelPurpose == "" {
|
||||
message = fmt.Sprintf(utils.T("app.channel.post_update_channel_purpose_message.updated_to"), user.Username, newChannelPurpose)
|
||||
} else if newChannelPurpose == "" {
|
||||
message = fmt.Sprintf(utils.T("app.channel.post_update_channel_purpose_message.removed"), user.Username, oldChannelPurpose)
|
||||
} else {
|
||||
message = fmt.Sprintf(utils.T("app.channel.post_update_channel_purpose_message.updated_from"), user.Username, oldChannelPurpose, newChannelPurpose)
|
||||
}
|
||||
|
||||
post := &model.Post{
|
||||
ChannelId: channelId,
|
||||
Message: message,
|
||||
Type: model.POST_PURPOSE_CHANGE,
|
||||
UserId: userId,
|
||||
Props: model.StringInterface{
|
||||
"old_purpose": oldChannelPurpose,
|
||||
"new_purpose": newChannelPurpose,
|
||||
},
|
||||
}
|
||||
if _, err := CreatePost(post, teamId, false); err != nil {
|
||||
return model.NewLocAppError("", "app.channel.post_update_channel_purpose_message.post.error", nil, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func PostUpdateChannelDisplayNameMessage(userId string, channelId string, teamId string, oldChannelDisplayName, newChannelDisplayName string) *model.AppError {
|
||||
uc := Srv.Store.User().Get(userId)
|
||||
|
||||
|
||||
20
i18n/en.json
20
i18n/en.json
@@ -331,6 +331,26 @@
|
||||
"id": "api.channel.post_update_channel_header_message_and_forget.updated_to",
|
||||
"translation": "%s updated the channel header to: %s"
|
||||
},
|
||||
{
|
||||
"id": "app.channel.post_update_channel_purpose_message.post.error",
|
||||
"translation": "Failed to post channel purpose message"
|
||||
},
|
||||
{
|
||||
"id": "app.channel.post_update_channel_purpose_message.removed",
|
||||
"translation": "%s removed the channel purpose (was: %s)"
|
||||
},
|
||||
{
|
||||
"id": "app.channel.post_update_channel_purpose_message.retrieve_user.error",
|
||||
"translation": "Failed to retrieve user while trying to save update channel purpose message %v"
|
||||
},
|
||||
{
|
||||
"id": "app.channel.post_update_channel_purpose_message.updated_from",
|
||||
"translation": "%s updated the channel purpose from: %s to: %s"
|
||||
},
|
||||
{
|
||||
"id": "app.channel.post_update_channel_purpose_message.updated_to",
|
||||
"translation": "%s updated the channel purpose to: %s"
|
||||
},
|
||||
{
|
||||
"id": "api.channel.post_user_add_remove_message_and_forget.error",
|
||||
"translation": "Failed to post join/leave message"
|
||||
|
||||
@@ -18,6 +18,7 @@ const (
|
||||
POST_ADD_REMOVE = "system_add_remove"
|
||||
POST_HEADER_CHANGE = "system_header_change"
|
||||
POST_DISPLAYNAME_CHANGE = "system_displayname_change"
|
||||
POST_PURPOSE_CHANGE = "system_purpose_change"
|
||||
POST_CHANNEL_DELETED = "system_channel_deleted"
|
||||
POST_EPHEMERAL = "system_ephemeral"
|
||||
POST_FILEIDS_MAX_RUNES = 150
|
||||
@@ -120,7 +121,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 ||
|
||||
o.Type == POST_SLACK_ATTACHMENT || o.Type == POST_HEADER_CHANGE || o.Type == POST_PURPOSE_CHANGE ||
|
||||
o.Type == POST_DISPLAYNAME_CHANGE || o.Type == POST_CHANNEL_DELETED) {
|
||||
return NewLocAppError("Post.IsValid", "model.post.is_valid.type.app_error", nil, "id="+o.Type)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// See License.txt for license information.
|
||||
|
||||
import PreferenceStore from 'stores/preference_store.jsx';
|
||||
|
||||
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
||||
import * as AsyncClient from 'utils/async_client.jsx';
|
||||
import Client from 'client/web_client.jsx';
|
||||
import Constants from 'utils/constants.jsx';
|
||||
@@ -67,10 +67,15 @@ export default class EditChannelPurposeModal extends React.Component {
|
||||
Client.updateChannelPurpose(
|
||||
this.props.channel.id,
|
||||
this.refs.purpose.value.trim(),
|
||||
() => {
|
||||
(channel) => {
|
||||
AsyncClient.getChannel(this.props.channel.id);
|
||||
|
||||
this.handleHide();
|
||||
|
||||
AppDispatcher.handleServerAction({
|
||||
type: Constants.ActionTypes.RECEIVED_CHANNEL,
|
||||
channel
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
if (err.id === 'api.context.invalid_param.app_error') {
|
||||
|
||||
Ссылка в новой задаче
Block a user