github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+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  	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  
    42  func CompliancePostHeader() []string {
    43  	return []string{
    44  		"TeamName",
    45  		"TeamDisplayName",
    46  
    47  		"ChannelName",
    48  		"ChannelDisplayName",
    49  		"ChannelType",
    50  
    51  		"UserUsername",
    52  		"UserEmail",
    53  		"UserNickname",
    54  
    55  		"PostId",
    56  		"PostCreateAt",
    57  		"PostUpdateAt",
    58  		"PostDeleteAt",
    59  		"PostRootId",
    60  		"PostParentId",
    61  		"PostOriginalId",
    62  		"PostMessage",
    63  		"PostType",
    64  		"PostProps",
    65  		"PostHashtags",
    66  		"PostFileIds",
    67  	}
    68  }
    69  
    70  func cleanComplianceStrings(in string) string {
    71  	if matched, _ := regexp.MatchString("^\\s*(=|\\+|\\-)", in); matched {
    72  		return "'" + in
    73  
    74  	} else {
    75  		return in
    76  	}
    77  }
    78  
    79  func (me *CompliancePost) Row() []string {
    80  
    81  	postDeleteAt := ""
    82  	if me.PostDeleteAt > 0 {
    83  		postDeleteAt = time.Unix(0, me.PostDeleteAt*int64(1000*1000)).Format(time.RFC3339)
    84  	}
    85  
    86  	postUpdateAt := ""
    87  	if me.PostUpdateAt != me.PostCreateAt {
    88  		postUpdateAt = time.Unix(0, me.PostUpdateAt*int64(1000*1000)).Format(time.RFC3339)
    89  	}
    90  
    91  	return []string{
    92  		cleanComplianceStrings(me.TeamName),
    93  		cleanComplianceStrings(me.TeamDisplayName),
    94  
    95  		cleanComplianceStrings(me.ChannelName),
    96  		cleanComplianceStrings(me.ChannelDisplayName),
    97  		cleanComplianceStrings(me.ChannelType),
    98  
    99  		cleanComplianceStrings(me.UserUsername),
   100  		cleanComplianceStrings(me.UserEmail),
   101  		cleanComplianceStrings(me.UserNickname),
   102  
   103  		me.PostId,
   104  		time.Unix(0, me.PostCreateAt*int64(1000*1000)).Format(time.RFC3339),
   105  		postUpdateAt,
   106  		postDeleteAt,
   107  
   108  		me.PostRootId,
   109  		me.PostParentId,
   110  		me.PostOriginalId,
   111  		cleanComplianceStrings(me.PostMessage),
   112  		me.PostType,
   113  		me.PostProps,
   114  		me.PostHashtags,
   115  		me.PostFileIds,
   116  	}
   117  }