diff options
author | Wim <wim@42.be> | 2020-08-10 00:29:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-10 00:29:54 +0200 |
commit | 4e50fd864921c556988c919269448efdb90fa961 (patch) | |
tree | a3625f03f8de3c4f3841364000a4ea3aa42c1533 /vendor/github.com/mattermost/mattermost-server/v5/model/guest_invite.go | |
parent | dfdffa0027334e55ce213fc6eb62206dbf48baf6 (diff) | |
download | matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.tar.gz matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.tar.bz2 matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.zip |
Use mattermost v5 module (#1192)
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v5/model/guest_invite.go')
-rw-r--r-- | vendor/github.com/mattermost/mattermost-server/v5/model/guest_invite.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v5/model/guest_invite.go b/vendor/github.com/mattermost/mattermost-server/v5/model/guest_invite.go new file mode 100644 index 00000000..3cdd4893 --- /dev/null +++ b/vendor/github.com/mattermost/mattermost-server/v5/model/guest_invite.go @@ -0,0 +1,53 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package model + +import ( + "encoding/json" + "io" + "net/http" +) + +type GuestsInvite struct { + Emails []string `json:"emails"` + Channels []string `json:"channels"` + Message string `json:"message"` +} + +// IsValid validates the user and returns an error if it isn't configured +// correctly. +func (i *GuestsInvite) IsValid() *AppError { + if len(i.Emails) == 0 { + return NewAppError("GuestsInvite.IsValid", "model.guest.is_valid.emails.app_error", nil, "", http.StatusBadRequest) + } + + for _, email := range i.Emails { + if len(email) > USER_EMAIL_MAX_LENGTH || len(email) == 0 || !IsValidEmail(email) { + return NewAppError("GuestsInvite.IsValid", "model.guest.is_valid.email.app_error", nil, "email="+email, http.StatusBadRequest) + } + } + + if len(i.Channels) == 0 { + return NewAppError("GuestsInvite.IsValid", "model.guest.is_valid.channels.app_error", nil, "", http.StatusBadRequest) + } + + for _, channel := range i.Channels { + if len(channel) != 26 { + return NewAppError("GuestsInvite.IsValid", "model.guest.is_valid.channel.app_error", nil, "channel="+channel, http.StatusBadRequest) + } + } + return nil +} + +// GuestsInviteFromJson will decode the input and return a GuestsInvite +func GuestsInviteFromJson(data io.Reader) *GuestsInvite { + var i *GuestsInvite + json.NewDecoder(data).Decode(&i) + return i +} + +func (i *GuestsInvite) ToJson() string { + b, _ := json.Marshal(i) + return string(b) +} |