Fixing edit direct channel header (#2842)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
6f1489b788
Коммит
f8ed606a5f
@@ -113,7 +113,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if sc, err := CreateDirectChannel(c, userId); err != nil {
|
if sc, err := CreateDirectChannel(c.Session.UserId, userId); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@@ -121,19 +121,14 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model.AppError) {
|
func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
||||||
if len(otherUserId) != 26 {
|
|
||||||
return nil, model.NewLocAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, otherUserId)
|
|
||||||
}
|
|
||||||
|
|
||||||
uc := Srv.Store.User().Get(otherUserId)
|
uc := Srv.Store.User().Get(otherUserId)
|
||||||
|
|
||||||
channel := new(model.Channel)
|
channel := new(model.Channel)
|
||||||
|
|
||||||
channel.DisplayName = ""
|
channel.DisplayName = ""
|
||||||
channel.Name = model.GetDMNameFromIds(otherUserId, c.Session.UserId)
|
channel.Name = model.GetDMNameFromIds(otherUserId, userId)
|
||||||
|
|
||||||
channel.TeamId = c.TeamId
|
|
||||||
channel.Header = ""
|
channel.Header = ""
|
||||||
channel.Type = model.CHANNEL_DIRECT
|
channel.Type = model.CHANNEL_DIRECT
|
||||||
|
|
||||||
@@ -142,13 +137,11 @@ func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model
|
|||||||
}
|
}
|
||||||
|
|
||||||
cm1 := &model.ChannelMember{
|
cm1 := &model.ChannelMember{
|
||||||
UserId: c.Session.UserId,
|
UserId: userId,
|
||||||
Roles: model.CHANNEL_ROLE_ADMIN,
|
|
||||||
NotifyProps: model.GetDefaultChannelNotifyProps(),
|
NotifyProps: model.GetDefaultChannelNotifyProps(),
|
||||||
}
|
}
|
||||||
cm2 := &model.ChannelMember{
|
cm2 := &model.ChannelMember{
|
||||||
UserId: otherUserId,
|
UserId: otherUserId,
|
||||||
Roles: "",
|
|
||||||
NotifyProps: model.GetDefaultChannelNotifyProps(),
|
NotifyProps: model.GetDefaultChannelNotifyProps(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +267,7 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
channel := cresult.Data.(*model.Channel)
|
channel := cresult.Data.(*model.Channel)
|
||||||
// Don't need to do anything channel member, just wanted to confirm it exists
|
// Don't need to do anything channel member, just wanted to confirm it exists
|
||||||
|
|
||||||
if !c.HasPermissionsToTeam(channel.TeamId, "updateChannelHeader") {
|
if channel.TeamId != "" && !c.HasPermissionsToTeam(channel.TeamId, "updateChannelHeader") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
oldChannelHeader := channel.Header
|
oldChannelHeader := channel.Header
|
||||||
|
|||||||
@@ -215,6 +215,20 @@ func TestUpdateChannelHeader(t *testing.T) {
|
|||||||
t.Fatal("should have errored on bad channel header")
|
t.Fatal("should have errored on bad channel header")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rchannel := Client.Must(Client.CreateDirectChannel(th.BasicUser2.Id)).Data.(*model.Channel)
|
||||||
|
data["channel_id"] = rchannel.Id
|
||||||
|
data["channel_header"] = "new header"
|
||||||
|
var upChanneld *model.Channel
|
||||||
|
if result, err := Client.UpdateChannelHeader(data); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else {
|
||||||
|
upChanneld = result.Data.(*model.Channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
if upChanneld.Header != data["channel_header"] {
|
||||||
|
t.Fatal("Failed to update header")
|
||||||
|
}
|
||||||
|
|
||||||
th.LoginBasic2()
|
th.LoginBasic2()
|
||||||
|
|
||||||
data["channel_id"] = channel1.Id
|
data["channel_id"] = channel1.Id
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (me *msgProvider) DoCommand(c *Context, channelId string, message string) *
|
|||||||
|
|
||||||
if channel := <-Srv.Store.Channel().GetByName(c.TeamId, channelName); channel.Err != nil {
|
if channel := <-Srv.Store.Channel().GetByName(c.TeamId, channelName); channel.Err != nil {
|
||||||
if channel.Err.Id == "store.sql_channel.get_by_name.missing.app_error" {
|
if channel.Err.Id == "store.sql_channel.get_by_name.missing.app_error" {
|
||||||
if directChannel, err := CreateDirectChannel(c, userProfile.Id); err != nil {
|
if directChannel, err := CreateDirectChannel(c.Session.UserId, userProfile.Id); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return &model.CommandResponse{Text: c.T("api.command_msg.dm_fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
return &model.CommandResponse{Text: c.T("api.command_msg.dm_fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user