[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
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ type Bot struct {
|
|||||||
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"`
|
||||||
|
LastIconUpdate int64 `json:"last_icon_update,omitempty"`
|
||||||
CreateAt int64 `json:"create_at"`
|
CreateAt int64 `json:"create_at"`
|
||||||
UpdateAt int64 `json:"update_at"`
|
UpdateAt int64 `json:"update_at"`
|
||||||
DeleteAt int64 `json:"delete_at"`
|
DeleteAt int64 `json:"delete_at"`
|
||||||
|
|||||||
@@ -19,9 +19,10 @@ func TestBotTrace(t *testing.T) {
|
|||||||
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())
|
||||||
@@ -34,9 +35,10 @@ func TestBotClone(t *testing.T) {
|
|||||||
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()
|
||||||
@@ -64,9 +66,10 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
@@ -78,9 +81,10 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
@@ -92,9 +96,10 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
@@ -106,9 +111,10 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
@@ -120,9 +126,10 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
@@ -134,9 +141,10 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
@@ -148,9 +156,10 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
|
LastIconUpdate: 1,
|
||||||
CreateAt: 0,
|
CreateAt: 0,
|
||||||
UpdateAt: 2,
|
UpdateAt: 3,
|
||||||
DeleteAt: 3,
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
@@ -162,9 +171,10 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
|
CreateAt: 2,
|
||||||
UpdateAt: 0,
|
UpdateAt: 0,
|
||||||
DeleteAt: 3,
|
DeleteAt: 4,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
@@ -176,8 +186,9 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
|
UpdateAt: 3,
|
||||||
DeleteAt: 0,
|
DeleteAt: 0,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
@@ -190,8 +201,9 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "",
|
Description: "",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
UpdateAt: 2,
|
CreateAt: 2,
|
||||||
|
UpdateAt: 3,
|
||||||
DeleteAt: 0,
|
DeleteAt: 0,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
@@ -204,9 +216,10 @@ func TestBotIsValid(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
@@ -230,6 +243,7 @@ func TestBotPreSave(t *testing.T) {
|
|||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
|
LastIconUpdate: 0,
|
||||||
DeleteAt: 0,
|
DeleteAt: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +265,8 @@ func TestBotPreUpdate(t *testing.T) {
|
|||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
|
CreateAt: 2,
|
||||||
DeleteAt: 0,
|
DeleteAt: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,9 +287,10 @@ func TestBotEtag(t *testing.T) {
|
|||||||
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
|
||||||
|
|
||||||
@@ -288,9 +304,10 @@ func TestBotEtag(t *testing.T) {
|
|||||||
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(),
|
||||||
@@ -298,9 +315,10 @@ func TestBotEtag(t *testing.T) {
|
|||||||
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())
|
||||||
@@ -312,9 +330,10 @@ func TestBotEtag(t *testing.T) {
|
|||||||
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,
|
||||||
@@ -322,9 +341,10 @@ func TestBotEtag(t *testing.T) {
|
|||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: bot1.OwnerId,
|
OwnerId: bot1.OwnerId,
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
|
CreateAt: 2,
|
||||||
UpdateAt: 10,
|
UpdateAt: 10,
|
||||||
DeleteAt: 3,
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NotEqual(t, bot1.Etag(), bot2.Etag())
|
assert.NotEqual(t, bot1.Etag(), bot2.Etag())
|
||||||
@@ -339,9 +359,10 @@ func TestBotToAndFromJson(t *testing.T) {
|
|||||||
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{
|
||||||
@@ -350,9 +371,10 @@ func TestBotToAndFromJson(t *testing.T) {
|
|||||||
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())))
|
||||||
@@ -381,9 +403,10 @@ func TestBotPatch(t *testing.T) {
|
|||||||
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{
|
||||||
@@ -392,9 +415,10 @@ func TestBotPatch(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -405,9 +429,10 @@ func TestBotPatch(t *testing.T) {
|
|||||||
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"),
|
||||||
@@ -420,9 +445,10 @@ func TestBotPatch(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -433,9 +459,10 @@ func TestBotPatch(t *testing.T) {
|
|||||||
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"),
|
||||||
@@ -448,9 +475,10 @@ func TestBotPatch(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -487,9 +515,10 @@ func TestUserFromBot(t *testing.T) {
|
|||||||
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{
|
||||||
@@ -498,9 +527,10 @@ func TestUserFromBot(t *testing.T) {
|
|||||||
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{
|
||||||
@@ -554,9 +584,10 @@ func TestBotListToAndFromJson(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -569,9 +600,10 @@ func TestBotListToAndFromJson(t *testing.T) {
|
|||||||
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{
|
||||||
@@ -580,9 +612,10 @@ func TestBotListToAndFromJson(t *testing.T) {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -602,9 +635,10 @@ func TestBotListEtag(t *testing.T) {
|
|||||||
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{
|
||||||
@@ -613,9 +647,10 @@ func TestBotListEtag(t *testing.T) {
|
|||||||
DisplayName: "display name",
|
DisplayName: "display name",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OwnerId: NewId(),
|
OwnerId: NewId(),
|
||||||
CreateAt: 1,
|
LastIconUpdate: 1,
|
||||||
|
CreateAt: 2,
|
||||||
UpdateAt: 10,
|
UpdateAt: 10,
|
||||||
DeleteAt: 3,
|
DeleteAt: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
bot2 := &Bot{
|
bot2 := &Bot{
|
||||||
@@ -624,9 +659,10 @@ func TestBotListEtag(t *testing.T) {
|
|||||||
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
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ 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"`
|
||||||
|
LastIconUpdate int64 `json:"last_icon_update"`
|
||||||
CreateAt int64 `json:"create_at"`
|
CreateAt int64 `json:"create_at"`
|
||||||
UpdateAt int64 `json:"update_at"`
|
UpdateAt int64 `json:"update_at"`
|
||||||
DeleteAt int64 `json:"delete_at"`
|
DeleteAt int64 `json:"delete_at"`
|
||||||
@@ -28,6 +29,7 @@ func botFromModel(b *model.Bot) *bot {
|
|||||||
UserId: b.UserId,
|
UserId: b.UserId,
|
||||||
Description: b.Description,
|
Description: b.Description,
|
||||||
OwnerId: b.OwnerId,
|
OwnerId: b.OwnerId,
|
||||||
|
LastIconUpdate: b.LastIconUpdate,
|
||||||
CreateAt: b.CreateAt,
|
CreateAt: b.CreateAt,
|
||||||
UpdateAt: b.UpdateAt,
|
UpdateAt: b.UpdateAt,
|
||||||
DeleteAt: b.DeleteAt,
|
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