post a system message after a channel is converted from public to private (#8501)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9e6db178b0
Коммит
07b14c370a
@@ -118,6 +118,7 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
oldChannel.Purpose = channel.Purpose
|
oldChannel.Purpose = channel.Purpose
|
||||||
|
|
||||||
oldChannelDisplayName := oldChannel.DisplayName
|
oldChannelDisplayName := oldChannel.DisplayName
|
||||||
|
oldChannelType := oldChannel.Type
|
||||||
|
|
||||||
if len(channel.DisplayName) > 0 {
|
if len(channel.DisplayName) > 0 {
|
||||||
oldChannel.DisplayName = channel.DisplayName
|
oldChannel.DisplayName = channel.DisplayName
|
||||||
@@ -140,6 +141,13 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
l4g.Error(err.Error())
|
l4g.Error(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if oldChannelType == model.CHANNEL_OPEN && channel.Type == model.CHANNEL_PRIVATE {
|
||||||
|
if err := c.App.PostConvertChannelToPrivate(c.Session.UserId, channel); err != nil {
|
||||||
|
l4g.Error(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.LogAudit("name=" + channel.Name)
|
c.LogAudit("name=" + channel.Name)
|
||||||
w.Write([]byte(oldChannel.ToJson()))
|
w.Write([]byte(oldChannel.ToJson()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -805,6 +805,34 @@ func (a *App) PostUpdateChannelDisplayNameMessage(userId string, channel *model.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) PostConvertChannelToPrivate(userId string, channel *model.Channel) *model.AppError {
|
||||||
|
uc := a.Srv.Store.User().Get(userId)
|
||||||
|
|
||||||
|
if uresult := <-uc; uresult.Err != nil {
|
||||||
|
return model.NewAppError("PostConvertChannelToPrivate", "api.channel.post_convert_channel_to_private.retrieve_user.error", nil, uresult.Err.Error(), http.StatusBadRequest)
|
||||||
|
} else {
|
||||||
|
user := uresult.Data.(*model.User)
|
||||||
|
|
||||||
|
message := fmt.Sprintf(utils.T("api.channel.post_convert_channel_to_private.updated_from"), user.Username)
|
||||||
|
|
||||||
|
post := &model.Post{
|
||||||
|
ChannelId: channel.Id,
|
||||||
|
Message: message,
|
||||||
|
Type: model.POST_CONVERT_CHANNEL,
|
||||||
|
UserId: userId,
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"username": user.Username,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||||
|
return model.NewAppError("PostConvertChannelToPrivate", "api.channel.post_convert_channel_to_private.create_post.error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) GetChannel(channelId string) (*model.Channel, *model.AppError) {
|
func (a *App) GetChannel(channelId string) (*model.Channel, *model.AppError) {
|
||||||
if result := <-a.Srv.Store.Channel().Get(channelId, true); result.Err != nil && result.Err.Id == "store.sql_channel.get.existing.app_error" {
|
if result := <-a.Srv.Store.Channel().Get(channelId, true); result.Err != nil && result.Err.Id == "store.sql_channel.get.existing.app_error" {
|
||||||
result.Err.StatusCode = http.StatusNotFound
|
result.Err.StatusCode = http.StatusNotFound
|
||||||
|
|||||||
12
i18n/en.json
12
i18n/en.json
@@ -331,6 +331,18 @@
|
|||||||
"id": "api.channel.leave.left",
|
"id": "api.channel.leave.left",
|
||||||
"translation": "%v left the channel."
|
"translation": "%v left the channel."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.channel.post_convert_channel_to_private.create_post.error",
|
||||||
|
"translation": "Failed to post channel conversion to private message"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "api.channel.post_convert_channel_to_private.retrieve_user.error",
|
||||||
|
"translation": "Failed to retrieve user while converting the channel from public to private"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "api.channel.post_convert_channel_to_private.updated_from",
|
||||||
|
"translation": "%s converted the channel from public to private"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.channel.post_update_channel_displayname_message_and_forget.create_post.error",
|
"id": "api.channel.post_update_channel_displayname_message_and_forget.create_post.error",
|
||||||
"translation": "Failed to post displayname update message"
|
"translation": "Failed to post displayname update message"
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ const (
|
|||||||
POST_REMOVE_FROM_TEAM = "system_remove_from_team"
|
POST_REMOVE_FROM_TEAM = "system_remove_from_team"
|
||||||
POST_HEADER_CHANGE = "system_header_change"
|
POST_HEADER_CHANGE = "system_header_change"
|
||||||
POST_DISPLAYNAME_CHANGE = "system_displayname_change"
|
POST_DISPLAYNAME_CHANGE = "system_displayname_change"
|
||||||
|
POST_CONVERT_CHANNEL = "system_convert_channel"
|
||||||
POST_PURPOSE_CHANGE = "system_purpose_change"
|
POST_PURPOSE_CHANGE = "system_purpose_change"
|
||||||
POST_CHANNEL_DELETED = "system_channel_deleted"
|
POST_CHANNEL_DELETED = "system_channel_deleted"
|
||||||
POST_EPHEMERAL = "system_ephemeral"
|
POST_EPHEMERAL = "system_ephemeral"
|
||||||
@@ -207,6 +208,7 @@ func (o *Post) IsValid(maxPostSize int) *AppError {
|
|||||||
POST_HEADER_CHANGE,
|
POST_HEADER_CHANGE,
|
||||||
POST_PURPOSE_CHANGE,
|
POST_PURPOSE_CHANGE,
|
||||||
POST_DISPLAYNAME_CHANGE,
|
POST_DISPLAYNAME_CHANGE,
|
||||||
|
POST_CONVERT_CHANNEL,
|
||||||
POST_CHANNEL_DELETED,
|
POST_CHANNEL_DELETED,
|
||||||
POST_CHANGE_CHANNEL_PRIVACY:
|
POST_CHANGE_CHANNEL_PRIVACY:
|
||||||
default:
|
default:
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user