mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* Add audits for accessing posts without membership * Fix tests * Use correct audit level * Address feedback * Add missing checks all over the app * Fix lint * Fix test * Fix tests * Fix enterprise test * Add missing test and docs * Fix merge * Fix lint * Add audit logs on the web socket hook for permalink posts * Fix lint * Fix merge conflicts * Handle all events with "non_channel_member_access" parameter * Fix lint and tests * Fix merge * Fix tests
59 lines
2.1 KiB
Go
59 lines
2.1 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, bool, *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, ¬FoundErr):
|
|
statusCode = http.StatusNotFound
|
|
default:
|
|
statusCode = http.StatusInternalServerError
|
|
}
|
|
|
|
return nil, false, 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, false, 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, false, 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, false, 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)
|
|
}
|