mattermost-community-enterp.../channels/app/post_restore.go
Claude ec1f89217a Merge: Complete Mattermost Server with Community Enterprise
Full Mattermost server source with integrated Community Enterprise features.
Includes vendor directory for offline/air-gapped builds.

Structure:
- enterprise-impl/: Enterprise feature implementations
- enterprise-community/: Init files that register implementations
- enterprise/: Bridge imports (community_imports.go)
- vendor/: All dependencies for offline builds

Build (online):
  go build ./cmd/mattermost

Build (offline/air-gapped):
  go build -mod=vendor ./cmd/mattermost

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 23:59:07 +09:00

59 lines
2.0 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"net/http"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/pkg/errors"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
)
func (a *App) RestorePostVersion(rctx request.CTX, userID, postID, restoreVersionID string) (*model.Post, *model.AppError) {
toRestorePostVersion, err := a.Srv().Store().Post().GetSingle(rctx, restoreVersionID, true)
if err != nil {
var statusCode int
var notFoundErr *store.ErrNotFound
switch {
case errors.As(err, &notFoundErr):
statusCode = http.StatusNotFound
default:
statusCode = http.StatusInternalServerError
}
return nil, model.NewAppError("RestorePostVersion", "app.post.restore_post_version.get_single.app_error", nil, err.Error(), statusCode)
}
// restoreVersionID needs to be an old version of postID
// this is only a safeguard and this should never happen in practice.
if toRestorePostVersion.OriginalId != postID {
return nil, model.NewAppError("RestorePostVersion", "app.post.restore_post_version.not_an_history_item.app_error", nil, "", http.StatusBadRequest)
}
// the user needs to be the author of the post
// this is only a safeguard and this should never happen in practice.
if toRestorePostVersion.UserId != userID {
return nil, model.NewAppError("RestorePostVersion", "app.post.restore_post_version.not_allowed.app_error", nil, "", http.StatusForbidden)
}
// the old version of post needs to be a deleted post
if toRestorePostVersion.DeleteAt == 0 {
return nil, model.NewAppError("RestorePostVersion", "app.post.restore_post_version.not_valid_post_history_item.app_error", nil, "", http.StatusBadRequest)
}
postPatch := &model.PostPatch{
Message: &toRestorePostVersion.Message,
FileIds: &toRestorePostVersion.FileIds,
}
patchPostOptions := &model.UpdatePostOptions{
IsRestorePost: true,
}
return a.PatchPost(rctx, postID, postPatch, patchPostOptions)
}