github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/model/compliance_post.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"regexp"
     8  	"time"
     9  )
    10  
    11  type CompliancePost struct {
    12  
    13  	// From Team
    14  	TeamName        string
    15  	TeamDisplayName string
    16  
    17  	// From Channel
    18  	ChannelName        string
    19  	ChannelDisplayName string
    20  	ChannelType        string
    21  
    22  	// From User
    23  	UserUsername string
    24  	UserEmail    string
    25  	UserNickname string
    26  
    27  	// From Post
    28  	PostId         string
    29  	PostCreateAt   int64
    30  	PostUpdateAt   int64
    31  	PostDeleteAt   int64
    32  	PostRootId     string
    33  	PostParentId   string
    34  	PostOriginalId string
    35  	PostMessage    string
    36  	PostType       string
    37  	PostProps      string
    38  	PostHashtags   string
    39  	PostFileIds    string
    40  
    41  	IsBot bool
    42  }
    43  
    44  func CompliancePostHeader() []string {
    45  	return []string{
    46  		"TeamName",
    47  		"TeamDisplayName",
    48  
    49  		"ChannelName",
    50  		"ChannelDisplayName",
    51  		"ChannelType",
    52  
    53  		"UserUsername",
    54  		"UserEmail",
    55  		"UserNickname",
    56  
    57  		"PostId",
    58  		"PostCreateAt",
    59  		"PostUpdateAt",
    60  		"PostDeleteAt",
    61  		"PostRootId",
    62  		"PostParentId",
    63  		"PostOriginalId",
    64  		"PostMessage",
    65  		"PostType",
    66  		"PostProps",
    67  		"PostHashtags",
    68  		"PostFileIds",
    69  		"UserType",
    70  	}
    71  }
    72  
    73  func cleanComplianceStrings(in string) string {
    74  	if matched, _ := regexp.MatchString("^\\s*(=|\\+|\\-)", in); matched {
    75  		return "'" + in
    76  
    77  	} else {
    78  		return in
    79  	}
    80  }
    81  
    82  func (me *CompliancePost) Row() []string {
    83  
    84  	postDeleteAt := ""
    85  	if me.PostDeleteAt > 0 {
    86  		postDeleteAt = time.Unix(0, me.PostDeleteAt*int64(1000*1000)).Format(time.RFC3339)
    87  	}
    88  
    89  	postUpdateAt := ""
    90  	if me.PostUpdateAt != me.PostCreateAt {
    91  		postUpdateAt = time.Unix(0, me.PostUpdateAt*int64(1000*1000)).Format(time.RFC3339)
    92  	}
    93  
    94  	userType := "user"
    95  	if me.IsBot {
    96  		userType = "bot"
    97  	}
    98  
    99  	return []string{
   100  		cleanComplianceStrings(me.TeamName),
   101  		cleanComplianceStrings(me.TeamDisplayName),
   102  
   103  		cleanComplianceStrings(me.ChannelName),
   104  		cleanComplianceStrings(me.ChannelDisplayName),
   105  		cleanComplianceStrings(me.ChannelType),
   106  
   107  		cleanComplianceStrings(me.UserUsername),
   108  		cleanComplianceStrings(me.UserEmail),
   109  		cleanComplianceStrings(me.UserNickname),
   110  		userType,
   111  
   112  		me.PostId,
   113  		time.Unix(0, me.PostCreateAt*int64(1000*1000)).Format(time.RFC3339),
   114  		postUpdateAt,
   115  		postDeleteAt,
   116  
   117  		me.PostRootId,
   118  		me.PostParentId,
   119  		me.PostOriginalId,
   120  		cleanComplianceStrings(me.PostMessage),
   121  		me.PostType,
   122  		me.PostProps,
   123  		me.PostHashtags,
   124  		me.PostFileIds,
   125  	}
   126  }