Adding SetFileSearchableContent plugin API endpoint (#24355)
* Adding SetFileSearchableContent plugin API endpoint * Fixing CI problems * Fixing CI problems * Fixing CI problems * Fixing CI problems * Fixing CI problems * Exposing it to the public API * Fix CI problems * Adding SetSearchableContent to the pluginapi File struct
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fd74208af1
Коммит
c9d49536f8
@@ -1069,6 +1069,7 @@ type AppIface interface {
|
||||
SetChannels(ch *Channels)
|
||||
SetCustomStatus(c request.CTX, userID string, cs *model.CustomStatus) *model.AppError
|
||||
SetDefaultProfileImage(c request.CTX, user *model.User) *model.AppError
|
||||
SetFileSearchableContent(fileID string, data string) *model.AppError
|
||||
SetPhase2PermissionsMigrationStatus(isComplete bool) error
|
||||
SetPluginKey(pluginID string, key string, value []byte) *model.AppError
|
||||
SetPluginKeyWithExpiry(pluginID string, key string, value []byte, expireInSeconds int64) *model.AppError
|
||||
|
||||
@@ -1224,6 +1224,26 @@ func (a *App) GetFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
||||
return fileInfo, appErr
|
||||
}
|
||||
|
||||
func (a *App) SetFileSearchableContent(fileID string, data string) *model.AppError {
|
||||
fileInfo, appErr := a.Srv().getFileInfo(fileID)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
err := a.Srv().Store().FileInfo().SetContent(fileInfo.Id, data)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return model.NewAppError("SetFileSearchableContent", "app.file_info.set_searchable_content.app_error", nil, "", http.StatusNotFound).Wrap(err)
|
||||
default:
|
||||
return model.NewAppError("SetFileSearchableContent", "app.file_info.set_searchable_content.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) getFileInfoIgnoreCloudLimit(fileID string) (*model.FileInfo, *model.AppError) {
|
||||
fileInfo, appErr := a.Srv().getFileInfo(fileID)
|
||||
if appErr == nil {
|
||||
|
||||
@@ -650,3 +650,30 @@ func TestComputeLastAccessibleFileTime(t *testing.T) {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestSetFileSearchableContent(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
fileInfo, err := th.App.Srv().Store().FileInfo().Save(&model.FileInfo{
|
||||
CreatorId: th.BasicUser.Id,
|
||||
PostId: th.BasicPost.Id,
|
||||
ChannelId: th.BasicPost.ChannelId,
|
||||
Name: "test",
|
||||
Path: "test",
|
||||
Extension: "jpg",
|
||||
MimeType: "image/jpeg",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
result, appErr := th.App.SearchFilesInTeamForUser(th.Context, "searchable", th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, 0, 60)
|
||||
require.Nil(t, appErr)
|
||||
assert.Equal(t, 0, len(result.Order))
|
||||
|
||||
appErr = th.App.SetFileSearchableContent(fileInfo.Id, "searchable")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
result, appErr = th.App.SearchFilesInTeamForUser(th.Context, "searchable", th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, 0, 60)
|
||||
require.Nil(t, appErr)
|
||||
assert.Equal(t, 1, len(result.Order))
|
||||
}
|
||||
|
||||
@@ -16138,6 +16138,28 @@ func (a *OpenTracingAppLayer) SetDefaultProfileImage(c request.CTX, user *model.
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SetFileSearchableContent(fileID string, data string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetFileSearchableContent")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store().SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store().SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.SetFileSearchableContent(fileID, data)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SetPhase2PermissionsMigrationStatus(isComplete bool) error {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetPhase2PermissionsMigrationStatus")
|
||||
|
||||
@@ -766,6 +766,10 @@ func (api *PluginAPI) GetFileInfo(fileID string) (*model.FileInfo, *model.AppErr
|
||||
return api.app.GetFileInfo(fileID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) SetFileSearchableContent(fileID string, content string) *model.AppError {
|
||||
return api.app.SetFileSearchableContent(fileID, content)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
||||
return api.app.GetFileInfos(page, perPage, opt)
|
||||
}
|
||||
|
||||
@@ -356,16 +356,6 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
|
||||
// might be duplicating requests.
|
||||
a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, rpost.Id, PendingPostIDsCacheTTL)
|
||||
|
||||
// We make a copy of the post for the plugin hook to avoid a race condition,
|
||||
// and to remove the non-GOB-encodable Metadata from it.
|
||||
pluginPost := rpost.ForPlugin()
|
||||
a.Srv().Go(func() {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.MessageHasBeenPosted(pluginContext, pluginPost)
|
||||
return true
|
||||
}, plugin.MessageHasBeenPostedID)
|
||||
})
|
||||
|
||||
if a.Metrics() != nil {
|
||||
a.Metrics().IncrementPostCreate()
|
||||
}
|
||||
@@ -380,6 +370,16 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
|
||||
}
|
||||
}
|
||||
|
||||
// We make a copy of the post for the plugin hook to avoid a race condition,
|
||||
// and to remove the non-GOB-encodable Metadata from it.
|
||||
pluginPost := rpost.ForPlugin()
|
||||
a.Srv().Go(func() {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.MessageHasBeenPosted(pluginContext, pluginPost)
|
||||
return true
|
||||
}, plugin.MessageHasBeenPostedID)
|
||||
})
|
||||
|
||||
// Normally, we would let the API layer call PreparePostForClient, but we do it here since it also needs
|
||||
// to be done when we send the post over the websocket in handlePostEvents
|
||||
// PS: we don't want to include PostPriority from the db to avoid the replica lag,
|
||||
|
||||
Ссылка в новой задаче
Block a user