github.com/adacta-ru/mattermost-server/v6@v6.0.0/model/team_member.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  	"encoding/json"
     8  	"fmt"
     9  	"io"
    10  	"net/http"
    11  	"strings"
    12  )
    13  
    14  const (
    15  	USERNAME = "Username"
    16  )
    17  
    18  type TeamMember struct {
    19  	TeamId        string `json:"team_id"`
    20  	UserId        string `json:"user_id"`
    21  	Roles         string `json:"roles"`
    22  	DeleteAt      int64  `json:"delete_at"`
    23  	SchemeGuest   bool   `json:"scheme_guest"`
    24  	SchemeUser    bool   `json:"scheme_user"`
    25  	SchemeAdmin   bool   `json:"scheme_admin"`
    26  	ExplicitRoles string `json:"explicit_roles"`
    27  }
    28  
    29  type TeamUnread struct {
    30  	TeamId       string `json:"team_id"`
    31  	MsgCount     int64  `json:"msg_count"`
    32  	MentionCount int64  `json:"mention_count"`
    33  }
    34  
    35  type TeamMemberForExport struct {
    36  	TeamMember
    37  	TeamName string
    38  }
    39  
    40  type TeamMemberWithError struct {
    41  	UserId string      `json:"user_id"`
    42  	Member *TeamMember `json:"member"`
    43  	Error  *AppError   `json:"error"`
    44  }
    45  
    46  type EmailInviteWithError struct {
    47  	Email string    `json:"email"`
    48  	Error *AppError `json:"error"`
    49  }
    50  
    51  type TeamMembersGetOptions struct {
    52  	// Sort the team members. Accepts "Username", but defaults to "Id".
    53  	Sort string
    54  
    55  	// If true, exclude team members whose corresponding user is deleted.
    56  	ExcludeDeletedUsers bool
    57  
    58  	// Restrict to search in a list of teams and channels
    59  	ViewRestrictions *ViewUsersRestrictions
    60  }
    61  
    62  func (o *TeamMember) ToJson() string {
    63  	b, _ := json.Marshal(o)
    64  	return string(b)
    65  }
    66  
    67  func (o *TeamUnread) ToJson() string {
    68  	b, _ := json.Marshal(o)
    69  	return string(b)
    70  }
    71  
    72  func TeamMemberFromJson(data io.Reader) *TeamMember {
    73  	var o *TeamMember
    74  	json.NewDecoder(data).Decode(&o)
    75  	return o
    76  }
    77  
    78  func TeamUnreadFromJson(data io.Reader) *TeamUnread {
    79  	var o *TeamUnread
    80  	json.NewDecoder(data).Decode(&o)
    81  	return o
    82  }
    83  
    84  func EmailInviteWithErrorFromJson(data io.Reader) []*EmailInviteWithError {
    85  	var o []*EmailInviteWithError
    86  	json.NewDecoder(data).Decode(&o)
    87  	return o
    88  }
    89  
    90  func EmailInviteWithErrorToEmails(o []*EmailInviteWithError) []string {
    91  	var ret []string
    92  	for _, o := range o {
    93  		if o.Error == nil {
    94  			ret = append(ret, o.Email)
    95  		}
    96  	}
    97  	return ret
    98  }
    99  
   100  func EmailInviteWithErrorToJson(o []*EmailInviteWithError) string {
   101  	b, err := json.Marshal(o)
   102  	if err != nil {
   103  		return "[]"
   104  	}
   105  	return string(b)
   106  }
   107  
   108  func EmailInviteWithErrorToString(o *EmailInviteWithError) string {
   109  	return fmt.Sprintf("%s:%s", o.Email, o.Error.Error())
   110  }
   111  
   112  func TeamMembersWithErrorToTeamMembers(o []*TeamMemberWithError) []*TeamMember {
   113  	var ret []*TeamMember
   114  	for _, o := range o {
   115  		if o.Error == nil {
   116  			ret = append(ret, o.Member)
   117  		}
   118  	}
   119  	return ret
   120  }
   121  
   122  func TeamMembersWithErrorToJson(o []*TeamMemberWithError) string {
   123  	b, err := json.Marshal(o)
   124  	if err != nil {
   125  		return "[]"
   126  	}
   127  	return string(b)
   128  }
   129  
   130  func TeamMemberWithErrorToString(o *TeamMemberWithError) string {
   131  	return fmt.Sprintf("%s:%s", o.UserId, o.Error.Error())
   132  }
   133  
   134  func TeamMembersWithErrorFromJson(data io.Reader) []*TeamMemberWithError {
   135  	var o []*TeamMemberWithError
   136  	json.NewDecoder(data).Decode(&o)
   137  	return o
   138  }
   139  
   140  func TeamMembersToJson(o []*TeamMember) string {
   141  	b, err := json.Marshal(o)
   142  	if err != nil {
   143  		return "[]"
   144  	}
   145  	return string(b)
   146  }
   147  
   148  func TeamMembersFromJson(data io.Reader) []*TeamMember {
   149  	var o []*TeamMember
   150  	json.NewDecoder(data).Decode(&o)
   151  	return o
   152  }
   153  
   154  func TeamsUnreadToJson(o []*TeamUnread) string {
   155  	b, err := json.Marshal(o)
   156  	if err != nil {
   157  		return "[]"
   158  	}
   159  	return string(b)
   160  }
   161  
   162  func TeamsUnreadFromJson(data io.Reader) []*TeamUnread {
   163  	var o []*TeamUnread
   164  	json.NewDecoder(data).Decode(&o)
   165  	return o
   166  }
   167  
   168  func (o *TeamMember) IsValid() *AppError {
   169  
   170  	if !IsValidId(o.TeamId) {
   171  		return NewAppError("TeamMember.IsValid", "model.team_member.is_valid.team_id.app_error", nil, "", http.StatusBadRequest)
   172  	}
   173  
   174  	if !IsValidId(o.UserId) {
   175  		return NewAppError("TeamMember.IsValid", "model.team_member.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
   176  	}
   177  
   178  	return nil
   179  }
   180  
   181  func (o *TeamMember) PreUpdate() {
   182  }
   183  
   184  func (o *TeamMember) GetRoles() []string {
   185  	return strings.Fields(o.Roles)
   186  }