Feature edit attachments (#29769)
* Updated patch/update post API to allow file modification (#29447) * WIP * WIP * Atatched new files ton post * WIP: deleting removed files * Deleted removed files and invalidated file metadata cache * removed file ignore logif from update post API * Added TestFindExclusives * Added tests for DeleteForPostByIds * Added app layer tests * Added tests * Added API level tests * test enhancements * Fixed a test * Edit history include file metadata (#29505) * Send file metadata in edit history metadata * Added app tests * Added store tests * Added tests for populateEditHistoryFileMetadata{ * Added cache to avoid repetitigve DB calls for edits with only message changes * Added API tests * i18m fix * removed commented code * Improved test helper * Show attachments in edit history RHS (#29519) * Send file metadata in edit history metadata * Added app tests * Added store tests * Added tests for populateEditHistoryFileMetadata{ * Added cache to avoid repetitigve DB calls for edits with only message changes * Added API tests * i18m fix * WIUP: displa files in edit * removed commented code * Displayed file in edit history * Handled file icon * Fixed closing history component on clicking on file * Simplified selector * Simplified selector * Improved test helper * Disabled action menu on edit history file * Added tests * Improved selector * Updated snapshot * review Fixes * restructured componnets * Updated test * Updated test * Restore post api (#29643) * Restore post version API WIP * Undelete files WIP * Added store tests * Created post restore API * Updated updatepost safeUpdate signature * review fixex and improvements * Fixed an app test * Added API laer tests * Added API tests and OpenAPI specs * Fixed a typo * Allow editing files when editing posts (#29709) * WIP - basic view files when editing post * Cleanup * bg color * Added text editor tests for files * WIP * WIP * removed debug log * Allowed admin to add and remove files on someone else's post * Handled drafts and scheduled posts * linter fixes * Updated snapshot * server test fix * CI * Added doc * Restore post api integration (#29719) * WIP - basic view files when editing post * Cleanup * bg color * Added text editor tests for files * WIP * WIP * removed debug log * Allowed admin to add and remove files on someone else's post * Handled drafts and scheduled posts * linter fixes * Updated snapshot * server test fix * Used new API to restore post * handled edut limit and undo * lint fix * added comments * Fixed edit post item tests * Fixed buttons * Aded snapshots * fix test * Updated snapshot * Minor fixes * fixed snapshot * Edit file dnd area (#29763) * dnd wip * DND continued * Supported multiple unbind dragster funcs * lint fixes * Got center channel file drop working when editing a post * file dnd working with center channel and rhs * file dnd working with center channel and rhs * removed unneeded stopPropogation calls * cleanup * DND overlay fix * Lint fix * Advanced text editor test updates for file upload overlay * fixed use upload hook tests * Updated some more snapshots * minor cleanup * Updated i18n * removed need of array for dragster unbind events * lint fixes * edit history cursor * Fixed bugu causing faliure to delete empty posts (#29778) * Files in restore confirmation (#29781) * Added files to restore post confirmation dialog * Fixed post restore toast colors * Fixed restore bug * Fixed restore confirmation toast tests * a11y improvement and modal width fix * Edit attachment misc fixes (#29808) * Removed single image actions in restore post confirmation dialog * Fixed file drop overlay size and position * Made edit indiator accessible * Lint fix * Added bunch of more tests * ANother test migrated from enzyme to react testing library * More test enhancements * More test enhancements * More test enhancements * lint fixes * Fixed a test * Added missing snapshots * Test fixes
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ecdce71fc4
Коммит
6e5a67caec
@@ -458,16 +458,7 @@ func (a *App) addPostPreviewProp(rctx request.CTX, post *model.Post) (*model.Pos
|
||||
}
|
||||
|
||||
func (a *App) attachFilesToPost(rctx request.CTX, post *model.Post) *model.AppError {
|
||||
var attachedIds []string
|
||||
for _, fileID := range post.FileIds {
|
||||
err := a.Srv().Store().FileInfo().AttachToPost(rctx, fileID, post.Id, post.ChannelId, post.UserId)
|
||||
if err != nil {
|
||||
rctx.Logger().Warn("Failed to attach file to post", mlog.String("file_id", fileID), mlog.String("post_id", post.Id), mlog.Err(err))
|
||||
continue
|
||||
}
|
||||
|
||||
attachedIds = append(attachedIds, fileID)
|
||||
}
|
||||
attachedIds := a.attachFileIDsToPost(rctx, post.Id, post.ChannelId, post.UserId, post.FileIds)
|
||||
|
||||
if len(post.FileIds) != len(attachedIds) {
|
||||
// We couldn't attach all files to the post, so ensure that post.FileIds reflects what was actually attached
|
||||
@@ -481,6 +472,20 @@ func (a *App) attachFilesToPost(rctx request.CTX, post *model.Post) *model.AppEr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) attachFileIDsToPost(rctx request.CTX, postID, channelID, userID string, fileIDs []string) []string {
|
||||
var attachedIds []string
|
||||
for _, fileID := range fileIDs {
|
||||
err := a.Srv().Store().FileInfo().AttachToPost(rctx, fileID, postID, channelID, userID)
|
||||
if err != nil {
|
||||
rctx.Logger().Warn("Failed to attach file to post", mlog.String("file_id", fileID), mlog.String("post_id", postID), mlog.Err(err))
|
||||
continue
|
||||
}
|
||||
|
||||
attachedIds = append(attachedIds, fileID)
|
||||
}
|
||||
return attachedIds
|
||||
}
|
||||
|
||||
// FillInPostProps should be invoked before saving posts to fill in properties such as
|
||||
// channel_mentions.
|
||||
//
|
||||
@@ -674,7 +679,11 @@ func (a *App) DeleteEphemeralPost(rctx request.CTX, userID, postID string) {
|
||||
a.Publish(message)
|
||||
}
|
||||
|
||||
func (a *App) UpdatePost(c request.CTX, receivedUpdatedPost *model.Post, safeUpdate bool) (*model.Post, *model.AppError) {
|
||||
func (a *App) UpdatePost(c request.CTX, receivedUpdatedPost *model.Post, updatePostOptions *model.UpdatePostOptions) (*model.Post, *model.AppError) {
|
||||
if updatePostOptions == nil {
|
||||
updatePostOptions = model.DefaultUpdatePostOptions()
|
||||
}
|
||||
|
||||
receivedUpdatedPost.SanitizeProps()
|
||||
|
||||
postLists, nErr := a.Srv().Store().Post().Get(context.Background(), receivedUpdatedPost.Id, model.GetPostsOptions{}, "", a.Config().GetSanitizeOptions())
|
||||
@@ -725,11 +734,17 @@ func (a *App) UpdatePost(c request.CTX, receivedUpdatedPost *model.Post, safeUpd
|
||||
newPost.Hashtags, _ = model.ParseHashtags(receivedUpdatedPost.Message)
|
||||
}
|
||||
|
||||
if !safeUpdate {
|
||||
if !updatePostOptions.SafeUpdate {
|
||||
newPost.IsPinned = receivedUpdatedPost.IsPinned
|
||||
newPost.HasReactions = receivedUpdatedPost.HasReactions
|
||||
newPost.FileIds = receivedUpdatedPost.FileIds
|
||||
newPost.SetProps(receivedUpdatedPost.GetProps())
|
||||
|
||||
var fileIds []string
|
||||
fileIds, appErr = a.processPostFileChanges(c, receivedUpdatedPost, oldPost, updatePostOptions)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
newPost.FileIds = fileIds
|
||||
}
|
||||
|
||||
// Avoid deep-equal checks if EditAt was already modified through message change
|
||||
@@ -928,7 +943,11 @@ func (a *App) setupBroadcastHookForPermalink(rctx request.CTX, post *model.Post,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) PatchPost(c request.CTX, postID string, patch *model.PostPatch) (*model.Post, *model.AppError) {
|
||||
func (a *App) PatchPost(c request.CTX, postID string, patch *model.PostPatch, patchPostOptions *model.UpdatePostOptions) (*model.Post, *model.AppError) {
|
||||
if patchPostOptions == nil {
|
||||
patchPostOptions = model.DefaultUpdatePostOptions()
|
||||
}
|
||||
|
||||
post, err := a.GetSinglePost(c, postID, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -950,7 +969,8 @@ func (a *App) PatchPost(c request.CTX, postID string, patch *model.PostPatch) (*
|
||||
|
||||
post.Patch(patch)
|
||||
|
||||
updatedPost, err := a.UpdatePost(c, post, false)
|
||||
patchPostOptions.SafeUpdate = false
|
||||
updatedPost, err := a.UpdatePost(c, post, patchPostOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -2144,9 +2164,30 @@ func (a *App) GetEditHistoryForPost(postID string) ([]*model.Post, *model.AppErr
|
||||
}
|
||||
}
|
||||
|
||||
if appErr := a.populateEditHistoryFileMetadata(posts); appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
func (a *App) populateEditHistoryFileMetadata(editHistoryPosts []*model.Post) *model.AppError {
|
||||
for _, post := range editHistoryPosts {
|
||||
fileInfos, err := a.Srv().Store().FileInfo().GetByIds(post.FileIds, true, true)
|
||||
if err != nil {
|
||||
return model.NewAppError("app.populateEditHistoryFileMetadata", "app.file_info.get_by_ids.app_error", map[string]any{"post_id": post.Id}, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
if post.Metadata == nil {
|
||||
post.Metadata = &model.PostMetadata{}
|
||||
}
|
||||
|
||||
post.Metadata.Files = fileInfos
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) SetPostReminder(rctx request.CTX, postID, userID string, targetTime int64) *model.AppError {
|
||||
// Store the reminder in the DB
|
||||
reminder := &model.PostReminder{
|
||||
|
||||
Ссылка в новой задаче
Block a user