[MM-17422] Added code to update, delete last bot_icon time in model.bot. (#12229)
Display LHS bot Icon in web app. As part of mentioned task, Added LastIconUpdate variable in model.bot to store last update time of icon. Also added code to update/delete value of the mentioned variable when setting/deleting bot icon.
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
f8d31def8e
Коммит
803a58f991
23
app/bot.go
23
app/bot.go
@@ -328,7 +328,8 @@ func (a *App) SetBotIconImageFromMultiPartFile(botUserId string, imageData *mult
|
|||||||
|
|
||||||
// SetBotIconImage sets LHS icon for a bot.
|
// SetBotIconImage sets LHS icon for a bot.
|
||||||
func (a *App) SetBotIconImage(botUserId string, file io.ReadSeeker) *model.AppError {
|
func (a *App) SetBotIconImage(botUserId string, file io.ReadSeeker) *model.AppError {
|
||||||
if _, err := a.GetBot(botUserId, true); err != nil {
|
bot, err := a.GetBot(botUserId, true)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,12 +339,13 @@ func (a *App) SetBotIconImage(botUserId string, file io.ReadSeeker) *model.AppEr
|
|||||||
|
|
||||||
// Set icon
|
// Set icon
|
||||||
file.Seek(0, 0)
|
file.Seek(0, 0)
|
||||||
if _, err := a.WriteFile(file, getBotIconPath(botUserId)); err != nil {
|
if _, err = a.WriteFile(file, getBotIconPath(botUserId)); err != nil {
|
||||||
return model.NewAppError("SetBotIconImage", "api.bot.set_bot_icon_image.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("SetBotIconImage", "api.bot.set_bot_icon_image.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.Srv.Store.User().UpdateLastPictureUpdate(botUserId); err != nil {
|
bot.LastIconUpdate = model.GetMillis()
|
||||||
mlog.Error(err.Error())
|
if _, err = a.Srv.Store.Bot().Update(bot); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
a.invalidateUserCacheAndPublish(botUserId)
|
a.invalidateUserCacheAndPublish(botUserId)
|
||||||
|
|
||||||
@@ -352,18 +354,25 @@ func (a *App) SetBotIconImage(botUserId string, file io.ReadSeeker) *model.AppEr
|
|||||||
|
|
||||||
// DeleteBotIconImage deletes LHS icon for a bot.
|
// DeleteBotIconImage deletes LHS icon for a bot.
|
||||||
func (a *App) DeleteBotIconImage(botUserId string) *model.AppError {
|
func (a *App) DeleteBotIconImage(botUserId string) *model.AppError {
|
||||||
if _, err := a.GetBot(botUserId, true); err != nil {
|
bot, err := a.GetBot(botUserId, true)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete icon
|
// Delete icon
|
||||||
if err := a.RemoveFile(getBotIconPath(botUserId)); err != nil {
|
if err = a.RemoveFile(getBotIconPath(botUserId)); err != nil {
|
||||||
return model.NewAppError("DeleteBotIconImage", "api.bot.delete_bot_icon_image.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("DeleteBotIconImage", "api.bot.delete_bot_icon_image.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.Srv.Store.User().UpdateLastPictureUpdate(botUserId); err != nil {
|
if err = a.Srv.Store.User().UpdateLastPictureUpdate(botUserId); err != nil {
|
||||||
mlog.Error(err.Error())
|
mlog.Error(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bot.LastIconUpdate = int64(0)
|
||||||
|
if _, err = a.Srv.Store.Bot().Update(bot); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
a.invalidateUserCacheAndPublish(botUserId)
|
a.invalidateUserCacheAndPublish(botUserId)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
17
model/bot.go
17
model/bot.go
@@ -22,14 +22,15 @@ const (
|
|||||||
// Note that the primary key of a bot is the UserId, and matches the primary key of the
|
// Note that the primary key of a bot is the UserId, and matches the primary key of the
|
||||||
// corresponding user.
|
// corresponding user.
|
||||||
type Bot struct {
|
type Bot struct {
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
DisplayName string `json:"display_name,omitempty"`
|
DisplayName string `json:"display_name,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
OwnerId string `json:"owner_id"`
|
OwnerId string `json:"owner_id"`
|
||||||
CreateAt int64 `json:"create_at"`
|
LastIconUpdate int64 `json:"last_icon_update,omitempty"`
|
||||||
UpdateAt int64 `json:"update_at"`
|
CreateAt int64 `json:"create_at"`
|
||||||
DeleteAt int64 `json:"delete_at"`
|
UpdateAt int64 `json:"update_at"`
|
||||||
|
DeleteAt int64 `json:"delete_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BotPatch is a description of what fields to update on an existing bot.
|
// BotPatch is a description of what fields to update on an existing bot.
|
||||||
|
|||||||
@@ -14,14 +14,15 @@ import (
|
|||||||
|
|
||||||
func TestBotTrace(t *testing.T) {
|
func TestBotTrace(t *testing.T) {
|
||||||
bot := &Bot{
|
bot := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(t, map[string]interface{}{"user_id": bot.UserId}, bot.Trace())
|
require.Equal(t, map[string]interface{}{"user_id": bot.UserId}, bot.Trace())
|
||||||
@@ -29,14 +30,15 @@ func TestBotTrace(t *testing.T) {
|
|||||||
|
|
||||||
func TestBotClone(t *testing.T) {
|
func TestBotClone(t *testing.T) {
|
||||||
bot := &Bot{
|
bot := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
clone := bot.Clone()
|
clone := bot.Clone()
|
||||||
@@ -59,154 +61,165 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"bot with missing user id",
|
"bot with missing user id",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: "",
|
UserId: "",
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bot with invalid user id",
|
"bot with invalid user id",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: "invalid",
|
UserId: "invalid",
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bot with missing username",
|
"bot with missing username",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "",
|
Username: "",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bot with invalid username",
|
"bot with invalid username",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "a@",
|
Username: "a@",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bot with long description",
|
"bot with long description",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: "",
|
UserId: "",
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: strings.Repeat("x", 1025),
|
Description: strings.Repeat("x", 1025),
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bot with missing creator id",
|
"bot with missing creator id",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: "",
|
OwnerId: "",
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bot without create at timestamp",
|
"bot without create at timestamp",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 0,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 0,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bot without update at timestamp",
|
"bot without update at timestamp",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 0,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 0,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bot",
|
"bot",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 0,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 0,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bot without description",
|
"bot without description",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "",
|
Description: "",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 0,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 0,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"deleted bot",
|
"deleted bot",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "a description",
|
Description: "a description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
@@ -225,12 +238,13 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
|
|
||||||
func TestBotPreSave(t *testing.T) {
|
func TestBotPreSave(t *testing.T) {
|
||||||
bot := &Bot{
|
bot := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
DeleteAt: 0,
|
LastIconUpdate: 0,
|
||||||
|
DeleteAt: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
originalBot := &*bot
|
originalBot := &*bot
|
||||||
@@ -246,13 +260,14 @@ func TestBotPreSave(t *testing.T) {
|
|||||||
|
|
||||||
func TestBotPreUpdate(t *testing.T) {
|
func TestBotPreUpdate(t *testing.T) {
|
||||||
bot := &Bot{
|
bot := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
DeleteAt: 0,
|
CreateAt: 2,
|
||||||
|
DeleteAt: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
originalBot := &*bot
|
originalBot := &*bot
|
||||||
@@ -267,14 +282,15 @@ func TestBotPreUpdate(t *testing.T) {
|
|||||||
func TestBotEtag(t *testing.T) {
|
func TestBotEtag(t *testing.T) {
|
||||||
t.Run("same etags", func(t *testing.T) {
|
t.Run("same etags", func(t *testing.T) {
|
||||||
bot1 := &Bot{
|
bot1 := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
bot2 := bot1
|
bot2 := bot1
|
||||||
|
|
||||||
@@ -283,48 +299,52 @@ func TestBotEtag(t *testing.T) {
|
|||||||
t.Run("different etags", func(t *testing.T) {
|
t.Run("different etags", func(t *testing.T) {
|
||||||
t.Run("different user id", func(t *testing.T) {
|
t.Run("different user id", func(t *testing.T) {
|
||||||
bot1 := &Bot{
|
bot1 := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
bot2 := &Bot{
|
bot2 := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: bot1.OwnerId,
|
OwnerId: bot1.OwnerId,
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NotEqual(t, bot1.Etag(), bot2.Etag())
|
assert.NotEqual(t, bot1.Etag(), bot2.Etag())
|
||||||
})
|
})
|
||||||
t.Run("different update at", func(t *testing.T) {
|
t.Run("different update at", func(t *testing.T) {
|
||||||
bot1 := &Bot{
|
bot1 := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
bot2 := &Bot{
|
bot2 := &Bot{
|
||||||
UserId: bot1.UserId,
|
UserId: bot1.UserId,
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: bot1.OwnerId,
|
OwnerId: bot1.OwnerId,
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 10,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 10,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NotEqual(t, bot1.Etag(), bot2.Etag())
|
assert.NotEqual(t, bot1.Etag(), bot2.Etag())
|
||||||
@@ -334,25 +354,27 @@ func TestBotEtag(t *testing.T) {
|
|||||||
|
|
||||||
func TestBotToAndFromJson(t *testing.T) {
|
func TestBotToAndFromJson(t *testing.T) {
|
||||||
bot1 := &Bot{
|
bot1 := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
bot2 := &Bot{
|
bot2 := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description 2",
|
Description: "description 2",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 4,
|
LastIconUpdate: 5,
|
||||||
UpdateAt: 5,
|
CreateAt: 6,
|
||||||
DeleteAt: 6,
|
UpdateAt: 7,
|
||||||
|
DeleteAt: 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, bot1, BotFromJson(bytes.NewReader(bot1.ToJson())))
|
assert.Equal(t, bot1, BotFromJson(bytes.NewReader(bot1.ToJson())))
|
||||||
@@ -376,38 +398,41 @@ func TestBotPatch(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"no update",
|
"no update",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: userId1,
|
UserId: userId1,
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: creatorId1,
|
OwnerId: creatorId1,
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
&BotPatch{},
|
&BotPatch{},
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: userId1,
|
UserId: userId1,
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: creatorId1,
|
OwnerId: creatorId1,
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"partial update",
|
"partial update",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: userId1,
|
UserId: userId1,
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: creatorId1,
|
OwnerId: creatorId1,
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
&BotPatch{
|
&BotPatch{
|
||||||
Username: sToP("new_username"),
|
Username: sToP("new_username"),
|
||||||
@@ -415,27 +440,29 @@ func TestBotPatch(t *testing.T) {
|
|||||||
Description: sToP("new description"),
|
Description: sToP("new description"),
|
||||||
},
|
},
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: userId1,
|
UserId: userId1,
|
||||||
Username: "new_username",
|
Username: "new_username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "new description",
|
Description: "new description",
|
||||||
OwnerId: creatorId1,
|
OwnerId: creatorId1,
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"full update",
|
"full update",
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: userId1,
|
UserId: userId1,
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: creatorId1,
|
OwnerId: creatorId1,
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
&BotPatch{
|
&BotPatch{
|
||||||
Username: sToP("new_username"),
|
Username: sToP("new_username"),
|
||||||
@@ -443,14 +470,15 @@ func TestBotPatch(t *testing.T) {
|
|||||||
Description: sToP("new description"),
|
Description: sToP("new description"),
|
||||||
},
|
},
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: userId1,
|
UserId: userId1,
|
||||||
Username: "new_username",
|
Username: "new_username",
|
||||||
DisplayName: "new display name",
|
DisplayName: "new display name",
|
||||||
Description: "new description",
|
Description: "new description",
|
||||||
OwnerId: creatorId1,
|
OwnerId: creatorId1,
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -482,25 +510,27 @@ func TestBotPatchToAndFromJson(t *testing.T) {
|
|||||||
|
|
||||||
func TestUserFromBot(t *testing.T) {
|
func TestUserFromBot(t *testing.T) {
|
||||||
bot1 := &Bot{
|
bot1 := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
bot2 := &Bot{
|
bot2 := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username2",
|
Username: "username2",
|
||||||
DisplayName: "display name 2",
|
DisplayName: "display name 2",
|
||||||
Description: "description 2",
|
Description: "description 2",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 4,
|
LastIconUpdate: 5,
|
||||||
UpdateAt: 5,
|
CreateAt: 6,
|
||||||
DeleteAt: 6,
|
UpdateAt: 7,
|
||||||
|
DeleteAt: 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, &User{
|
assert.Equal(t, &User{
|
||||||
@@ -549,14 +579,15 @@ func TestBotListToAndFromJson(t *testing.T) {
|
|||||||
"single item",
|
"single item",
|
||||||
BotList{
|
BotList{
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -564,25 +595,27 @@ func TestBotListToAndFromJson(t *testing.T) {
|
|||||||
"multiple items",
|
"multiple items",
|
||||||
BotList{
|
BotList{
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
|
|
||||||
&Bot{
|
&Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description 2",
|
Description: "description 2",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 4,
|
LastIconUpdate: 5,
|
||||||
UpdateAt: 5,
|
CreateAt: 6,
|
||||||
DeleteAt: 6,
|
UpdateAt: 7,
|
||||||
|
DeleteAt: 8,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -597,36 +630,39 @@ func TestBotListToAndFromJson(t *testing.T) {
|
|||||||
|
|
||||||
func TestBotListEtag(t *testing.T) {
|
func TestBotListEtag(t *testing.T) {
|
||||||
bot1 := &Bot{
|
bot1 := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 3,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
bot1Updated := &Bot{
|
bot1Updated := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 10,
|
CreateAt: 2,
|
||||||
DeleteAt: 3,
|
UpdateAt: 10,
|
||||||
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
bot2 := &Bot{
|
bot2 := &Bot{
|
||||||
UserId: NewId(),
|
UserId: NewId(),
|
||||||
Username: "username",
|
Username: "username",
|
||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 4,
|
LastIconUpdate: 5,
|
||||||
UpdateAt: 5,
|
CreateAt: 6,
|
||||||
DeleteAt: 6,
|
UpdateAt: 7,
|
||||||
|
DeleteAt: 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ type User struct {
|
|||||||
LastActivityAt int64 `db:"-" json:"last_activity_at,omitempty"`
|
LastActivityAt int64 `db:"-" json:"last_activity_at,omitempty"`
|
||||||
IsBot bool `db:"-" json:"is_bot,omitempty"`
|
IsBot bool `db:"-" json:"is_bot,omitempty"`
|
||||||
BotDescription string `db:"-" json:"bot_description,omitempty"`
|
BotDescription string `db:"-" json:"bot_description,omitempty"`
|
||||||
|
BotLastIconUpdate int64 `db:"-" json:"bot_last_icon_update,omitempty"`
|
||||||
TermsOfServiceId string `db:"-" json:"terms_of_service_id,omitempty"`
|
TermsOfServiceId string `db:"-" json:"terms_of_service_id,omitempty"`
|
||||||
TermsOfServiceCreateAt int64 `db:"-" json:"terms_of_service_create_at,omitempty"`
|
TermsOfServiceCreateAt int64 `db:"-" json:"terms_of_service_create_at,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -487,7 +488,7 @@ func (u *UserAuth) ToJson() string {
|
|||||||
|
|
||||||
// Generate a valid strong etag so the browser can cache the results
|
// Generate a valid strong etag so the browser can cache the results
|
||||||
func (u *User) Etag(showFullName, showEmail bool) string {
|
func (u *User) Etag(showFullName, showEmail bool) string {
|
||||||
return Etag(u.Id, u.UpdateAt, u.TermsOfServiceId, u.TermsOfServiceCreateAt, showFullName, showEmail)
|
return Etag(u.Id, u.UpdateAt, u.TermsOfServiceId, u.TermsOfServiceCreateAt, showFullName, showEmail, u.BotLastIconUpdate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any private data from the user object
|
// Remove any private data from the user object
|
||||||
|
|||||||
@@ -15,22 +15,24 @@ import (
|
|||||||
|
|
||||||
// bot is a subset of the model.Bot type, omitting the model.User fields.
|
// bot is a subset of the model.Bot type, omitting the model.User fields.
|
||||||
type bot struct {
|
type bot struct {
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
OwnerId string `json:"owner_id"`
|
OwnerId string `json:"owner_id"`
|
||||||
CreateAt int64 `json:"create_at"`
|
LastIconUpdate int64 `json:"last_icon_update"`
|
||||||
UpdateAt int64 `json:"update_at"`
|
CreateAt int64 `json:"create_at"`
|
||||||
DeleteAt int64 `json:"delete_at"`
|
UpdateAt int64 `json:"update_at"`
|
||||||
|
DeleteAt int64 `json:"delete_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func botFromModel(b *model.Bot) *bot {
|
func botFromModel(b *model.Bot) *bot {
|
||||||
return &bot{
|
return &bot{
|
||||||
UserId: b.UserId,
|
UserId: b.UserId,
|
||||||
Description: b.Description,
|
Description: b.Description,
|
||||||
OwnerId: b.OwnerId,
|
OwnerId: b.OwnerId,
|
||||||
CreateAt: b.CreateAt,
|
LastIconUpdate: b.LastIconUpdate,
|
||||||
UpdateAt: b.UpdateAt,
|
CreateAt: b.CreateAt,
|
||||||
DeleteAt: b.DeleteAt,
|
UpdateAt: b.UpdateAt,
|
||||||
|
DeleteAt: b.DeleteAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +91,7 @@ func (us SqlBotStore) Get(botUserId string, includeDeleted bool) (*model.Bot, *m
|
|||||||
u.FirstName AS DisplayName,
|
u.FirstName AS DisplayName,
|
||||||
b.Description,
|
b.Description,
|
||||||
b.OwnerId,
|
b.OwnerId,
|
||||||
|
b.LastIconUpdate,
|
||||||
b.CreateAt,
|
b.CreateAt,
|
||||||
b.UpdateAt,
|
b.UpdateAt,
|
||||||
b.DeleteAt
|
b.DeleteAt
|
||||||
@@ -145,6 +148,7 @@ func (us SqlBotStore) GetAll(options *model.BotGetOptions) ([]*model.Bot, *model
|
|||||||
u.FirstName AS DisplayName,
|
u.FirstName AS DisplayName,
|
||||||
b.Description,
|
b.Description,
|
||||||
b.OwnerId,
|
b.OwnerId,
|
||||||
|
b.LastIconUpdate,
|
||||||
b.CreateAt,
|
b.CreateAt,
|
||||||
b.UpdateAt,
|
b.UpdateAt,
|
||||||
b.DeleteAt
|
b.DeleteAt
|
||||||
@@ -205,6 +209,7 @@ func (us SqlBotStore) Update(bot *model.Bot) (*model.Bot, *model.AppError) {
|
|||||||
|
|
||||||
oldBot.Description = bot.Description
|
oldBot.Description = bot.Description
|
||||||
oldBot.OwnerId = bot.OwnerId
|
oldBot.OwnerId = bot.OwnerId
|
||||||
|
oldBot.LastIconUpdate = bot.LastIconUpdate
|
||||||
oldBot.UpdateAt = bot.UpdateAt
|
oldBot.UpdateAt = bot.UpdateAt
|
||||||
oldBot.DeleteAt = bot.DeleteAt
|
oldBot.DeleteAt = bot.DeleteAt
|
||||||
bot = oldBot
|
bot = oldBot
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func NewSqlUserStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) st
|
|||||||
}
|
}
|
||||||
|
|
||||||
us.usersQuery = us.getQueryBuilder().
|
us.usersQuery = us.getQueryBuilder().
|
||||||
Select("u.*", "b.UserId IS NOT NULL AS IsBot", "COALESCE(b.Description, '') AS BotDescription").
|
Select("u.*", "b.UserId IS NOT NULL AS IsBot", "COALESCE(b.Description, '') AS BotDescription", "COALESCE(b.LastIconUpdate, 0) AS BotLastIconUpdate").
|
||||||
From("Users u").
|
From("Users u").
|
||||||
LeftJoin("Bots b ON ( b.UserId = u.Id )")
|
LeftJoin("Bots b ON ( b.UserId = u.Id )")
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user