PLT-1380: Post system message when user updates channel header
Этот коммит содержится в:
@@ -268,19 +268,51 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
if !c.HasPermissionsToTeam(channel.TeamId, "updateChannelHeader") {
|
if !c.HasPermissionsToTeam(channel.TeamId, "updateChannelHeader") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
oldChannelHeader := channel.Header
|
||||||
channel.Header = channelHeader
|
channel.Header = channelHeader
|
||||||
|
|
||||||
if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
|
if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
|
||||||
c.Err = ucresult.Err
|
c.Err = ucresult.Err
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
PostUpdateChannelHeaderMessageAndForget(c, channel.Id, oldChannelHeader, channelHeader)
|
||||||
c.LogAudit("name=" + channel.Name)
|
c.LogAudit("name=" + channel.Name)
|
||||||
w.Write([]byte(channel.ToJson()))
|
w.Write([]byte(channel.ToJson()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PostUpdateChannelHeaderMessageAndForget(c *Context, channelId string, oldChannelHeader, newChannelHeader string) {
|
||||||
|
go func() {
|
||||||
|
uc := Srv.Store.User().Get(c.Session.UserId)
|
||||||
|
|
||||||
|
if uresult := <-uc; uresult.Err != nil {
|
||||||
|
l4g.Error("Failed to retrieve user while trying to save update channel header message %v", uresult.Err)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
user := uresult.Data.(*model.User)
|
||||||
|
|
||||||
|
var message string
|
||||||
|
if oldChannelHeader == "" {
|
||||||
|
message = fmt.Sprintf("%s updated the channel header to: %s", user.Username, newChannelHeader)
|
||||||
|
} else if newChannelHeader == "" {
|
||||||
|
message = fmt.Sprintf("%s removed the channel header (was: %s)", user.Username, oldChannelHeader)
|
||||||
|
} else {
|
||||||
|
message = fmt.Sprintf("%s updated the channel header from: %s to: %s", user.Username, oldChannelHeader, newChannelHeader)
|
||||||
|
}
|
||||||
|
|
||||||
|
post := &model.Post{
|
||||||
|
ChannelId: channelId,
|
||||||
|
Message: message,
|
||||||
|
Type: model.POST_HEADER_CHANGE,
|
||||||
|
}
|
||||||
|
if _, err := CreatePost(c, post, false); err != nil {
|
||||||
|
l4g.Error("Failed to post join/leave message %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
|
func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
props := model.MapFromJson(r.Body)
|
props := model.MapFromJson(r.Body)
|
||||||
channelId := props["channel_id"]
|
channelId := props["channel_id"]
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const (
|
|||||||
POST_DEFAULT = ""
|
POST_DEFAULT = ""
|
||||||
POST_SLACK_ATTACHMENT = "slack_attachment"
|
POST_SLACK_ATTACHMENT = "slack_attachment"
|
||||||
POST_JOIN_LEAVE = "system_join_leave"
|
POST_JOIN_LEAVE = "system_join_leave"
|
||||||
|
POST_HEADER_CHANGE = "system_header_change"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Post struct {
|
type Post struct {
|
||||||
@@ -105,7 +106,7 @@ func (o *Post) IsValid() *AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// should be removed once more message types are supported
|
// should be removed once more message types are supported
|
||||||
if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_SLACK_ATTACHMENT) {
|
if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_SLACK_ATTACHMENT || o.Type == POST_HEADER_CHANGE) {
|
||||||
return NewAppError("Post.IsValid", "Invalid type", "id="+o.Type)
|
return NewAppError("Post.IsValid", "Invalid type", "id="+o.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ export default class Post extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let currentUserCss = '';
|
let currentUserCss = '';
|
||||||
if (UserStore.getCurrentId() === post.user_id && !post.props.from_webhook) {
|
if (UserStore.getCurrentId() === post.user_id && !post.props.from_webhook && !utils.isSystemMessage(post)) {
|
||||||
currentUserCss = 'current--user';
|
currentUserCss = 'current--user';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user