Renamed Channel.Description to Channel.Header on the server
Этот коммит содержится в:
@@ -22,7 +22,7 @@ func InitChannel(r *mux.Router) {
|
||||
sr.Handle("/create", ApiUserRequired(createChannel)).Methods("POST")
|
||||
sr.Handle("/create_direct", ApiUserRequired(createDirectChannel)).Methods("POST")
|
||||
sr.Handle("/update", ApiUserRequired(updateChannel)).Methods("POST")
|
||||
sr.Handle("/update_desc", ApiUserRequired(updateChannelDesc)).Methods("POST")
|
||||
sr.Handle("/update_header", ApiUserRequired(updateChannelHeader)).Methods("POST")
|
||||
sr.Handle("/update_notify_props", ApiUserRequired(updateNotifyProps)).Methods("POST")
|
||||
sr.Handle("/{id:[A-Za-z0-9]+}/", ApiUserRequiredActivity(getChannel, false)).Methods("GET")
|
||||
sr.Handle("/{id:[A-Za-z0-9]+}/extra_info", ApiUserRequired(getChannelExtraInfo)).Methods("GET")
|
||||
@@ -124,7 +124,7 @@ func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model
|
||||
channel.Name = model.GetDMNameFromIds(otherUserId, c.Session.UserId)
|
||||
|
||||
channel.TeamId = c.Session.TeamId
|
||||
channel.Description = ""
|
||||
channel.Header = ""
|
||||
channel.Type = model.CHANNEL_DIRECT
|
||||
|
||||
if uresult := <-uc; uresult.Err != nil {
|
||||
@@ -209,7 +209,7 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
oldChannel.Description = channel.Description
|
||||
oldChannel.Header = channel.Header
|
||||
|
||||
if len(channel.DisplayName) > 0 {
|
||||
oldChannel.DisplayName = channel.DisplayName
|
||||
@@ -233,18 +233,18 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func updateChannelDesc(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
channelId := props["channel_id"]
|
||||
if len(channelId) != 26 {
|
||||
c.SetInvalidParam("updateChannelDesc", "channel_id")
|
||||
c.SetInvalidParam("updateChannelHeader", "channel_id")
|
||||
return
|
||||
}
|
||||
|
||||
channelDesc := props["channel_description"]
|
||||
if len(channelDesc) > 1024 {
|
||||
c.SetInvalidParam("updateChannelDesc", "channel_description")
|
||||
channelHeader := props["channel_header"]
|
||||
if len(channelHeader) > 1024 {
|
||||
c.SetInvalidParam("updateChannelHeader", "channel_header")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -261,11 +261,11 @@ func updateChannelDesc(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
channel := cresult.Data.(*model.Channel)
|
||||
// Don't need to do anything channel member, just wanted to confirm it exists
|
||||
|
||||
if !c.HasPermissionsToTeam(channel.TeamId, "updateChannelDesc") {
|
||||
if !c.HasPermissionsToTeam(channel.TeamId, "updateChannelHeader") {
|
||||
return
|
||||
}
|
||||
|
||||
channel.Description = channelDesc
|
||||
channel.Header = channelHeader
|
||||
|
||||
if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
|
||||
c.Err = ucresult.Err
|
||||
|
||||
@@ -61,8 +61,8 @@ func BenchmarkCreateDirectChannel(b *testing.B) {
|
||||
|
||||
func BenchmarkUpdateChannel(b *testing.B) {
|
||||
var (
|
||||
NUM_CHANNELS_RANGE = utils.Range{NUM_CHANNELS, NUM_CHANNELS}
|
||||
CHANNEL_DESCRIPTION_LEN = 50
|
||||
NUM_CHANNELS_RANGE = utils.Range{NUM_CHANNELS, NUM_CHANNELS}
|
||||
CHANNEL_HEADER_LEN = 50
|
||||
)
|
||||
team, _, _ := SetupBenchmark()
|
||||
|
||||
@@ -73,7 +73,7 @@ func BenchmarkUpdateChannel(b *testing.B) {
|
||||
}
|
||||
|
||||
for i := range channels {
|
||||
channels[i].Description = utils.RandString(CHANNEL_DESCRIPTION_LEN, utils.ALPHANUMERIC)
|
||||
channels[i].Header = utils.RandString(CHANNEL_HEADER_LEN, utils.ALPHANUMERIC)
|
||||
}
|
||||
|
||||
// Benchmark Start
|
||||
|
||||
@@ -173,12 +173,12 @@ func TestUpdateChannel(t *testing.T) {
|
||||
|
||||
Client.AddChannelMember(channel1.Id, userTeamAdmin.Id)
|
||||
|
||||
desc := "a" + model.NewId() + "a"
|
||||
upChannel1 := &model.Channel{Id: channel1.Id, Description: desc}
|
||||
header := "a" + model.NewId() + "a"
|
||||
upChannel1 := &model.Channel{Id: channel1.Id, Header: header}
|
||||
upChannel1 = Client.Must(Client.UpdateChannel(upChannel1)).Data.(*model.Channel)
|
||||
|
||||
if upChannel1.Description != desc {
|
||||
t.Fatal("Channel admin failed to update desc")
|
||||
if upChannel1.Header != header {
|
||||
t.Fatal("Channel admin failed to update header")
|
||||
}
|
||||
|
||||
if upChannel1.DisplayName != channel1.DisplayName {
|
||||
@@ -187,12 +187,12 @@ func TestUpdateChannel(t *testing.T) {
|
||||
|
||||
Client.LoginByEmail(team.Name, userTeamAdmin.Email, "pwd")
|
||||
|
||||
desc = "b" + model.NewId() + "b"
|
||||
upChannel1 = &model.Channel{Id: channel1.Id, Description: desc}
|
||||
header = "b" + model.NewId() + "b"
|
||||
upChannel1 = &model.Channel{Id: channel1.Id, Header: header}
|
||||
upChannel1 = Client.Must(Client.UpdateChannel(upChannel1)).Data.(*model.Channel)
|
||||
|
||||
if upChannel1.Description != desc {
|
||||
t.Fatal("Team admin failed to update desc")
|
||||
if upChannel1.Header != header {
|
||||
t.Fatal("Team admin failed to update header")
|
||||
}
|
||||
|
||||
if upChannel1.DisplayName != channel1.DisplayName {
|
||||
@@ -203,7 +203,7 @@ func TestUpdateChannel(t *testing.T) {
|
||||
data := rget.Data.(*model.ChannelList)
|
||||
for _, c := range data.Channels {
|
||||
if c.Name == model.DEFAULT_CHANNEL {
|
||||
c.Description = "new desc"
|
||||
c.Header = "new header"
|
||||
if _, err := Client.UpdateChannel(c); err == nil {
|
||||
t.Fatal("should have errored on updating default channel")
|
||||
}
|
||||
@@ -218,7 +218,7 @@ func TestUpdateChannel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateChannelDesc(t *testing.T) {
|
||||
func TestUpdateChannelHeader(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||
@@ -235,36 +235,36 @@ func TestUpdateChannelDesc(t *testing.T) {
|
||||
|
||||
data := make(map[string]string)
|
||||
data["channel_id"] = channel1.Id
|
||||
data["channel_description"] = "new desc"
|
||||
data["channel_header"] = "new header"
|
||||
|
||||
var upChannel1 *model.Channel
|
||||
if result, err := Client.UpdateChannelDesc(data); err != nil {
|
||||
if result, err := Client.UpdateChannelHeader(data); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
upChannel1 = result.Data.(*model.Channel)
|
||||
}
|
||||
|
||||
if upChannel1.Description != data["channel_description"] {
|
||||
t.Fatal("Failed to update desc")
|
||||
if upChannel1.Header != data["channel_header"] {
|
||||
t.Fatal("Failed to update header")
|
||||
}
|
||||
|
||||
data["channel_id"] = "junk"
|
||||
if _, err := Client.UpdateChannelDesc(data); err == nil {
|
||||
if _, err := Client.UpdateChannelHeader(data); err == nil {
|
||||
t.Fatal("should have errored on junk channel id")
|
||||
}
|
||||
|
||||
data["channel_id"] = "12345678901234567890123456"
|
||||
if _, err := Client.UpdateChannelDesc(data); err == nil {
|
||||
if _, err := Client.UpdateChannelHeader(data); err == nil {
|
||||
t.Fatal("should have errored on non-existent channel id")
|
||||
}
|
||||
|
||||
data["channel_id"] = channel1.Id
|
||||
data["channel_description"] = ""
|
||||
data["channel_header"] = ""
|
||||
for i := 0; i < 1050; i++ {
|
||||
data["channel_description"] += "a"
|
||||
data["channel_header"] += "a"
|
||||
}
|
||||
if _, err := Client.UpdateChannelDesc(data); err == nil {
|
||||
t.Fatal("should have errored on bad channel desc")
|
||||
if _, err := Client.UpdateChannelHeader(data); err == nil {
|
||||
t.Fatal("should have errored on bad channel header")
|
||||
}
|
||||
|
||||
user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
|
||||
@@ -274,9 +274,9 @@ func TestUpdateChannelDesc(t *testing.T) {
|
||||
Client.LoginByEmail(team.Name, user2.Email, "pwd")
|
||||
|
||||
data["channel_id"] = channel1.Id
|
||||
data["channel_description"] = "new desc"
|
||||
if _, err := Client.UpdateChannelDesc(data); err == nil {
|
||||
t.Fatal("should have errored non-channel member trying to update desc")
|
||||
data["channel_header"] = "new header"
|
||||
if _, err := Client.UpdateChannelHeader(data); err == nil {
|
||||
t.Fatal("should have errored non-channel member trying to update header")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[str
|
||||
Type: model.CHANNEL_OPEN,
|
||||
DisplayName: sChannel.Name,
|
||||
Name: SlackConvertChannelName(sChannel.Name),
|
||||
Description: sChannel.Topic["value"],
|
||||
//Purpose: sChannel.Topic["value"], // TODO uncomment this once Channel.Purpose is a field
|
||||
}
|
||||
mChannel := ImportChannel(&newChannel)
|
||||
if mChannel == nil {
|
||||
|
||||
@@ -24,7 +24,7 @@ type Channel struct {
|
||||
Type string `json:"type"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Header string `json:"header"`
|
||||
LastPostAt int64 `json:"last_post_at"`
|
||||
TotalMsgCount int64 `json:"total_msg_count"`
|
||||
ExtraUpdateAt int64 `json:"extra_update_at"`
|
||||
@@ -89,8 +89,8 @@ func (o *Channel) IsValid() *AppError {
|
||||
return NewAppError("Channel.IsValid", "Invalid type", "id="+o.Id)
|
||||
}
|
||||
|
||||
if len(o.Description) > 1024 {
|
||||
return NewAppError("Channel.IsValid", "Invalid description", "id="+o.Id)
|
||||
if len(o.Header) > 1024 {
|
||||
return NewAppError("Channel.IsValid", "Invalid header", "id="+o.Id)
|
||||
}
|
||||
|
||||
if len(o.CreatorId) > 26 {
|
||||
|
||||
@@ -443,8 +443,8 @@ func (c *Client) UpdateChannel(channel *Channel) (*Result, *AppError) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) UpdateChannelDesc(data map[string]string) (*Result, *AppError) {
|
||||
if r, err := c.DoApiPost("/channels/update_desc", MapToJson(data)); err != nil {
|
||||
func (c *Client) UpdateChannelHeader(data map[string]string) (*Result, *AppError) {
|
||||
if r, err := c.DoApiPost("/channels/update_header", MapToJson(data)); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
||||
|
||||
@@ -25,7 +25,7 @@ func NewSqlChannelStore(sqlStore *SqlStore) ChannelStore {
|
||||
table.ColMap("DisplayName").SetMaxSize(64)
|
||||
table.ColMap("Name").SetMaxSize(64)
|
||||
table.SetUniqueTogether("Name", "TeamId")
|
||||
table.ColMap("Description").SetMaxSize(1024)
|
||||
table.ColMap("Header").SetMaxSize(1024)
|
||||
table.ColMap("CreatorId").SetMaxSize(26)
|
||||
|
||||
tablem := db.AddTableWithName(model.ChannelMember{}, "ChannelMembers").SetKeys(false, "ChannelId", "UserId")
|
||||
@@ -83,6 +83,10 @@ func (s SqlChannelStore) UpgradeSchemaIfNeeded() {
|
||||
|
||||
s.RemoveColumnIfExists("ChannelMembers", "NotifyLevel")
|
||||
}
|
||||
|
||||
// BEGIN REMOVE AFTER 1.2.0
|
||||
s.RenameColumnIfExists("Channels", "Description", "Header", "varchar(1024)")
|
||||
// END REMOVE AFTER 1.2.0
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) CreateIndexesIfNotExists() {
|
||||
|
||||
@@ -364,27 +364,26 @@ func (ss SqlStore) RemoveColumnIfExists(tableName string, columnName string) boo
|
||||
return true
|
||||
}
|
||||
|
||||
// func (ss SqlStore) RenameColumnIfExists(tableName string, oldColumnName string, newColumnName string, colType string) bool {
|
||||
func (ss SqlStore) RenameColumnIfExists(tableName string, oldColumnName string, newColumnName string, colType string) bool {
|
||||
if !ss.DoesColumnExist(tableName, oldColumnName) {
|
||||
return false
|
||||
}
|
||||
|
||||
// // XXX TODO FIXME this should be removed after 0.6.0
|
||||
// if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
|
||||
// return false
|
||||
// }
|
||||
var err error
|
||||
if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
|
||||
_, err = ss.GetMaster().Exec("ALTER TABLE " + tableName + " CHANGE " + oldColumnName + " " + newColumnName + " " + colType)
|
||||
} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
|
||||
_, err = ss.GetMaster().Exec("ALTER TABLE " + tableName + " RENAME COLUMN " + oldColumnName + " TO " + newColumnName)
|
||||
}
|
||||
|
||||
// if !ss.DoesColumnExist(tableName, oldColumnName) {
|
||||
// return false
|
||||
// }
|
||||
if err != nil {
|
||||
l4g.Critical("Failed to rename column %v", err)
|
||||
time.Sleep(time.Second)
|
||||
panic("Failed to drop column " + err.Error())
|
||||
}
|
||||
|
||||
// _, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " CHANGE " + oldColumnName + " " + newColumnName + " " + colType)
|
||||
|
||||
// if err != nil {
|
||||
// l4g.Critical("Failed to rename column %v", err)
|
||||
// time.Sleep(time.Second)
|
||||
// panic("Failed to drop column " + err.Error())
|
||||
// }
|
||||
|
||||
// return true
|
||||
// }
|
||||
return true
|
||||
}
|
||||
|
||||
func (ss SqlStore) CreateIndexIfNotExists(indexName string, tableName string, columnName string) {
|
||||
ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_DEFAULT)
|
||||
|
||||
Ссылка в новой задаче
Block a user