github.com/jlevesy/mattermost-server@v5.3.2-0.20181003190404-7468f35cb0c8+incompatible/model/team_member.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 "encoding/json" 8 "io" 9 "net/http" 10 "strings" 11 ) 12 13 type TeamMember struct { 14 TeamId string `json:"team_id"` 15 UserId string `json:"user_id"` 16 Roles string `json:"roles"` 17 DeleteAt int64 `json:"delete_at"` 18 SchemeUser bool `json:"scheme_user"` 19 SchemeAdmin bool `json:"scheme_admin"` 20 ExplicitRoles string `json:"explicit_roles"` 21 } 22 23 type TeamUnread struct { 24 TeamId string `json:"team_id"` 25 MsgCount int64 `json:"msg_count"` 26 MentionCount int64 `json:"mention_count"` 27 } 28 29 type TeamMemberForExport struct { 30 TeamMember 31 TeamName string 32 } 33 34 func (o *TeamMember) ToJson() string { 35 b, _ := json.Marshal(o) 36 return string(b) 37 } 38 39 func (o *TeamUnread) ToJson() string { 40 b, _ := json.Marshal(o) 41 return string(b) 42 } 43 44 func TeamMemberFromJson(data io.Reader) *TeamMember { 45 var o *TeamMember 46 json.NewDecoder(data).Decode(&o) 47 return o 48 } 49 50 func TeamUnreadFromJson(data io.Reader) *TeamUnread { 51 var o *TeamUnread 52 json.NewDecoder(data).Decode(&o) 53 return o 54 } 55 56 func TeamMembersToJson(o []*TeamMember) string { 57 if b, err := json.Marshal(o); err != nil { 58 return "[]" 59 } else { 60 return string(b) 61 } 62 } 63 64 func TeamMembersFromJson(data io.Reader) []*TeamMember { 65 var o []*TeamMember 66 json.NewDecoder(data).Decode(&o) 67 return o 68 } 69 70 func TeamsUnreadToJson(o []*TeamUnread) string { 71 if b, err := json.Marshal(o); err != nil { 72 return "[]" 73 } else { 74 return string(b) 75 } 76 } 77 78 func TeamsUnreadFromJson(data io.Reader) []*TeamUnread { 79 var o []*TeamUnread 80 json.NewDecoder(data).Decode(&o) 81 return o 82 } 83 84 func (o *TeamMember) IsValid() *AppError { 85 86 if len(o.TeamId) != 26 { 87 return NewAppError("TeamMember.IsValid", "model.team_member.is_valid.team_id.app_error", nil, "", http.StatusBadRequest) 88 } 89 90 if len(o.UserId) != 26 { 91 return NewAppError("TeamMember.IsValid", "model.team_member.is_valid.user_id.app_error", nil, "", http.StatusBadRequest) 92 } 93 94 return nil 95 } 96 97 func (o *TeamMember) PreUpdate() { 98 } 99 100 func (o *TeamMember) GetRoles() []string { 101 return strings.Fields(o.Roles) 102 }