Manual Cherrypick: Add audits for accessing posts without membership (#31266) (#35022)

Automatic Merge
Этот коммит содержится в:
Daniel Espino García
2026-01-26 11:23:28 +01:00
коммит произвёл GitHub
родитель 12dce033d6
Коммит 21a86506f9
79 изменённых файлов: 1707 добавлений и 1001 удалений

Просмотреть файл

@@ -13,7 +13,7 @@ import (
"github.com/mattermost/mattermost/server/public/shared/request"
)
func (a *App) RestorePostVersion(c request.CTX, userID, postID, restoreVersionID string) (*model.Post, *model.AppError) {
func (a *App) RestorePostVersion(c request.CTX, userID, postID, restoreVersionID string) (*model.Post, bool, *model.AppError) {
toRestorePostVersion, err := a.Srv().Store().Post().GetSingle(c, restoreVersionID, true)
if err != nil {
var statusCode int
@@ -25,24 +25,24 @@ func (a *App) RestorePostVersion(c request.CTX, userID, postID, restoreVersionID
statusCode = http.StatusInternalServerError
}
return nil, model.NewAppError("RestorePostVersion", "app.post.restore_post_version.get_single.app_error", nil, err.Error(), statusCode)
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, model.NewAppError("RestorePostVersion", "app.post.restore_post_version.not_an_history_item.app_error", nil, "", http.StatusBadRequest)
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, model.NewAppError("RestorePostVersion", "app.post.restore_post_version.not_allowed.app_error", nil, "", http.StatusForbidden)
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, model.NewAppError("RestorePostVersion", "app.post.restore_post_version.not_valid_post_history_item.app_error", nil, "", http.StatusBadRequest)
return nil, false, model.NewAppError("RestorePostVersion", "app.post.restore_post_version.not_valid_post_history_item.app_error", nil, "", http.StatusBadRequest)
}
postPatch := &model.PostPatch{