This repository has been archived on 2024-11-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
mattermost-plugin-attachmen.../server/permissions.go
Felipe Martin 2d962d18d2
Some checks failed
ci / plugin-ci (push) Has been cancelled
added command with interactive dialog
2024-08-08 18:06:32 +02:00

37 lines
1.3 KiB
Go

package main
import "github.com/mattermost/mattermost/server/public/model"
// userHasRemovePermissionsToPost checks if the user has permissions to remove attachments from a post
// based on the post ID, the user ID, and the channel ID.
// Returns an error message if the user does not have permissions, or an empty string if the user has permissions.
func (p *Plugin) userHasRemovePermissionsToPost(userID, channelID, postID string) string {
// Check if the post exists
post, appErr := p.API.GetPost(postID)
if appErr != nil {
return "Post does not exist"
}
// Check if the post has attachments
if len(post.FileIds) == 0 {
return "Post has no attachments"
}
// Check if the user is the post author or has permissions to edit others posts
user, appErr := p.API.GetUser(userID)
if appErr != nil {
return "Internal error, check with your system administrator for assistance"
}
if post.UserId != user.Id && !p.API.HasPermissionToChannel(userID, channelID, model.PermissionEditOthersPosts) {
return "Not authorized"
}
// Check if the post is editable at this point in time
config := p.API.GetConfig()
if config.ServiceSettings.PostEditTimeLimit != nil && *config.ServiceSettings.PostEditTimeLimit > 0 && model.GetMillis() > post.CreateAt+int64(*config.ServiceSettings.PostEditTimeLimit*1000) {
return "Post is too old to edit"
}
return ""
}