2024-11-04 01:09:35 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
|
|
|
|
|
package api4
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
|
|
|
"github.com/mattermost/mattermost/server/v8/channels/app"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func userCreatePostPermissionCheckWithContext(c *Context, channelId string) {
|
|
|
|
|
hasPermission := false
|
2026-01-20 04:38:27 -05:00
|
|
|
if ok, _ := c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelId, model.PermissionCreatePost); ok {
|
2024-11-04 01:09:35 -05:00
|
|
|
hasPermission = true
|
|
|
|
|
} else if channel, err := c.App.GetChannel(c.AppContext, channelId); err == nil {
|
|
|
|
|
// Temporary permission check method until advanced permissions, please do not copy
|
|
|
|
|
if channel.Type == model.ChannelTypeOpen && c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), channel.TeamId, model.PermissionCreatePostPublic) {
|
|
|
|
|
hasPermission = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !hasPermission {
|
|
|
|
|
c.SetPermissionError(model.PermissionCreatePost)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func postHardenedModeCheckWithContext(where string, c *Context, props model.StringInterface) {
|
|
|
|
|
isIntegration := c.AppContext.Session().IsIntegration()
|
|
|
|
|
|
|
|
|
|
if appErr := app.PostHardenedModeCheckWithApp(c.App, isIntegration, props); appErr != nil {
|
|
|
|
|
appErr.Where = where
|
|
|
|
|
c.Err = appErr
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func postPriorityCheckWithContext(where string, c *Context, priority *model.PostPriority, rootId string) {
|
|
|
|
|
appErr := app.PostPriorityCheckWithApp(where, c.App, c.AppContext.Session().UserId, priority, rootId)
|
|
|
|
|
if appErr != nil {
|
|
|
|
|
appErr.Where = where
|
|
|
|
|
c.Err = appErr
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-07 09:40:05 -05:00
|
|
|
|
2026-03-27 11:51:29 -04:00
|
|
|
func postCardTypeCheckWithContext(where string, c *Context, postType string) {
|
|
|
|
|
if appErr := app.PostCardTypeCheckWithApp(where, c.App, postType); appErr != nil {
|
|
|
|
|
appErr.Where = where
|
|
|
|
|
c.Err = appErr
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-12 14:10:05 -05:00
|
|
|
func postBurnOnReadCheckWithContext(where string, c *Context, post *model.Post, channel *model.Channel) {
|
|
|
|
|
appErr := app.PostBurnOnReadCheckWithApp(where, c.App, c.AppContext, post.UserId, post.ChannelId, post.Type, channel)
|
|
|
|
|
if appErr != nil {
|
|
|
|
|
appErr.Where = where
|
|
|
|
|
c.Err = appErr
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-07 09:40:05 -05:00
|
|
|
// checkUploadFilePermissionForNewFiles checks upload_file permission only when
|
|
|
|
|
// adding new files to a post, preventing permission bypass via cross-channel file attachments.
|
|
|
|
|
func checkUploadFilePermissionForNewFiles(c *Context, newFileIds []string, originalPost *model.Post) {
|
|
|
|
|
if len(newFileIds) == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
originalFileIDsMap := make(map[string]bool, len(originalPost.FileIds))
|
|
|
|
|
for _, fileID := range originalPost.FileIds {
|
|
|
|
|
originalFileIDsMap[fileID] = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hasNewFiles := false
|
|
|
|
|
for _, fileID := range newFileIds {
|
|
|
|
|
if !originalFileIDsMap[fileID] {
|
|
|
|
|
hasNewFiles = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if hasNewFiles {
|
2026-01-20 04:38:27 -05:00
|
|
|
if ok, _ := c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), originalPost.ChannelId, model.PermissionUploadFile); !ok {
|
2026-01-07 09:40:05 -05:00
|
|
|
c.SetPermissionError(model.PermissionUploadFile)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|