2020-08-09 15:29:54 -07:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
2016-05-21 05:14:08 -07:00
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2017-08-16 14:37:37 -07:00
|
|
|
"regexp"
|
2016-05-21 05:14:08 -07:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CompliancePost struct {
|
|
|
|
|
|
|
|
// From Team
|
|
|
|
TeamName string
|
|
|
|
TeamDisplayName string
|
|
|
|
|
|
|
|
// From Channel
|
|
|
|
ChannelName string
|
|
|
|
ChannelDisplayName string
|
2018-11-18 09:55:05 -08:00
|
|
|
ChannelType string
|
2016-05-21 05:14:08 -07:00
|
|
|
|
|
|
|
// From User
|
|
|
|
UserUsername string
|
|
|
|
UserEmail string
|
|
|
|
UserNickname string
|
|
|
|
|
|
|
|
// From Post
|
|
|
|
PostId string
|
|
|
|
PostCreateAt int64
|
|
|
|
PostUpdateAt int64
|
|
|
|
PostDeleteAt int64
|
|
|
|
PostRootId string
|
|
|
|
PostParentId string
|
|
|
|
PostOriginalId string
|
|
|
|
PostMessage string
|
|
|
|
PostType string
|
|
|
|
PostProps string
|
|
|
|
PostHashtags string
|
2016-11-12 13:00:53 -08:00
|
|
|
PostFileIds string
|
2020-08-09 15:29:54 -07:00
|
|
|
|
|
|
|
IsBot bool
|
2016-05-21 05:14:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func CompliancePostHeader() []string {
|
|
|
|
return []string{
|
|
|
|
"TeamName",
|
|
|
|
"TeamDisplayName",
|
|
|
|
|
|
|
|
"ChannelName",
|
|
|
|
"ChannelDisplayName",
|
2018-11-18 09:55:05 -08:00
|
|
|
"ChannelType",
|
2016-05-21 05:14:08 -07:00
|
|
|
|
|
|
|
"UserUsername",
|
|
|
|
"UserEmail",
|
|
|
|
"UserNickname",
|
2021-10-16 15:47:22 -07:00
|
|
|
"UserType",
|
2016-05-21 05:14:08 -07:00
|
|
|
|
|
|
|
"PostId",
|
|
|
|
"PostCreateAt",
|
|
|
|
"PostUpdateAt",
|
|
|
|
"PostDeleteAt",
|
|
|
|
"PostRootId",
|
|
|
|
"PostParentId",
|
|
|
|
"PostOriginalId",
|
|
|
|
"PostMessage",
|
|
|
|
"PostType",
|
|
|
|
"PostProps",
|
|
|
|
"PostHashtags",
|
2016-11-12 13:00:53 -08:00
|
|
|
"PostFileIds",
|
2016-05-21 05:14:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 14:37:37 -07:00
|
|
|
func cleanComplianceStrings(in string) string {
|
|
|
|
if matched, _ := regexp.MatchString("^\\s*(=|\\+|\\-)", in); matched {
|
|
|
|
return "'" + in
|
|
|
|
}
|
2021-10-16 15:47:22 -07:00
|
|
|
return in
|
2017-08-16 14:37:37 -07:00
|
|
|
}
|
|
|
|
|
2021-10-16 15:47:22 -07:00
|
|
|
func (cp *CompliancePost) Row() []string {
|
2016-05-21 05:14:08 -07:00
|
|
|
|
|
|
|
postDeleteAt := ""
|
2021-10-16 15:47:22 -07:00
|
|
|
if cp.PostDeleteAt > 0 {
|
|
|
|
postDeleteAt = time.Unix(0, cp.PostDeleteAt*int64(1000*1000)).Format(time.RFC3339)
|
2016-05-21 05:14:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
postUpdateAt := ""
|
2021-10-16 15:47:22 -07:00
|
|
|
if cp.PostUpdateAt != cp.PostCreateAt {
|
|
|
|
postUpdateAt = time.Unix(0, cp.PostUpdateAt*int64(1000*1000)).Format(time.RFC3339)
|
2016-05-21 05:14:08 -07:00
|
|
|
}
|
|
|
|
|
2020-08-09 15:29:54 -07:00
|
|
|
userType := "user"
|
2021-10-16 15:47:22 -07:00
|
|
|
if cp.IsBot {
|
2020-08-09 15:29:54 -07:00
|
|
|
userType = "bot"
|
|
|
|
}
|
|
|
|
|
2016-05-21 05:14:08 -07:00
|
|
|
return []string{
|
2021-10-16 15:47:22 -07:00
|
|
|
cleanComplianceStrings(cp.TeamName),
|
|
|
|
cleanComplianceStrings(cp.TeamDisplayName),
|
2016-05-21 05:14:08 -07:00
|
|
|
|
2021-10-16 15:47:22 -07:00
|
|
|
cleanComplianceStrings(cp.ChannelName),
|
|
|
|
cleanComplianceStrings(cp.ChannelDisplayName),
|
|
|
|
cleanComplianceStrings(cp.ChannelType),
|
2016-05-21 05:14:08 -07:00
|
|
|
|
2021-10-16 15:47:22 -07:00
|
|
|
cleanComplianceStrings(cp.UserUsername),
|
|
|
|
cleanComplianceStrings(cp.UserEmail),
|
|
|
|
cleanComplianceStrings(cp.UserNickname),
|
2020-08-09 15:29:54 -07:00
|
|
|
userType,
|
2016-05-21 05:14:08 -07:00
|
|
|
|
2021-10-16 15:47:22 -07:00
|
|
|
cp.PostId,
|
|
|
|
time.Unix(0, cp.PostCreateAt*int64(1000*1000)).Format(time.RFC3339),
|
2016-05-21 05:14:08 -07:00
|
|
|
postUpdateAt,
|
|
|
|
postDeleteAt,
|
|
|
|
|
2021-10-16 15:47:22 -07:00
|
|
|
cp.PostRootId,
|
|
|
|
cp.PostParentId,
|
|
|
|
cp.PostOriginalId,
|
|
|
|
cleanComplianceStrings(cp.PostMessage),
|
|
|
|
cp.PostType,
|
|
|
|
cp.PostProps,
|
|
|
|
cp.PostHashtags,
|
|
|
|
cp.PostFileIds,
|
2016-05-21 05:14:08 -07:00
|
|
|
}
|
|
|
|
}
|