github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/model/compliance_post.go (about)

     1  // Copyright (c) 2016-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  
    21  	// From User
    22  	UserUsername string
    23  	UserEmail    string
    24  	UserNickname string
    25  
    26  	// From Post
    27  	PostId         string
    28  	PostCreateAt   int64
    29  	PostUpdateAt   int64
    30  	PostDeleteAt   int64
    31  	PostRootId     string
    32  	PostParentId   string
    33  	PostOriginalId string
    34  	PostMessage    string
    35  	PostType       string
    36  	PostProps      string
    37  	PostHashtags   string
    38  	PostFileIds    string
    39  }
    40  
    41  func CompliancePostHeader() []string {
    42  	return []string{
    43  		"TeamName",
    44  		"TeamDisplayName",
    45  
    46  		"ChannelName",
    47  		"ChannelDisplayName",
    48  
    49  		"UserUsername",
    50  		"UserEmail",
    51  		"UserNickname",
    52  
    53  		"PostId",
    54  		"PostCreateAt",
    55  		"PostUpdateAt",
    56  		"PostDeleteAt",
    57  		"PostRootId",
    58  		"PostParentId",
    59  		"PostOriginalId",
    60  		"PostMessage",
    61  		"PostType",
    62  		"PostProps",
    63  		"PostHashtags",
    64  		"PostFileIds",
    65  	}
    66  }
    67  
    68  func cleanComplianceStrings(in string) string {
    69  	if matched, _ := regexp.MatchString("^\\s*(=|\\+|\\-)", in); matched {
    70  		return "'" + in
    71  
    72  	} else {
    73  		return in
    74  	}
    75  }
    76  
    77  func (me *CompliancePost) Row() []string {
    78  
    79  	postDeleteAt := ""
    80  	if me.PostDeleteAt > 0 {
    81  		postDeleteAt = time.Unix(0, me.PostDeleteAt*int64(1000*1000)).Format(time.RFC3339)
    82  	}
    83  
    84  	postUpdateAt := ""
    85  	if me.PostUpdateAt != me.PostCreateAt {
    86  		postUpdateAt = time.Unix(0, me.PostUpdateAt*int64(1000*1000)).Format(time.RFC3339)
    87  	}
    88  
    89  	return []string{
    90  		cleanComplianceStrings(me.TeamName),
    91  		cleanComplianceStrings(me.TeamDisplayName),
    92  
    93  		cleanComplianceStrings(me.ChannelName),
    94  		cleanComplianceStrings(me.ChannelDisplayName),
    95  
    96  		cleanComplianceStrings(me.UserUsername),
    97  		cleanComplianceStrings(me.UserEmail),
    98  		cleanComplianceStrings(me.UserNickname),
    99  
   100  		me.PostId,
   101  		time.Unix(0, me.PostCreateAt*int64(1000*1000)).Format(time.RFC3339),
   102  		postUpdateAt,
   103  		postDeleteAt,
   104  
   105  		me.PostRootId,
   106  		me.PostParentId,
   107  		me.PostOriginalId,
   108  		cleanComplianceStrings(me.PostMessage),
   109  		me.PostType,
   110  		me.PostProps,
   111  		me.PostHashtags,
   112  		me.PostFileIds,
   113  	}
   114  }