s/vgo/dep/
This commit is contained in:
parent
f387133c21
commit
8788b41ab2
321 changed files with 55322 additions and 145 deletions
96
build/manifest/vendor/github.com/mattermost/mattermost-server/model/access.go
generated
vendored
Normal file
96
build/manifest/vendor/github.com/mattermost/mattermost-server/model/access.go
generated
vendored
Normal file
|
@ -0,0 +1,96 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
ACCESS_TOKEN_GRANT_TYPE = "authorization_code"
|
||||
ACCESS_TOKEN_TYPE = "bearer"
|
||||
REFRESH_TOKEN_GRANT_TYPE = "refresh_token"
|
||||
)
|
||||
|
||||
type AccessData struct {
|
||||
ClientId string `json:"client_id"`
|
||||
UserId string `json:"user_id"`
|
||||
Token string `json:"token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
RedirectUri string `json:"redirect_uri"`
|
||||
ExpiresAt int64 `json:"expires_at"`
|
||||
Scope string `json:"scope"`
|
||||
}
|
||||
|
||||
type AccessResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
TokenType string `json:"token_type"`
|
||||
ExpiresIn int32 `json:"expires_in"`
|
||||
Scope string `json:"scope"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
|
||||
// IsValid validates the AccessData and returns an error if it isn't configured
|
||||
// correctly.
|
||||
func (ad *AccessData) IsValid() *AppError {
|
||||
|
||||
if len(ad.ClientId) == 0 || len(ad.ClientId) > 26 {
|
||||
return NewAppError("AccessData.IsValid", "model.access.is_valid.client_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ad.UserId) == 0 || len(ad.UserId) > 26 {
|
||||
return NewAppError("AccessData.IsValid", "model.access.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ad.Token) != 26 {
|
||||
return NewAppError("AccessData.IsValid", "model.access.is_valid.access_token.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ad.RefreshToken) > 26 {
|
||||
return NewAppError("AccessData.IsValid", "model.access.is_valid.refresh_token.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ad.RedirectUri) == 0 || len(ad.RedirectUri) > 256 || !IsValidHttpUrl(ad.RedirectUri) {
|
||||
return NewAppError("AccessData.IsValid", "model.access.is_valid.redirect_uri.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *AccessData) IsExpired() bool {
|
||||
|
||||
if me.ExpiresAt <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if GetMillis() > me.ExpiresAt {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (ad *AccessData) ToJson() string {
|
||||
b, _ := json.Marshal(ad)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func AccessDataFromJson(data io.Reader) *AccessData {
|
||||
var ad *AccessData
|
||||
json.NewDecoder(data).Decode(&ad)
|
||||
return ad
|
||||
}
|
||||
|
||||
func (ar *AccessResponse) ToJson() string {
|
||||
b, _ := json.Marshal(ar)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func AccessResponseFromJson(data io.Reader) *AccessResponse {
|
||||
var ar *AccessResponse
|
||||
json.NewDecoder(data).Decode(&ar)
|
||||
return ar
|
||||
}
|
41
build/manifest/vendor/github.com/mattermost/mattermost-server/model/analytics_row.go
generated
vendored
Normal file
41
build/manifest/vendor/github.com/mattermost/mattermost-server/model/analytics_row.go
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type AnalyticsRow struct {
|
||||
Name string `json:"name"`
|
||||
Value float64 `json:"value"`
|
||||
}
|
||||
|
||||
type AnalyticsRows []*AnalyticsRow
|
||||
|
||||
func (me *AnalyticsRow) ToJson() string {
|
||||
b, _ := json.Marshal(me)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func AnalyticsRowFromJson(data io.Reader) *AnalyticsRow {
|
||||
var me *AnalyticsRow
|
||||
json.NewDecoder(data).Decode(&me)
|
||||
return me
|
||||
}
|
||||
|
||||
func (me AnalyticsRows) ToJson() string {
|
||||
if b, err := json.Marshal(me); err != nil {
|
||||
return "[]"
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func AnalyticsRowsFromJson(data io.Reader) AnalyticsRows {
|
||||
var me AnalyticsRows
|
||||
json.NewDecoder(data).Decode(&me)
|
||||
return me
|
||||
}
|
30
build/manifest/vendor/github.com/mattermost/mattermost-server/model/audit.go
generated
vendored
Normal file
30
build/manifest/vendor/github.com/mattermost/mattermost-server/model/audit.go
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type Audit struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UserId string `json:"user_id"`
|
||||
Action string `json:"action"`
|
||||
ExtraInfo string `json:"extra_info"`
|
||||
IpAddress string `json:"ip_address"`
|
||||
SessionId string `json:"session_id"`
|
||||
}
|
||||
|
||||
func (o *Audit) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func AuditFromJson(data io.Reader) *Audit {
|
||||
var o *Audit
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
34
build/manifest/vendor/github.com/mattermost/mattermost-server/model/audits.go
generated
vendored
Normal file
34
build/manifest/vendor/github.com/mattermost/mattermost-server/model/audits.go
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type Audits []Audit
|
||||
|
||||
func (o Audits) Etag() string {
|
||||
if len(o) > 0 {
|
||||
// the first in the list is always the most current
|
||||
return Etag(o[0].CreateAt)
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (o Audits) ToJson() string {
|
||||
if b, err := json.Marshal(o); err != nil {
|
||||
return "[]"
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func AuditsFromJson(data io.Reader) Audits {
|
||||
var o Audits
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
141
build/manifest/vendor/github.com/mattermost/mattermost-server/model/authorize.go
generated
vendored
Normal file
141
build/manifest/vendor/github.com/mattermost/mattermost-server/model/authorize.go
generated
vendored
Normal file
|
@ -0,0 +1,141 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
AUTHCODE_EXPIRE_TIME = 60 * 10 // 10 minutes
|
||||
AUTHCODE_RESPONSE_TYPE = "code"
|
||||
DEFAULT_SCOPE = "user"
|
||||
)
|
||||
|
||||
type AuthData struct {
|
||||
ClientId string `json:"client_id"`
|
||||
UserId string `json:"user_id"`
|
||||
Code string `json:"code"`
|
||||
ExpiresIn int32 `json:"expires_in"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
RedirectUri string `json:"redirect_uri"`
|
||||
State string `json:"state"`
|
||||
Scope string `json:"scope"`
|
||||
}
|
||||
|
||||
type AuthorizeRequest struct {
|
||||
ResponseType string `json:"response_type"`
|
||||
ClientId string `json:"client_id"`
|
||||
RedirectUri string `json:"redirect_uri"`
|
||||
Scope string `json:"scope"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
// IsValid validates the AuthData and returns an error if it isn't configured
|
||||
// correctly.
|
||||
func (ad *AuthData) IsValid() *AppError {
|
||||
|
||||
if len(ad.ClientId) != 26 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.client_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ad.UserId) != 26 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ad.Code) == 0 || len(ad.Code) > 128 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.auth_code.app_error", nil, "client_id="+ad.ClientId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if ad.ExpiresIn == 0 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.expires.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if ad.CreateAt <= 0 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.create_at.app_error", nil, "client_id="+ad.ClientId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ad.RedirectUri) == 0 || len(ad.RedirectUri) > 256 || !IsValidHttpUrl(ad.RedirectUri) {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.redirect_uri.app_error", nil, "client_id="+ad.ClientId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ad.State) > 1024 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.state.app_error", nil, "client_id="+ad.ClientId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ad.Scope) > 128 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.scope.app_error", nil, "client_id="+ad.ClientId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsValid validates the AuthorizeRequest and returns an error if it isn't configured
|
||||
// correctly.
|
||||
func (ar *AuthorizeRequest) IsValid() *AppError {
|
||||
|
||||
if len(ar.ClientId) != 26 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.client_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ar.ResponseType) == 0 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.response_type.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ar.RedirectUri) == 0 || len(ar.RedirectUri) > 256 || !IsValidHttpUrl(ar.RedirectUri) {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.redirect_uri.app_error", nil, "client_id="+ar.ClientId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ar.State) > 128 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.state.app_error", nil, "client_id="+ar.ClientId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(ar.Scope) > 128 {
|
||||
return NewAppError("AuthData.IsValid", "model.authorize.is_valid.scope.app_error", nil, "client_id="+ar.ClientId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ad *AuthData) PreSave() {
|
||||
if ad.ExpiresIn == 0 {
|
||||
ad.ExpiresIn = AUTHCODE_EXPIRE_TIME
|
||||
}
|
||||
|
||||
if ad.CreateAt == 0 {
|
||||
ad.CreateAt = GetMillis()
|
||||
}
|
||||
|
||||
if len(ad.Scope) == 0 {
|
||||
ad.Scope = DEFAULT_SCOPE
|
||||
}
|
||||
}
|
||||
|
||||
func (ad *AuthData) ToJson() string {
|
||||
b, _ := json.Marshal(ad)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func AuthDataFromJson(data io.Reader) *AuthData {
|
||||
var ad *AuthData
|
||||
json.NewDecoder(data).Decode(&ad)
|
||||
return ad
|
||||
}
|
||||
|
||||
func (ar *AuthorizeRequest) ToJson() string {
|
||||
b, _ := json.Marshal(ar)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func AuthorizeRequestFromJson(data io.Reader) *AuthorizeRequest {
|
||||
var ar *AuthorizeRequest
|
||||
json.NewDecoder(data).Decode(&ar)
|
||||
return ar
|
||||
}
|
||||
|
||||
func (ad *AuthData) IsExpired() bool {
|
||||
return GetMillis() > ad.CreateAt+int64(ad.ExpiresIn*1000)
|
||||
}
|
9
build/manifest/vendor/github.com/mattermost/mattermost-server/model/builtin.go
generated
vendored
Normal file
9
build/manifest/vendor/github.com/mattermost/mattermost-server/model/builtin.go
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
func NewBool(b bool) *bool { return &b }
|
||||
func NewInt(n int) *int { return &n }
|
||||
func NewInt64(n int64) *int64 { return &n }
|
||||
func NewString(s string) *string { return &s }
|
32
build/manifest/vendor/github.com/mattermost/mattermost-server/model/bundle_info.go
generated
vendored
Normal file
32
build/manifest/vendor/github.com/mattermost/mattermost-server/model/bundle_info.go
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import "github.com/mattermost/mattermost-server/mlog"
|
||||
|
||||
type BundleInfo struct {
|
||||
Path string
|
||||
|
||||
Manifest *Manifest
|
||||
ManifestPath string
|
||||
ManifestError error
|
||||
}
|
||||
|
||||
func (b *BundleInfo) WrapLogger(logger *mlog.Logger) *mlog.Logger {
|
||||
if b.Manifest != nil {
|
||||
return logger.With(mlog.String("plugin_id", b.Manifest.Id))
|
||||
}
|
||||
return logger.With(mlog.String("plugin_path", b.Path))
|
||||
}
|
||||
|
||||
// Returns bundle info for the given path. The return value is never nil.
|
||||
func BundleInfoForPath(path string) *BundleInfo {
|
||||
m, mpath, err := FindManifest(path)
|
||||
return &BundleInfo{
|
||||
Path: path,
|
||||
Manifest: m,
|
||||
ManifestPath: mpath,
|
||||
ManifestError: err,
|
||||
}
|
||||
}
|
213
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel.go
generated
vendored
Normal file
213
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel.go
generated
vendored
Normal file
|
@ -0,0 +1,213 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
CHANNEL_OPEN = "O"
|
||||
CHANNEL_PRIVATE = "P"
|
||||
CHANNEL_DIRECT = "D"
|
||||
CHANNEL_GROUP = "G"
|
||||
CHANNEL_GROUP_MAX_USERS = 8
|
||||
CHANNEL_GROUP_MIN_USERS = 3
|
||||
DEFAULT_CHANNEL = "town-square"
|
||||
CHANNEL_DISPLAY_NAME_MAX_RUNES = 64
|
||||
CHANNEL_NAME_MIN_LENGTH = 2
|
||||
CHANNEL_NAME_MAX_LENGTH = 64
|
||||
CHANNEL_NAME_UI_MAX_LENGTH = 22
|
||||
CHANNEL_HEADER_MAX_RUNES = 1024
|
||||
CHANNEL_PURPOSE_MAX_RUNES = 250
|
||||
CHANNEL_CACHE_SIZE = 25000
|
||||
)
|
||||
|
||||
type Channel struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
TeamId string `json:"team_id"`
|
||||
Type string `json:"type"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Name string `json:"name"`
|
||||
Header string `json:"header"`
|
||||
Purpose string `json:"purpose"`
|
||||
LastPostAt int64 `json:"last_post_at"`
|
||||
TotalMsgCount int64 `json:"total_msg_count"`
|
||||
ExtraUpdateAt int64 `json:"extra_update_at"`
|
||||
CreatorId string `json:"creator_id"`
|
||||
SchemeId *string `json:"scheme_id"`
|
||||
Props map[string]interface{} `json:"props" db:"-"`
|
||||
}
|
||||
|
||||
type ChannelPatch struct {
|
||||
DisplayName *string `json:"display_name"`
|
||||
Name *string `json:"name"`
|
||||
Header *string `json:"header"`
|
||||
Purpose *string `json:"purpose"`
|
||||
}
|
||||
|
||||
func (o *Channel) DeepCopy() *Channel {
|
||||
copy := *o
|
||||
return ©
|
||||
}
|
||||
|
||||
func (o *Channel) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *ChannelPatch) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ChannelFromJson(data io.Reader) *Channel {
|
||||
var o *Channel
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func ChannelPatchFromJson(data io.Reader) *ChannelPatch {
|
||||
var o *ChannelPatch
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *Channel) Etag() string {
|
||||
return Etag(o.Id, o.UpdateAt)
|
||||
}
|
||||
|
||||
func (o *Channel) IsValid() *AppError {
|
||||
if len(o.Id) != 26 {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.create_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.UpdateAt == 0 {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.update_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(o.DisplayName) > CHANNEL_DISPLAY_NAME_MAX_RUNES {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.display_name.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !IsValidChannelIdentifier(o.Name) {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.2_or_more.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !(o.Type == CHANNEL_OPEN || o.Type == CHANNEL_PRIVATE || o.Type == CHANNEL_DIRECT || o.Type == CHANNEL_GROUP) {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.type.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(o.Header) > CHANNEL_HEADER_MAX_RUNES {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.header.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(o.Purpose) > CHANNEL_PURPOSE_MAX_RUNES {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.purpose.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.CreatorId) > 26 {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.creator_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Channel) PreSave() {
|
||||
if o.Id == "" {
|
||||
o.Id = NewId()
|
||||
}
|
||||
|
||||
o.CreateAt = GetMillis()
|
||||
o.UpdateAt = o.CreateAt
|
||||
o.ExtraUpdateAt = 0
|
||||
}
|
||||
|
||||
func (o *Channel) PreUpdate() {
|
||||
o.UpdateAt = GetMillis()
|
||||
}
|
||||
|
||||
func (o *Channel) IsGroupOrDirect() bool {
|
||||
return o.Type == CHANNEL_DIRECT || o.Type == CHANNEL_GROUP
|
||||
}
|
||||
|
||||
func (o *Channel) Patch(patch *ChannelPatch) {
|
||||
if patch.DisplayName != nil {
|
||||
o.DisplayName = *patch.DisplayName
|
||||
}
|
||||
|
||||
if patch.Name != nil {
|
||||
o.Name = *patch.Name
|
||||
}
|
||||
|
||||
if patch.Header != nil {
|
||||
o.Header = *patch.Header
|
||||
}
|
||||
|
||||
if patch.Purpose != nil {
|
||||
o.Purpose = *patch.Purpose
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Channel) MakeNonNil() {
|
||||
if o.Props == nil {
|
||||
o.Props = make(map[string]interface{})
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Channel) AddProp(key string, value interface{}) {
|
||||
o.MakeNonNil()
|
||||
|
||||
o.Props[key] = value
|
||||
}
|
||||
|
||||
func GetDMNameFromIds(userId1, userId2 string) string {
|
||||
if userId1 > userId2 {
|
||||
return userId2 + "__" + userId1
|
||||
} else {
|
||||
return userId1 + "__" + userId2
|
||||
}
|
||||
}
|
||||
|
||||
func GetGroupDisplayNameFromUsers(users []*User, truncate bool) string {
|
||||
usernames := make([]string, len(users))
|
||||
for index, user := range users {
|
||||
usernames[index] = user.Username
|
||||
}
|
||||
|
||||
sort.Strings(usernames)
|
||||
|
||||
name := strings.Join(usernames, ", ")
|
||||
|
||||
if truncate && len(name) > CHANNEL_NAME_MAX_LENGTH {
|
||||
name = name[:CHANNEL_NAME_MAX_LENGTH]
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
func GetGroupNameFromUserIds(userIds []string) string {
|
||||
sort.Strings(userIds)
|
||||
|
||||
h := sha1.New()
|
||||
for _, id := range userIds {
|
||||
io.WriteString(h, id)
|
||||
}
|
||||
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
54
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_count.go
generated
vendored
Normal file
54
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_count.go
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ChannelCounts struct {
|
||||
Counts map[string]int64 `json:"counts"`
|
||||
UpdateTimes map[string]int64 `json:"update_times"`
|
||||
}
|
||||
|
||||
func (o *ChannelCounts) Etag() string {
|
||||
|
||||
ids := []string{}
|
||||
for id := range o.Counts {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
sort.Strings(ids)
|
||||
|
||||
str := ""
|
||||
for _, id := range ids {
|
||||
str += id + strconv.FormatInt(o.Counts[id], 10)
|
||||
}
|
||||
|
||||
md5Counts := fmt.Sprintf("%x", md5.Sum([]byte(str)))
|
||||
|
||||
var update int64 = 0
|
||||
for _, u := range o.UpdateTimes {
|
||||
if u > update {
|
||||
update = u
|
||||
}
|
||||
}
|
||||
|
||||
return Etag(md5Counts, update)
|
||||
}
|
||||
|
||||
func (o *ChannelCounts) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ChannelCountsFromJson(data io.Reader) *ChannelCounts {
|
||||
var o *ChannelCounts
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
34
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_data.go
generated
vendored
Normal file
34
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_data.go
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ChannelData struct {
|
||||
Channel *Channel `json:"channel"`
|
||||
Member *ChannelMember `json:"member"`
|
||||
}
|
||||
|
||||
func (o *ChannelData) Etag() string {
|
||||
var mt int64 = 0
|
||||
if o.Member != nil {
|
||||
mt = o.Member.LastUpdateAt
|
||||
}
|
||||
|
||||
return Etag(o.Channel.Id, o.Channel.UpdateAt, o.Channel.LastPostAt, mt)
|
||||
}
|
||||
|
||||
func (o *ChannelData) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ChannelDataFromJson(data io.Reader) *ChannelData {
|
||||
var o *ChannelData
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
53
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_list.go
generated
vendored
Normal file
53
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_list.go
generated
vendored
Normal file
|
@ -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"
|
||||
)
|
||||
|
||||
type ChannelList []*Channel
|
||||
|
||||
func (o *ChannelList) ToJson() string {
|
||||
if b, err := json.Marshal(o); err != nil {
|
||||
return "[]"
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ChannelList) Etag() string {
|
||||
|
||||
id := "0"
|
||||
var t int64 = 0
|
||||
var delta int64 = 0
|
||||
|
||||
for _, v := range *o {
|
||||
if v.LastPostAt > t {
|
||||
t = v.LastPostAt
|
||||
id = v.Id
|
||||
}
|
||||
|
||||
if v.UpdateAt > t {
|
||||
t = v.UpdateAt
|
||||
id = v.Id
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Etag(id, t, delta, len(*o))
|
||||
}
|
||||
|
||||
func ChannelListFromJson(data io.Reader) *ChannelList {
|
||||
var o *ChannelList
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func ChannelSliceFromJson(data io.Reader) []*Channel {
|
||||
var o []*Channel
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
151
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_member.go
generated
vendored
Normal file
151
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_member.go
generated
vendored
Normal file
|
@ -0,0 +1,151 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
CHANNEL_NOTIFY_DEFAULT = "default"
|
||||
CHANNEL_NOTIFY_ALL = "all"
|
||||
CHANNEL_NOTIFY_MENTION = "mention"
|
||||
CHANNEL_NOTIFY_NONE = "none"
|
||||
CHANNEL_MARK_UNREAD_ALL = "all"
|
||||
CHANNEL_MARK_UNREAD_MENTION = "mention"
|
||||
)
|
||||
|
||||
type ChannelUnread struct {
|
||||
TeamId string `json:"team_id"`
|
||||
ChannelId string `json:"channel_id"`
|
||||
MsgCount int64 `json:"msg_count"`
|
||||
MentionCount int64 `json:"mention_count"`
|
||||
NotifyProps StringMap `json:"-"`
|
||||
}
|
||||
|
||||
type ChannelMember struct {
|
||||
ChannelId string `json:"channel_id"`
|
||||
UserId string `json:"user_id"`
|
||||
Roles string `json:"roles"`
|
||||
LastViewedAt int64 `json:"last_viewed_at"`
|
||||
MsgCount int64 `json:"msg_count"`
|
||||
MentionCount int64 `json:"mention_count"`
|
||||
NotifyProps StringMap `json:"notify_props"`
|
||||
LastUpdateAt int64 `json:"last_update_at"`
|
||||
SchemeUser bool `json:"scheme_user"`
|
||||
SchemeAdmin bool `json:"scheme_admin"`
|
||||
ExplicitRoles string `json:"explicit_roles"`
|
||||
}
|
||||
|
||||
type ChannelMembers []ChannelMember
|
||||
|
||||
func (o *ChannelMembers) ToJson() string {
|
||||
if b, err := json.Marshal(o); err != nil {
|
||||
return "[]"
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ChannelUnread) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ChannelMembersFromJson(data io.Reader) *ChannelMembers {
|
||||
var o *ChannelMembers
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func ChannelUnreadFromJson(data io.Reader) *ChannelUnread {
|
||||
var o *ChannelUnread
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *ChannelMember) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ChannelMemberFromJson(data io.Reader) *ChannelMember {
|
||||
var o *ChannelMember
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *ChannelMember) IsValid() *AppError {
|
||||
|
||||
if len(o.ChannelId) != 26 {
|
||||
return NewAppError("ChannelMember.IsValid", "model.channel_member.is_valid.channel_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.UserId) != 26 {
|
||||
return NewAppError("ChannelMember.IsValid", "model.channel_member.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
notifyLevel := o.NotifyProps[DESKTOP_NOTIFY_PROP]
|
||||
if len(notifyLevel) > 20 || !IsChannelNotifyLevelValid(notifyLevel) {
|
||||
return NewAppError("ChannelMember.IsValid", "model.channel_member.is_valid.notify_level.app_error", nil, "notify_level="+notifyLevel, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
markUnreadLevel := o.NotifyProps[MARK_UNREAD_NOTIFY_PROP]
|
||||
if len(markUnreadLevel) > 20 || !IsChannelMarkUnreadLevelValid(markUnreadLevel) {
|
||||
return NewAppError("ChannelMember.IsValid", "model.channel_member.is_valid.unread_level.app_error", nil, "mark_unread_level="+markUnreadLevel, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if pushLevel, ok := o.NotifyProps[PUSH_NOTIFY_PROP]; ok {
|
||||
if len(pushLevel) > 20 || !IsChannelNotifyLevelValid(pushLevel) {
|
||||
return NewAppError("ChannelMember.IsValid", "model.channel_member.is_valid.push_level.app_error", nil, "push_notification_level="+pushLevel, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
if sendEmail, ok := o.NotifyProps[EMAIL_NOTIFY_PROP]; ok {
|
||||
if len(sendEmail) > 20 || !IsSendEmailValid(sendEmail) {
|
||||
return NewAppError("ChannelMember.IsValid", "model.channel_member.is_valid.email_value.app_error", nil, "push_notification_level="+sendEmail, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *ChannelMember) PreSave() {
|
||||
o.LastUpdateAt = GetMillis()
|
||||
}
|
||||
|
||||
func (o *ChannelMember) PreUpdate() {
|
||||
o.LastUpdateAt = GetMillis()
|
||||
}
|
||||
|
||||
func (o *ChannelMember) GetRoles() []string {
|
||||
return strings.Fields(o.Roles)
|
||||
}
|
||||
|
||||
func IsChannelNotifyLevelValid(notifyLevel string) bool {
|
||||
return notifyLevel == CHANNEL_NOTIFY_DEFAULT ||
|
||||
notifyLevel == CHANNEL_NOTIFY_ALL ||
|
||||
notifyLevel == CHANNEL_NOTIFY_MENTION ||
|
||||
notifyLevel == CHANNEL_NOTIFY_NONE
|
||||
}
|
||||
|
||||
func IsChannelMarkUnreadLevelValid(markUnreadLevel string) bool {
|
||||
return markUnreadLevel == CHANNEL_MARK_UNREAD_ALL || markUnreadLevel == CHANNEL_MARK_UNREAD_MENTION
|
||||
}
|
||||
|
||||
func IsSendEmailValid(sendEmail string) bool {
|
||||
return sendEmail == CHANNEL_NOTIFY_DEFAULT || sendEmail == "true" || sendEmail == "false"
|
||||
}
|
||||
|
||||
func GetDefaultChannelNotifyProps() StringMap {
|
||||
return StringMap{
|
||||
DESKTOP_NOTIFY_PROP: CHANNEL_NOTIFY_DEFAULT,
|
||||
MARK_UNREAD_NOTIFY_PROP: CHANNEL_MARK_UNREAD_ALL,
|
||||
PUSH_NOTIFY_PROP: CHANNEL_NOTIFY_DEFAULT,
|
||||
EMAIL_NOTIFY_PROP: CHANNEL_NOTIFY_DEFAULT,
|
||||
}
|
||||
}
|
11
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_member_history.go
generated
vendored
Normal file
11
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_member_history.go
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
type ChannelMemberHistory struct {
|
||||
ChannelId string
|
||||
UserId string
|
||||
JoinTime int64
|
||||
LeaveTime *int64
|
||||
}
|
15
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_member_history_result.go
generated
vendored
Normal file
15
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_member_history_result.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
type ChannelMemberHistoryResult struct {
|
||||
ChannelId string
|
||||
UserId string
|
||||
JoinTime int64
|
||||
LeaveTime *int64
|
||||
|
||||
// these two fields are never set in the database - when we SELECT, we join on Users to get them
|
||||
UserEmail string `db:"Email"`
|
||||
Username string
|
||||
}
|
28
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_mentions.go
generated
vendored
Normal file
28
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_mentions.go
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var channelMentionRegexp = regexp.MustCompile(`\B~[a-zA-Z0-9\-_]+`)
|
||||
|
||||
func ChannelMentions(message string) []string {
|
||||
var names []string
|
||||
|
||||
if strings.Contains(message, "~") {
|
||||
alreadyMentioned := make(map[string]bool)
|
||||
for _, match := range channelMentionRegexp.FindAllString(message, -1) {
|
||||
name := match[1:]
|
||||
if !alreadyMentioned[name] {
|
||||
names = append(names, name)
|
||||
alreadyMentioned[name] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
26
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_search.go
generated
vendored
Normal file
26
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_search.go
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ChannelSearch struct {
|
||||
Term string `json:"term"`
|
||||
}
|
||||
|
||||
// ToJson convert a Channel to a json string
|
||||
func (c *ChannelSearch) ToJson() string {
|
||||
b, _ := json.Marshal(c)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// ChannelSearchFromJson will decode the input and return a Channel
|
||||
func ChannelSearchFromJson(data io.Reader) *ChannelSearch {
|
||||
var cs *ChannelSearch
|
||||
json.NewDecoder(data).Decode(&cs)
|
||||
return cs
|
||||
}
|
25
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_stats.go
generated
vendored
Normal file
25
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_stats.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ChannelStats struct {
|
||||
ChannelId string `json:"channel_id"`
|
||||
MemberCount int64 `json:"member_count"`
|
||||
}
|
||||
|
||||
func (o *ChannelStats) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ChannelStatsFromJson(data io.Reader) *ChannelStats {
|
||||
var o *ChannelStats
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
41
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_view.go
generated
vendored
Normal file
41
build/manifest/vendor/github.com/mattermost/mattermost-server/model/channel_view.go
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ChannelView struct {
|
||||
ChannelId string `json:"channel_id"`
|
||||
PrevChannelId string `json:"prev_channel_id"`
|
||||
}
|
||||
|
||||
func (o *ChannelView) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ChannelViewFromJson(data io.Reader) *ChannelView {
|
||||
var o *ChannelView
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
type ChannelViewResponse struct {
|
||||
Status string `json:"status"`
|
||||
LastViewedAtTimes map[string]int64 `json:"last_viewed_at_times"`
|
||||
}
|
||||
|
||||
func (o *ChannelViewResponse) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ChannelViewResponseFromJson(data io.Reader) *ChannelViewResponse {
|
||||
var o *ChannelViewResponse
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
3744
build/manifest/vendor/github.com/mattermost/mattermost-server/model/client4.go
generated
vendored
Normal file
3744
build/manifest/vendor/github.com/mattermost/mattermost-server/model/client4.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
133
build/manifest/vendor/github.com/mattermost/mattermost-server/model/cluster_discovery.go
generated
vendored
Normal file
133
build/manifest/vendor/github.com/mattermost/mattermost-server/model/cluster_discovery.go
generated
vendored
Normal file
|
@ -0,0 +1,133 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
CDS_OFFLINE_AFTER_MILLIS = 1000 * 60 * 30 // 30 minutes
|
||||
CDS_TYPE_APP = "mattermost_app"
|
||||
)
|
||||
|
||||
type ClusterDiscovery struct {
|
||||
Id string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
ClusterName string `json:"cluster_name"`
|
||||
Hostname string `json:"hostname"`
|
||||
GossipPort int32 `json:"gossip_port"`
|
||||
Port int32 `json:"port"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
LastPingAt int64 `json:"last_ping_at"`
|
||||
}
|
||||
|
||||
func (o *ClusterDiscovery) PreSave() {
|
||||
if o.Id == "" {
|
||||
o.Id = NewId()
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
o.CreateAt = GetMillis()
|
||||
o.LastPingAt = o.CreateAt
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ClusterDiscovery) AutoFillHostname() {
|
||||
// attempt to set the hostname from the OS
|
||||
if len(o.Hostname) == 0 {
|
||||
if hn, err := os.Hostname(); err == nil {
|
||||
o.Hostname = hn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ClusterDiscovery) AutoFillIpAddress() {
|
||||
// attempt to set the hostname to the first non-local IP address
|
||||
if len(o.Hostname) == 0 {
|
||||
o.Hostname = GetServerIpAddress()
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ClusterDiscovery) IsEqual(in *ClusterDiscovery) bool {
|
||||
if in == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if o.Type != in.Type {
|
||||
return false
|
||||
}
|
||||
|
||||
if o.ClusterName != in.ClusterName {
|
||||
return false
|
||||
}
|
||||
|
||||
if o.Hostname != in.Hostname {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func FilterClusterDiscovery(vs []*ClusterDiscovery, f func(*ClusterDiscovery) bool) []*ClusterDiscovery {
|
||||
copy := make([]*ClusterDiscovery, 0)
|
||||
for _, v := range vs {
|
||||
if f(v) {
|
||||
copy = append(copy, v)
|
||||
}
|
||||
}
|
||||
|
||||
return copy
|
||||
}
|
||||
|
||||
func (o *ClusterDiscovery) IsValid() *AppError {
|
||||
if len(o.Id) != 26 {
|
||||
return NewAppError("ClusterDiscovery.IsValid", "model.cluster.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.ClusterName) == 0 {
|
||||
return NewAppError("ClusterDiscovery.IsValid", "model.cluster.is_valid.name.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Type) == 0 {
|
||||
return NewAppError("ClusterDiscovery.IsValid", "model.cluster.is_valid.type.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Hostname) == 0 {
|
||||
return NewAppError("ClusterDiscovery.IsValid", "model.cluster.is_valid.hostname.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
return NewAppError("ClusterDiscovery.IsValid", "model.cluster.is_valid.create_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.LastPingAt == 0 {
|
||||
return NewAppError("ClusterDiscovery.IsValid", "model.cluster.is_valid.last_ping_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *ClusterDiscovery) ToJson() string {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ClusterDiscoveryFromJson(data io.Reader) *ClusterDiscovery {
|
||||
decoder := json.NewDecoder(data)
|
||||
var me ClusterDiscovery
|
||||
err := decoder.Decode(&me)
|
||||
if err == nil {
|
||||
return &me
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
44
build/manifest/vendor/github.com/mattermost/mattermost-server/model/cluster_info.go
generated
vendored
Normal file
44
build/manifest/vendor/github.com/mattermost/mattermost-server/model/cluster_info.go
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ClusterInfo struct {
|
||||
Id string `json:"id"`
|
||||
Version string `json:"version"`
|
||||
ConfigHash string `json:"config_hash"`
|
||||
IpAddress string `json:"ipaddress"`
|
||||
Hostname string `json:"hostname"`
|
||||
}
|
||||
|
||||
func (me *ClusterInfo) ToJson() string {
|
||||
b, _ := json.Marshal(me)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ClusterInfoFromJson(data io.Reader) *ClusterInfo {
|
||||
var me *ClusterInfo
|
||||
json.NewDecoder(data).Decode(&me)
|
||||
return me
|
||||
}
|
||||
|
||||
func ClusterInfosToJson(objmap []*ClusterInfo) string {
|
||||
b, _ := json.Marshal(objmap)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ClusterInfosFromJson(data io.Reader) []*ClusterInfo {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap []*ClusterInfo
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
return make([]*ClusterInfo, 0)
|
||||
} else {
|
||||
return objmap
|
||||
}
|
||||
}
|
48
build/manifest/vendor/github.com/mattermost/mattermost-server/model/cluster_message.go
generated
vendored
Normal file
48
build/manifest/vendor/github.com/mattermost/mattermost-server/model/cluster_message.go
generated
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
CLUSTER_EVENT_PUBLISH = "publish"
|
||||
CLUSTER_EVENT_UPDATE_STATUS = "update_status"
|
||||
CLUSTER_EVENT_INVALIDATE_ALL_CACHES = "inv_all_caches"
|
||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_REACTIONS = "inv_reactions"
|
||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK = "inv_webhook"
|
||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS = "inv_channel_posts"
|
||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS = "inv_channel_members_notify_props"
|
||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS = "inv_channel_members"
|
||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME = "inv_channel_name"
|
||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL = "inv_channel"
|
||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER = "inv_user"
|
||||
CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER = "clear_session_user"
|
||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES = "inv_roles"
|
||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_SCHEMES = "inv_schemes"
|
||||
|
||||
CLUSTER_SEND_BEST_EFFORT = "best_effort"
|
||||
CLUSTER_SEND_RELIABLE = "reliable"
|
||||
)
|
||||
|
||||
type ClusterMessage struct {
|
||||
Event string `json:"event"`
|
||||
SendType string `json:"-"`
|
||||
WaitForAllToSend bool `json:"-"`
|
||||
Data string `json:"data,omitempty"`
|
||||
Props map[string]string `json:"props,omitempty"`
|
||||
}
|
||||
|
||||
func (o *ClusterMessage) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ClusterMessageFromJson(data io.Reader) *ClusterMessage {
|
||||
var o *ClusterMessage
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
27
build/manifest/vendor/github.com/mattermost/mattermost-server/model/cluster_stats.go
generated
vendored
Normal file
27
build/manifest/vendor/github.com/mattermost/mattermost-server/model/cluster_stats.go
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ClusterStats struct {
|
||||
Id string `json:"id"`
|
||||
TotalWebsocketConnections int `json:"total_websocket_connections"`
|
||||
TotalReadDbConnections int `json:"total_read_db_connections"`
|
||||
TotalMasterDbConnections int `json:"total_master_db_connections"`
|
||||
}
|
||||
|
||||
func (me *ClusterStats) ToJson() string {
|
||||
b, _ := json.Marshal(me)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ClusterStatsFromJson(data io.Reader) *ClusterStats {
|
||||
var me *ClusterStats
|
||||
json.NewDecoder(data).Decode(&me)
|
||||
return me
|
||||
}
|
139
build/manifest/vendor/github.com/mattermost/mattermost-server/model/command.go
generated
vendored
Normal file
139
build/manifest/vendor/github.com/mattermost/mattermost-server/model/command.go
generated
vendored
Normal file
|
@ -0,0 +1,139 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
COMMAND_METHOD_POST = "P"
|
||||
COMMAND_METHOD_GET = "G"
|
||||
MIN_TRIGGER_LENGTH = 1
|
||||
MAX_TRIGGER_LENGTH = 128
|
||||
)
|
||||
|
||||
type Command struct {
|
||||
Id string `json:"id"`
|
||||
Token string `json:"token"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
CreatorId string `json:"creator_id"`
|
||||
TeamId string `json:"team_id"`
|
||||
Trigger string `json:"trigger"`
|
||||
Method string `json:"method"`
|
||||
Username string `json:"username"`
|
||||
IconURL string `json:"icon_url"`
|
||||
AutoComplete bool `json:"auto_complete"`
|
||||
AutoCompleteDesc string `json:"auto_complete_desc"`
|
||||
AutoCompleteHint string `json:"auto_complete_hint"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
func (o *Command) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func CommandFromJson(data io.Reader) *Command {
|
||||
var o *Command
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func CommandListToJson(l []*Command) string {
|
||||
b, _ := json.Marshal(l)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func CommandListFromJson(data io.Reader) []*Command {
|
||||
var o []*Command
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *Command) IsValid() *AppError {
|
||||
|
||||
if len(o.Id) != 26 {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Token) != 26 {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.token.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.create_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.UpdateAt == 0 {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.update_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.CreatorId) != 26 {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.TeamId) != 26 {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.team_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Trigger) < MIN_TRIGGER_LENGTH || len(o.Trigger) > MAX_TRIGGER_LENGTH || strings.Index(o.Trigger, "/") == 0 || strings.Contains(o.Trigger, " ") {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.trigger.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.URL) == 0 || len(o.URL) > 1024 {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.url.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !IsValidHttpUrl(o.URL) {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.url_http.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !(o.Method == COMMAND_METHOD_GET || o.Method == COMMAND_METHOD_POST) {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.method.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.DisplayName) > 64 {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.display_name.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Description) > 128 {
|
||||
return NewAppError("Command.IsValid", "model.command.is_valid.description.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Command) PreSave() {
|
||||
if o.Id == "" {
|
||||
o.Id = NewId()
|
||||
}
|
||||
|
||||
if o.Token == "" {
|
||||
o.Token = NewId()
|
||||
}
|
||||
|
||||
o.CreateAt = GetMillis()
|
||||
o.UpdateAt = o.CreateAt
|
||||
}
|
||||
|
||||
func (o *Command) PreUpdate() {
|
||||
o.UpdateAt = GetMillis()
|
||||
}
|
||||
|
||||
func (o *Command) Sanitize() {
|
||||
o.Token = ""
|
||||
o.CreatorId = ""
|
||||
o.Method = ""
|
||||
o.URL = ""
|
||||
o.Username = ""
|
||||
o.IconURL = ""
|
||||
}
|
34
build/manifest/vendor/github.com/mattermost/mattermost-server/model/command_args.go
generated
vendored
Normal file
34
build/manifest/vendor/github.com/mattermost/mattermost-server/model/command_args.go
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||
)
|
||||
|
||||
type CommandArgs struct {
|
||||
UserId string `json:"user_id"`
|
||||
ChannelId string `json:"channel_id"`
|
||||
TeamId string `json:"team_id"`
|
||||
RootId string `json:"root_id"`
|
||||
ParentId string `json:"parent_id"`
|
||||
Command string `json:"command"`
|
||||
SiteURL string `json:"-"`
|
||||
T goi18n.TranslateFunc `json:"-"`
|
||||
Session Session `json:"-"`
|
||||
}
|
||||
|
||||
func (o *CommandArgs) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func CommandArgsFromJson(data io.Reader) *CommandArgs {
|
||||
var o *CommandArgs
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
67
build/manifest/vendor/github.com/mattermost/mattermost-server/model/command_response.go
generated
vendored
Normal file
67
build/manifest/vendor/github.com/mattermost/mattermost-server/model/command_response.go
generated
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/utils/jsonutils"
|
||||
)
|
||||
|
||||
const (
|
||||
COMMAND_RESPONSE_TYPE_IN_CHANNEL = "in_channel"
|
||||
COMMAND_RESPONSE_TYPE_EPHEMERAL = "ephemeral"
|
||||
)
|
||||
|
||||
type CommandResponse struct {
|
||||
ResponseType string `json:"response_type"`
|
||||
Text string `json:"text"`
|
||||
Username string `json:"username"`
|
||||
IconURL string `json:"icon_url"`
|
||||
Type string `json:"type"`
|
||||
Props StringInterface `json:"props"`
|
||||
GotoLocation string `json:"goto_location"`
|
||||
Attachments []*SlackAttachment `json:"attachments"`
|
||||
}
|
||||
|
||||
func (o *CommandResponse) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func CommandResponseFromHTTPBody(contentType string, body io.Reader) (*CommandResponse, error) {
|
||||
if strings.TrimSpace(strings.Split(contentType, ";")[0]) == "application/json" {
|
||||
return CommandResponseFromJson(body)
|
||||
}
|
||||
if b, err := ioutil.ReadAll(body); err == nil {
|
||||
return CommandResponseFromPlainText(string(b)), nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func CommandResponseFromPlainText(text string) *CommandResponse {
|
||||
return &CommandResponse{
|
||||
Text: text,
|
||||
}
|
||||
}
|
||||
|
||||
func CommandResponseFromJson(data io.Reader) (*CommandResponse, error) {
|
||||
b, err := ioutil.ReadAll(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var o CommandResponse
|
||||
err = json.Unmarshal(b, &o)
|
||||
if err != nil {
|
||||
return nil, jsonutils.HumanizeJsonError(err, b)
|
||||
}
|
||||
|
||||
o.Attachments = StringifySlackFieldValue(o.Attachments)
|
||||
|
||||
return &o, nil
|
||||
}
|
65
build/manifest/vendor/github.com/mattermost/mattermost-server/model/command_webhook.go
generated
vendored
Normal file
65
build/manifest/vendor/github.com/mattermost/mattermost-server/model/command_webhook.go
generated
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CommandWebhook struct {
|
||||
Id string
|
||||
CreateAt int64
|
||||
CommandId string
|
||||
UserId string
|
||||
ChannelId string
|
||||
RootId string
|
||||
ParentId string
|
||||
UseCount int
|
||||
}
|
||||
|
||||
const (
|
||||
COMMAND_WEBHOOK_LIFETIME = 1000 * 60 * 30
|
||||
)
|
||||
|
||||
func (o *CommandWebhook) PreSave() {
|
||||
if o.Id == "" {
|
||||
o.Id = NewId()
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
o.CreateAt = GetMillis()
|
||||
}
|
||||
}
|
||||
|
||||
func (o *CommandWebhook) IsValid() *AppError {
|
||||
if len(o.Id) != 26 {
|
||||
return NewAppError("CommandWebhook.IsValid", "model.command_hook.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
return NewAppError("CommandWebhook.IsValid", "model.command_hook.create_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.CommandId) != 26 {
|
||||
return NewAppError("CommandWebhook.IsValid", "model.command_hook.command_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.UserId) != 26 {
|
||||
return NewAppError("CommandWebhook.IsValid", "model.command_hook.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.ChannelId) != 26 {
|
||||
return NewAppError("CommandWebhook.IsValid", "model.command_hook.channel_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.RootId) != 0 && len(o.RootId) != 26 {
|
||||
return NewAppError("CommandWebhook.IsValid", "model.command_hook.root_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.ParentId) != 0 && len(o.ParentId) != 26 {
|
||||
return NewAppError("CommandWebhook.IsValid", "model.command_hook.parent_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
119
build/manifest/vendor/github.com/mattermost/mattermost-server/model/compliance.go
generated
vendored
Normal file
119
build/manifest/vendor/github.com/mattermost/mattermost-server/model/compliance.go
generated
vendored
Normal file
|
@ -0,0 +1,119 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
COMPLIANCE_STATUS_CREATED = "created"
|
||||
COMPLIANCE_STATUS_RUNNING = "running"
|
||||
COMPLIANCE_STATUS_FINISHED = "finished"
|
||||
COMPLIANCE_STATUS_FAILED = "failed"
|
||||
COMPLIANCE_STATUS_REMOVED = "removed"
|
||||
|
||||
COMPLIANCE_TYPE_DAILY = "daily"
|
||||
COMPLIANCE_TYPE_ADHOC = "adhoc"
|
||||
)
|
||||
|
||||
type Compliance struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UserId string `json:"user_id"`
|
||||
Status string `json:"status"`
|
||||
Count int `json:"count"`
|
||||
Desc string `json:"desc"`
|
||||
Type string `json:"type"`
|
||||
StartAt int64 `json:"start_at"`
|
||||
EndAt int64 `json:"end_at"`
|
||||
Keywords string `json:"keywords"`
|
||||
Emails string `json:"emails"`
|
||||
}
|
||||
|
||||
type Compliances []Compliance
|
||||
|
||||
func (o *Compliance) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (me *Compliance) PreSave() {
|
||||
if me.Id == "" {
|
||||
me.Id = NewId()
|
||||
}
|
||||
|
||||
if me.Status == "" {
|
||||
me.Status = COMPLIANCE_STATUS_CREATED
|
||||
}
|
||||
|
||||
me.Count = 0
|
||||
me.Emails = NormalizeEmail(me.Emails)
|
||||
me.Keywords = strings.ToLower(me.Keywords)
|
||||
|
||||
me.CreateAt = GetMillis()
|
||||
}
|
||||
|
||||
func (me *Compliance) JobName() string {
|
||||
jobName := me.Type
|
||||
if me.Type == COMPLIANCE_TYPE_DAILY {
|
||||
jobName += "-" + me.Desc
|
||||
}
|
||||
|
||||
jobName += "-" + me.Id
|
||||
|
||||
return jobName
|
||||
}
|
||||
|
||||
func (me *Compliance) IsValid() *AppError {
|
||||
|
||||
if len(me.Id) != 26 {
|
||||
return NewAppError("Compliance.IsValid", "model.compliance.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if me.CreateAt == 0 {
|
||||
return NewAppError("Compliance.IsValid", "model.compliance.is_valid.create_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(me.Desc) > 512 || len(me.Desc) == 0 {
|
||||
return NewAppError("Compliance.IsValid", "model.compliance.is_valid.desc.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if me.StartAt == 0 {
|
||||
return NewAppError("Compliance.IsValid", "model.compliance.is_valid.start_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if me.EndAt == 0 {
|
||||
return NewAppError("Compliance.IsValid", "model.compliance.is_valid.end_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if me.EndAt <= me.StartAt {
|
||||
return NewAppError("Compliance.IsValid", "model.compliance.is_valid.start_end_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ComplianceFromJson(data io.Reader) *Compliance {
|
||||
var o *Compliance
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o Compliances) ToJson() string {
|
||||
if b, err := json.Marshal(o); err != nil {
|
||||
return "[]"
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func CompliancesFromJson(data io.Reader) Compliances {
|
||||
var o Compliances
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
117
build/manifest/vendor/github.com/mattermost/mattermost-server/model/compliance_post.go
generated
vendored
Normal file
117
build/manifest/vendor/github.com/mattermost/mattermost-server/model/compliance_post.go
generated
vendored
Normal file
|
@ -0,0 +1,117 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CompliancePost struct {
|
||||
|
||||
// From Team
|
||||
TeamName string
|
||||
TeamDisplayName string
|
||||
|
||||
// From Channel
|
||||
ChannelName string
|
||||
ChannelDisplayName string
|
||||
ChannelType string
|
||||
|
||||
// From User
|
||||
UserUsername string
|
||||
UserEmail string
|
||||
UserNickname string
|
||||
|
||||
// From Post
|
||||
PostId string
|
||||
PostCreateAt int64
|
||||
PostUpdateAt int64
|
||||
PostDeleteAt int64
|
||||
PostRootId string
|
||||
PostParentId string
|
||||
PostOriginalId string
|
||||
PostMessage string
|
||||
PostType string
|
||||
PostProps string
|
||||
PostHashtags string
|
||||
PostFileIds string
|
||||
}
|
||||
|
||||
func CompliancePostHeader() []string {
|
||||
return []string{
|
||||
"TeamName",
|
||||
"TeamDisplayName",
|
||||
|
||||
"ChannelName",
|
||||
"ChannelDisplayName",
|
||||
"ChannelType",
|
||||
|
||||
"UserUsername",
|
||||
"UserEmail",
|
||||
"UserNickname",
|
||||
|
||||
"PostId",
|
||||
"PostCreateAt",
|
||||
"PostUpdateAt",
|
||||
"PostDeleteAt",
|
||||
"PostRootId",
|
||||
"PostParentId",
|
||||
"PostOriginalId",
|
||||
"PostMessage",
|
||||
"PostType",
|
||||
"PostProps",
|
||||
"PostHashtags",
|
||||
"PostFileIds",
|
||||
}
|
||||
}
|
||||
|
||||
func cleanComplianceStrings(in string) string {
|
||||
if matched, _ := regexp.MatchString("^\\s*(=|\\+|\\-)", in); matched {
|
||||
return "'" + in
|
||||
|
||||
} else {
|
||||
return in
|
||||
}
|
||||
}
|
||||
|
||||
func (me *CompliancePost) Row() []string {
|
||||
|
||||
postDeleteAt := ""
|
||||
if me.PostDeleteAt > 0 {
|
||||
postDeleteAt = time.Unix(0, me.PostDeleteAt*int64(1000*1000)).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
postUpdateAt := ""
|
||||
if me.PostUpdateAt != me.PostCreateAt {
|
||||
postUpdateAt = time.Unix(0, me.PostUpdateAt*int64(1000*1000)).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
return []string{
|
||||
cleanComplianceStrings(me.TeamName),
|
||||
cleanComplianceStrings(me.TeamDisplayName),
|
||||
|
||||
cleanComplianceStrings(me.ChannelName),
|
||||
cleanComplianceStrings(me.ChannelDisplayName),
|
||||
cleanComplianceStrings(me.ChannelType),
|
||||
|
||||
cleanComplianceStrings(me.UserUsername),
|
||||
cleanComplianceStrings(me.UserEmail),
|
||||
cleanComplianceStrings(me.UserNickname),
|
||||
|
||||
me.PostId,
|
||||
time.Unix(0, me.PostCreateAt*int64(1000*1000)).Format(time.RFC3339),
|
||||
postUpdateAt,
|
||||
postDeleteAt,
|
||||
|
||||
me.PostRootId,
|
||||
me.PostParentId,
|
||||
me.PostOriginalId,
|
||||
cleanComplianceStrings(me.PostMessage),
|
||||
me.PostType,
|
||||
me.PostProps,
|
||||
me.PostHashtags,
|
||||
me.PostFileIds,
|
||||
}
|
||||
}
|
2533
build/manifest/vendor/github.com/mattermost/mattermost-server/model/config.go
generated
vendored
Normal file
2533
build/manifest/vendor/github.com/mattermost/mattermost-server/model/config.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
27
build/manifest/vendor/github.com/mattermost/mattermost-server/model/data_retention_policy.go
generated
vendored
Normal file
27
build/manifest/vendor/github.com/mattermost/mattermost-server/model/data_retention_policy.go
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type DataRetentionPolicy struct {
|
||||
MessageDeletionEnabled bool `json:"message_deletion_enabled"`
|
||||
FileDeletionEnabled bool `json:"file_deletion_enabled"`
|
||||
MessageRetentionCutoff int64 `json:"message_retention_cutoff"`
|
||||
FileRetentionCutoff int64 `json:"file_retention_cutoff"`
|
||||
}
|
||||
|
||||
func (me *DataRetentionPolicy) ToJson() string {
|
||||
b, _ := json.Marshal(me)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func DataRetentionPolicyFromJson(data io.Reader) *DataRetentionPolicy {
|
||||
var me *DataRetentionPolicy
|
||||
json.NewDecoder(data).Decode(&me)
|
||||
return me
|
||||
}
|
88
build/manifest/vendor/github.com/mattermost/mattermost-server/model/emoji.go
generated
vendored
Normal file
88
build/manifest/vendor/github.com/mattermost/mattermost-server/model/emoji.go
generated
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
EMOJI_NAME_MAX_LENGTH = 64
|
||||
EMOJI_SORT_BY_NAME = "name"
|
||||
)
|
||||
|
||||
type Emoji struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
CreatorId string `json:"creator_id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func inSystemEmoji(emojiName string) bool {
|
||||
_, ok := SystemEmojis[emojiName]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (emoji *Emoji) IsValid() *AppError {
|
||||
if len(emoji.Id) != 26 {
|
||||
return NewAppError("Emoji.IsValid", "model.emoji.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if emoji.CreateAt == 0 {
|
||||
return NewAppError("Emoji.IsValid", "model.emoji.create_at.app_error", nil, "id="+emoji.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if emoji.UpdateAt == 0 {
|
||||
return NewAppError("Emoji.IsValid", "model.emoji.update_at.app_error", nil, "id="+emoji.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(emoji.CreatorId) > 26 {
|
||||
return NewAppError("Emoji.IsValid", "model.emoji.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return IsValidEmojiName(emoji.Name)
|
||||
}
|
||||
|
||||
func IsValidEmojiName(name string) *AppError {
|
||||
if len(name) == 0 || len(name) > EMOJI_NAME_MAX_LENGTH || !IsValidAlphaNumHyphenUnderscore(name, false) || inSystemEmoji(name) {
|
||||
return NewAppError("Emoji.IsValid", "model.emoji.name.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (emoji *Emoji) PreSave() {
|
||||
if emoji.Id == "" {
|
||||
emoji.Id = NewId()
|
||||
}
|
||||
|
||||
emoji.CreateAt = GetMillis()
|
||||
emoji.UpdateAt = emoji.CreateAt
|
||||
}
|
||||
|
||||
func (emoji *Emoji) ToJson() string {
|
||||
b, _ := json.Marshal(emoji)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func EmojiFromJson(data io.Reader) *Emoji {
|
||||
var emoji *Emoji
|
||||
json.NewDecoder(data).Decode(&emoji)
|
||||
return emoji
|
||||
}
|
||||
|
||||
func EmojiListToJson(emojiList []*Emoji) string {
|
||||
b, _ := json.Marshal(emojiList)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func EmojiListFromJson(data io.Reader) []*Emoji {
|
||||
var emojiList []*Emoji
|
||||
json.NewDecoder(data).Decode(&emojiList)
|
||||
return emojiList
|
||||
}
|
6
build/manifest/vendor/github.com/mattermost/mattermost-server/model/emoji_data.go
generated
vendored
Normal file
6
build/manifest/vendor/github.com/mattermost/mattermost-server/model/emoji_data.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
25
build/manifest/vendor/github.com/mattermost/mattermost-server/model/emoji_search.go
generated
vendored
Normal file
25
build/manifest/vendor/github.com/mattermost/mattermost-server/model/emoji_search.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type EmojiSearch struct {
|
||||
Term string `json:"term"`
|
||||
PrefixOnly bool `json:"prefix_only"`
|
||||
}
|
||||
|
||||
func (es *EmojiSearch) ToJson() string {
|
||||
b, _ := json.Marshal(es)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func EmojiSearchFromJson(data io.Reader) *EmojiSearch {
|
||||
var es *EmojiSearch
|
||||
json.NewDecoder(data).Decode(&es)
|
||||
return es
|
||||
}
|
34
build/manifest/vendor/github.com/mattermost/mattermost-server/model/file.go
generated
vendored
Normal file
34
build/manifest/vendor/github.com/mattermost/mattermost-server/model/file.go
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxImageSize = 6048 * 4032 // 24 megapixels, roughly 36MB as a raw image
|
||||
)
|
||||
|
||||
var (
|
||||
IMAGE_EXTENSIONS = [5]string{".jpg", ".jpeg", ".gif", ".bmp", ".png"}
|
||||
IMAGE_MIME_TYPES = map[string]string{".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".bmp": "image/bmp", ".png": "image/png", ".tiff": "image/tiff"}
|
||||
)
|
||||
|
||||
type FileUploadResponse struct {
|
||||
FileInfos []*FileInfo `json:"file_infos"`
|
||||
ClientIds []string `json:"client_ids"`
|
||||
}
|
||||
|
||||
func FileUploadResponseFromJson(data io.Reader) *FileUploadResponse {
|
||||
var o *FileUploadResponse
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *FileUploadResponse) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
170
build/manifest/vendor/github.com/mattermost/mattermost-server/model/file_info.go
generated
vendored
Normal file
170
build/manifest/vendor/github.com/mattermost/mattermost-server/model/file_info.go
generated
vendored
Normal file
|
@ -0,0 +1,170 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"image"
|
||||
"image/gif"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type FileInfo struct {
|
||||
Id string `json:"id"`
|
||||
CreatorId string `json:"user_id"`
|
||||
PostId string `json:"post_id,omitempty"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
Path string `json:"-"` // not sent back to the client
|
||||
ThumbnailPath string `json:"-"` // not sent back to the client
|
||||
PreviewPath string `json:"-"` // not sent back to the client
|
||||
Name string `json:"name"`
|
||||
Extension string `json:"extension"`
|
||||
Size int64 `json:"size"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Width int `json:"width,omitempty"`
|
||||
Height int `json:"height,omitempty"`
|
||||
HasPreviewImage bool `json:"has_preview_image,omitempty"`
|
||||
}
|
||||
|
||||
func (info *FileInfo) ToJson() string {
|
||||
b, _ := json.Marshal(info)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func FileInfoFromJson(data io.Reader) *FileInfo {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var info FileInfo
|
||||
if err := decoder.Decode(&info); err != nil {
|
||||
return nil
|
||||
} else {
|
||||
return &info
|
||||
}
|
||||
}
|
||||
|
||||
func FileInfosToJson(infos []*FileInfo) string {
|
||||
b, _ := json.Marshal(infos)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func FileInfosFromJson(data io.Reader) []*FileInfo {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var infos []*FileInfo
|
||||
if err := decoder.Decode(&infos); err != nil {
|
||||
return nil
|
||||
} else {
|
||||
return infos
|
||||
}
|
||||
}
|
||||
|
||||
func (o *FileInfo) PreSave() {
|
||||
if o.Id == "" {
|
||||
o.Id = NewId()
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
o.CreateAt = GetMillis()
|
||||
}
|
||||
|
||||
if o.UpdateAt < o.CreateAt {
|
||||
o.UpdateAt = o.CreateAt
|
||||
}
|
||||
}
|
||||
|
||||
func (o *FileInfo) IsValid() *AppError {
|
||||
if len(o.Id) != 26 {
|
||||
return NewAppError("FileInfo.IsValid", "model.file_info.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.CreatorId) != 26 {
|
||||
return NewAppError("FileInfo.IsValid", "model.file_info.is_valid.user_id.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.PostId) != 0 && len(o.PostId) != 26 {
|
||||
return NewAppError("FileInfo.IsValid", "model.file_info.is_valid.post_id.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
return NewAppError("FileInfo.IsValid", "model.file_info.is_valid.create_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.UpdateAt == 0 {
|
||||
return NewAppError("FileInfo.IsValid", "model.file_info.is_valid.update_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.Path == "" {
|
||||
return NewAppError("FileInfo.IsValid", "model.file_info.is_valid.path.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *FileInfo) IsImage() bool {
|
||||
return strings.HasPrefix(o.MimeType, "image")
|
||||
}
|
||||
|
||||
func GetInfoForBytes(name string, data []byte) (*FileInfo, *AppError) {
|
||||
info := &FileInfo{
|
||||
Name: name,
|
||||
Size: int64(len(data)),
|
||||
}
|
||||
var err *AppError
|
||||
|
||||
extension := strings.ToLower(filepath.Ext(name))
|
||||
info.MimeType = mime.TypeByExtension(extension)
|
||||
|
||||
if extension != "" && extension[0] == '.' {
|
||||
// The client expects a file extension without the leading period
|
||||
info.Extension = extension[1:]
|
||||
} else {
|
||||
info.Extension = extension
|
||||
}
|
||||
|
||||
if info.IsImage() {
|
||||
// Only set the width and height if it's actually an image that we can understand
|
||||
if config, _, err := image.DecodeConfig(bytes.NewReader(data)); err == nil {
|
||||
info.Width = config.Width
|
||||
info.Height = config.Height
|
||||
|
||||
if info.MimeType == "image/gif" {
|
||||
// Just show the gif itself instead of a preview image for animated gifs
|
||||
if gifConfig, err := gif.DecodeAll(bytes.NewReader(data)); err != nil {
|
||||
// Still return the rest of the info even though it doesn't appear to be an actual gif
|
||||
info.HasPreviewImage = true
|
||||
err = NewAppError("GetInfoForBytes", "model.file_info.get.gif.app_error", nil, "name="+name, http.StatusBadRequest)
|
||||
} else {
|
||||
info.HasPreviewImage = len(gifConfig.Image) == 1
|
||||
}
|
||||
} else {
|
||||
info.HasPreviewImage = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return info, err
|
||||
}
|
||||
|
||||
func GetEtagForFileInfos(infos []*FileInfo) string {
|
||||
if len(infos) == 0 {
|
||||
return Etag()
|
||||
}
|
||||
|
||||
var maxUpdateAt int64
|
||||
|
||||
for _, info := range infos {
|
||||
if info.UpdateAt > maxUpdateAt {
|
||||
maxUpdateAt = info.UpdateAt
|
||||
}
|
||||
}
|
||||
|
||||
return Etag(infos[0].PostId, maxUpdateAt)
|
||||
}
|
8
build/manifest/vendor/github.com/mattermost/mattermost-server/model/gitlab.go
generated
vendored
Normal file
8
build/manifest/vendor/github.com/mattermost/mattermost-server/model/gitlab.go
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
const (
|
||||
USER_AUTH_SERVICE_GITLAB = "gitlab"
|
||||
)
|
216
build/manifest/vendor/github.com/mattermost/mattermost-server/model/incoming_webhook.go
generated
vendored
Normal file
216
build/manifest/vendor/github.com/mattermost/mattermost-server/model/incoming_webhook.go
generated
vendored
Normal file
|
@ -0,0 +1,216 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_WEBHOOK_USERNAME = "webhook"
|
||||
)
|
||||
|
||||
type IncomingWebhook struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
UserId string `json:"user_id"`
|
||||
ChannelId string `json:"channel_id"`
|
||||
TeamId string `json:"team_id"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
Username string `json:"username"`
|
||||
IconURL string `json:"icon_url"`
|
||||
ChannelLocked bool `json:"channel_locked"`
|
||||
}
|
||||
|
||||
type IncomingWebhookRequest struct {
|
||||
Text string `json:"text"`
|
||||
Username string `json:"username"`
|
||||
IconURL string `json:"icon_url"`
|
||||
ChannelName string `json:"channel"`
|
||||
Props StringInterface `json:"props"`
|
||||
Attachments []*SlackAttachment `json:"attachments"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
func (o *IncomingWebhook) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func IncomingWebhookFromJson(data io.Reader) *IncomingWebhook {
|
||||
var o *IncomingWebhook
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func IncomingWebhookListToJson(l []*IncomingWebhook) string {
|
||||
b, _ := json.Marshal(l)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func IncomingWebhookListFromJson(data io.Reader) []*IncomingWebhook {
|
||||
var o []*IncomingWebhook
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *IncomingWebhook) IsValid() *AppError {
|
||||
|
||||
if len(o.Id) != 26 {
|
||||
return NewAppError("IncomingWebhook.IsValid", "model.incoming_hook.id.app_error", nil, "", http.StatusBadRequest)
|
||||
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
return NewAppError("IncomingWebhook.IsValid", "model.incoming_hook.create_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.UpdateAt == 0 {
|
||||
return NewAppError("IncomingWebhook.IsValid", "model.incoming_hook.update_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.UserId) != 26 {
|
||||
return NewAppError("IncomingWebhook.IsValid", "model.incoming_hook.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.ChannelId) != 26 {
|
||||
return NewAppError("IncomingWebhook.IsValid", "model.incoming_hook.channel_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.TeamId) != 26 {
|
||||
return NewAppError("IncomingWebhook.IsValid", "model.incoming_hook.team_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.DisplayName) > 64 {
|
||||
return NewAppError("IncomingWebhook.IsValid", "model.incoming_hook.display_name.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Description) > 128 {
|
||||
return NewAppError("IncomingWebhook.IsValid", "model.incoming_hook.description.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Username) > 64 {
|
||||
return NewAppError("IncomingWebhook.IsValid", "model.incoming_hook.username.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.IconURL) > 1024 {
|
||||
return NewAppError("IncomingWebhook.IsValid", "model.incoming_hook.icon_url.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *IncomingWebhook) PreSave() {
|
||||
if o.Id == "" {
|
||||
o.Id = NewId()
|
||||
}
|
||||
|
||||
o.CreateAt = GetMillis()
|
||||
o.UpdateAt = o.CreateAt
|
||||
}
|
||||
|
||||
func (o *IncomingWebhook) PreUpdate() {
|
||||
o.UpdateAt = GetMillis()
|
||||
}
|
||||
|
||||
// escapeControlCharsFromPayload escapes control chars (\n, \t) from a byte slice.
|
||||
// Context:
|
||||
// JSON strings are not supposed to contain control characters such as \n, \t,
|
||||
// ... but some incoming webhooks might still send invalid JSON and we want to
|
||||
// try to handle that. An example invalid JSON string from an incoming webhook
|
||||
// might look like this (strings for both "text" and "fallback" attributes are
|
||||
// invalid JSON strings because they contain unescaped newlines and tabs):
|
||||
// `{
|
||||
// "text": "this is a test
|
||||
// that contains a newline and tabs",
|
||||
// "attachments": [
|
||||
// {
|
||||
// "fallback": "Required plain-text summary of the attachment
|
||||
// that contains a newline and tabs",
|
||||
// "color": "#36a64f",
|
||||
// ...
|
||||
// "text": "Optional text that appears within the attachment
|
||||
// that contains a newline and tabs",
|
||||
// ...
|
||||
// "thumb_url": "http://example.com/path/to/thumb.png"
|
||||
// }
|
||||
// ]
|
||||
// }`
|
||||
// This function will search for `"key": "value"` pairs, and escape \n, \t
|
||||
// from the value.
|
||||
func escapeControlCharsFromPayload(by []byte) []byte {
|
||||
// we'll search for `"text": "..."` or `"fallback": "..."`, ...
|
||||
keys := "text|fallback|pretext|author_name|title|value"
|
||||
|
||||
// the regexp reads like this:
|
||||
// (?s): this flag let . match \n (default is false)
|
||||
// "(keys)": we search for the keys defined above
|
||||
// \s*:\s*: followed by 0..n spaces/tabs, a colon then 0..n spaces/tabs
|
||||
// ": a double-quote
|
||||
// (\\"|[^"])*: any number of times the `\"` string or any char but a double-quote
|
||||
// ": a double-quote
|
||||
r := `(?s)"(` + keys + `)"\s*:\s*"(\\"|[^"])*"`
|
||||
re := regexp.MustCompile(r)
|
||||
|
||||
// the function that will escape \n and \t on the regexp matches
|
||||
repl := func(b []byte) []byte {
|
||||
if bytes.Contains(b, []byte("\n")) {
|
||||
b = bytes.Replace(b, []byte("\n"), []byte("\\n"), -1)
|
||||
}
|
||||
if bytes.Contains(b, []byte("\t")) {
|
||||
b = bytes.Replace(b, []byte("\t"), []byte("\\t"), -1)
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
return re.ReplaceAllFunc(by, repl)
|
||||
}
|
||||
|
||||
func decodeIncomingWebhookRequest(by []byte) (*IncomingWebhookRequest, error) {
|
||||
decoder := json.NewDecoder(bytes.NewReader(by))
|
||||
var o IncomingWebhookRequest
|
||||
err := decoder.Decode(&o)
|
||||
if err == nil {
|
||||
return &o, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func IncomingWebhookRequestFromJson(data io.Reader) (*IncomingWebhookRequest, *AppError) {
|
||||
buf := new(bytes.Buffer)
|
||||
buf.ReadFrom(data)
|
||||
by := buf.Bytes()
|
||||
|
||||
// Try to decode the JSON data. Only if it fails, try to escape control
|
||||
// characters from the strings contained in the JSON data.
|
||||
o, err := decodeIncomingWebhookRequest(by)
|
||||
if err != nil {
|
||||
o, err = decodeIncomingWebhookRequest(escapeControlCharsFromPayload(by))
|
||||
if err != nil {
|
||||
return nil, NewAppError("IncomingWebhookRequestFromJson", "model.incoming_hook.parse_data.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
o.Attachments = StringifySlackFieldValue(o.Attachments)
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
func (o *IncomingWebhookRequest) ToJson() string {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
return ""
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
30
build/manifest/vendor/github.com/mattermost/mattermost-server/model/initial_load.go
generated
vendored
Normal file
30
build/manifest/vendor/github.com/mattermost/mattermost-server/model/initial_load.go
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type InitialLoad struct {
|
||||
User *User `json:"user"`
|
||||
TeamMembers []*TeamMember `json:"team_members"`
|
||||
Teams []*Team `json:"teams"`
|
||||
Preferences Preferences `json:"preferences"`
|
||||
ClientCfg map[string]string `json:"client_cfg"`
|
||||
LicenseCfg map[string]string `json:"license_cfg"`
|
||||
NoAccounts bool `json:"no_accounts"`
|
||||
}
|
||||
|
||||
func (me *InitialLoad) ToJson() string {
|
||||
b, _ := json.Marshal(me)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func InitialLoadFromJson(data io.Reader) *InitialLoad {
|
||||
var o *InitialLoad
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
120
build/manifest/vendor/github.com/mattermost/mattermost-server/model/job.go
generated
vendored
Normal file
120
build/manifest/vendor/github.com/mattermost/mattermost-server/model/job.go
generated
vendored
Normal file
|
@ -0,0 +1,120 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
JOB_TYPE_DATA_RETENTION = "data_retention"
|
||||
JOB_TYPE_MESSAGE_EXPORT = "message_export"
|
||||
JOB_TYPE_ELASTICSEARCH_POST_INDEXING = "elasticsearch_post_indexing"
|
||||
JOB_TYPE_ELASTICSEARCH_POST_AGGREGATION = "elasticsearch_post_aggregation"
|
||||
JOB_TYPE_LDAP_SYNC = "ldap_sync"
|
||||
JOB_TYPE_MIGRATIONS = "migrations"
|
||||
|
||||
JOB_STATUS_PENDING = "pending"
|
||||
JOB_STATUS_IN_PROGRESS = "in_progress"
|
||||
JOB_STATUS_SUCCESS = "success"
|
||||
JOB_STATUS_ERROR = "error"
|
||||
JOB_STATUS_CANCEL_REQUESTED = "cancel_requested"
|
||||
JOB_STATUS_CANCELED = "canceled"
|
||||
)
|
||||
|
||||
type Job struct {
|
||||
Id string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Priority int64 `json:"priority"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
StartAt int64 `json:"start_at"`
|
||||
LastActivityAt int64 `json:"last_activity_at"`
|
||||
Status string `json:"status"`
|
||||
Progress int64 `json:"progress"`
|
||||
Data map[string]string `json:"data"`
|
||||
}
|
||||
|
||||
func (j *Job) IsValid() *AppError {
|
||||
if len(j.Id) != 26 {
|
||||
return NewAppError("Job.IsValid", "model.job.is_valid.id.app_error", nil, "id="+j.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if j.CreateAt == 0 {
|
||||
return NewAppError("Job.IsValid", "model.job.is_valid.create_at.app_error", nil, "id="+j.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
switch j.Type {
|
||||
case JOB_TYPE_DATA_RETENTION:
|
||||
case JOB_TYPE_ELASTICSEARCH_POST_INDEXING:
|
||||
case JOB_TYPE_ELASTICSEARCH_POST_AGGREGATION:
|
||||
case JOB_TYPE_LDAP_SYNC:
|
||||
case JOB_TYPE_MESSAGE_EXPORT:
|
||||
case JOB_TYPE_MIGRATIONS:
|
||||
default:
|
||||
return NewAppError("Job.IsValid", "model.job.is_valid.type.app_error", nil, "id="+j.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
switch j.Status {
|
||||
case JOB_STATUS_PENDING:
|
||||
case JOB_STATUS_IN_PROGRESS:
|
||||
case JOB_STATUS_SUCCESS:
|
||||
case JOB_STATUS_ERROR:
|
||||
case JOB_STATUS_CANCEL_REQUESTED:
|
||||
case JOB_STATUS_CANCELED:
|
||||
default:
|
||||
return NewAppError("Job.IsValid", "model.job.is_valid.status.app_error", nil, "id="+j.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (js *Job) ToJson() string {
|
||||
b, _ := json.Marshal(js)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func JobFromJson(data io.Reader) *Job {
|
||||
var job Job
|
||||
if err := json.NewDecoder(data).Decode(&job); err == nil {
|
||||
return &job
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func JobsToJson(jobs []*Job) string {
|
||||
b, _ := json.Marshal(jobs)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func JobsFromJson(data io.Reader) []*Job {
|
||||
var jobs []*Job
|
||||
if err := json.NewDecoder(data).Decode(&jobs); err == nil {
|
||||
return jobs
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (js *Job) DataToJson() string {
|
||||
b, _ := json.Marshal(js.Data)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
type Worker interface {
|
||||
Run()
|
||||
Stop()
|
||||
JobChannel() chan<- Job
|
||||
}
|
||||
|
||||
type Scheduler interface {
|
||||
Name() string
|
||||
JobType() string
|
||||
Enabled(cfg *Config) bool
|
||||
NextScheduleTime(cfg *Config, now time.Time, pendingJobs bool, lastSuccessfulJob *Job) *time.Time
|
||||
ScheduleJob(cfg *Config, pendingJobs bool, lastSuccessfulJob *Job) (*Job, *AppError)
|
||||
}
|
8
build/manifest/vendor/github.com/mattermost/mattermost-server/model/ldap.go
generated
vendored
Normal file
8
build/manifest/vendor/github.com/mattermost/mattermost-server/model/ldap.go
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
const (
|
||||
USER_AUTH_SERVICE_LDAP = "ldap"
|
||||
)
|
213
build/manifest/vendor/github.com/mattermost/mattermost-server/model/license.go
generated
vendored
Normal file
213
build/manifest/vendor/github.com/mattermost/mattermost-server/model/license.go
generated
vendored
Normal file
|
@ -0,0 +1,213 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
EXPIRED_LICENSE_ERROR = "api.license.add_license.expired.app_error"
|
||||
INVALID_LICENSE_ERROR = "api.license.add_license.invalid.app_error"
|
||||
)
|
||||
|
||||
type LicenseRecord struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
Bytes string `json:"-"`
|
||||
}
|
||||
|
||||
type License struct {
|
||||
Id string `json:"id"`
|
||||
IssuedAt int64 `json:"issued_at"`
|
||||
StartsAt int64 `json:"starts_at"`
|
||||
ExpiresAt int64 `json:"expires_at"`
|
||||
Customer *Customer `json:"customer"`
|
||||
Features *Features `json:"features"`
|
||||
}
|
||||
|
||||
type Customer struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Company string `json:"company"`
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
}
|
||||
|
||||
type Features struct {
|
||||
Users *int `json:"users"`
|
||||
LDAP *bool `json:"ldap"`
|
||||
MFA *bool `json:"mfa"`
|
||||
GoogleOAuth *bool `json:"google_oauth"`
|
||||
Office365OAuth *bool `json:"office365_oauth"`
|
||||
Compliance *bool `json:"compliance"`
|
||||
Cluster *bool `json:"cluster"`
|
||||
Metrics *bool `json:"metrics"`
|
||||
MHPNS *bool `json:"mhpns"`
|
||||
SAML *bool `json:"saml"`
|
||||
Elasticsearch *bool `json:"elastic_search"`
|
||||
Announcement *bool `json:"announcement"`
|
||||
ThemeManagement *bool `json:"theme_management"`
|
||||
EmailNotificationContents *bool `json:"email_notification_contents"`
|
||||
DataRetention *bool `json:"data_retention"`
|
||||
MessageExport *bool `json:"message_export"`
|
||||
CustomPermissionsSchemes *bool `json:"custom_permissions_schemes"`
|
||||
|
||||
// after we enabled more features for webrtc we'll need to control them with this
|
||||
FutureFeatures *bool `json:"future_features"`
|
||||
}
|
||||
|
||||
func (f *Features) ToMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"ldap": *f.LDAP,
|
||||
"mfa": *f.MFA,
|
||||
"google": *f.GoogleOAuth,
|
||||
"office365": *f.Office365OAuth,
|
||||
"compliance": *f.Compliance,
|
||||
"cluster": *f.Cluster,
|
||||
"metrics": *f.Metrics,
|
||||
"mhpns": *f.MHPNS,
|
||||
"saml": *f.SAML,
|
||||
"elastic_search": *f.Elasticsearch,
|
||||
"email_notification_contents": *f.EmailNotificationContents,
|
||||
"data_retention": *f.DataRetention,
|
||||
"message_export": *f.MessageExport,
|
||||
"custom_permissions_schemes": *f.CustomPermissionsSchemes,
|
||||
"future": *f.FutureFeatures,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Features) SetDefaults() {
|
||||
if f.FutureFeatures == nil {
|
||||
f.FutureFeatures = NewBool(true)
|
||||
}
|
||||
|
||||
if f.Users == nil {
|
||||
f.Users = NewInt(0)
|
||||
}
|
||||
|
||||
if f.LDAP == nil {
|
||||
f.LDAP = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.MFA == nil {
|
||||
f.MFA = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.GoogleOAuth == nil {
|
||||
f.GoogleOAuth = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.Office365OAuth == nil {
|
||||
f.Office365OAuth = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.Compliance == nil {
|
||||
f.Compliance = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.Cluster == nil {
|
||||
f.Cluster = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.Metrics == nil {
|
||||
f.Metrics = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.MHPNS == nil {
|
||||
f.MHPNS = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.SAML == nil {
|
||||
f.SAML = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.Elasticsearch == nil {
|
||||
f.Elasticsearch = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.Announcement == nil {
|
||||
f.Announcement = NewBool(true)
|
||||
}
|
||||
|
||||
if f.ThemeManagement == nil {
|
||||
f.ThemeManagement = NewBool(true)
|
||||
}
|
||||
|
||||
if f.EmailNotificationContents == nil {
|
||||
f.EmailNotificationContents = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.DataRetention == nil {
|
||||
f.DataRetention = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.MessageExport == nil {
|
||||
f.MessageExport = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.CustomPermissionsSchemes == nil {
|
||||
f.CustomPermissionsSchemes = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *License) IsExpired() bool {
|
||||
return l.ExpiresAt < GetMillis()
|
||||
}
|
||||
|
||||
func (l *License) IsStarted() bool {
|
||||
return l.StartsAt < GetMillis()
|
||||
}
|
||||
|
||||
func (l *License) ToJson() string {
|
||||
b, _ := json.Marshal(l)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// NewTestLicense returns a license that expires in the future and has the given features.
|
||||
func NewTestLicense(features ...string) *License {
|
||||
ret := &License{
|
||||
ExpiresAt: GetMillis() + 90*24*60*60*1000,
|
||||
Customer: &Customer{},
|
||||
Features: &Features{},
|
||||
}
|
||||
ret.Features.SetDefaults()
|
||||
|
||||
featureMap := map[string]bool{}
|
||||
for _, feature := range features {
|
||||
featureMap[feature] = true
|
||||
}
|
||||
featureJson, _ := json.Marshal(featureMap)
|
||||
json.Unmarshal(featureJson, &ret.Features)
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func LicenseFromJson(data io.Reader) *License {
|
||||
var o *License
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (lr *LicenseRecord) IsValid() *AppError {
|
||||
if len(lr.Id) != 26 {
|
||||
return NewAppError("LicenseRecord.IsValid", "model.license_record.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if lr.CreateAt == 0 {
|
||||
return NewAppError("LicenseRecord.IsValid", "model.license_record.is_valid.create_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(lr.Bytes) == 0 || len(lr.Bytes) > 10000 {
|
||||
return NewAppError("LicenseRecord.IsValid", "model.license_record.is_valid.create_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lr *LicenseRecord) PreSave() {
|
||||
lr.CreateAt = GetMillis()
|
||||
}
|
290
build/manifest/vendor/github.com/mattermost/mattermost-server/model/manifest.go
generated
vendored
Normal file
290
build/manifest/vendor/github.com/mattermost/mattermost-server/model/manifest.go
generated
vendored
Normal file
|
@ -0,0 +1,290 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type PluginOption struct {
|
||||
// The display name for the option.
|
||||
DisplayName string `json:"display_name" yaml:"display_name"`
|
||||
|
||||
// The string value for the option.
|
||||
Value string `json:"value" yaml:"value"`
|
||||
}
|
||||
|
||||
type PluginSetting struct {
|
||||
// The key that the setting will be assigned to in the configuration file.
|
||||
Key string `json:"key" yaml:"key"`
|
||||
|
||||
// The display name for the setting.
|
||||
DisplayName string `json:"display_name" yaml:"display_name"`
|
||||
|
||||
// The type of the setting.
|
||||
//
|
||||
// "bool" will result in a boolean true or false setting.
|
||||
//
|
||||
// "dropdown" will result in a string setting that allows the user to select from a list of
|
||||
// pre-defined options.
|
||||
//
|
||||
// "generated" will result in a string setting that is set to a random, cryptographically secure
|
||||
// string.
|
||||
//
|
||||
// "radio" will result in a string setting that allows the user to select from a short selection
|
||||
// of pre-defined options.
|
||||
//
|
||||
// "text" will result in a string setting that can be typed in manually.
|
||||
//
|
||||
// "username" will result in a text setting that will autocomplete to a username.
|
||||
Type string `json:"type" yaml:"type"`
|
||||
|
||||
// The help text to display to the user.
|
||||
HelpText string `json:"help_text" yaml:"help_text"`
|
||||
|
||||
// The help text to display alongside the "Regenerate" button for settings of the "generated" type.
|
||||
RegenerateHelpText string `json:"regenerate_help_text,omitempty" yaml:"regenerate_help_text,omitempty"`
|
||||
|
||||
// The placeholder to display for "text", "generated" and "username" types when blank.
|
||||
Placeholder string `json:"placeholder" yaml:"placeholder"`
|
||||
|
||||
// The default value of the setting.
|
||||
Default interface{} `json:"default" yaml:"default"`
|
||||
|
||||
// For "radio" or "dropdown" settings, this is the list of pre-defined options that the user can choose
|
||||
// from.
|
||||
Options []*PluginOption `json:"options,omitempty" yaml:"options,omitempty"`
|
||||
}
|
||||
|
||||
type PluginSettingsSchema struct {
|
||||
// Optional text to display above the settings.
|
||||
Header string `json:"header" yaml:"header"`
|
||||
|
||||
// Optional text to display below the settings.
|
||||
Footer string `json:"footer" yaml:"footer"`
|
||||
|
||||
// A list of setting definitions.
|
||||
Settings []*PluginSetting `json:"settings" yaml:"settings"`
|
||||
}
|
||||
|
||||
// The plugin manifest defines the metadata required to load and present your plugin. The manifest
|
||||
// file should be named plugin.json or plugin.yaml and placed in the top of your
|
||||
// plugin bundle.
|
||||
//
|
||||
// Example plugin.yaml:
|
||||
//
|
||||
// id: com.mycompany.myplugin
|
||||
// name: My Plugin
|
||||
// description: This is my plugin. It does stuff.
|
||||
// server:
|
||||
// executable: myplugin
|
||||
// settings_schema:
|
||||
// settings:
|
||||
// - key: enable_extra_thing
|
||||
// type: bool
|
||||
// display_name: Enable Extra Thing
|
||||
// help_text: When true, an extra thing will be enabled!
|
||||
// default: false
|
||||
type Manifest struct {
|
||||
// The id is a globally unique identifier that represents your plugin. Ids must be at least
|
||||
// 3 characters, at most 190 characters and must match ^[a-zA-Z0-9-_\.]+$.
|
||||
// Reverse-DNS notation using a name you control is a good option, e.g. "com.mycompany.myplugin".
|
||||
Id string `json:"id" yaml:"id"`
|
||||
|
||||
// The name to be displayed for the plugin.
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
|
||||
// A description of what your plugin is and does.
|
||||
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
||||
|
||||
// A version number for your plugin. Semantic versioning is recommended: http://semver.org
|
||||
Version string `json:"version" yaml:"version"`
|
||||
|
||||
// Server defines the server-side portion of your plugin.
|
||||
Server *ManifestServer `json:"server,omitempty" yaml:"server,omitempty"`
|
||||
|
||||
// Backend is a deprecated flag for defining the server-side portion of your plugin. Going forward, use Server instead.
|
||||
Backend *ManifestServer `json:"backend,omitempty" yaml:"backend,omitempty"`
|
||||
|
||||
// If your plugin extends the web app, you'll need to define webapp.
|
||||
Webapp *ManifestWebapp `json:"webapp,omitempty" yaml:"webapp,omitempty"`
|
||||
|
||||
// To allow administrators to configure your plugin via the Mattermost system console, you can
|
||||
// provide your settings schema.
|
||||
SettingsSchema *PluginSettingsSchema `json:"settings_schema,omitempty" yaml:"settings_schema,omitempty"`
|
||||
}
|
||||
|
||||
type ManifestServer struct {
|
||||
// Executables are the paths to your executable binaries, specifying multiple entry points
|
||||
// for different platforms when bundled together in a single plugin.
|
||||
Executables *ManifestExecutables `json:"executables,omitempty" yaml:"executables,omitempty"`
|
||||
|
||||
// Executable is the path to your executable binary. This should be relative to the root
|
||||
// of your bundle and the location of the manifest file.
|
||||
//
|
||||
// On Windows, this file must have a ".exe" extension.
|
||||
//
|
||||
// If your plugin is compiled for multiple platforms, consider bundling them together
|
||||
// and using the Executables field instead.
|
||||
Executable string `json:"executable" yaml:"executable"`
|
||||
}
|
||||
|
||||
type ManifestExecutables struct {
|
||||
// LinuxAmd64 is the path to your executable binary for the corresponding platform
|
||||
LinuxAmd64 string `json:"linux-amd64,omitempty" yaml:"linux-amd64,omitempty"`
|
||||
// DarwinAmd64 is the path to your executable binary for the corresponding platform
|
||||
DarwinAmd64 string `json:"darwin-amd64,omitempty" yaml:"darwin-amd64,omitempty"`
|
||||
// WindowsAmd64 is the path to your executable binary for the corresponding platform
|
||||
// This file must have a ".exe" extension
|
||||
WindowsAmd64 string `json:"windows-amd64,omitempty" yaml:"windows-amd64,omitempty"`
|
||||
}
|
||||
|
||||
type ManifestWebapp struct {
|
||||
// The path to your webapp bundle. This should be relative to the root of your bundle and the
|
||||
// location of the manifest file.
|
||||
BundlePath string `json:"bundle_path" yaml:"bundle_path"`
|
||||
}
|
||||
|
||||
func (m *Manifest) ToJson() string {
|
||||
b, _ := json.Marshal(m)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ManifestListToJson(m []*Manifest) string {
|
||||
b, _ := json.Marshal(m)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ManifestFromJson(data io.Reader) *Manifest {
|
||||
var m *Manifest
|
||||
json.NewDecoder(data).Decode(&m)
|
||||
return m
|
||||
}
|
||||
|
||||
func ManifestListFromJson(data io.Reader) []*Manifest {
|
||||
var manifests []*Manifest
|
||||
json.NewDecoder(data).Decode(&manifests)
|
||||
return manifests
|
||||
}
|
||||
|
||||
func (m *Manifest) HasClient() bool {
|
||||
return m.Webapp != nil
|
||||
}
|
||||
|
||||
func (m *Manifest) ClientManifest() *Manifest {
|
||||
cm := new(Manifest)
|
||||
*cm = *m
|
||||
cm.Name = ""
|
||||
cm.Description = ""
|
||||
cm.Server = nil
|
||||
if cm.Webapp != nil {
|
||||
cm.Webapp = new(ManifestWebapp)
|
||||
*cm.Webapp = *m.Webapp
|
||||
cm.Webapp.BundlePath = "/static/" + m.Id + "_bundle.js"
|
||||
}
|
||||
return cm
|
||||
}
|
||||
|
||||
// GetExecutableForRuntime returns the path to the executable for the given runtime architecture.
|
||||
//
|
||||
// If the manifest defines multiple executables, but none match, or if only a single executable
|
||||
// is defined, the Executable field will be returned. This method does not guarantee that the
|
||||
// resulting binary can actually execute on the given platform.
|
||||
func (m *Manifest) GetExecutableForRuntime(goOs, goArch string) string {
|
||||
server := m.Server
|
||||
|
||||
// Support the deprecated backend parameter.
|
||||
if server == nil {
|
||||
server = m.Backend
|
||||
}
|
||||
|
||||
if server == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
var executable string
|
||||
if server.Executables != nil {
|
||||
if goOs == "linux" && goArch == "amd64" {
|
||||
executable = server.Executables.LinuxAmd64
|
||||
} else if goOs == "darwin" && goArch == "amd64" {
|
||||
executable = server.Executables.DarwinAmd64
|
||||
} else if goOs == "windows" && goArch == "amd64" {
|
||||
executable = server.Executables.WindowsAmd64
|
||||
}
|
||||
}
|
||||
|
||||
if executable == "" {
|
||||
executable = server.Executable
|
||||
}
|
||||
|
||||
return executable
|
||||
}
|
||||
|
||||
func (m *Manifest) HasServer() bool {
|
||||
return m.Server != nil || m.Backend != nil
|
||||
}
|
||||
|
||||
func (m *Manifest) HasWebapp() bool {
|
||||
return m.Webapp != nil
|
||||
}
|
||||
|
||||
// FindManifest will find and parse the manifest in a given directory.
|
||||
//
|
||||
// In all cases other than a does-not-exist error, path is set to the path of the manifest file that was
|
||||
// found.
|
||||
//
|
||||
// Manifests are JSON or YAML files named plugin.json, plugin.yaml, or plugin.yml.
|
||||
func FindManifest(dir string) (manifest *Manifest, path string, err error) {
|
||||
for _, name := range []string{"plugin.yml", "plugin.yaml"} {
|
||||
path = filepath.Join(dir, name)
|
||||
f, ferr := os.Open(path)
|
||||
if ferr != nil {
|
||||
if !os.IsNotExist(ferr) {
|
||||
err = ferr
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
b, ioerr := ioutil.ReadAll(f)
|
||||
f.Close()
|
||||
if ioerr != nil {
|
||||
err = ioerr
|
||||
return
|
||||
}
|
||||
var parsed Manifest
|
||||
err = yaml.Unmarshal(b, &parsed)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
manifest = &parsed
|
||||
manifest.Id = strings.ToLower(manifest.Id)
|
||||
return
|
||||
}
|
||||
|
||||
path = filepath.Join(dir, "plugin.json")
|
||||
f, ferr := os.Open(path)
|
||||
if ferr != nil {
|
||||
if os.IsNotExist(ferr) {
|
||||
path = ""
|
||||
}
|
||||
err = ferr
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
var parsed Manifest
|
||||
err = json.NewDecoder(f).Decode(&parsed)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
manifest = &parsed
|
||||
manifest.Id = strings.ToLower(manifest.Id)
|
||||
return
|
||||
}
|
27
build/manifest/vendor/github.com/mattermost/mattermost-server/model/message_export.go
generated
vendored
Normal file
27
build/manifest/vendor/github.com/mattermost/mattermost-server/model/message_export.go
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
type MessageExport struct {
|
||||
TeamId *string
|
||||
TeamName *string
|
||||
TeamDisplayName *string
|
||||
|
||||
ChannelId *string
|
||||
ChannelName *string
|
||||
ChannelDisplayName *string
|
||||
ChannelType *string
|
||||
|
||||
UserId *string
|
||||
UserEmail *string
|
||||
Username *string
|
||||
|
||||
PostId *string
|
||||
PostCreateAt *int64
|
||||
PostMessage *string
|
||||
PostType *string
|
||||
PostRootId *string
|
||||
PostOriginalId *string
|
||||
PostFileIds StringArray
|
||||
}
|
25
build/manifest/vendor/github.com/mattermost/mattermost-server/model/mfa_secret.go
generated
vendored
Normal file
25
build/manifest/vendor/github.com/mattermost/mattermost-server/model/mfa_secret.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type MfaSecret struct {
|
||||
Secret string `json:"secret"`
|
||||
QRCode string `json:"qr_code"`
|
||||
}
|
||||
|
||||
func (me *MfaSecret) ToJson() string {
|
||||
b, _ := json.Marshal(me)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func MfaSecretFromJson(data io.Reader) *MfaSecret {
|
||||
var me *MfaSecret
|
||||
json.NewDecoder(data).Decode(&me)
|
||||
return me
|
||||
}
|
8
build/manifest/vendor/github.com/mattermost/mattermost-server/model/migration.go
generated
vendored
Normal file
8
build/manifest/vendor/github.com/mattermost/mattermost-server/model/migration.go
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
const (
|
||||
MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2 = "migration_advanced_permissions_phase_2"
|
||||
)
|
154
build/manifest/vendor/github.com/mattermost/mattermost-server/model/oauth.go
generated
vendored
Normal file
154
build/manifest/vendor/github.com/mattermost/mattermost-server/model/oauth.go
generated
vendored
Normal file
|
@ -0,0 +1,154 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
OAUTH_ACTION_SIGNUP = "signup"
|
||||
OAUTH_ACTION_LOGIN = "login"
|
||||
OAUTH_ACTION_EMAIL_TO_SSO = "email_to_sso"
|
||||
OAUTH_ACTION_SSO_TO_EMAIL = "sso_to_email"
|
||||
OAUTH_ACTION_MOBILE = "mobile"
|
||||
OAUTH_ACTION_CLIENT = "client"
|
||||
)
|
||||
|
||||
type OAuthApp struct {
|
||||
Id string `json:"id"`
|
||||
CreatorId string `json:"creator_id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
IconURL string `json:"icon_url"`
|
||||
CallbackUrls StringArray `json:"callback_urls"`
|
||||
Homepage string `json:"homepage"`
|
||||
IsTrusted bool `json:"is_trusted"`
|
||||
}
|
||||
|
||||
// IsValid validates the app and returns an error if it isn't configured
|
||||
// correctly.
|
||||
func (a *OAuthApp) IsValid() *AppError {
|
||||
|
||||
if len(a.Id) != 26 {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.app_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if a.CreateAt == 0 {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.create_at.app_error", nil, "app_id="+a.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if a.UpdateAt == 0 {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.update_at.app_error", nil, "app_id="+a.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(a.CreatorId) != 26 {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.creator_id.app_error", nil, "app_id="+a.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(a.ClientSecret) == 0 || len(a.ClientSecret) > 128 {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.client_secret.app_error", nil, "app_id="+a.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(a.Name) == 0 || len(a.Name) > 64 {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.name.app_error", nil, "app_id="+a.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(a.CallbackUrls) == 0 || len(fmt.Sprintf("%s", a.CallbackUrls)) > 1024 {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.callback.app_error", nil, "app_id="+a.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
for _, callback := range a.CallbackUrls {
|
||||
if !IsValidHttpUrl(callback) {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.callback.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
if len(a.Homepage) == 0 || len(a.Homepage) > 256 || !IsValidHttpUrl(a.Homepage) {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.homepage.app_error", nil, "app_id="+a.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(a.Description) > 512 {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.description.app_error", nil, "app_id="+a.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(a.IconURL) > 0 {
|
||||
if len(a.IconURL) > 512 || !IsValidHttpUrl(a.IconURL) {
|
||||
return NewAppError("OAuthApp.IsValid", "model.oauth.is_valid.icon_url.app_error", nil, "app_id="+a.Id, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PreSave will set the Id and ClientSecret if missing. It will also fill
|
||||
// in the CreateAt, UpdateAt times. It should be run before saving the app to the db.
|
||||
func (a *OAuthApp) PreSave() {
|
||||
if a.Id == "" {
|
||||
a.Id = NewId()
|
||||
}
|
||||
|
||||
if a.ClientSecret == "" {
|
||||
a.ClientSecret = NewId()
|
||||
}
|
||||
|
||||
a.CreateAt = GetMillis()
|
||||
a.UpdateAt = a.CreateAt
|
||||
}
|
||||
|
||||
// PreUpdate should be run before updating the app in the db.
|
||||
func (a *OAuthApp) PreUpdate() {
|
||||
a.UpdateAt = GetMillis()
|
||||
}
|
||||
|
||||
// ToJson convert a User to a json string
|
||||
func (a *OAuthApp) ToJson() string {
|
||||
b, _ := json.Marshal(a)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Generate a valid strong etag so the browser can cache the results
|
||||
func (a *OAuthApp) Etag() string {
|
||||
return Etag(a.Id, a.UpdateAt)
|
||||
}
|
||||
|
||||
// Remove any private data from the app object
|
||||
func (a *OAuthApp) Sanitize() {
|
||||
a.ClientSecret = ""
|
||||
}
|
||||
|
||||
func (a *OAuthApp) IsValidRedirectURL(url string) bool {
|
||||
for _, u := range a.CallbackUrls {
|
||||
if u == url {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// OAuthAppFromJson will decode the input and return a User
|
||||
func OAuthAppFromJson(data io.Reader) *OAuthApp {
|
||||
var app *OAuthApp
|
||||
json.NewDecoder(data).Decode(&app)
|
||||
return app
|
||||
}
|
||||
|
||||
func OAuthAppListToJson(l []*OAuthApp) string {
|
||||
b, _ := json.Marshal(l)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func OAuthAppListFromJson(data io.Reader) []*OAuthApp {
|
||||
var o []*OAuthApp
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
264
build/manifest/vendor/github.com/mattermost/mattermost-server/model/outgoing_webhook.go
generated
vendored
Normal file
264
build/manifest/vendor/github.com/mattermost/mattermost-server/model/outgoing_webhook.go
generated
vendored
Normal file
|
@ -0,0 +1,264 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type OutgoingWebhook struct {
|
||||
Id string `json:"id"`
|
||||
Token string `json:"token"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
CreatorId string `json:"creator_id"`
|
||||
ChannelId string `json:"channel_id"`
|
||||
TeamId string `json:"team_id"`
|
||||
TriggerWords StringArray `json:"trigger_words"`
|
||||
TriggerWhen int `json:"trigger_when"`
|
||||
CallbackURLs StringArray `json:"callback_urls"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
ContentType string `json:"content_type"`
|
||||
Username string `json:"username"`
|
||||
IconURL string `json:"icon_url"`
|
||||
}
|
||||
|
||||
type OutgoingWebhookPayload struct {
|
||||
Token string `json:"token"`
|
||||
TeamId string `json:"team_id"`
|
||||
TeamDomain string `json:"team_domain"`
|
||||
ChannelId string `json:"channel_id"`
|
||||
ChannelName string `json:"channel_name"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
UserId string `json:"user_id"`
|
||||
UserName string `json:"user_name"`
|
||||
PostId string `json:"post_id"`
|
||||
Text string `json:"text"`
|
||||
TriggerWord string `json:"trigger_word"`
|
||||
FileIds string `json:"file_ids"`
|
||||
}
|
||||
|
||||
type OutgoingWebhookResponse struct {
|
||||
Text *string `json:"text"`
|
||||
Username string `json:"username"`
|
||||
IconURL string `json:"icon_url"`
|
||||
Props StringInterface `json:"props"`
|
||||
Attachments []*SlackAttachment `json:"attachments"`
|
||||
Type string `json:"type"`
|
||||
ResponseType string `json:"response_type"`
|
||||
}
|
||||
|
||||
const OUTGOING_HOOK_RESPONSE_TYPE_COMMENT = "comment"
|
||||
|
||||
func (o *OutgoingWebhookPayload) ToJSON() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhookPayload) ToFormValues() string {
|
||||
v := url.Values{}
|
||||
v.Set("token", o.Token)
|
||||
v.Set("team_id", o.TeamId)
|
||||
v.Set("team_domain", o.TeamDomain)
|
||||
v.Set("channel_id", o.ChannelId)
|
||||
v.Set("channel_name", o.ChannelName)
|
||||
v.Set("timestamp", strconv.FormatInt(o.Timestamp/1000, 10))
|
||||
v.Set("user_id", o.UserId)
|
||||
v.Set("user_name", o.UserName)
|
||||
v.Set("post_id", o.PostId)
|
||||
v.Set("text", o.Text)
|
||||
v.Set("trigger_word", o.TriggerWord)
|
||||
v.Set("file_ids", o.FileIds)
|
||||
|
||||
return v.Encode()
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhook) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func OutgoingWebhookFromJson(data io.Reader) *OutgoingWebhook {
|
||||
var o *OutgoingWebhook
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func OutgoingWebhookListToJson(l []*OutgoingWebhook) string {
|
||||
b, _ := json.Marshal(l)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func OutgoingWebhookListFromJson(data io.Reader) []*OutgoingWebhook {
|
||||
var o []*OutgoingWebhook
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhookResponse) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func OutgoingWebhookResponseFromJson(data io.Reader) *OutgoingWebhookResponse {
|
||||
var o *OutgoingWebhookResponse
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhook) IsValid() *AppError {
|
||||
|
||||
if len(o.Id) != 26 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Token) != 26 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.token.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.create_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.UpdateAt == 0 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.update_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.CreatorId) != 26 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.ChannelId) != 0 && len(o.ChannelId) != 26 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.channel_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.TeamId) != 26 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.team_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(fmt.Sprintf("%s", o.TriggerWords)) > 1024 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.words.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.TriggerWords) != 0 {
|
||||
for _, triggerWord := range o.TriggerWords {
|
||||
if len(triggerWord) == 0 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.trigger_words.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(o.CallbackURLs) == 0 || len(fmt.Sprintf("%s", o.CallbackURLs)) > 1024 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.callback.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
for _, callback := range o.CallbackURLs {
|
||||
if !IsValidHttpUrl(callback) {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.url.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
if len(o.DisplayName) > 64 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.display_name.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Description) > 128 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.description.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.ContentType) > 128 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.content_type.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.TriggerWhen > 1 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.content_type.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Username) > 64 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.username.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.IconURL) > 1024 {
|
||||
return NewAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.icon_url.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhook) PreSave() {
|
||||
if o.Id == "" {
|
||||
o.Id = NewId()
|
||||
}
|
||||
|
||||
if o.Token == "" {
|
||||
o.Token = NewId()
|
||||
}
|
||||
|
||||
o.CreateAt = GetMillis()
|
||||
o.UpdateAt = o.CreateAt
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhook) PreUpdate() {
|
||||
o.UpdateAt = GetMillis()
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhook) TriggerWordExactMatch(word string) bool {
|
||||
if len(word) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, trigger := range o.TriggerWords {
|
||||
if trigger == word {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhook) TriggerWordStartsWith(word string) bool {
|
||||
if len(word) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, trigger := range o.TriggerWords {
|
||||
if strings.HasPrefix(word, trigger) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhook) GetTriggerWord(word string, isExactMatch bool) (triggerWord string) {
|
||||
if len(word) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if isExactMatch {
|
||||
for _, trigger := range o.TriggerWords {
|
||||
if trigger == word {
|
||||
triggerWord = trigger
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, trigger := range o.TriggerWords {
|
||||
if strings.HasPrefix(word, trigger) {
|
||||
triggerWord = trigger
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return triggerWord
|
||||
}
|
466
build/manifest/vendor/github.com/mattermost/mattermost-server/model/permission.go
generated
vendored
Normal file
466
build/manifest/vendor/github.com/mattermost/mattermost-server/model/permission.go
generated
vendored
Normal file
|
@ -0,0 +1,466 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
const (
|
||||
PERMISSION_SCOPE_SYSTEM = "system_scope"
|
||||
PERMISSION_SCOPE_TEAM = "team_scope"
|
||||
PERMISSION_SCOPE_CHANNEL = "channel_scope"
|
||||
)
|
||||
|
||||
type Permission struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Scope string `json:"scope"`
|
||||
}
|
||||
|
||||
var PERMISSION_INVITE_USER *Permission
|
||||
var PERMISSION_ADD_USER_TO_TEAM *Permission
|
||||
var PERMISSION_USE_SLASH_COMMANDS *Permission
|
||||
var PERMISSION_MANAGE_SLASH_COMMANDS *Permission
|
||||
var PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS *Permission
|
||||
var PERMISSION_CREATE_PUBLIC_CHANNEL *Permission
|
||||
var PERMISSION_CREATE_PRIVATE_CHANNEL *Permission
|
||||
var PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS *Permission
|
||||
var PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS *Permission
|
||||
var PERMISSION_ASSIGN_SYSTEM_ADMIN_ROLE *Permission
|
||||
var PERMISSION_MANAGE_ROLES *Permission
|
||||
var PERMISSION_MANAGE_TEAM_ROLES *Permission
|
||||
var PERMISSION_MANAGE_CHANNEL_ROLES *Permission
|
||||
var PERMISSION_CREATE_DIRECT_CHANNEL *Permission
|
||||
var PERMISSION_CREATE_GROUP_CHANNEL *Permission
|
||||
var PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES *Permission
|
||||
var PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES *Permission
|
||||
var PERMISSION_LIST_TEAM_CHANNELS *Permission
|
||||
var PERMISSION_JOIN_PUBLIC_CHANNELS *Permission
|
||||
var PERMISSION_DELETE_PUBLIC_CHANNEL *Permission
|
||||
var PERMISSION_DELETE_PRIVATE_CHANNEL *Permission
|
||||
var PERMISSION_EDIT_OTHER_USERS *Permission
|
||||
var PERMISSION_READ_CHANNEL *Permission
|
||||
var PERMISSION_READ_PUBLIC_CHANNEL *Permission
|
||||
var PERMISSION_ADD_REACTION *Permission
|
||||
var PERMISSION_REMOVE_REACTION *Permission
|
||||
var PERMISSION_REMOVE_OTHERS_REACTIONS *Permission
|
||||
var PERMISSION_PERMANENT_DELETE_USER *Permission
|
||||
var PERMISSION_UPLOAD_FILE *Permission
|
||||
var PERMISSION_GET_PUBLIC_LINK *Permission
|
||||
var PERMISSION_MANAGE_WEBHOOKS *Permission
|
||||
var PERMISSION_MANAGE_OTHERS_WEBHOOKS *Permission
|
||||
var PERMISSION_MANAGE_OAUTH *Permission
|
||||
var PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH *Permission
|
||||
var PERMISSION_MANAGE_EMOJIS *Permission
|
||||
var PERMISSION_MANAGE_OTHERS_EMOJIS *Permission
|
||||
var PERMISSION_CREATE_POST *Permission
|
||||
var PERMISSION_CREATE_POST_PUBLIC *Permission
|
||||
var PERMISSION_CREATE_POST_EPHEMERAL *Permission
|
||||
var PERMISSION_EDIT_POST *Permission
|
||||
var PERMISSION_EDIT_OTHERS_POSTS *Permission
|
||||
var PERMISSION_DELETE_POST *Permission
|
||||
var PERMISSION_DELETE_OTHERS_POSTS *Permission
|
||||
var PERMISSION_REMOVE_USER_FROM_TEAM *Permission
|
||||
var PERMISSION_CREATE_TEAM *Permission
|
||||
var PERMISSION_MANAGE_TEAM *Permission
|
||||
var PERMISSION_IMPORT_TEAM *Permission
|
||||
var PERMISSION_VIEW_TEAM *Permission
|
||||
var PERMISSION_LIST_USERS_WITHOUT_TEAM *Permission
|
||||
var PERMISSION_MANAGE_JOBS *Permission
|
||||
var PERMISSION_CREATE_USER_ACCESS_TOKEN *Permission
|
||||
var PERMISSION_READ_USER_ACCESS_TOKEN *Permission
|
||||
var PERMISSION_REVOKE_USER_ACCESS_TOKEN *Permission
|
||||
|
||||
// General permission that encompasses all system admin functions
|
||||
// in the future this could be broken up to allow access to some
|
||||
// admin functions but not others
|
||||
var PERMISSION_MANAGE_SYSTEM *Permission
|
||||
|
||||
var ALL_PERMISSIONS []*Permission
|
||||
|
||||
func initializePermissions() {
|
||||
PERMISSION_INVITE_USER = &Permission{
|
||||
"invite_user",
|
||||
"authentication.permissions.team_invite_user.name",
|
||||
"authentication.permissions.team_invite_user.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_ADD_USER_TO_TEAM = &Permission{
|
||||
"add_user_to_team",
|
||||
"authentication.permissions.add_user_to_team.name",
|
||||
"authentication.permissions.add_user_to_team.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_USE_SLASH_COMMANDS = &Permission{
|
||||
"use_slash_commands",
|
||||
"authentication.permissions.team_use_slash_commands.name",
|
||||
"authentication.permissions.team_use_slash_commands.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_MANAGE_SLASH_COMMANDS = &Permission{
|
||||
"manage_slash_commands",
|
||||
"authentication.permissions.manage_slash_commands.name",
|
||||
"authentication.permissions.manage_slash_commands.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS = &Permission{
|
||||
"manage_others_slash_commands",
|
||||
"authentication.permissions.manage_others_slash_commands.name",
|
||||
"authentication.permissions.manage_others_slash_commands.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_CREATE_PUBLIC_CHANNEL = &Permission{
|
||||
"create_public_channel",
|
||||
"authentication.permissions.create_public_channel.name",
|
||||
"authentication.permissions.create_public_channel.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_CREATE_PRIVATE_CHANNEL = &Permission{
|
||||
"create_private_channel",
|
||||
"authentication.permissions.create_private_channel.name",
|
||||
"authentication.permissions.create_private_channel.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS = &Permission{
|
||||
"manage_public_channel_members",
|
||||
"authentication.permissions.manage_public_channel_members.name",
|
||||
"authentication.permissions.manage_public_channel_members.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS = &Permission{
|
||||
"manage_private_channel_members",
|
||||
"authentication.permissions.manage_private_channel_members.name",
|
||||
"authentication.permissions.manage_private_channel_members.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_ASSIGN_SYSTEM_ADMIN_ROLE = &Permission{
|
||||
"assign_system_admin_role",
|
||||
"authentication.permissions.assign_system_admin_role.name",
|
||||
"authentication.permissions.assign_system_admin_role.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_MANAGE_ROLES = &Permission{
|
||||
"manage_roles",
|
||||
"authentication.permissions.manage_roles.name",
|
||||
"authentication.permissions.manage_roles.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_MANAGE_TEAM_ROLES = &Permission{
|
||||
"manage_team_roles",
|
||||
"authentication.permissions.manage_team_roles.name",
|
||||
"authentication.permissions.manage_team_roles.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_MANAGE_CHANNEL_ROLES = &Permission{
|
||||
"manage_channel_roles",
|
||||
"authentication.permissions.manage_channel_roles.name",
|
||||
"authentication.permissions.manage_channel_roles.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_MANAGE_SYSTEM = &Permission{
|
||||
"manage_system",
|
||||
"authentication.permissions.manage_system.name",
|
||||
"authentication.permissions.manage_system.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_CREATE_DIRECT_CHANNEL = &Permission{
|
||||
"create_direct_channel",
|
||||
"authentication.permissions.create_direct_channel.name",
|
||||
"authentication.permissions.create_direct_channel.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_CREATE_GROUP_CHANNEL = &Permission{
|
||||
"create_group_channel",
|
||||
"authentication.permissions.create_group_channel.name",
|
||||
"authentication.permissions.create_group_channel.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES = &Permission{
|
||||
"manage_public_channel_properties",
|
||||
"authentication.permissions.manage_public_channel_properties.name",
|
||||
"authentication.permissions.manage_public_channel_properties.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES = &Permission{
|
||||
"manage_private_channel_properties",
|
||||
"authentication.permissions.manage_private_channel_properties.name",
|
||||
"authentication.permissions.manage_private_channel_properties.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_LIST_TEAM_CHANNELS = &Permission{
|
||||
"list_team_channels",
|
||||
"authentication.permissions.list_team_channels.name",
|
||||
"authentication.permissions.list_team_channels.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_JOIN_PUBLIC_CHANNELS = &Permission{
|
||||
"join_public_channels",
|
||||
"authentication.permissions.join_public_channels.name",
|
||||
"authentication.permissions.join_public_channels.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_DELETE_PUBLIC_CHANNEL = &Permission{
|
||||
"delete_public_channel",
|
||||
"authentication.permissions.delete_public_channel.name",
|
||||
"authentication.permissions.delete_public_channel.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_DELETE_PRIVATE_CHANNEL = &Permission{
|
||||
"delete_private_channel",
|
||||
"authentication.permissions.delete_private_channel.name",
|
||||
"authentication.permissions.delete_private_channel.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_EDIT_OTHER_USERS = &Permission{
|
||||
"edit_other_users",
|
||||
"authentication.permissions.edit_other_users.name",
|
||||
"authentication.permissions.edit_other_users.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_READ_CHANNEL = &Permission{
|
||||
"read_channel",
|
||||
"authentication.permissions.read_channel.name",
|
||||
"authentication.permissions.read_channel.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_READ_PUBLIC_CHANNEL = &Permission{
|
||||
"read_public_channel",
|
||||
"authentication.permissions.read_public_channel.name",
|
||||
"authentication.permissions.read_public_channel.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_ADD_REACTION = &Permission{
|
||||
"add_reaction",
|
||||
"authentication.permissions.add_reaction.name",
|
||||
"authentication.permissions.add_reaction.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_REMOVE_REACTION = &Permission{
|
||||
"remove_reaction",
|
||||
"authentication.permissions.remove_reaction.name",
|
||||
"authentication.permissions.remove_reaction.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_REMOVE_OTHERS_REACTIONS = &Permission{
|
||||
"remove_others_reactions",
|
||||
"authentication.permissions.remove_others_reactions.name",
|
||||
"authentication.permissions.remove_others_reactions.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_PERMANENT_DELETE_USER = &Permission{
|
||||
"permanent_delete_user",
|
||||
"authentication.permissions.permanent_delete_user.name",
|
||||
"authentication.permissions.permanent_delete_user.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_UPLOAD_FILE = &Permission{
|
||||
"upload_file",
|
||||
"authentication.permissions.upload_file.name",
|
||||
"authentication.permissions.upload_file.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_GET_PUBLIC_LINK = &Permission{
|
||||
"get_public_link",
|
||||
"authentication.permissions.get_public_link.name",
|
||||
"authentication.permissions.get_public_link.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_MANAGE_WEBHOOKS = &Permission{
|
||||
"manage_webhooks",
|
||||
"authentication.permissions.manage_webhooks.name",
|
||||
"authentication.permissions.manage_webhooks.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_MANAGE_OTHERS_WEBHOOKS = &Permission{
|
||||
"manage_others_webhooks",
|
||||
"authentication.permissions.manage_others_webhooks.name",
|
||||
"authentication.permissions.manage_others_webhooks.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_MANAGE_OAUTH = &Permission{
|
||||
"manage_oauth",
|
||||
"authentication.permissions.manage_oauth.name",
|
||||
"authentication.permissions.manage_oauth.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH = &Permission{
|
||||
"manage_system_wide_oauth",
|
||||
"authentication.permissions.manage_system_wide_oauth.name",
|
||||
"authentication.permissions.manage_system_wide_oauth.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_MANAGE_EMOJIS = &Permission{
|
||||
"manage_emojis",
|
||||
"authentication.permissions.manage_emojis.name",
|
||||
"authentication.permissions.manage_emojis.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_MANAGE_OTHERS_EMOJIS = &Permission{
|
||||
"manage_others_emojis",
|
||||
"authentication.permissions.manage_others_emojis.name",
|
||||
"authentication.permissions.manage_others_emojis.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_CREATE_POST = &Permission{
|
||||
"create_post",
|
||||
"authentication.permissions.create_post.name",
|
||||
"authentication.permissions.create_post.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_CREATE_POST_PUBLIC = &Permission{
|
||||
"create_post_public",
|
||||
"authentication.permissions.create_post_public.name",
|
||||
"authentication.permissions.create_post_public.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_CREATE_POST_EPHEMERAL = &Permission{
|
||||
"create_post_ephemeral",
|
||||
"authentication.permissions.create_post_ephemeral.name",
|
||||
"authentication.permissions.create_post_ephemeral.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_EDIT_POST = &Permission{
|
||||
"edit_post",
|
||||
"authentication.permissions.edit_post.name",
|
||||
"authentication.permissions.edit_post.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_EDIT_OTHERS_POSTS = &Permission{
|
||||
"edit_others_posts",
|
||||
"authentication.permissions.edit_others_posts.name",
|
||||
"authentication.permissions.edit_others_posts.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_DELETE_POST = &Permission{
|
||||
"delete_post",
|
||||
"authentication.permissions.delete_post.name",
|
||||
"authentication.permissions.delete_post.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_DELETE_OTHERS_POSTS = &Permission{
|
||||
"delete_others_posts",
|
||||
"authentication.permissions.delete_others_posts.name",
|
||||
"authentication.permissions.delete_others_posts.description",
|
||||
PERMISSION_SCOPE_CHANNEL,
|
||||
}
|
||||
PERMISSION_REMOVE_USER_FROM_TEAM = &Permission{
|
||||
"remove_user_from_team",
|
||||
"authentication.permissions.remove_user_from_team.name",
|
||||
"authentication.permissions.remove_user_from_team.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_CREATE_TEAM = &Permission{
|
||||
"create_team",
|
||||
"authentication.permissions.create_team.name",
|
||||
"authentication.permissions.create_team.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_MANAGE_TEAM = &Permission{
|
||||
"manage_team",
|
||||
"authentication.permissions.manage_team.name",
|
||||
"authentication.permissions.manage_team.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_IMPORT_TEAM = &Permission{
|
||||
"import_team",
|
||||
"authentication.permissions.import_team.name",
|
||||
"authentication.permissions.import_team.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_VIEW_TEAM = &Permission{
|
||||
"view_team",
|
||||
"authentication.permissions.view_team.name",
|
||||
"authentication.permissions.view_team.description",
|
||||
PERMISSION_SCOPE_TEAM,
|
||||
}
|
||||
PERMISSION_LIST_USERS_WITHOUT_TEAM = &Permission{
|
||||
"list_users_without_team",
|
||||
"authentication.permissions.list_users_without_team.name",
|
||||
"authentication.permissions.list_users_without_team.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_CREATE_USER_ACCESS_TOKEN = &Permission{
|
||||
"create_user_access_token",
|
||||
"authentication.permissions.create_user_access_token.name",
|
||||
"authentication.permissions.create_user_access_token.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_READ_USER_ACCESS_TOKEN = &Permission{
|
||||
"read_user_access_token",
|
||||
"authentication.permissions.read_user_access_token.name",
|
||||
"authentication.permissions.read_user_access_token.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_REVOKE_USER_ACCESS_TOKEN = &Permission{
|
||||
"revoke_user_access_token",
|
||||
"authentication.permissions.revoke_user_access_token.name",
|
||||
"authentication.permissions.revoke_user_access_token.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
PERMISSION_MANAGE_JOBS = &Permission{
|
||||
"manage_jobs",
|
||||
"authentication.permisssions.manage_jobs.name",
|
||||
"authentication.permisssions.manage_jobs.description",
|
||||
PERMISSION_SCOPE_SYSTEM,
|
||||
}
|
||||
|
||||
ALL_PERMISSIONS = []*Permission{
|
||||
PERMISSION_INVITE_USER,
|
||||
PERMISSION_ADD_USER_TO_TEAM,
|
||||
PERMISSION_USE_SLASH_COMMANDS,
|
||||
PERMISSION_MANAGE_SLASH_COMMANDS,
|
||||
PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS,
|
||||
PERMISSION_CREATE_PUBLIC_CHANNEL,
|
||||
PERMISSION_CREATE_PRIVATE_CHANNEL,
|
||||
PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS,
|
||||
PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS,
|
||||
PERMISSION_ASSIGN_SYSTEM_ADMIN_ROLE,
|
||||
PERMISSION_MANAGE_ROLES,
|
||||
PERMISSION_MANAGE_TEAM_ROLES,
|
||||
PERMISSION_MANAGE_CHANNEL_ROLES,
|
||||
PERMISSION_CREATE_DIRECT_CHANNEL,
|
||||
PERMISSION_CREATE_GROUP_CHANNEL,
|
||||
PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES,
|
||||
PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES,
|
||||
PERMISSION_LIST_TEAM_CHANNELS,
|
||||
PERMISSION_JOIN_PUBLIC_CHANNELS,
|
||||
PERMISSION_DELETE_PUBLIC_CHANNEL,
|
||||
PERMISSION_DELETE_PRIVATE_CHANNEL,
|
||||
PERMISSION_EDIT_OTHER_USERS,
|
||||
PERMISSION_READ_CHANNEL,
|
||||
PERMISSION_READ_PUBLIC_CHANNEL,
|
||||
PERMISSION_ADD_REACTION,
|
||||
PERMISSION_REMOVE_REACTION,
|
||||
PERMISSION_REMOVE_OTHERS_REACTIONS,
|
||||
PERMISSION_PERMANENT_DELETE_USER,
|
||||
PERMISSION_UPLOAD_FILE,
|
||||
PERMISSION_GET_PUBLIC_LINK,
|
||||
PERMISSION_MANAGE_WEBHOOKS,
|
||||
PERMISSION_MANAGE_OTHERS_WEBHOOKS,
|
||||
PERMISSION_MANAGE_OAUTH,
|
||||
PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH,
|
||||
PERMISSION_MANAGE_EMOJIS,
|
||||
PERMISSION_MANAGE_OTHERS_EMOJIS,
|
||||
PERMISSION_CREATE_POST,
|
||||
PERMISSION_CREATE_POST_PUBLIC,
|
||||
PERMISSION_CREATE_POST_EPHEMERAL,
|
||||
PERMISSION_EDIT_POST,
|
||||
PERMISSION_EDIT_OTHERS_POSTS,
|
||||
PERMISSION_DELETE_POST,
|
||||
PERMISSION_DELETE_OTHERS_POSTS,
|
||||
PERMISSION_REMOVE_USER_FROM_TEAM,
|
||||
PERMISSION_CREATE_TEAM,
|
||||
PERMISSION_MANAGE_TEAM,
|
||||
PERMISSION_IMPORT_TEAM,
|
||||
PERMISSION_VIEW_TEAM,
|
||||
PERMISSION_LIST_USERS_WITHOUT_TEAM,
|
||||
PERMISSION_MANAGE_JOBS,
|
||||
PERMISSION_CREATE_USER_ACCESS_TOKEN,
|
||||
PERMISSION_READ_USER_ACCESS_TOKEN,
|
||||
PERMISSION_REVOKE_USER_ACCESS_TOKEN,
|
||||
PERMISSION_MANAGE_SYSTEM,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
initializePermissions()
|
||||
}
|
32
build/manifest/vendor/github.com/mattermost/mattermost-server/model/plugin_key_value.go
generated
vendored
Normal file
32
build/manifest/vendor/github.com/mattermost/mattermost-server/model/plugin_key_value.go
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
KEY_VALUE_PLUGIN_ID_MAX_RUNES = 190
|
||||
KEY_VALUE_KEY_MAX_RUNES = 50
|
||||
)
|
||||
|
||||
type PluginKeyValue struct {
|
||||
PluginId string `json:"plugin_id"`
|
||||
Key string `json:"key" db:"PKey"`
|
||||
Value []byte `json:"value" db:"PValue"`
|
||||
}
|
||||
|
||||
func (kv *PluginKeyValue) IsValid() *AppError {
|
||||
if len(kv.PluginId) == 0 || utf8.RuneCountInString(kv.PluginId) > KEY_VALUE_PLUGIN_ID_MAX_RUNES {
|
||||
return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.plugin_id.app_error", map[string]interface{}{"Max": KEY_VALUE_KEY_MAX_RUNES, "Min": 0}, "key="+kv.Key, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(kv.Key) == 0 || utf8.RuneCountInString(kv.Key) > KEY_VALUE_KEY_MAX_RUNES {
|
||||
return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.key.app_error", map[string]interface{}{"Max": KEY_VALUE_KEY_MAX_RUNES, "Min": 0}, "key="+kv.Key, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
42
build/manifest/vendor/github.com/mattermost/mattermost-server/model/plugin_status.go
generated
vendored
Normal file
42
build/manifest/vendor/github.com/mattermost/mattermost-server/model/plugin_status.go
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
PluginStateNotRunning = 0
|
||||
PluginStateStarting = 1 // unused by server
|
||||
PluginStateRunning = 2
|
||||
PluginStateFailedToStart = 3
|
||||
PluginStateFailedToStayRunning = 4 // unused by server
|
||||
PluginStateStopping = 5 // unused by server
|
||||
)
|
||||
|
||||
// PluginStatus provides a cluster-aware view of installed plugins.
|
||||
type PluginStatus struct {
|
||||
PluginId string `json:"plugin_id"`
|
||||
ClusterId string `json:"cluster_id"`
|
||||
PluginPath string `json:"plugin_path"`
|
||||
State int `json:"state"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type PluginStatuses []*PluginStatus
|
||||
|
||||
func (m *PluginStatuses) ToJson() string {
|
||||
b, _ := json.Marshal(m)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func PluginStatusesFromJson(data io.Reader) PluginStatuses {
|
||||
var m PluginStatuses
|
||||
json.NewDecoder(data).Decode(&m)
|
||||
return m
|
||||
}
|
29
build/manifest/vendor/github.com/mattermost/mattermost-server/model/plugins_response.go
generated
vendored
Normal file
29
build/manifest/vendor/github.com/mattermost/mattermost-server/model/plugins_response.go
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type PluginInfo struct {
|
||||
Manifest
|
||||
}
|
||||
|
||||
type PluginsResponse struct {
|
||||
Active []*PluginInfo `json:"active"`
|
||||
Inactive []*PluginInfo `json:"inactive"`
|
||||
}
|
||||
|
||||
func (m *PluginsResponse) ToJson() string {
|
||||
b, _ := json.Marshal(m)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func PluginsResponseFromJson(data io.Reader) *PluginsResponse {
|
||||
var m *PluginsResponse
|
||||
json.NewDecoder(data).Decode(&m)
|
||||
return m
|
||||
}
|
497
build/manifest/vendor/github.com/mattermost/mattermost-server/model/post.go
generated
vendored
Normal file
497
build/manifest/vendor/github.com/mattermost/mattermost-server/model/post.go
generated
vendored
Normal file
|
@ -0,0 +1,497 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/mattermost/mattermost-server/utils/markdown"
|
||||
)
|
||||
|
||||
const (
|
||||
POST_SYSTEM_MESSAGE_PREFIX = "system_"
|
||||
POST_DEFAULT = ""
|
||||
POST_SLACK_ATTACHMENT = "slack_attachment"
|
||||
POST_SYSTEM_GENERIC = "system_generic"
|
||||
POST_JOIN_LEAVE = "system_join_leave" // Deprecated, use POST_JOIN_CHANNEL or POST_LEAVE_CHANNEL instead
|
||||
POST_JOIN_CHANNEL = "system_join_channel"
|
||||
POST_LEAVE_CHANNEL = "system_leave_channel"
|
||||
POST_JOIN_TEAM = "system_join_team"
|
||||
POST_LEAVE_TEAM = "system_leave_team"
|
||||
POST_AUTO_RESPONDER = "system_auto_responder"
|
||||
POST_ADD_REMOVE = "system_add_remove" // Deprecated, use POST_ADD_TO_CHANNEL or POST_REMOVE_FROM_CHANNEL instead
|
||||
POST_ADD_TO_CHANNEL = "system_add_to_channel"
|
||||
POST_REMOVE_FROM_CHANNEL = "system_remove_from_channel"
|
||||
POST_MOVE_CHANNEL = "system_move_channel"
|
||||
POST_ADD_TO_TEAM = "system_add_to_team"
|
||||
POST_REMOVE_FROM_TEAM = "system_remove_from_team"
|
||||
POST_HEADER_CHANGE = "system_header_change"
|
||||
POST_DISPLAYNAME_CHANGE = "system_displayname_change"
|
||||
POST_CONVERT_CHANNEL = "system_convert_channel"
|
||||
POST_PURPOSE_CHANGE = "system_purpose_change"
|
||||
POST_CHANNEL_DELETED = "system_channel_deleted"
|
||||
POST_EPHEMERAL = "system_ephemeral"
|
||||
POST_CHANGE_CHANNEL_PRIVACY = "system_change_chan_privacy"
|
||||
POST_FILEIDS_MAX_RUNES = 150
|
||||
POST_FILENAMES_MAX_RUNES = 4000
|
||||
POST_HASHTAGS_MAX_RUNES = 1000
|
||||
POST_MESSAGE_MAX_RUNES_V1 = 4000
|
||||
POST_MESSAGE_MAX_BYTES_V2 = 65535 // Maximum size of a TEXT column in MySQL
|
||||
POST_MESSAGE_MAX_RUNES_V2 = POST_MESSAGE_MAX_BYTES_V2 / 4 // Assume a worst-case representation
|
||||
POST_PROPS_MAX_RUNES = 8000
|
||||
POST_PROPS_MAX_USER_RUNES = POST_PROPS_MAX_RUNES - 400 // Leave some room for system / pre-save modifications
|
||||
POST_CUSTOM_TYPE_PREFIX = "custom_"
|
||||
PROPS_ADD_CHANNEL_MEMBER = "add_channel_member"
|
||||
POST_PROPS_ADDED_USER_ID = "addedUserId"
|
||||
POST_PROPS_DELETE_BY = "deleteBy"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
EditAt int64 `json:"edit_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
UserId string `json:"user_id"`
|
||||
ChannelId string `json:"channel_id"`
|
||||
RootId string `json:"root_id"`
|
||||
ParentId string `json:"parent_id"`
|
||||
OriginalId string `json:"original_id"`
|
||||
|
||||
Message string `json:"message"`
|
||||
|
||||
// MessageSource will contain the message as submitted by the user if Message has been modified
|
||||
// by Mattermost for presentation (e.g if an image proxy is being used). It should be used to
|
||||
// populate edit boxes if present.
|
||||
MessageSource string `json:"message_source,omitempty" db:"-"`
|
||||
|
||||
Type string `json:"type"`
|
||||
Props StringInterface `json:"props"`
|
||||
Hashtags string `json:"hashtags"`
|
||||
Filenames StringArray `json:"filenames,omitempty"` // Deprecated, do not use this field any more
|
||||
FileIds StringArray `json:"file_ids,omitempty"`
|
||||
PendingPostId string `json:"pending_post_id" db:"-"`
|
||||
HasReactions bool `json:"has_reactions,omitempty"`
|
||||
}
|
||||
|
||||
type PostEphemeral struct {
|
||||
UserID string `json:"user_id"`
|
||||
Post *Post `json:"post"`
|
||||
}
|
||||
|
||||
type PostPatch struct {
|
||||
IsPinned *bool `json:"is_pinned"`
|
||||
Message *string `json:"message"`
|
||||
Props *StringInterface `json:"props"`
|
||||
FileIds *StringArray `json:"file_ids"`
|
||||
HasReactions *bool `json:"has_reactions"`
|
||||
}
|
||||
|
||||
func (o *PostPatch) WithRewrittenImageURLs(f func(string) string) *PostPatch {
|
||||
copy := *o
|
||||
if copy.Message != nil {
|
||||
*copy.Message = RewriteImageURLs(*o.Message, f)
|
||||
}
|
||||
return ©
|
||||
}
|
||||
|
||||
type PostForIndexing struct {
|
||||
Post
|
||||
TeamId string `json:"team_id"`
|
||||
ParentCreateAt *int64 `json:"parent_create_at"`
|
||||
}
|
||||
|
||||
type PostAction struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Integration *PostActionIntegration `json:"integration,omitempty"`
|
||||
}
|
||||
|
||||
type PostActionIntegration struct {
|
||||
URL string `json:"url,omitempty"`
|
||||
Context StringInterface `json:"context,omitempty"`
|
||||
}
|
||||
|
||||
type PostActionIntegrationRequest struct {
|
||||
UserId string `json:"user_id"`
|
||||
Context StringInterface `json:"context,omitempty"`
|
||||
}
|
||||
|
||||
type PostActionIntegrationResponse struct {
|
||||
Update *Post `json:"update"`
|
||||
EphemeralText string `json:"ephemeral_text"`
|
||||
}
|
||||
|
||||
func (o *Post) ToJson() string {
|
||||
copy := *o
|
||||
copy.StripActionIntegrations()
|
||||
b, _ := json.Marshal(©)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *Post) ToUnsanitizedJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func PostFromJson(data io.Reader) *Post {
|
||||
var o *Post
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *Post) Etag() string {
|
||||
return Etag(o.Id, o.UpdateAt)
|
||||
}
|
||||
|
||||
func (o *Post) IsValid(maxPostSize int) *AppError {
|
||||
|
||||
if len(o.Id) != 26 {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.create_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.UpdateAt == 0 {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.update_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.UserId) != 26 {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.ChannelId) != 26 {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.channel_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !(len(o.RootId) == 26 || len(o.RootId) == 0) {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.root_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !(len(o.ParentId) == 26 || len(o.ParentId) == 0) {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.parent_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.ParentId) == 26 && len(o.RootId) == 0 {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.root_parent.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !(len(o.OriginalId) == 26 || len(o.OriginalId) == 0) {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.original_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(o.Message) > maxPostSize {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.msg.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(o.Hashtags) > POST_HASHTAGS_MAX_RUNES {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.hashtags.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
switch o.Type {
|
||||
case
|
||||
POST_DEFAULT,
|
||||
POST_JOIN_LEAVE,
|
||||
POST_AUTO_RESPONDER,
|
||||
POST_ADD_REMOVE,
|
||||
POST_JOIN_CHANNEL,
|
||||
POST_LEAVE_CHANNEL,
|
||||
POST_JOIN_TEAM,
|
||||
POST_LEAVE_TEAM,
|
||||
POST_ADD_TO_CHANNEL,
|
||||
POST_REMOVE_FROM_CHANNEL,
|
||||
POST_MOVE_CHANNEL,
|
||||
POST_ADD_TO_TEAM,
|
||||
POST_REMOVE_FROM_TEAM,
|
||||
POST_SLACK_ATTACHMENT,
|
||||
POST_HEADER_CHANGE,
|
||||
POST_PURPOSE_CHANGE,
|
||||
POST_DISPLAYNAME_CHANGE,
|
||||
POST_CONVERT_CHANNEL,
|
||||
POST_CHANNEL_DELETED,
|
||||
POST_CHANGE_CHANNEL_PRIVACY:
|
||||
default:
|
||||
if !strings.HasPrefix(o.Type, POST_CUSTOM_TYPE_PREFIX) {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.type.app_error", nil, "id="+o.Type, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(ArrayToJson(o.Filenames)) > POST_FILENAMES_MAX_RUNES {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.filenames.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(ArrayToJson(o.FileIds)) > POST_FILEIDS_MAX_RUNES {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.file_ids.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(StringInterfaceToJson(o.Props)) > POST_PROPS_MAX_RUNES {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.props.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Post) SanitizeProps() {
|
||||
membersToSanitize := []string{
|
||||
PROPS_ADD_CHANNEL_MEMBER,
|
||||
}
|
||||
|
||||
for _, member := range membersToSanitize {
|
||||
if _, ok := o.Props[member]; ok {
|
||||
delete(o.Props, member)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Post) PreSave() {
|
||||
if o.Id == "" {
|
||||
o.Id = NewId()
|
||||
}
|
||||
|
||||
o.OriginalId = ""
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
o.CreateAt = GetMillis()
|
||||
}
|
||||
|
||||
o.UpdateAt = o.CreateAt
|
||||
o.PreCommit()
|
||||
}
|
||||
|
||||
func (o *Post) PreCommit() {
|
||||
if o.Props == nil {
|
||||
o.Props = make(map[string]interface{})
|
||||
}
|
||||
|
||||
if o.Filenames == nil {
|
||||
o.Filenames = []string{}
|
||||
}
|
||||
|
||||
if o.FileIds == nil {
|
||||
o.FileIds = []string{}
|
||||
}
|
||||
|
||||
o.GenerateActionIds()
|
||||
}
|
||||
|
||||
func (o *Post) MakeNonNil() {
|
||||
if o.Props == nil {
|
||||
o.Props = make(map[string]interface{})
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Post) AddProp(key string, value interface{}) {
|
||||
|
||||
o.MakeNonNil()
|
||||
|
||||
o.Props[key] = value
|
||||
}
|
||||
|
||||
func (o *Post) IsSystemMessage() bool {
|
||||
return len(o.Type) >= len(POST_SYSTEM_MESSAGE_PREFIX) && o.Type[:len(POST_SYSTEM_MESSAGE_PREFIX)] == POST_SYSTEM_MESSAGE_PREFIX
|
||||
}
|
||||
|
||||
func (p *Post) Patch(patch *PostPatch) {
|
||||
if patch.IsPinned != nil {
|
||||
p.IsPinned = *patch.IsPinned
|
||||
}
|
||||
|
||||
if patch.Message != nil {
|
||||
p.Message = *patch.Message
|
||||
}
|
||||
|
||||
if patch.Props != nil {
|
||||
p.Props = *patch.Props
|
||||
}
|
||||
|
||||
if patch.FileIds != nil {
|
||||
p.FileIds = *patch.FileIds
|
||||
}
|
||||
|
||||
if patch.HasReactions != nil {
|
||||
p.HasReactions = *patch.HasReactions
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PostPatch) ToJson() string {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func PostPatchFromJson(data io.Reader) *PostPatch {
|
||||
decoder := json.NewDecoder(data)
|
||||
var post PostPatch
|
||||
err := decoder.Decode(&post)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &post
|
||||
}
|
||||
|
||||
func (o *Post) ChannelMentions() []string {
|
||||
return ChannelMentions(o.Message)
|
||||
}
|
||||
|
||||
func (r *PostActionIntegrationRequest) ToJson() string {
|
||||
b, _ := json.Marshal(r)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *Post) Attachments() []*SlackAttachment {
|
||||
if attachments, ok := o.Props["attachments"].([]*SlackAttachment); ok {
|
||||
return attachments
|
||||
}
|
||||
var ret []*SlackAttachment
|
||||
if attachments, ok := o.Props["attachments"].([]interface{}); ok {
|
||||
for _, attachment := range attachments {
|
||||
if enc, err := json.Marshal(attachment); err == nil {
|
||||
var decoded SlackAttachment
|
||||
if json.Unmarshal(enc, &decoded) == nil {
|
||||
ret = append(ret, &decoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (o *Post) StripActionIntegrations() {
|
||||
attachments := o.Attachments()
|
||||
if o.Props["attachments"] != nil {
|
||||
o.Props["attachments"] = attachments
|
||||
}
|
||||
for _, attachment := range attachments {
|
||||
for _, action := range attachment.Actions {
|
||||
action.Integration = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Post) GetAction(id string) *PostAction {
|
||||
for _, attachment := range o.Attachments() {
|
||||
for _, action := range attachment.Actions {
|
||||
if action.Id == id {
|
||||
return action
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Post) GenerateActionIds() {
|
||||
if o.Props["attachments"] != nil {
|
||||
o.Props["attachments"] = o.Attachments()
|
||||
}
|
||||
if attachments, ok := o.Props["attachments"].([]*SlackAttachment); ok {
|
||||
for _, attachment := range attachments {
|
||||
for _, action := range attachment.Actions {
|
||||
if action.Id == "" {
|
||||
action.Id = NewId()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var markdownDestinationEscaper = strings.NewReplacer(
|
||||
`\`, `\\`,
|
||||
`<`, `\<`,
|
||||
`>`, `\>`,
|
||||
`(`, `\(`,
|
||||
`)`, `\)`,
|
||||
)
|
||||
|
||||
// WithRewrittenImageURLs returns a new shallow copy of the post where the message has been
|
||||
// rewritten via RewriteImageURLs.
|
||||
func (o *Post) WithRewrittenImageURLs(f func(string) string) *Post {
|
||||
copy := *o
|
||||
copy.Message = RewriteImageURLs(o.Message, f)
|
||||
if copy.MessageSource == "" && copy.Message != o.Message {
|
||||
copy.MessageSource = o.Message
|
||||
}
|
||||
return ©
|
||||
}
|
||||
|
||||
func (o *PostEphemeral) ToUnsanitizedJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// RewriteImageURLs takes a message and returns a copy that has all of the image URLs replaced
|
||||
// according to the function f. For each image URL, f will be invoked, and the resulting markdown
|
||||
// will contain the URL returned by that invocation instead.
|
||||
//
|
||||
// Image URLs are destination URLs used in inline images or reference definitions that are used
|
||||
// anywhere in the input markdown as an image.
|
||||
func RewriteImageURLs(message string, f func(string) string) string {
|
||||
if !strings.Contains(message, "![") {
|
||||
return message
|
||||
}
|
||||
|
||||
var ranges []markdown.Range
|
||||
|
||||
markdown.Inspect(message, func(blockOrInline interface{}) bool {
|
||||
switch v := blockOrInline.(type) {
|
||||
case *markdown.ReferenceImage:
|
||||
ranges = append(ranges, v.ReferenceDefinition.RawDestination)
|
||||
case *markdown.InlineImage:
|
||||
ranges = append(ranges, v.RawDestination)
|
||||
default:
|
||||
return true
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
if ranges == nil {
|
||||
return message
|
||||
}
|
||||
|
||||
sort.Slice(ranges, func(i, j int) bool {
|
||||
return ranges[i].Position < ranges[j].Position
|
||||
})
|
||||
|
||||
copyRanges := make([]markdown.Range, 0, len(ranges))
|
||||
urls := make([]string, 0, len(ranges))
|
||||
resultLength := len(message)
|
||||
|
||||
start := 0
|
||||
for i, r := range ranges {
|
||||
switch {
|
||||
case i == 0:
|
||||
case r.Position != ranges[i-1].Position:
|
||||
start = ranges[i-1].End
|
||||
default:
|
||||
continue
|
||||
}
|
||||
original := message[r.Position:r.End]
|
||||
replacement := markdownDestinationEscaper.Replace(f(markdown.Unescape(original)))
|
||||
resultLength += len(replacement) - len(original)
|
||||
copyRanges = append(copyRanges, markdown.Range{Position: start, End: r.Position})
|
||||
urls = append(urls, replacement)
|
||||
}
|
||||
|
||||
result := make([]byte, resultLength)
|
||||
|
||||
offset := 0
|
||||
for i, r := range copyRanges {
|
||||
offset += copy(result[offset:], message[r.Position:r.End])
|
||||
offset += copy(result[offset:], urls[i])
|
||||
}
|
||||
copy(result[offset:], message[ranges[len(ranges)-1].End:])
|
||||
|
||||
return string(result)
|
||||
}
|
138
build/manifest/vendor/github.com/mattermost/mattermost-server/model/post_list.go
generated
vendored
Normal file
138
build/manifest/vendor/github.com/mattermost/mattermost-server/model/post_list.go
generated
vendored
Normal file
|
@ -0,0 +1,138 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type PostList struct {
|
||||
Order []string `json:"order"`
|
||||
Posts map[string]*Post `json:"posts"`
|
||||
}
|
||||
|
||||
func NewPostList() *PostList {
|
||||
return &PostList{
|
||||
Order: make([]string, 0),
|
||||
Posts: make(map[string]*Post),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PostList) WithRewrittenImageURLs(f func(string) string) *PostList {
|
||||
copy := *o
|
||||
copy.Posts = make(map[string]*Post)
|
||||
for id, post := range o.Posts {
|
||||
copy.Posts[id] = post.WithRewrittenImageURLs(f)
|
||||
}
|
||||
return ©
|
||||
}
|
||||
|
||||
func (o *PostList) StripActionIntegrations() {
|
||||
posts := o.Posts
|
||||
o.Posts = make(map[string]*Post)
|
||||
for id, post := range posts {
|
||||
pcopy := *post
|
||||
pcopy.StripActionIntegrations()
|
||||
o.Posts[id] = &pcopy
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PostList) ToJson() string {
|
||||
copy := *o
|
||||
copy.StripActionIntegrations()
|
||||
b, err := json.Marshal(©)
|
||||
if err != nil {
|
||||
return ""
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PostList) MakeNonNil() {
|
||||
if o.Order == nil {
|
||||
o.Order = make([]string, 0)
|
||||
}
|
||||
|
||||
if o.Posts == nil {
|
||||
o.Posts = make(map[string]*Post)
|
||||
}
|
||||
|
||||
for _, v := range o.Posts {
|
||||
v.MakeNonNil()
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PostList) AddOrder(id string) {
|
||||
|
||||
if o.Order == nil {
|
||||
o.Order = make([]string, 0, 128)
|
||||
}
|
||||
|
||||
o.Order = append(o.Order, id)
|
||||
}
|
||||
|
||||
func (o *PostList) AddPost(post *Post) {
|
||||
|
||||
if o.Posts == nil {
|
||||
o.Posts = make(map[string]*Post)
|
||||
}
|
||||
|
||||
o.Posts[post.Id] = post
|
||||
}
|
||||
|
||||
func (o *PostList) Extend(other *PostList) {
|
||||
for _, postId := range other.Order {
|
||||
if _, ok := o.Posts[postId]; !ok {
|
||||
o.AddPost(other.Posts[postId])
|
||||
o.AddOrder(postId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PostList) SortByCreateAt() {
|
||||
sort.Slice(o.Order, func(i, j int) bool {
|
||||
return o.Posts[o.Order[i]].CreateAt > o.Posts[o.Order[j]].CreateAt
|
||||
})
|
||||
}
|
||||
|
||||
func (o *PostList) Etag() string {
|
||||
|
||||
id := "0"
|
||||
var t int64 = 0
|
||||
|
||||
for _, v := range o.Posts {
|
||||
if v.UpdateAt > t {
|
||||
t = v.UpdateAt
|
||||
id = v.Id
|
||||
} else if v.UpdateAt == t && v.Id > id {
|
||||
t = v.UpdateAt
|
||||
id = v.Id
|
||||
}
|
||||
}
|
||||
|
||||
orderId := ""
|
||||
if len(o.Order) > 0 {
|
||||
orderId = o.Order[0]
|
||||
}
|
||||
|
||||
return Etag(orderId, id, t)
|
||||
}
|
||||
|
||||
func (o *PostList) IsChannelId(channelId string) bool {
|
||||
for _, v := range o.Posts {
|
||||
if v.ChannelId != channelId {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func PostListFromJson(data io.Reader) *PostList {
|
||||
var o *PostList
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
40
build/manifest/vendor/github.com/mattermost/mattermost-server/model/post_search_results.go
generated
vendored
Normal file
40
build/manifest/vendor/github.com/mattermost/mattermost-server/model/post_search_results.go
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type PostSearchMatches map[string][]string
|
||||
|
||||
type PostSearchResults struct {
|
||||
*PostList
|
||||
Matches PostSearchMatches `json:"matches"`
|
||||
}
|
||||
|
||||
func MakePostSearchResults(posts *PostList, matches PostSearchMatches) *PostSearchResults {
|
||||
return &PostSearchResults{
|
||||
posts,
|
||||
matches,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PostSearchResults) ToJson() string {
|
||||
copy := *o
|
||||
copy.PostList.StripActionIntegrations()
|
||||
b, err := json.Marshal(©)
|
||||
if err != nil {
|
||||
return ""
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func PostSearchResultsFromJson(data io.Reader) *PostSearchResults {
|
||||
var o *PostSearchResults
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
113
build/manifest/vendor/github.com/mattermost/mattermost-server/model/preference.go
generated
vendored
Normal file
113
build/manifest/vendor/github.com/mattermost/mattermost-server/model/preference.go
generated
vendored
Normal file
|
@ -0,0 +1,113 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW = "direct_channel_show"
|
||||
PREFERENCE_CATEGORY_TUTORIAL_STEPS = "tutorial_step"
|
||||
PREFERENCE_CATEGORY_ADVANCED_SETTINGS = "advanced_settings"
|
||||
PREFERENCE_CATEGORY_FLAGGED_POST = "flagged_post"
|
||||
PREFERENCE_CATEGORY_FAVORITE_CHANNEL = "favorite_channel"
|
||||
|
||||
PREFERENCE_CATEGORY_DISPLAY_SETTINGS = "display_settings"
|
||||
PREFERENCE_NAME_COLLAPSE_SETTING = "collapse_previews"
|
||||
|
||||
PREFERENCE_CATEGORY_THEME = "theme"
|
||||
// the name for theme props is the team id
|
||||
|
||||
PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP = "oauth_app"
|
||||
// the name for oauth_app is the client_id and value is the current scope
|
||||
|
||||
PREFERENCE_CATEGORY_LAST = "last"
|
||||
PREFERENCE_NAME_LAST_CHANNEL = "channel"
|
||||
PREFERENCE_NAME_LAST_TEAM = "team"
|
||||
|
||||
PREFERENCE_CATEGORY_NOTIFICATIONS = "notifications"
|
||||
PREFERENCE_NAME_EMAIL_INTERVAL = "email_interval"
|
||||
|
||||
PREFERENCE_EMAIL_INTERVAL_NO_BATCHING_SECONDS = "30" // the "immediate" setting is actually 30s
|
||||
PREFERENCE_EMAIL_INTERVAL_BATCHING_SECONDS = "900" // fifteen minutes is 900 seconds
|
||||
)
|
||||
|
||||
type Preference struct {
|
||||
UserId string `json:"user_id"`
|
||||
Category string `json:"category"`
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
func (o *Preference) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func PreferenceFromJson(data io.Reader) *Preference {
|
||||
var o *Preference
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *Preference) IsValid() *AppError {
|
||||
if len(o.UserId) != 26 {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.id.app_error", nil, "user_id="+o.UserId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Category) == 0 || len(o.Category) > 32 {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.category.app_error", nil, "category="+o.Category, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Name) > 32 {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.name.app_error", nil, "name="+o.Name, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(o.Value) > 2000 {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.value.app_error", nil, "value="+o.Value, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.Category == PREFERENCE_CATEGORY_THEME {
|
||||
var unused map[string]string
|
||||
if err := json.NewDecoder(strings.NewReader(o.Value)).Decode(&unused); err != nil {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.theme.app_error", nil, "value="+o.Value, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Preference) PreUpdate() {
|
||||
if o.Category == PREFERENCE_CATEGORY_THEME {
|
||||
// decode the value of theme (a map of strings to string) and eliminate any invalid values
|
||||
var props map[string]string
|
||||
if err := json.NewDecoder(strings.NewReader(o.Value)).Decode(&props); err != nil {
|
||||
// just continue, the invalid preference value should get caught by IsValid before saving
|
||||
return
|
||||
}
|
||||
|
||||
colorPattern := regexp.MustCompile(`^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$`)
|
||||
|
||||
// blank out any invalid theme values
|
||||
for name, value := range props {
|
||||
if name == "image" || name == "type" || name == "codeTheme" {
|
||||
continue
|
||||
}
|
||||
|
||||
if !colorPattern.MatchString(value) {
|
||||
props[name] = "#ffffff"
|
||||
}
|
||||
}
|
||||
|
||||
if b, err := json.Marshal(props); err == nil {
|
||||
o.Value = string(b)
|
||||
}
|
||||
}
|
||||
}
|
27
build/manifest/vendor/github.com/mattermost/mattermost-server/model/preferences.go
generated
vendored
Normal file
27
build/manifest/vendor/github.com/mattermost/mattermost-server/model/preferences.go
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type Preferences []Preference
|
||||
|
||||
func (o *Preferences) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func PreferencesFromJson(data io.Reader) (Preferences, error) {
|
||||
decoder := json.NewDecoder(data)
|
||||
var o Preferences
|
||||
err := decoder.Decode(&o)
|
||||
if err == nil {
|
||||
return o, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
70
build/manifest/vendor/github.com/mattermost/mattermost-server/model/push_notification.go
generated
vendored
Normal file
70
build/manifest/vendor/github.com/mattermost/mattermost-server/model/push_notification.go
generated
vendored
Normal file
|
@ -0,0 +1,70 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
PUSH_NOTIFY_APPLE = "apple"
|
||||
PUSH_NOTIFY_ANDROID = "android"
|
||||
PUSH_NOTIFY_APPLE_REACT_NATIVE = "apple_rn"
|
||||
PUSH_NOTIFY_ANDROID_REACT_NATIVE = "android_rn"
|
||||
|
||||
PUSH_TYPE_MESSAGE = "message"
|
||||
PUSH_TYPE_CLEAR = "clear"
|
||||
PUSH_MESSAGE_V2 = "v2"
|
||||
|
||||
// The category is set to handle a set of interactive Actions
|
||||
// with the push notifications
|
||||
CATEGORY_CAN_REPLY = "CAN_REPLY"
|
||||
|
||||
MHPNS = "https://push.mattermost.com"
|
||||
)
|
||||
|
||||
type PushNotification struct {
|
||||
Platform string `json:"platform"`
|
||||
ServerId string `json:"server_id"`
|
||||
DeviceId string `json:"device_id"`
|
||||
Category string `json:"category"`
|
||||
Sound string `json:"sound"`
|
||||
Message string `json:"message"`
|
||||
Badge int `json:"badge"`
|
||||
ContentAvailable int `json:"cont_ava"`
|
||||
TeamId string `json:"team_id"`
|
||||
ChannelId string `json:"channel_id"`
|
||||
PostId string `json:"post_id"`
|
||||
RootId string `json:"root_id"`
|
||||
ChannelName string `json:"channel_name"`
|
||||
Type string `json:"type"`
|
||||
SenderId string `json:"sender_id"`
|
||||
OverrideUsername string `json:"override_username"`
|
||||
OverrideIconUrl string `json:"override_icon_url"`
|
||||
FromWebhook string `json:"from_webhook"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
func (me *PushNotification) ToJson() string {
|
||||
b, _ := json.Marshal(me)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (me *PushNotification) SetDeviceIdAndPlatform(deviceId string) {
|
||||
|
||||
index := strings.Index(deviceId, ":")
|
||||
|
||||
if index > -1 {
|
||||
me.Platform = deviceId[:index]
|
||||
me.DeviceId = deviceId[index+1:]
|
||||
}
|
||||
}
|
||||
|
||||
func PushNotificationFromJson(data io.Reader) *PushNotification {
|
||||
var me *PushNotification
|
||||
json.NewDecoder(data).Decode(&me)
|
||||
return me
|
||||
}
|
54
build/manifest/vendor/github.com/mattermost/mattermost-server/model/push_response.go
generated
vendored
Normal file
54
build/manifest/vendor/github.com/mattermost/mattermost-server/model/push_response.go
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
PUSH_STATUS = "status"
|
||||
PUSH_STATUS_OK = "OK"
|
||||
PUSH_STATUS_FAIL = "FAIL"
|
||||
PUSH_STATUS_REMOVE = "REMOVE"
|
||||
PUSH_STATUS_ERROR_MSG = "error"
|
||||
)
|
||||
|
||||
type PushResponse map[string]string
|
||||
|
||||
func NewOkPushResponse() PushResponse {
|
||||
m := make(map[string]string)
|
||||
m[PUSH_STATUS] = PUSH_STATUS_OK
|
||||
return m
|
||||
}
|
||||
|
||||
func NewRemovePushResponse() PushResponse {
|
||||
m := make(map[string]string)
|
||||
m[PUSH_STATUS] = PUSH_STATUS_REMOVE
|
||||
return m
|
||||
}
|
||||
|
||||
func NewErrorPushResponse(message string) PushResponse {
|
||||
m := make(map[string]string)
|
||||
m[PUSH_STATUS] = PUSH_STATUS_FAIL
|
||||
m[PUSH_STATUS_ERROR_MSG] = message
|
||||
return m
|
||||
}
|
||||
|
||||
func (me *PushResponse) ToJson() string {
|
||||
b, _ := json.Marshal(me)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func PushResponseFromJson(data io.Reader) PushResponse {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap PushResponse
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
return make(map[string]string)
|
||||
} else {
|
||||
return objmap
|
||||
}
|
||||
}
|
76
build/manifest/vendor/github.com/mattermost/mattermost-server/model/reaction.go
generated
vendored
Normal file
76
build/manifest/vendor/github.com/mattermost/mattermost-server/model/reaction.go
generated
vendored
Normal file
|
@ -0,0 +1,76 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type Reaction struct {
|
||||
UserId string `json:"user_id"`
|
||||
PostId string `json:"post_id"`
|
||||
EmojiName string `json:"emoji_name"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
}
|
||||
|
||||
func (o *Reaction) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ReactionFromJson(data io.Reader) *Reaction {
|
||||
var o Reaction
|
||||
|
||||
if err := json.NewDecoder(data).Decode(&o); err != nil {
|
||||
return nil
|
||||
} else {
|
||||
return &o
|
||||
}
|
||||
}
|
||||
|
||||
func ReactionsToJson(o []*Reaction) string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ReactionsFromJson(data io.Reader) []*Reaction {
|
||||
var o []*Reaction
|
||||
|
||||
if err := json.NewDecoder(data).Decode(&o); err != nil {
|
||||
return nil
|
||||
} else {
|
||||
return o
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Reaction) IsValid() *AppError {
|
||||
if len(o.UserId) != 26 {
|
||||
return NewAppError("Reaction.IsValid", "model.reaction.is_valid.user_id.app_error", nil, "user_id="+o.UserId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.PostId) != 26 {
|
||||
return NewAppError("Reaction.IsValid", "model.reaction.is_valid.post_id.app_error", nil, "post_id="+o.PostId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
validName := regexp.MustCompile(`^[a-zA-Z0-9\-\+_]+$`)
|
||||
|
||||
if len(o.EmojiName) == 0 || len(o.EmojiName) > EMOJI_NAME_MAX_LENGTH || !validName.MatchString(o.EmojiName) {
|
||||
return NewAppError("Reaction.IsValid", "model.reaction.is_valid.emoji_name.app_error", nil, "emoji_name="+o.EmojiName, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
return NewAppError("Reaction.IsValid", "model.reaction.is_valid.create_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Reaction) PreSave() {
|
||||
if o.CreateAt == 0 {
|
||||
o.CreateAt = GetMillis()
|
||||
}
|
||||
}
|
363
build/manifest/vendor/github.com/mattermost/mattermost-server/model/role.go
generated
vendored
Normal file
363
build/manifest/vendor/github.com/mattermost/mattermost-server/model/role.go
generated
vendored
Normal file
|
@ -0,0 +1,363 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
SYSTEM_USER_ROLE_ID = "system_user"
|
||||
SYSTEM_ADMIN_ROLE_ID = "system_admin"
|
||||
SYSTEM_POST_ALL_ROLE_ID = "system_post_all"
|
||||
SYSTEM_POST_ALL_PUBLIC_ROLE_ID = "system_post_all_public"
|
||||
SYSTEM_USER_ACCESS_TOKEN_ROLE_ID = "system_user_access_token"
|
||||
|
||||
TEAM_USER_ROLE_ID = "team_user"
|
||||
TEAM_ADMIN_ROLE_ID = "team_admin"
|
||||
TEAM_POST_ALL_ROLE_ID = "team_post_all"
|
||||
TEAM_POST_ALL_PUBLIC_ROLE_ID = "team_post_all_public"
|
||||
|
||||
CHANNEL_USER_ROLE_ID = "channel_user"
|
||||
CHANNEL_ADMIN_ROLE_ID = "channel_admin"
|
||||
|
||||
ROLE_NAME_MAX_LENGTH = 64
|
||||
ROLE_DISPLAY_NAME_MAX_LENGTH = 128
|
||||
ROLE_DESCRIPTION_MAX_LENGTH = 1024
|
||||
)
|
||||
|
||||
type Role struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
Permissions []string `json:"permissions"`
|
||||
SchemeManaged bool `json:"scheme_managed"`
|
||||
BuiltIn bool `json:"built_in"`
|
||||
}
|
||||
|
||||
type RolePatch struct {
|
||||
Permissions *[]string `json:"permissions"`
|
||||
}
|
||||
|
||||
func (role *Role) ToJson() string {
|
||||
b, _ := json.Marshal(role)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func RoleFromJson(data io.Reader) *Role {
|
||||
var role *Role
|
||||
json.NewDecoder(data).Decode(&role)
|
||||
return role
|
||||
}
|
||||
|
||||
func RoleListToJson(r []*Role) string {
|
||||
b, _ := json.Marshal(r)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func RoleListFromJson(data io.Reader) []*Role {
|
||||
var roles []*Role
|
||||
json.NewDecoder(data).Decode(&roles)
|
||||
return roles
|
||||
}
|
||||
|
||||
func (r *RolePatch) ToJson() string {
|
||||
b, _ := json.Marshal(r)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func RolePatchFromJson(data io.Reader) *RolePatch {
|
||||
var rolePatch *RolePatch
|
||||
json.NewDecoder(data).Decode(&rolePatch)
|
||||
return rolePatch
|
||||
}
|
||||
|
||||
func (o *Role) Patch(patch *RolePatch) {
|
||||
if patch.Permissions != nil {
|
||||
o.Permissions = *patch.Permissions
|
||||
}
|
||||
}
|
||||
|
||||
// Returns an array of permissions that are in either role.Permissions
|
||||
// or patch.Permissions, but not both.
|
||||
func PermissionsChangedByPatch(role *Role, patch *RolePatch) []string {
|
||||
var result []string
|
||||
|
||||
if patch.Permissions == nil {
|
||||
return result
|
||||
}
|
||||
|
||||
roleMap := make(map[string]bool)
|
||||
patchMap := make(map[string]bool)
|
||||
|
||||
for _, permission := range role.Permissions {
|
||||
roleMap[permission] = true
|
||||
}
|
||||
|
||||
for _, permission := range *patch.Permissions {
|
||||
patchMap[permission] = true
|
||||
}
|
||||
|
||||
for _, permission := range role.Permissions {
|
||||
if !patchMap[permission] {
|
||||
result = append(result, permission)
|
||||
}
|
||||
}
|
||||
|
||||
for _, permission := range *patch.Permissions {
|
||||
if !roleMap[permission] {
|
||||
result = append(result, permission)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (role *Role) IsValid() bool {
|
||||
if len(role.Id) != 26 {
|
||||
return false
|
||||
}
|
||||
|
||||
return role.IsValidWithoutId()
|
||||
}
|
||||
|
||||
func (role *Role) IsValidWithoutId() bool {
|
||||
if !IsValidRoleName(role.Name) {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(role.DisplayName) == 0 || len(role.DisplayName) > ROLE_DISPLAY_NAME_MAX_LENGTH {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(role.Description) > ROLE_DESCRIPTION_MAX_LENGTH {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, permission := range role.Permissions {
|
||||
permissionValidated := false
|
||||
for _, p := range ALL_PERMISSIONS {
|
||||
if permission == p.Id {
|
||||
permissionValidated = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !permissionValidated {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func IsValidRoleName(roleName string) bool {
|
||||
if len(roleName) <= 0 || len(roleName) > ROLE_NAME_MAX_LENGTH {
|
||||
return false
|
||||
}
|
||||
|
||||
if strings.TrimLeft(roleName, "abcdefghijklmnopqrstuvwxyz0123456789_") != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func MakeDefaultRoles() map[string]*Role {
|
||||
roles := make(map[string]*Role)
|
||||
|
||||
roles[CHANNEL_USER_ROLE_ID] = &Role{
|
||||
Name: "channel_user",
|
||||
DisplayName: "authentication.roles.channel_user.name",
|
||||
Description: "authentication.roles.channel_user.description",
|
||||
Permissions: []string{
|
||||
PERMISSION_READ_CHANNEL.Id,
|
||||
PERMISSION_ADD_REACTION.Id,
|
||||
PERMISSION_REMOVE_REACTION.Id,
|
||||
PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS.Id,
|
||||
PERMISSION_UPLOAD_FILE.Id,
|
||||
PERMISSION_GET_PUBLIC_LINK.Id,
|
||||
PERMISSION_CREATE_POST.Id,
|
||||
PERMISSION_USE_SLASH_COMMANDS.Id,
|
||||
},
|
||||
SchemeManaged: true,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
roles[CHANNEL_ADMIN_ROLE_ID] = &Role{
|
||||
Name: "channel_admin",
|
||||
DisplayName: "authentication.roles.channel_admin.name",
|
||||
Description: "authentication.roles.channel_admin.description",
|
||||
Permissions: []string{
|
||||
PERMISSION_MANAGE_CHANNEL_ROLES.Id,
|
||||
},
|
||||
SchemeManaged: true,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
roles[TEAM_USER_ROLE_ID] = &Role{
|
||||
Name: "team_user",
|
||||
DisplayName: "authentication.roles.team_user.name",
|
||||
Description: "authentication.roles.team_user.description",
|
||||
Permissions: []string{
|
||||
PERMISSION_LIST_TEAM_CHANNELS.Id,
|
||||
PERMISSION_JOIN_PUBLIC_CHANNELS.Id,
|
||||
PERMISSION_READ_PUBLIC_CHANNEL.Id,
|
||||
PERMISSION_VIEW_TEAM.Id,
|
||||
},
|
||||
SchemeManaged: true,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
roles[TEAM_POST_ALL_ROLE_ID] = &Role{
|
||||
Name: "team_post_all",
|
||||
DisplayName: "authentication.roles.team_post_all.name",
|
||||
Description: "authentication.roles.team_post_all.description",
|
||||
Permissions: []string{
|
||||
PERMISSION_CREATE_POST.Id,
|
||||
},
|
||||
SchemeManaged: false,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
roles[TEAM_POST_ALL_PUBLIC_ROLE_ID] = &Role{
|
||||
Name: "team_post_all_public",
|
||||
DisplayName: "authentication.roles.team_post_all_public.name",
|
||||
Description: "authentication.roles.team_post_all_public.description",
|
||||
Permissions: []string{
|
||||
PERMISSION_CREATE_POST_PUBLIC.Id,
|
||||
},
|
||||
SchemeManaged: false,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
roles[TEAM_ADMIN_ROLE_ID] = &Role{
|
||||
Name: "team_admin",
|
||||
DisplayName: "authentication.roles.team_admin.name",
|
||||
Description: "authentication.roles.team_admin.description",
|
||||
Permissions: []string{
|
||||
PERMISSION_EDIT_OTHERS_POSTS.Id,
|
||||
PERMISSION_REMOVE_USER_FROM_TEAM.Id,
|
||||
PERMISSION_MANAGE_TEAM.Id,
|
||||
PERMISSION_IMPORT_TEAM.Id,
|
||||
PERMISSION_MANAGE_TEAM_ROLES.Id,
|
||||
PERMISSION_MANAGE_CHANNEL_ROLES.Id,
|
||||
PERMISSION_MANAGE_OTHERS_WEBHOOKS.Id,
|
||||
PERMISSION_MANAGE_SLASH_COMMANDS.Id,
|
||||
PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS.Id,
|
||||
PERMISSION_MANAGE_WEBHOOKS.Id,
|
||||
},
|
||||
SchemeManaged: true,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
roles[SYSTEM_USER_ROLE_ID] = &Role{
|
||||
Name: "system_user",
|
||||
DisplayName: "authentication.roles.global_user.name",
|
||||
Description: "authentication.roles.global_user.description",
|
||||
Permissions: []string{
|
||||
PERMISSION_CREATE_DIRECT_CHANNEL.Id,
|
||||
PERMISSION_CREATE_GROUP_CHANNEL.Id,
|
||||
PERMISSION_PERMANENT_DELETE_USER.Id,
|
||||
},
|
||||
SchemeManaged: true,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
roles[SYSTEM_POST_ALL_ROLE_ID] = &Role{
|
||||
Name: "system_post_all",
|
||||
DisplayName: "authentication.roles.system_post_all.name",
|
||||
Description: "authentication.roles.system_post_all.description",
|
||||
Permissions: []string{
|
||||
PERMISSION_CREATE_POST.Id,
|
||||
},
|
||||
SchemeManaged: false,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
roles[SYSTEM_POST_ALL_PUBLIC_ROLE_ID] = &Role{
|
||||
Name: "system_post_all_public",
|
||||
DisplayName: "authentication.roles.system_post_all_public.name",
|
||||
Description: "authentication.roles.system_post_all_public.description",
|
||||
Permissions: []string{
|
||||
PERMISSION_CREATE_POST_PUBLIC.Id,
|
||||
},
|
||||
SchemeManaged: false,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
roles[SYSTEM_USER_ACCESS_TOKEN_ROLE_ID] = &Role{
|
||||
Name: "system_user_access_token",
|
||||
DisplayName: "authentication.roles.system_user_access_token.name",
|
||||
Description: "authentication.roles.system_user_access_token.description",
|
||||
Permissions: []string{
|
||||
PERMISSION_CREATE_USER_ACCESS_TOKEN.Id,
|
||||
PERMISSION_READ_USER_ACCESS_TOKEN.Id,
|
||||
PERMISSION_REVOKE_USER_ACCESS_TOKEN.Id,
|
||||
},
|
||||
SchemeManaged: false,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
roles[SYSTEM_ADMIN_ROLE_ID] = &Role{
|
||||
Name: "system_admin",
|
||||
DisplayName: "authentication.roles.global_admin.name",
|
||||
Description: "authentication.roles.global_admin.description",
|
||||
// System admins can do anything channel and team admins can do
|
||||
// plus everything members of teams and channels can do to all teams
|
||||
// and channels on the system
|
||||
Permissions: append(
|
||||
append(
|
||||
append(
|
||||
append(
|
||||
[]string{
|
||||
PERMISSION_ASSIGN_SYSTEM_ADMIN_ROLE.Id,
|
||||
PERMISSION_MANAGE_SYSTEM.Id,
|
||||
PERMISSION_MANAGE_ROLES.Id,
|
||||
PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id,
|
||||
PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS.Id,
|
||||
PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS.Id,
|
||||
PERMISSION_DELETE_PUBLIC_CHANNEL.Id,
|
||||
PERMISSION_CREATE_PUBLIC_CHANNEL.Id,
|
||||
PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id,
|
||||
PERMISSION_DELETE_PRIVATE_CHANNEL.Id,
|
||||
PERMISSION_CREATE_PRIVATE_CHANNEL.Id,
|
||||
PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH.Id,
|
||||
PERMISSION_MANAGE_OTHERS_WEBHOOKS.Id,
|
||||
PERMISSION_EDIT_OTHER_USERS.Id,
|
||||
PERMISSION_MANAGE_OAUTH.Id,
|
||||
PERMISSION_INVITE_USER.Id,
|
||||
PERMISSION_DELETE_POST.Id,
|
||||
PERMISSION_DELETE_OTHERS_POSTS.Id,
|
||||
PERMISSION_CREATE_TEAM.Id,
|
||||
PERMISSION_ADD_USER_TO_TEAM.Id,
|
||||
PERMISSION_LIST_USERS_WITHOUT_TEAM.Id,
|
||||
PERMISSION_MANAGE_JOBS.Id,
|
||||
PERMISSION_CREATE_POST_PUBLIC.Id,
|
||||
PERMISSION_CREATE_POST_EPHEMERAL.Id,
|
||||
PERMISSION_CREATE_USER_ACCESS_TOKEN.Id,
|
||||
PERMISSION_READ_USER_ACCESS_TOKEN.Id,
|
||||
PERMISSION_REVOKE_USER_ACCESS_TOKEN.Id,
|
||||
PERMISSION_REMOVE_OTHERS_REACTIONS.Id,
|
||||
},
|
||||
roles[TEAM_USER_ROLE_ID].Permissions...,
|
||||
),
|
||||
roles[CHANNEL_USER_ROLE_ID].Permissions...,
|
||||
),
|
||||
roles[TEAM_ADMIN_ROLE_ID].Permissions...,
|
||||
),
|
||||
roles[CHANNEL_ADMIN_ROLE_ID].Permissions...,
|
||||
),
|
||||
SchemeManaged: true,
|
||||
BuiltIn: true,
|
||||
}
|
||||
|
||||
return roles
|
||||
}
|
37
build/manifest/vendor/github.com/mattermost/mattermost-server/model/saml.go
generated
vendored
Normal file
37
build/manifest/vendor/github.com/mattermost/mattermost-server/model/saml.go
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
USER_AUTH_SERVICE_SAML = "saml"
|
||||
USER_AUTH_SERVICE_SAML_TEXT = "With SAML"
|
||||
)
|
||||
|
||||
type SamlAuthRequest struct {
|
||||
Base64AuthRequest string
|
||||
URL string
|
||||
RelayState string
|
||||
}
|
||||
|
||||
type SamlCertificateStatus struct {
|
||||
IdpCertificateFile bool `json:"idp_certificate_file"`
|
||||
PrivateKeyFile bool `json:"private_key_file"`
|
||||
PublicCertificateFile bool `json:"public_certificate_file"`
|
||||
}
|
||||
|
||||
func (s *SamlCertificateStatus) ToJson() string {
|
||||
b, _ := json.Marshal(s)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SamlCertificateStatusFromJson(data io.Reader) *SamlCertificateStatus {
|
||||
var status *SamlCertificateStatus
|
||||
json.NewDecoder(data).Decode(&status)
|
||||
return status
|
||||
}
|
77
build/manifest/vendor/github.com/mattermost/mattermost-server/model/scheduled_task.go
generated
vendored
Normal file
77
build/manifest/vendor/github.com/mattermost/mattermost-server/model/scheduled_task.go
generated
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TaskFunc func()
|
||||
|
||||
type ScheduledTask struct {
|
||||
Name string `json:"name"`
|
||||
Interval time.Duration `json:"interval"`
|
||||
Recurring bool `json:"recurring"`
|
||||
function func()
|
||||
cancel chan struct{}
|
||||
cancelled chan struct{}
|
||||
}
|
||||
|
||||
func CreateTask(name string, function TaskFunc, timeToExecution time.Duration) *ScheduledTask {
|
||||
return createTask(name, function, timeToExecution, false)
|
||||
}
|
||||
|
||||
func CreateRecurringTask(name string, function TaskFunc, interval time.Duration) *ScheduledTask {
|
||||
return createTask(name, function, interval, true)
|
||||
}
|
||||
|
||||
func createTask(name string, function TaskFunc, interval time.Duration, recurring bool) *ScheduledTask {
|
||||
task := &ScheduledTask{
|
||||
Name: name,
|
||||
Interval: interval,
|
||||
Recurring: recurring,
|
||||
function: function,
|
||||
cancel: make(chan struct{}),
|
||||
cancelled: make(chan struct{}),
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer close(task.cancelled)
|
||||
|
||||
ticker := time.NewTicker(interval)
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
function()
|
||||
case <-task.cancel:
|
||||
return
|
||||
}
|
||||
|
||||
if !task.Recurring {
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return task
|
||||
}
|
||||
|
||||
func (task *ScheduledTask) Cancel() {
|
||||
close(task.cancel)
|
||||
<-task.cancelled
|
||||
}
|
||||
|
||||
func (task *ScheduledTask) String() string {
|
||||
return fmt.Sprintf(
|
||||
"%s\nInterval: %s\nRecurring: %t\n",
|
||||
task.Name,
|
||||
task.Interval.String(),
|
||||
task.Recurring,
|
||||
)
|
||||
}
|
208
build/manifest/vendor/github.com/mattermost/mattermost-server/model/scheme.go
generated
vendored
Normal file
208
build/manifest/vendor/github.com/mattermost/mattermost-server/model/scheme.go
generated
vendored
Normal file
|
@ -0,0 +1,208 @@
|
|||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const (
|
||||
SCHEME_DISPLAY_NAME_MAX_LENGTH = 128
|
||||
SCHEME_NAME_MAX_LENGTH = 64
|
||||
SCHEME_DESCRIPTION_MAX_LENGTH = 1024
|
||||
SCHEME_SCOPE_TEAM = "team"
|
||||
SCHEME_SCOPE_CHANNEL = "channel"
|
||||
)
|
||||
|
||||
type Scheme struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
Scope string `json:"scope"`
|
||||
DefaultTeamAdminRole string `json:"default_team_admin_role"`
|
||||
DefaultTeamUserRole string `json:"default_team_user_role"`
|
||||
DefaultChannelAdminRole string `json:"default_channel_admin_role"`
|
||||
DefaultChannelUserRole string `json:"default_channel_user_role"`
|
||||
}
|
||||
|
||||
type SchemePatch struct {
|
||||
Name *string `json:"name"`
|
||||
DisplayName *string `json:"display_name"`
|
||||
Description *string `json:"description"`
|
||||
}
|
||||
|
||||
type SchemeIDPatch struct {
|
||||
SchemeID *string `json:"scheme_id"`
|
||||
}
|
||||
|
||||
// SchemeConveyor is used for importing and exporting a Scheme and its associated Roles.
|
||||
type SchemeConveyor struct {
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
Scope string `json:"scope"`
|
||||
TeamAdmin string `json:"default_team_admin_role"`
|
||||
TeamUser string `json:"default_team_user_role"`
|
||||
ChannelAdmin string `json:"default_channel_admin_role"`
|
||||
ChannelUser string `json:"default_channel_user_role"`
|
||||
Roles []*Role `json:"roles"`
|
||||
}
|
||||
|
||||
func (sc *SchemeConveyor) Scheme() *Scheme {
|
||||
return &Scheme{
|
||||
DisplayName: sc.DisplayName,
|
||||
Name: sc.Name,
|
||||
Description: sc.Description,
|
||||
Scope: sc.Scope,
|
||||
DefaultTeamAdminRole: sc.TeamAdmin,
|
||||
DefaultTeamUserRole: sc.TeamUser,
|
||||
DefaultChannelAdminRole: sc.ChannelAdmin,
|
||||
DefaultChannelUserRole: sc.ChannelUser,
|
||||
}
|
||||
}
|
||||
|
||||
type SchemeRoles struct {
|
||||
SchemeAdmin bool `json:"scheme_admin"`
|
||||
SchemeUser bool `json:"scheme_user"`
|
||||
}
|
||||
|
||||
func (scheme *Scheme) ToJson() string {
|
||||
b, _ := json.Marshal(scheme)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SchemeFromJson(data io.Reader) *Scheme {
|
||||
var scheme *Scheme
|
||||
json.NewDecoder(data).Decode(&scheme)
|
||||
return scheme
|
||||
}
|
||||
|
||||
func SchemesToJson(schemes []*Scheme) string {
|
||||
b, _ := json.Marshal(schemes)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SchemesFromJson(data io.Reader) []*Scheme {
|
||||
var schemes []*Scheme
|
||||
if err := json.NewDecoder(data).Decode(&schemes); err == nil {
|
||||
return schemes
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (scheme *Scheme) IsValid() bool {
|
||||
if len(scheme.Id) != 26 {
|
||||
return false
|
||||
}
|
||||
|
||||
return scheme.IsValidForCreate()
|
||||
}
|
||||
|
||||
func (scheme *Scheme) IsValidForCreate() bool {
|
||||
if len(scheme.DisplayName) == 0 || len(scheme.DisplayName) > SCHEME_DISPLAY_NAME_MAX_LENGTH {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidSchemeName(scheme.Name) {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(scheme.Description) > SCHEME_DESCRIPTION_MAX_LENGTH {
|
||||
return false
|
||||
}
|
||||
|
||||
switch scheme.Scope {
|
||||
case SCHEME_SCOPE_TEAM, SCHEME_SCOPE_CHANNEL:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultChannelAdminRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultChannelUserRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if scheme.Scope == SCHEME_SCOPE_TEAM {
|
||||
if !IsValidRoleName(scheme.DefaultTeamAdminRole) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !IsValidRoleName(scheme.DefaultTeamUserRole) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if scheme.Scope == SCHEME_SCOPE_CHANNEL {
|
||||
if len(scheme.DefaultTeamAdminRole) != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(scheme.DefaultTeamUserRole) != 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (scheme *Scheme) Patch(patch *SchemePatch) {
|
||||
if patch.DisplayName != nil {
|
||||
scheme.DisplayName = *patch.DisplayName
|
||||
}
|
||||
if patch.Name != nil {
|
||||
scheme.Name = *patch.Name
|
||||
}
|
||||
if patch.Description != nil {
|
||||
scheme.Description = *patch.Description
|
||||
}
|
||||
}
|
||||
|
||||
func (patch *SchemePatch) ToJson() string {
|
||||
b, _ := json.Marshal(patch)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SchemePatchFromJson(data io.Reader) *SchemePatch {
|
||||
var patch *SchemePatch
|
||||
json.NewDecoder(data).Decode(&patch)
|
||||
return patch
|
||||
}
|
||||
|
||||
func SchemeIDFromJson(data io.Reader) *string {
|
||||
var p *SchemeIDPatch
|
||||
json.NewDecoder(data).Decode(&p)
|
||||
return p.SchemeID
|
||||
}
|
||||
|
||||
func (p *SchemeIDPatch) ToJson() string {
|
||||
b, _ := json.Marshal(p)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func IsValidSchemeName(name string) bool {
|
||||
re := regexp.MustCompile(fmt.Sprintf("^[a-z0-9_]{2,%d}$", SCHEME_NAME_MAX_LENGTH))
|
||||
return re.MatchString(name)
|
||||
}
|
||||
|
||||
func (schemeRoles *SchemeRoles) ToJson() string {
|
||||
b, _ := json.Marshal(schemeRoles)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SchemeRolesFromJson(data io.Reader) *SchemeRoles {
|
||||
var schemeRoles *SchemeRoles
|
||||
json.NewDecoder(data).Decode(&schemeRoles)
|
||||
return schemeRoles
|
||||
}
|
165
build/manifest/vendor/github.com/mattermost/mattermost-server/model/search_params.go
generated
vendored
Normal file
165
build/manifest/vendor/github.com/mattermost/mattermost-server/model/search_params.go
generated
vendored
Normal file
|
@ -0,0 +1,165 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var searchTermPuncStart = regexp.MustCompile(`^[^\pL\d\s#"]+`)
|
||||
var searchTermPuncEnd = regexp.MustCompile(`[^\pL\d\s*"]+$`)
|
||||
|
||||
type SearchParams struct {
|
||||
Terms string
|
||||
IsHashtag bool
|
||||
InChannels []string
|
||||
FromUsers []string
|
||||
OrTerms bool
|
||||
}
|
||||
|
||||
var searchFlags = [...]string{"from", "channel", "in"}
|
||||
|
||||
func splitWords(text string) []string {
|
||||
words := []string{}
|
||||
|
||||
foundQuote := false
|
||||
location := 0
|
||||
for i, char := range text {
|
||||
if char == '"' {
|
||||
if foundQuote {
|
||||
// Grab the quoted section
|
||||
word := text[location : i+1]
|
||||
words = append(words, word)
|
||||
foundQuote = false
|
||||
location = i + 1
|
||||
} else {
|
||||
words = append(words, strings.Fields(text[location:i])...)
|
||||
foundQuote = true
|
||||
location = i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
words = append(words, strings.Fields(text[location:])...)
|
||||
|
||||
return words
|
||||
}
|
||||
|
||||
func parseSearchFlags(input []string) ([]string, [][2]string) {
|
||||
words := []string{}
|
||||
flags := [][2]string{}
|
||||
|
||||
skipNextWord := false
|
||||
for i, word := range input {
|
||||
if skipNextWord {
|
||||
skipNextWord = false
|
||||
continue
|
||||
}
|
||||
|
||||
isFlag := false
|
||||
|
||||
if colon := strings.Index(word, ":"); colon != -1 {
|
||||
flag := word[:colon]
|
||||
value := word[colon+1:]
|
||||
|
||||
for _, searchFlag := range searchFlags {
|
||||
// check for case insensitive equality
|
||||
if strings.EqualFold(flag, searchFlag) {
|
||||
if value != "" {
|
||||
flags = append(flags, [2]string{searchFlag, value})
|
||||
isFlag = true
|
||||
} else if i < len(input)-1 {
|
||||
flags = append(flags, [2]string{searchFlag, input[i+1]})
|
||||
skipNextWord = true
|
||||
isFlag = true
|
||||
}
|
||||
|
||||
if isFlag {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !isFlag {
|
||||
// trim off surrounding punctuation (note that we leave trailing asterisks to allow wildcards)
|
||||
word = searchTermPuncStart.ReplaceAllString(word, "")
|
||||
word = searchTermPuncEnd.ReplaceAllString(word, "")
|
||||
|
||||
// and remove extra pound #s
|
||||
word = hashtagStart.ReplaceAllString(word, "#")
|
||||
|
||||
if len(word) != 0 {
|
||||
words = append(words, word)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return words, flags
|
||||
}
|
||||
|
||||
func ParseSearchParams(text string) []*SearchParams {
|
||||
words, flags := parseSearchFlags(splitWords(text))
|
||||
|
||||
hashtagTermList := []string{}
|
||||
plainTermList := []string{}
|
||||
|
||||
for _, word := range words {
|
||||
if validHashtag.MatchString(word) {
|
||||
hashtagTermList = append(hashtagTermList, word)
|
||||
} else {
|
||||
plainTermList = append(plainTermList, word)
|
||||
}
|
||||
}
|
||||
|
||||
hashtagTerms := strings.Join(hashtagTermList, " ")
|
||||
plainTerms := strings.Join(plainTermList, " ")
|
||||
|
||||
inChannels := []string{}
|
||||
fromUsers := []string{}
|
||||
|
||||
for _, flagPair := range flags {
|
||||
flag := flagPair[0]
|
||||
value := flagPair[1]
|
||||
|
||||
if flag == "in" || flag == "channel" {
|
||||
inChannels = append(inChannels, value)
|
||||
} else if flag == "from" {
|
||||
fromUsers = append(fromUsers, value)
|
||||
}
|
||||
}
|
||||
|
||||
paramsList := []*SearchParams{}
|
||||
|
||||
if len(plainTerms) > 0 {
|
||||
paramsList = append(paramsList, &SearchParams{
|
||||
Terms: plainTerms,
|
||||
IsHashtag: false,
|
||||
InChannels: inChannels,
|
||||
FromUsers: fromUsers,
|
||||
})
|
||||
}
|
||||
|
||||
if len(hashtagTerms) > 0 {
|
||||
paramsList = append(paramsList, &SearchParams{
|
||||
Terms: hashtagTerms,
|
||||
IsHashtag: true,
|
||||
InChannels: inChannels,
|
||||
FromUsers: fromUsers,
|
||||
})
|
||||
}
|
||||
|
||||
// special case for when no terms are specified but we still have a filter
|
||||
if len(plainTerms) == 0 && len(hashtagTerms) == 0 && (len(inChannels) != 0 || len(fromUsers) != 0) {
|
||||
paramsList = append(paramsList, &SearchParams{
|
||||
Terms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: inChannels,
|
||||
FromUsers: fromUsers,
|
||||
})
|
||||
}
|
||||
|
||||
return paramsList
|
||||
}
|
41
build/manifest/vendor/github.com/mattermost/mattermost-server/model/security_bulletin.go
generated
vendored
Normal file
41
build/manifest/vendor/github.com/mattermost/mattermost-server/model/security_bulletin.go
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type SecurityBulletin struct {
|
||||
Id string `json:"id"`
|
||||
AppliesToVersion string `json:"applies_to_version"`
|
||||
}
|
||||
|
||||
type SecurityBulletins []SecurityBulletin
|
||||
|
||||
func (me *SecurityBulletin) ToJson() string {
|
||||
b, _ := json.Marshal(me)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SecurityBulletinFromJson(data io.Reader) *SecurityBulletin {
|
||||
var o *SecurityBulletin
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (me SecurityBulletins) ToJson() string {
|
||||
if b, err := json.Marshal(me); err != nil {
|
||||
return "[]"
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func SecurityBulletinsFromJson(data io.Reader) SecurityBulletins {
|
||||
var o SecurityBulletins
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
150
build/manifest/vendor/github.com/mattermost/mattermost-server/model/session.go
generated
vendored
Normal file
150
build/manifest/vendor/github.com/mattermost/mattermost-server/model/session.go
generated
vendored
Normal file
|
@ -0,0 +1,150 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
SESSION_COOKIE_TOKEN = "MMAUTHTOKEN"
|
||||
SESSION_COOKIE_USER = "MMUSERID"
|
||||
SESSION_CACHE_SIZE = 35000
|
||||
SESSION_PROP_PLATFORM = "platform"
|
||||
SESSION_PROP_OS = "os"
|
||||
SESSION_PROP_BROWSER = "browser"
|
||||
SESSION_PROP_TYPE = "type"
|
||||
SESSION_PROP_USER_ACCESS_TOKEN_ID = "user_access_token_id"
|
||||
SESSION_TYPE_USER_ACCESS_TOKEN = "UserAccessToken"
|
||||
SESSION_ACTIVITY_TIMEOUT = 1000 * 60 * 5 // 5 minutes
|
||||
SESSION_USER_ACCESS_TOKEN_EXPIRY = 100 * 365 // 100 years
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
Id string `json:"id"`
|
||||
Token string `json:"token"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
ExpiresAt int64 `json:"expires_at"`
|
||||
LastActivityAt int64 `json:"last_activity_at"`
|
||||
UserId string `json:"user_id"`
|
||||
DeviceId string `json:"device_id"`
|
||||
Roles string `json:"roles"`
|
||||
IsOAuth bool `json:"is_oauth"`
|
||||
Props StringMap `json:"props"`
|
||||
TeamMembers []*TeamMember `json:"team_members" db:"-"`
|
||||
}
|
||||
|
||||
func (me *Session) DeepCopy() *Session {
|
||||
copySession := *me
|
||||
|
||||
if me.Props != nil {
|
||||
copySession.Props = CopyStringMap(me.Props)
|
||||
}
|
||||
|
||||
if me.TeamMembers != nil {
|
||||
copySession.TeamMembers = make([]*TeamMember, len(me.TeamMembers))
|
||||
for index, tm := range me.TeamMembers {
|
||||
copySession.TeamMembers[index] = new(TeamMember)
|
||||
*copySession.TeamMembers[index] = *tm
|
||||
}
|
||||
}
|
||||
|
||||
return ©Session
|
||||
}
|
||||
|
||||
func (me *Session) ToJson() string {
|
||||
b, _ := json.Marshal(me)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SessionFromJson(data io.Reader) *Session {
|
||||
var me *Session
|
||||
json.NewDecoder(data).Decode(&me)
|
||||
return me
|
||||
}
|
||||
|
||||
func (me *Session) PreSave() {
|
||||
if me.Id == "" {
|
||||
me.Id = NewId()
|
||||
}
|
||||
|
||||
if me.Token == "" {
|
||||
me.Token = NewId()
|
||||
}
|
||||
|
||||
me.CreateAt = GetMillis()
|
||||
me.LastActivityAt = me.CreateAt
|
||||
|
||||
if me.Props == nil {
|
||||
me.Props = make(map[string]string)
|
||||
}
|
||||
}
|
||||
|
||||
func (me *Session) Sanitize() {
|
||||
me.Token = ""
|
||||
}
|
||||
|
||||
func (me *Session) IsExpired() bool {
|
||||
|
||||
if me.ExpiresAt <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if GetMillis() > me.ExpiresAt {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (me *Session) SetExpireInDays(days int) {
|
||||
if me.CreateAt == 0 {
|
||||
me.ExpiresAt = GetMillis() + (1000 * 60 * 60 * 24 * int64(days))
|
||||
} else {
|
||||
me.ExpiresAt = me.CreateAt + (1000 * 60 * 60 * 24 * int64(days))
|
||||
}
|
||||
}
|
||||
|
||||
func (me *Session) AddProp(key string, value string) {
|
||||
|
||||
if me.Props == nil {
|
||||
me.Props = make(map[string]string)
|
||||
}
|
||||
|
||||
me.Props[key] = value
|
||||
}
|
||||
|
||||
func (me *Session) GetTeamByTeamId(teamId string) *TeamMember {
|
||||
for _, team := range me.TeamMembers {
|
||||
if team.TeamId == teamId {
|
||||
return team
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *Session) IsMobileApp() bool {
|
||||
return len(me.DeviceId) > 0
|
||||
}
|
||||
|
||||
func (me *Session) GetUserRoles() []string {
|
||||
return strings.Fields(me.Roles)
|
||||
}
|
||||
|
||||
func SessionsToJson(o []*Session) string {
|
||||
if b, err := json.Marshal(o); err != nil {
|
||||
return "[]"
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func SessionsFromJson(data io.Reader) []*Session {
|
||||
var o []*Session
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
59
build/manifest/vendor/github.com/mattermost/mattermost-server/model/slack_attachment.go
generated
vendored
Normal file
59
build/manifest/vendor/github.com/mattermost/mattermost-server/model/slack_attachment.go
generated
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SlackAttachment struct {
|
||||
Id int64 `json:"id"`
|
||||
Fallback string `json:"fallback"`
|
||||
Color string `json:"color"`
|
||||
Pretext string `json:"pretext"`
|
||||
AuthorName string `json:"author_name"`
|
||||
AuthorLink string `json:"author_link"`
|
||||
AuthorIcon string `json:"author_icon"`
|
||||
Title string `json:"title"`
|
||||
TitleLink string `json:"title_link"`
|
||||
Text string `json:"text"`
|
||||
Fields []*SlackAttachmentField `json:"fields"`
|
||||
ImageURL string `json:"image_url"`
|
||||
ThumbURL string `json:"thumb_url"`
|
||||
Footer string `json:"footer"`
|
||||
FooterIcon string `json:"footer_icon"`
|
||||
Timestamp interface{} `json:"ts"` // This is either a string or an int64
|
||||
Actions []*PostAction `json:"actions,omitempty"`
|
||||
}
|
||||
|
||||
type SlackAttachmentField struct {
|
||||
Title string `json:"title"`
|
||||
Value interface{} `json:"value"`
|
||||
Short bool `json:"short"`
|
||||
}
|
||||
|
||||
func StringifySlackFieldValue(a []*SlackAttachment) []*SlackAttachment {
|
||||
var nonNilAttachments []*SlackAttachment
|
||||
for _, attachment := range a {
|
||||
if attachment == nil {
|
||||
continue
|
||||
}
|
||||
nonNilAttachments = append(nonNilAttachments, attachment)
|
||||
|
||||
var nonNilFields []*SlackAttachmentField
|
||||
for _, field := range attachment.Fields {
|
||||
if field == nil {
|
||||
continue
|
||||
}
|
||||
nonNilFields = append(nonNilFields, field)
|
||||
|
||||
if field.Value != nil {
|
||||
// Ensure the value is set to a string if it is set
|
||||
field.Value = fmt.Sprintf("%v", field.Value)
|
||||
}
|
||||
}
|
||||
attachment.Fields = nonNilFields
|
||||
}
|
||||
return nonNilAttachments
|
||||
}
|
80
build/manifest/vendor/github.com/mattermost/mattermost-server/model/status.go
generated
vendored
Normal file
80
build/manifest/vendor/github.com/mattermost/mattermost-server/model/status.go
generated
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
STATUS_OUT_OF_OFFICE = "ooo"
|
||||
STATUS_OFFLINE = "offline"
|
||||
STATUS_AWAY = "away"
|
||||
STATUS_DND = "dnd"
|
||||
STATUS_ONLINE = "online"
|
||||
STATUS_CACHE_SIZE = SESSION_CACHE_SIZE
|
||||
STATUS_CHANNEL_TIMEOUT = 20000 // 20 seconds
|
||||
STATUS_MIN_UPDATE_TIME = 120000 // 2 minutes
|
||||
)
|
||||
|
||||
type Status struct {
|
||||
UserId string `json:"user_id"`
|
||||
Status string `json:"status"`
|
||||
Manual bool `json:"manual"`
|
||||
LastActivityAt int64 `json:"last_activity_at"`
|
||||
ActiveChannel string `json:"active_channel,omitempty" db:"-"`
|
||||
}
|
||||
|
||||
func (o *Status) ToJson() string {
|
||||
tempChannelId := o.ActiveChannel
|
||||
o.ActiveChannel = ""
|
||||
b, _ := json.Marshal(o)
|
||||
o.ActiveChannel = tempChannelId
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *Status) ToClusterJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func StatusFromJson(data io.Reader) *Status {
|
||||
var o *Status
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func StatusListToJson(u []*Status) string {
|
||||
activeChannels := make([]string, len(u))
|
||||
for index, s := range u {
|
||||
activeChannels[index] = s.ActiveChannel
|
||||
s.ActiveChannel = ""
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(u)
|
||||
|
||||
for index, s := range u {
|
||||
s.ActiveChannel = activeChannels[index]
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func StatusListFromJson(data io.Reader) []*Status {
|
||||
var statuses []*Status
|
||||
json.NewDecoder(data).Decode(&statuses)
|
||||
return statuses
|
||||
}
|
||||
|
||||
func StatusMapToInterfaceMap(statusMap map[string]*Status) map[string]interface{} {
|
||||
interfaceMap := map[string]interface{}{}
|
||||
for _, s := range statusMap {
|
||||
// Omitted statues mean offline
|
||||
if s.Status != STATUS_OFFLINE {
|
||||
interfaceMap[s.UserId] = s.Status
|
||||
}
|
||||
}
|
||||
return interfaceMap
|
||||
}
|
25
build/manifest/vendor/github.com/mattermost/mattermost-server/model/suggest_command.go
generated
vendored
Normal file
25
build/manifest/vendor/github.com/mattermost/mattermost-server/model/suggest_command.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type SuggestCommand struct {
|
||||
Suggestion string `json:"suggestion"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
func (o *SuggestCommand) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SuggestCommandFromJson(data io.Reader) *SuggestCommand {
|
||||
var o *SuggestCommand
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
53
build/manifest/vendor/github.com/mattermost/mattermost-server/model/switch_request.go
generated
vendored
Normal file
53
build/manifest/vendor/github.com/mattermost/mattermost-server/model/switch_request.go
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type SwitchRequest struct {
|
||||
CurrentService string `json:"current_service"`
|
||||
NewService string `json:"new_service"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
NewPassword string `json:"new_password"`
|
||||
MfaCode string `json:"mfa_code"`
|
||||
LdapLoginId string `json:"ldap_id"`
|
||||
}
|
||||
|
||||
func (o *SwitchRequest) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SwitchRequestFromJson(data io.Reader) *SwitchRequest {
|
||||
var o *SwitchRequest
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *SwitchRequest) EmailToOAuth() bool {
|
||||
return o.CurrentService == USER_AUTH_SERVICE_EMAIL &&
|
||||
(o.NewService == USER_AUTH_SERVICE_SAML ||
|
||||
o.NewService == USER_AUTH_SERVICE_GITLAB ||
|
||||
o.NewService == SERVICE_GOOGLE ||
|
||||
o.NewService == SERVICE_OFFICE365)
|
||||
}
|
||||
|
||||
func (o *SwitchRequest) OAuthToEmail() bool {
|
||||
return (o.CurrentService == USER_AUTH_SERVICE_SAML ||
|
||||
o.CurrentService == USER_AUTH_SERVICE_GITLAB ||
|
||||
o.CurrentService == SERVICE_GOOGLE ||
|
||||
o.CurrentService == SERVICE_OFFICE365) && o.NewService == USER_AUTH_SERVICE_EMAIL
|
||||
}
|
||||
|
||||
func (o *SwitchRequest) EmailToLdap() bool {
|
||||
return o.CurrentService == USER_AUTH_SERVICE_EMAIL && o.NewService == USER_AUTH_SERVICE_LDAP
|
||||
}
|
||||
|
||||
func (o *SwitchRequest) LdapToEmail() bool {
|
||||
return o.CurrentService == USER_AUTH_SERVICE_LDAP && o.NewService == USER_AUTH_SERVICE_EMAIL
|
||||
}
|
46
build/manifest/vendor/github.com/mattermost/mattermost-server/model/system.go
generated
vendored
Normal file
46
build/manifest/vendor/github.com/mattermost/mattermost-server/model/system.go
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
const (
|
||||
SYSTEM_DIAGNOSTIC_ID = "DiagnosticId"
|
||||
SYSTEM_RAN_UNIT_TESTS = "RanUnitTests"
|
||||
SYSTEM_LAST_SECURITY_TIME = "LastSecurityTime"
|
||||
SYSTEM_ACTIVE_LICENSE_ID = "ActiveLicenseId"
|
||||
SYSTEM_LAST_COMPLIANCE_TIME = "LastComplianceTime"
|
||||
SYSTEM_ASYMMETRIC_SIGNING_KEY = "AsymmetricSigningKey"
|
||||
)
|
||||
|
||||
type System struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
func (o *System) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SystemFromJson(data io.Reader) *System {
|
||||
var o *System
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
type SystemAsymmetricSigningKey struct {
|
||||
ECDSAKey *SystemECDSAKey `json:"ecdsa_key,omitempty"`
|
||||
}
|
||||
|
||||
type SystemECDSAKey struct {
|
||||
Curve string `json:"curve"`
|
||||
X *big.Int `json:"x"`
|
||||
Y *big.Int `json:"y"`
|
||||
D *big.Int `json:"d,omitempty"`
|
||||
}
|
287
build/manifest/vendor/github.com/mattermost/mattermost-server/model/team.go
generated
vendored
Normal file
287
build/manifest/vendor/github.com/mattermost/mattermost-server/model/team.go
generated
vendored
Normal file
|
@ -0,0 +1,287 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
TEAM_OPEN = "O"
|
||||
TEAM_INVITE = "I"
|
||||
TEAM_ALLOWED_DOMAINS_MAX_LENGTH = 500
|
||||
TEAM_COMPANY_NAME_MAX_LENGTH = 64
|
||||
TEAM_DESCRIPTION_MAX_LENGTH = 255
|
||||
TEAM_DISPLAY_NAME_MAX_RUNES = 64
|
||||
TEAM_EMAIL_MAX_LENGTH = 128
|
||||
TEAM_NAME_MAX_LENGTH = 64
|
||||
TEAM_NAME_MIN_LENGTH = 2
|
||||
)
|
||||
|
||||
type Team struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Email string `json:"email"`
|
||||
Type string `json:"type"`
|
||||
CompanyName string `json:"company_name"`
|
||||
AllowedDomains string `json:"allowed_domains"`
|
||||
InviteId string `json:"invite_id"`
|
||||
AllowOpenInvite bool `json:"allow_open_invite"`
|
||||
LastTeamIconUpdate int64 `json:"last_team_icon_update,omitempty"`
|
||||
SchemeId *string `json:"scheme_id"`
|
||||
}
|
||||
|
||||
type TeamPatch struct {
|
||||
DisplayName *string `json:"display_name"`
|
||||
Description *string `json:"description"`
|
||||
CompanyName *string `json:"company_name"`
|
||||
InviteId *string `json:"invite_id"`
|
||||
AllowOpenInvite *bool `json:"allow_open_invite"`
|
||||
}
|
||||
|
||||
type Invites struct {
|
||||
Invites []map[string]string `json:"invites"`
|
||||
}
|
||||
|
||||
func InvitesFromJson(data io.Reader) *Invites {
|
||||
var o *Invites
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *Invites) ToEmailList() []string {
|
||||
emailList := make([]string, len(o.Invites))
|
||||
for _, invite := range o.Invites {
|
||||
emailList = append(emailList, invite["email"])
|
||||
}
|
||||
return emailList
|
||||
}
|
||||
|
||||
func (o *Invites) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *Team) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TeamFromJson(data io.Reader) *Team {
|
||||
var o *Team
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func TeamMapToJson(u map[string]*Team) string {
|
||||
b, _ := json.Marshal(u)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TeamMapFromJson(data io.Reader) map[string]*Team {
|
||||
var teams map[string]*Team
|
||||
json.NewDecoder(data).Decode(&teams)
|
||||
return teams
|
||||
}
|
||||
|
||||
func TeamListToJson(t []*Team) string {
|
||||
b, _ := json.Marshal(t)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TeamListFromJson(data io.Reader) []*Team {
|
||||
var teams []*Team
|
||||
json.NewDecoder(data).Decode(&teams)
|
||||
return teams
|
||||
}
|
||||
|
||||
func (o *Team) Etag() string {
|
||||
return Etag(o.Id, o.UpdateAt)
|
||||
}
|
||||
|
||||
func (o *Team) IsValid() *AppError {
|
||||
|
||||
if len(o.Id) != 26 {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.create_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.UpdateAt == 0 {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.update_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Email) > TEAM_EMAIL_MAX_LENGTH {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.email.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Email) > 0 && !IsValidEmail(o.Email) {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.email.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(o.DisplayName) == 0 || utf8.RuneCountInString(o.DisplayName) > TEAM_DISPLAY_NAME_MAX_RUNES {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.name.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Name) > TEAM_NAME_MAX_LENGTH {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.url.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Description) > TEAM_DESCRIPTION_MAX_LENGTH {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.description.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if IsReservedTeamName(o.Name) {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.reserved.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !IsValidTeamName(o.Name) {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.characters.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !(o.Type == TEAM_OPEN || o.Type == TEAM_INVITE) {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.type.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.CompanyName) > TEAM_COMPANY_NAME_MAX_LENGTH {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.company.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.AllowedDomains) > TEAM_ALLOWED_DOMAINS_MAX_LENGTH {
|
||||
return NewAppError("Team.IsValid", "model.team.is_valid.domains.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Team) PreSave() {
|
||||
if o.Id == "" {
|
||||
o.Id = NewId()
|
||||
}
|
||||
|
||||
o.CreateAt = GetMillis()
|
||||
o.UpdateAt = o.CreateAt
|
||||
|
||||
if len(o.InviteId) == 0 {
|
||||
o.InviteId = NewId()
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Team) PreUpdate() {
|
||||
o.UpdateAt = GetMillis()
|
||||
}
|
||||
|
||||
func IsReservedTeamName(s string) bool {
|
||||
s = strings.ToLower(s)
|
||||
|
||||
for _, value := range reservedName {
|
||||
if strings.Index(s, value) == 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func IsValidTeamName(s string) bool {
|
||||
|
||||
if !IsValidAlphaNum(s) {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(s) < TEAM_NAME_MIN_LENGTH {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
var validTeamNameCharacter = regexp.MustCompile(`^[a-z0-9-]$`)
|
||||
|
||||
func CleanTeamName(s string) string {
|
||||
s = strings.ToLower(strings.Replace(s, " ", "-", -1))
|
||||
|
||||
for _, value := range reservedName {
|
||||
if strings.Index(s, value) == 0 {
|
||||
s = strings.Replace(s, value, "", -1)
|
||||
}
|
||||
}
|
||||
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
for _, c := range s {
|
||||
char := fmt.Sprintf("%c", c)
|
||||
if !validTeamNameCharacter.MatchString(char) {
|
||||
s = strings.Replace(s, char, "", -1)
|
||||
}
|
||||
}
|
||||
|
||||
s = strings.Trim(s, "-")
|
||||
|
||||
if !IsValidTeamName(s) {
|
||||
s = NewId()
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (o *Team) Sanitize() {
|
||||
o.Email = ""
|
||||
o.AllowedDomains = ""
|
||||
}
|
||||
|
||||
func (t *Team) Patch(patch *TeamPatch) {
|
||||
if patch.DisplayName != nil {
|
||||
t.DisplayName = *patch.DisplayName
|
||||
}
|
||||
|
||||
if patch.Description != nil {
|
||||
t.Description = *patch.Description
|
||||
}
|
||||
|
||||
if patch.CompanyName != nil {
|
||||
t.CompanyName = *patch.CompanyName
|
||||
}
|
||||
|
||||
if patch.InviteId != nil {
|
||||
t.InviteId = *patch.InviteId
|
||||
}
|
||||
|
||||
if patch.AllowOpenInvite != nil {
|
||||
t.AllowOpenInvite = *patch.AllowOpenInvite
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TeamPatch) ToJson() string {
|
||||
b, err := json.Marshal(t)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TeamPatchFromJson(data io.Reader) *TeamPatch {
|
||||
decoder := json.NewDecoder(data)
|
||||
var team TeamPatch
|
||||
err := decoder.Decode(&team)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &team
|
||||
}
|
97
build/manifest/vendor/github.com/mattermost/mattermost-server/model/team_member.go
generated
vendored
Normal file
97
build/manifest/vendor/github.com/mattermost/mattermost-server/model/team_member.go
generated
vendored
Normal file
|
@ -0,0 +1,97 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type TeamMember struct {
|
||||
TeamId string `json:"team_id"`
|
||||
UserId string `json:"user_id"`
|
||||
Roles string `json:"roles"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
SchemeUser bool `json:"scheme_user"`
|
||||
SchemeAdmin bool `json:"scheme_admin"`
|
||||
ExplicitRoles string `json:"explicit_roles"`
|
||||
}
|
||||
|
||||
type TeamUnread struct {
|
||||
TeamId string `json:"team_id"`
|
||||
MsgCount int64 `json:"msg_count"`
|
||||
MentionCount int64 `json:"mention_count"`
|
||||
}
|
||||
|
||||
func (o *TeamMember) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *TeamUnread) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TeamMemberFromJson(data io.Reader) *TeamMember {
|
||||
var o *TeamMember
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func TeamUnreadFromJson(data io.Reader) *TeamUnread {
|
||||
var o *TeamUnread
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func TeamMembersToJson(o []*TeamMember) string {
|
||||
if b, err := json.Marshal(o); err != nil {
|
||||
return "[]"
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func TeamMembersFromJson(data io.Reader) []*TeamMember {
|
||||
var o []*TeamMember
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func TeamsUnreadToJson(o []*TeamUnread) string {
|
||||
if b, err := json.Marshal(o); err != nil {
|
||||
return "[]"
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func TeamsUnreadFromJson(data io.Reader) []*TeamUnread {
|
||||
var o []*TeamUnread
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *TeamMember) IsValid() *AppError {
|
||||
|
||||
if len(o.TeamId) != 26 {
|
||||
return NewAppError("TeamMember.IsValid", "model.team_member.is_valid.team_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.UserId) != 26 {
|
||||
return NewAppError("TeamMember.IsValid", "model.team_member.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *TeamMember) PreUpdate() {
|
||||
}
|
||||
|
||||
func (o *TeamMember) GetRoles() []string {
|
||||
return strings.Fields(o.Roles)
|
||||
}
|
35
build/manifest/vendor/github.com/mattermost/mattermost-server/model/team_search.go
generated
vendored
Normal file
35
build/manifest/vendor/github.com/mattermost/mattermost-server/model/team_search.go
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type TeamSearch struct {
|
||||
Term string `json:"term"`
|
||||
}
|
||||
|
||||
// ToJson convert a TeamSearch to json string
|
||||
func (c *TeamSearch) ToJson() string {
|
||||
b, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// TeamSearchFromJson decodes the input and returns a TeamSearch
|
||||
func TeamSearchFromJson(data io.Reader) *TeamSearch {
|
||||
decoder := json.NewDecoder(data)
|
||||
var cs TeamSearch
|
||||
err := decoder.Decode(&cs)
|
||||
if err == nil {
|
||||
return &cs
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
26
build/manifest/vendor/github.com/mattermost/mattermost-server/model/team_stats.go
generated
vendored
Normal file
26
build/manifest/vendor/github.com/mattermost/mattermost-server/model/team_stats.go
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type TeamStats struct {
|
||||
TeamId string `json:"team_id"`
|
||||
TotalMemberCount int64 `json:"total_member_count"`
|
||||
ActiveMemberCount int64 `json:"active_member_count"`
|
||||
}
|
||||
|
||||
func (o *TeamStats) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TeamStatsFromJson(data io.Reader) *TeamStats {
|
||||
var o *TeamStats
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
628
build/manifest/vendor/github.com/mattermost/mattermost-server/model/timezone.go
generated
vendored
Normal file
628
build/manifest/vendor/github.com/mattermost/mattermost-server/model/timezone.go
generated
vendored
Normal file
|
@ -0,0 +1,628 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type SupportedTimezones []string
|
||||
|
||||
func TimezonesToJson(timezoneList []string) string {
|
||||
b, _ := json.Marshal(timezoneList)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TimezonesFromJson(data io.Reader) SupportedTimezones {
|
||||
var timezones SupportedTimezones
|
||||
json.NewDecoder(data).Decode(&timezones)
|
||||
return timezones
|
||||
}
|
||||
|
||||
func DefaultUserTimezone() map[string]string {
|
||||
defaultTimezone := make(map[string]string)
|
||||
defaultTimezone["useAutomaticTimezone"] = "true"
|
||||
defaultTimezone["automaticTimezone"] = ""
|
||||
defaultTimezone["manualTimezone"] = ""
|
||||
|
||||
return defaultTimezone
|
||||
}
|
||||
|
||||
var DefaultSupportedTimezones = []string{
|
||||
"Africa/Abidjan",
|
||||
"Africa/Accra",
|
||||
"Africa/Addis_Ababa",
|
||||
"Africa/Algiers",
|
||||
"Africa/Asmara",
|
||||
"Africa/Asmera",
|
||||
"Africa/Bamako",
|
||||
"Africa/Bangui",
|
||||
"Africa/Banjul",
|
||||
"Africa/Bissau",
|
||||
"Africa/Blantyre",
|
||||
"Africa/Brazzaville",
|
||||
"Africa/Bujumbura",
|
||||
"Africa/Cairo",
|
||||
"Africa/Casablanca",
|
||||
"Africa/Ceuta",
|
||||
"Africa/Conakry",
|
||||
"Africa/Dakar",
|
||||
"Africa/Dar_es_Salaam",
|
||||
"Africa/Djibouti",
|
||||
"Africa/Douala",
|
||||
"Africa/El_Aaiun",
|
||||
"Africa/Freetown",
|
||||
"Africa/Gaborone",
|
||||
"Africa/Harare",
|
||||
"Africa/Johannesburg",
|
||||
"Africa/Juba",
|
||||
"Africa/Kampala",
|
||||
"Africa/Khartoum",
|
||||
"Africa/Kigali",
|
||||
"Africa/Kinshasa",
|
||||
"Africa/Lagos",
|
||||
"Africa/Libreville",
|
||||
"Africa/Lome",
|
||||
"Africa/Luanda",
|
||||
"Africa/Lubumbashi",
|
||||
"Africa/Lusaka",
|
||||
"Africa/Malabo",
|
||||
"Africa/Maputo",
|
||||
"Africa/Maseru",
|
||||
"Africa/Mbabane",
|
||||
"Africa/Mogadishu",
|
||||
"Africa/Monrovia",
|
||||
"Africa/Nairobi",
|
||||
"Africa/Ndjamena",
|
||||
"Africa/Niamey",
|
||||
"Africa/Nouakchott",
|
||||
"Africa/Ouagadougou",
|
||||
"Africa/Porto-Novo",
|
||||
"Africa/Sao_Tome",
|
||||
"Africa/Timbuktu",
|
||||
"Africa/Tripoli",
|
||||
"Africa/Tunis",
|
||||
"Africa/Windhoek",
|
||||
"America/Adak",
|
||||
"America/Anchorage",
|
||||
"America/Anguilla",
|
||||
"America/Antigua",
|
||||
"America/Araguaina",
|
||||
"America/Argentina/Buenos_Aires",
|
||||
"America/Argentina/Catamarca",
|
||||
"America/Argentina/ComodRivadavia",
|
||||
"America/Argentina/Cordoba",
|
||||
"America/Argentina/Jujuy",
|
||||
"America/Argentina/La_Rioja",
|
||||
"America/Argentina/Mendoza",
|
||||
"America/Argentina/Rio_Gallegos",
|
||||
"America/Argentina/Salta",
|
||||
"America/Argentina/San_Juan",
|
||||
"America/Argentina/San_Luis",
|
||||
"America/Argentina/Tucuman",
|
||||
"America/Argentina/Ushuaia",
|
||||
"America/Aruba",
|
||||
"America/Asuncion",
|
||||
"America/Atikokan",
|
||||
"America/Atka",
|
||||
"America/Bahia",
|
||||
"America/Bahia_Banderas",
|
||||
"America/Barbados",
|
||||
"America/Belem",
|
||||
"America/Belize",
|
||||
"America/Blanc-Sablon",
|
||||
"America/Boa_Vista",
|
||||
"America/Bogota",
|
||||
"America/Boise",
|
||||
"America/Buenos_Aires",
|
||||
"America/Cambridge_Bay",
|
||||
"America/Campo_Grande",
|
||||
"America/Cancun",
|
||||
"America/Caracas",
|
||||
"America/Catamarca",
|
||||
"America/Cayenne",
|
||||
"America/Cayman",
|
||||
"America/Chicago",
|
||||
"America/Chihuahua",
|
||||
"America/Coral_Harbour",
|
||||
"America/Cordoba",
|
||||
"America/Costa_Rica",
|
||||
"America/Creston",
|
||||
"America/Cuiaba",
|
||||
"America/Curacao",
|
||||
"America/Danmarkshavn",
|
||||
"America/Dawson",
|
||||
"America/Dawson_Creek",
|
||||
"America/Denver",
|
||||
"America/Detroit",
|
||||
"America/Dominica",
|
||||
"America/Edmonton",
|
||||
"America/Eirunepe",
|
||||
"America/El_Salvador",
|
||||
"America/Ensenada",
|
||||
"America/Fort_Nelson",
|
||||
"America/Fort_Wayne",
|
||||
"America/Fortaleza",
|
||||
"America/Glace_Bay",
|
||||
"America/Godthab",
|
||||
"America/Goose_Bay",
|
||||
"America/Grand_Turk",
|
||||
"America/Grenada",
|
||||
"America/Guadeloupe",
|
||||
"America/Guatemala",
|
||||
"America/Guayaquil",
|
||||
"America/Guyana",
|
||||
"America/Halifax",
|
||||
"America/Havana",
|
||||
"America/Hermosillo",
|
||||
"America/Indiana/Indianapolis",
|
||||
"America/Indiana/Knox",
|
||||
"America/Indiana/Marengo",
|
||||
"America/Indiana/Petersburg",
|
||||
"America/Indiana/Tell_City",
|
||||
"America/Indiana/Vevay",
|
||||
"America/Indiana/Vincennes",
|
||||
"America/Indiana/Winamac",
|
||||
"America/Indianapolis",
|
||||
"America/Inuvik",
|
||||
"America/Iqaluit",
|
||||
"America/Jamaica",
|
||||
"America/Jujuy",
|
||||
"America/Juneau",
|
||||
"America/Kentucky/Louisville",
|
||||
"America/Kentucky/Monticello",
|
||||
"America/Knox_IN",
|
||||
"America/Kralendijk",
|
||||
"America/La_Paz",
|
||||
"America/Lima",
|
||||
"America/Los_Angeles",
|
||||
"America/Louisville",
|
||||
"America/Lower_Princes",
|
||||
"America/Maceio",
|
||||
"America/Managua",
|
||||
"America/Manaus",
|
||||
"America/Marigot",
|
||||
"America/Martinique",
|
||||
"America/Matamoros",
|
||||
"America/Mazatlan",
|
||||
"America/Mendoza",
|
||||
"America/Menominee",
|
||||
"America/Merida",
|
||||
"America/Metlakatla",
|
||||
"America/Mexico_City",
|
||||
"America/Miquelon",
|
||||
"America/Moncton",
|
||||
"America/Monterrey",
|
||||
"America/Montevideo",
|
||||
"America/Montreal",
|
||||
"America/Montserrat",
|
||||
"America/Nassau",
|
||||
"America/New_York",
|
||||
"America/Nipigon",
|
||||
"America/Nome",
|
||||
"America/Noronha",
|
||||
"America/North_Dakota/Beulah",
|
||||
"America/North_Dakota/Center",
|
||||
"America/North_Dakota/New_Salem",
|
||||
"America/Ojinaga",
|
||||
"America/Panama",
|
||||
"America/Pangnirtung",
|
||||
"America/Paramaribo",
|
||||
"America/Phoenix",
|
||||
"America/Port-au-Prince",
|
||||
"America/Port_of_Spain",
|
||||
"America/Porto_Acre",
|
||||
"America/Porto_Velho",
|
||||
"America/Puerto_Rico",
|
||||
"America/Punta_Arenas",
|
||||
"America/Rainy_River",
|
||||
"America/Rankin_Inlet",
|
||||
"America/Recife",
|
||||
"America/Regina",
|
||||
"America/Resolute",
|
||||
"America/Rio_Branco",
|
||||
"America/Rosario",
|
||||
"America/Santa_Isabel",
|
||||
"America/Santarem",
|
||||
"America/Santiago",
|
||||
"America/Santo_Domingo",
|
||||
"America/Sao_Paulo",
|
||||
"America/Scoresbysund",
|
||||
"America/Shiprock",
|
||||
"America/Sitka",
|
||||
"America/St_Barthelemy",
|
||||
"America/St_Johns",
|
||||
"America/St_Kitts",
|
||||
"America/St_Lucia",
|
||||
"America/St_Thomas",
|
||||
"America/St_Vincent",
|
||||
"America/Swift_Current",
|
||||
"America/Tegucigalpa",
|
||||
"America/Thule",
|
||||
"America/Thunder_Bay",
|
||||
"America/Tijuana",
|
||||
"America/Toronto",
|
||||
"America/Tortola",
|
||||
"America/Vancouver",
|
||||
"America/Virgin",
|
||||
"America/Whitehorse",
|
||||
"America/Winnipeg",
|
||||
"America/Yakutat",
|
||||
"America/Yellowknife",
|
||||
"Antarctica/Casey",
|
||||
"Antarctica/Davis",
|
||||
"Antarctica/DumontDUrville",
|
||||
"Antarctica/Macquarie",
|
||||
"Antarctica/Mawson",
|
||||
"Antarctica/McMurdo",
|
||||
"Antarctica/Palmer",
|
||||
"Antarctica/Rothera",
|
||||
"Antarctica/South_Pole",
|
||||
"Antarctica/Syowa",
|
||||
"Antarctica/Troll",
|
||||
"Antarctica/Vostok",
|
||||
"Arctic/Longyearbyen",
|
||||
"Asia/Aden",
|
||||
"Asia/Almaty",
|
||||
"Asia/Amman",
|
||||
"Asia/Anadyr",
|
||||
"Asia/Aqtau",
|
||||
"Asia/Aqtobe",
|
||||
"Asia/Ashgabat",
|
||||
"Asia/Ashkhabad",
|
||||
"Asia/Atyrau",
|
||||
"Asia/Baghdad",
|
||||
"Asia/Bahrain",
|
||||
"Asia/Baku",
|
||||
"Asia/Bangkok",
|
||||
"Asia/Barnaul",
|
||||
"Asia/Beirut",
|
||||
"Asia/Bishkek",
|
||||
"Asia/Brunei",
|
||||
"Asia/Calcutta",
|
||||
"Asia/Chita",
|
||||
"Asia/Choibalsan",
|
||||
"Asia/Chongqing",
|
||||
"Asia/Chungking",
|
||||
"Asia/Colombo",
|
||||
"Asia/Dacca",
|
||||
"Asia/Damascus",
|
||||
"Asia/Dhaka",
|
||||
"Asia/Dili",
|
||||
"Asia/Dubai",
|
||||
"Asia/Dushanbe",
|
||||
"Asia/Famagusta",
|
||||
"Asia/Gaza",
|
||||
"Asia/Harbin",
|
||||
"Asia/Hebron",
|
||||
"Asia/Ho_Chi_Minh",
|
||||
"Asia/Hong_Kong",
|
||||
"Asia/Hovd",
|
||||
"Asia/Irkutsk",
|
||||
"Asia/Istanbul",
|
||||
"Asia/Jakarta",
|
||||
"Asia/Jayapura",
|
||||
"Asia/Jerusalem",
|
||||
"Asia/Kabul",
|
||||
"Asia/Kamchatka",
|
||||
"Asia/Karachi",
|
||||
"Asia/Kashgar",
|
||||
"Asia/Kathmandu",
|
||||
"Asia/Katmandu",
|
||||
"Asia/Khandyga",
|
||||
"Asia/Kolkata",
|
||||
"Asia/Krasnoyarsk",
|
||||
"Asia/Kuala_Lumpur",
|
||||
"Asia/Kuching",
|
||||
"Asia/Kuwait",
|
||||
"Asia/Macao",
|
||||
"Asia/Macau",
|
||||
"Asia/Magadan",
|
||||
"Asia/Makassar",
|
||||
"Asia/Manila",
|
||||
"Asia/Muscat",
|
||||
"Asia/Nicosia",
|
||||
"Asia/Novokuznetsk",
|
||||
"Asia/Novosibirsk",
|
||||
"Asia/Omsk",
|
||||
"Asia/Oral",
|
||||
"Asia/Phnom_Penh",
|
||||
"Asia/Pontianak",
|
||||
"Asia/Pyongyang",
|
||||
"Asia/Qatar",
|
||||
"Asia/Qyzylorda",
|
||||
"Asia/Rangoon",
|
||||
"Asia/Riyadh",
|
||||
"Asia/Saigon",
|
||||
"Asia/Sakhalin",
|
||||
"Asia/Samarkand",
|
||||
"Asia/Seoul",
|
||||
"Asia/Shanghai",
|
||||
"Asia/Singapore",
|
||||
"Asia/Srednekolymsk",
|
||||
"Asia/Taipei",
|
||||
"Asia/Tashkent",
|
||||
"Asia/Tbilisi",
|
||||
"Asia/Tehran",
|
||||
"Asia/Tel_Aviv",
|
||||
"Asia/Thimbu",
|
||||
"Asia/Thimphu",
|
||||
"Asia/Tokyo",
|
||||
"Asia/Tomsk",
|
||||
"Asia/Ujung_Pandang",
|
||||
"Asia/Ulaanbaatar",
|
||||
"Asia/Ulan_Bator",
|
||||
"Asia/Urumqi",
|
||||
"Asia/Ust-Nera",
|
||||
"Asia/Vientiane",
|
||||
"Asia/Vladivostok",
|
||||
"Asia/Yakutsk",
|
||||
"Asia/Yangon",
|
||||
"Asia/Yekaterinburg",
|
||||
"Asia/Yerevan",
|
||||
"Atlantic/Azores",
|
||||
"Atlantic/Bermuda",
|
||||
"Atlantic/Canary",
|
||||
"Atlantic/Cape_Verde",
|
||||
"Atlantic/Faeroe",
|
||||
"Atlantic/Faroe",
|
||||
"Atlantic/Jan_Mayen",
|
||||
"Atlantic/Madeira",
|
||||
"Atlantic/Reykjavik",
|
||||
"Atlantic/South_Georgia",
|
||||
"Atlantic/St_Helena",
|
||||
"Atlantic/Stanley",
|
||||
"Australia/ACT",
|
||||
"Australia/Adelaide",
|
||||
"Australia/Brisbane",
|
||||
"Australia/Broken_Hill",
|
||||
"Australia/Canberra",
|
||||
"Australia/Currie",
|
||||
"Australia/Darwin",
|
||||
"Australia/Eucla",
|
||||
"Australia/Hobart",
|
||||
"Australia/LHI",
|
||||
"Australia/Lindeman",
|
||||
"Australia/Lord_Howe",
|
||||
"Australia/Melbourne",
|
||||
"Australia/NSW",
|
||||
"Australia/North",
|
||||
"Australia/Perth",
|
||||
"Australia/Queensland",
|
||||
"Australia/South",
|
||||
"Australia/Sydney",
|
||||
"Australia/Tasmania",
|
||||
"Australia/Victoria",
|
||||
"Australia/West",
|
||||
"Australia/Yancowinna",
|
||||
"Brazil/Acre",
|
||||
"Brazil/DeNoronha",
|
||||
"Brazil/East",
|
||||
"Brazil/West",
|
||||
"CET",
|
||||
"CST6CDT",
|
||||
"Canada/Atlantic",
|
||||
"Canada/Central",
|
||||
"Canada/East-Saskatchewan",
|
||||
"Canada/Eastern",
|
||||
"Canada/Mountain",
|
||||
"Canada/Newfoundland",
|
||||
"Canada/Pacific",
|
||||
"Canada/Saskatchewan",
|
||||
"Canada/Yukon",
|
||||
"Chile/Continental",
|
||||
"Chile/EasterIsland",
|
||||
"Cuba",
|
||||
"EET",
|
||||
"EST",
|
||||
"EST5EDT",
|
||||
"Egypt",
|
||||
"Eire",
|
||||
"Etc/GMT",
|
||||
"Etc/GMT+0",
|
||||
"Etc/GMT+1",
|
||||
"Etc/GMT+10",
|
||||
"Etc/GMT+11",
|
||||
"Etc/GMT+12",
|
||||
"Etc/GMT+2",
|
||||
"Etc/GMT+3",
|
||||
"Etc/GMT+4",
|
||||
"Etc/GMT+5",
|
||||
"Etc/GMT+6",
|
||||
"Etc/GMT+7",
|
||||
"Etc/GMT+8",
|
||||
"Etc/GMT+9",
|
||||
"Etc/GMT-0",
|
||||
"Etc/GMT-1",
|
||||
"Etc/GMT-10",
|
||||
"Etc/GMT-11",
|
||||
"Etc/GMT-12",
|
||||
"Etc/GMT-13",
|
||||
"Etc/GMT-14",
|
||||
"Etc/GMT-2",
|
||||
"Etc/GMT-3",
|
||||
"Etc/GMT-4",
|
||||
"Etc/GMT-5",
|
||||
"Etc/GMT-6",
|
||||
"Etc/GMT-7",
|
||||
"Etc/GMT-8",
|
||||
"Etc/GMT-9",
|
||||
"Etc/GMT0",
|
||||
"Etc/Greenwich",
|
||||
"Etc/UCT",
|
||||
"Etc/UTC",
|
||||
"Etc/Universal",
|
||||
"Etc/Zulu",
|
||||
"Europe/Amsterdam",
|
||||
"Europe/Andorra",
|
||||
"Europe/Astrakhan",
|
||||
"Europe/Athens",
|
||||
"Europe/Belfast",
|
||||
"Europe/Belgrade",
|
||||
"Europe/Berlin",
|
||||
"Europe/Bratislava",
|
||||
"Europe/Brussels",
|
||||
"Europe/Bucharest",
|
||||
"Europe/Budapest",
|
||||
"Europe/Busingen",
|
||||
"Europe/Chisinau",
|
||||
"Europe/Copenhagen",
|
||||
"Europe/Dublin",
|
||||
"Europe/Gibraltar",
|
||||
"Europe/Guernsey",
|
||||
"Europe/Helsinki",
|
||||
"Europe/Isle_of_Man",
|
||||
"Europe/Istanbul",
|
||||
"Europe/Jersey",
|
||||
"Europe/Kaliningrad",
|
||||
"Europe/Kiev",
|
||||
"Europe/Kirov",
|
||||
"Europe/Lisbon",
|
||||
"Europe/Ljubljana",
|
||||
"Europe/London",
|
||||
"Europe/Luxembourg",
|
||||
"Europe/Madrid",
|
||||
"Europe/Malta",
|
||||
"Europe/Mariehamn",
|
||||
"Europe/Minsk",
|
||||
"Europe/Monaco",
|
||||
"Europe/Moscow",
|
||||
"Europe/Nicosia",
|
||||
"Europe/Oslo",
|
||||
"Europe/Paris",
|
||||
"Europe/Podgorica",
|
||||
"Europe/Prague",
|
||||
"Europe/Riga",
|
||||
"Europe/Rome",
|
||||
"Europe/Samara",
|
||||
"Europe/San_Marino",
|
||||
"Europe/Sarajevo",
|
||||
"Europe/Saratov",
|
||||
"Europe/Simferopol",
|
||||
"Europe/Skopje",
|
||||
"Europe/Sofia",
|
||||
"Europe/Stockholm",
|
||||
"Europe/Tallinn",
|
||||
"Europe/Tirane",
|
||||
"Europe/Tiraspol",
|
||||
"Europe/Ulyanovsk",
|
||||
"Europe/Uzhgorod",
|
||||
"Europe/Vaduz",
|
||||
"Europe/Vatican",
|
||||
"Europe/Vienna",
|
||||
"Europe/Vilnius",
|
||||
"Europe/Volgograd",
|
||||
"Europe/Warsaw",
|
||||
"Europe/Zagreb",
|
||||
"Europe/Zaporozhye",
|
||||
"Europe/Zurich",
|
||||
"Factory",
|
||||
"GB",
|
||||
"GB-Eire",
|
||||
"GMT",
|
||||
"GMT+0",
|
||||
"GMT-0",
|
||||
"GMT0",
|
||||
"Greenwich",
|
||||
"HST",
|
||||
"Hongkong",
|
||||
"Iceland",
|
||||
"Indian/Antananarivo",
|
||||
"Indian/Chagos",
|
||||
"Indian/Christmas",
|
||||
"Indian/Cocos",
|
||||
"Indian/Comoro",
|
||||
"Indian/Kerguelen",
|
||||
"Indian/Mahe",
|
||||
"Indian/Maldives",
|
||||
"Indian/Mauritius",
|
||||
"Indian/Mayotte",
|
||||
"Indian/Reunion",
|
||||
"Iran",
|
||||
"Israel",
|
||||
"Jamaica",
|
||||
"Japan",
|
||||
"Kwajalein",
|
||||
"Libya",
|
||||
"MET",
|
||||
"MST",
|
||||
"MST7MDT",
|
||||
"Mexico/BajaNorte",
|
||||
"Mexico/BajaSur",
|
||||
"Mexico/General",
|
||||
"NZ",
|
||||
"NZ-CHAT",
|
||||
"Navajo",
|
||||
"PRC",
|
||||
"PST8PDT",
|
||||
"Pacific/Apia",
|
||||
"Pacific/Auckland",
|
||||
"Pacific/Bougainville",
|
||||
"Pacific/Chatham",
|
||||
"Pacific/Chuuk",
|
||||
"Pacific/Easter",
|
||||
"Pacific/Efate",
|
||||
"Pacific/Enderbury",
|
||||
"Pacific/Fakaofo",
|
||||
"Pacific/Fiji",
|
||||
"Pacific/Funafuti",
|
||||
"Pacific/Galapagos",
|
||||
"Pacific/Gambier",
|
||||
"Pacific/Guadalcanal",
|
||||
"Pacific/Guam",
|
||||
"Pacific/Honolulu",
|
||||
"Pacific/Johnston",
|
||||
"Pacific/Kiritimati",
|
||||
"Pacific/Kosrae",
|
||||
"Pacific/Kwajalein",
|
||||
"Pacific/Majuro",
|
||||
"Pacific/Marquesas",
|
||||
"Pacific/Midway",
|
||||
"Pacific/Nauru",
|
||||
"Pacific/Niue",
|
||||
"Pacific/Norfolk",
|
||||
"Pacific/Noumea",
|
||||
"Pacific/Pago_Pago",
|
||||
"Pacific/Palau",
|
||||
"Pacific/Pitcairn",
|
||||
"Pacific/Pohnpei",
|
||||
"Pacific/Ponape",
|
||||
"Pacific/Port_Moresby",
|
||||
"Pacific/Rarotonga",
|
||||
"Pacific/Saipan",
|
||||
"Pacific/Samoa",
|
||||
"Pacific/Tahiti",
|
||||
"Pacific/Tarawa",
|
||||
"Pacific/Tongatapu",
|
||||
"Pacific/Truk",
|
||||
"Pacific/Wake",
|
||||
"Pacific/Wallis",
|
||||
"Pacific/Yap",
|
||||
"Poland",
|
||||
"Portugal",
|
||||
"ROC",
|
||||
"ROK",
|
||||
"Singapore",
|
||||
"Turkey",
|
||||
"UCT",
|
||||
"US/Alaska",
|
||||
"US/Aleutian",
|
||||
"US/Arizona",
|
||||
"US/Central",
|
||||
"US/East-Indiana",
|
||||
"US/Eastern",
|
||||
"US/Hawaii",
|
||||
"US/Indiana-Starke",
|
||||
"US/Michigan",
|
||||
"US/Mountain",
|
||||
"US/Pacific",
|
||||
"US/Pacific-New",
|
||||
"US/Samoa",
|
||||
"UTC",
|
||||
"Universal",
|
||||
"W-SU",
|
||||
"WET",
|
||||
"Zulu",
|
||||
}
|
40
build/manifest/vendor/github.com/mattermost/mattermost-server/model/token.go
generated
vendored
Normal file
40
build/manifest/vendor/github.com/mattermost/mattermost-server/model/token.go
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import "net/http"
|
||||
|
||||
const (
|
||||
TOKEN_SIZE = 64
|
||||
MAX_TOKEN_EXIPRY_TIME = 1000 * 60 * 60 * 24 // 24 hour
|
||||
TOKEN_TYPE_OAUTH = "oauth"
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
Token string
|
||||
CreateAt int64
|
||||
Type string
|
||||
Extra string
|
||||
}
|
||||
|
||||
func NewToken(tokentype, extra string) *Token {
|
||||
return &Token{
|
||||
Token: NewRandomString(TOKEN_SIZE),
|
||||
CreateAt: GetMillis(),
|
||||
Type: tokentype,
|
||||
Extra: extra,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Token) IsValid() *AppError {
|
||||
if len(t.Token) != TOKEN_SIZE {
|
||||
return NewAppError("Token.IsValid", "model.token.is_valid.size", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if t.CreateAt == 0 {
|
||||
return NewAppError("Token.IsValid", "model.token.is_valid.expiry", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
640
build/manifest/vendor/github.com/mattermost/mattermost-server/model/user.go
generated
vendored
Normal file
640
build/manifest/vendor/github.com/mattermost/mattermost-server/model/user.go
generated
vendored
Normal file
|
@ -0,0 +1,640 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
const (
|
||||
ME = "me"
|
||||
USER_NOTIFY_ALL = "all"
|
||||
USER_NOTIFY_MENTION = "mention"
|
||||
USER_NOTIFY_NONE = "none"
|
||||
DESKTOP_NOTIFY_PROP = "desktop"
|
||||
DESKTOP_SOUND_NOTIFY_PROP = "desktop_sound"
|
||||
MARK_UNREAD_NOTIFY_PROP = "mark_unread"
|
||||
PUSH_NOTIFY_PROP = "push"
|
||||
PUSH_STATUS_NOTIFY_PROP = "push_status"
|
||||
EMAIL_NOTIFY_PROP = "email"
|
||||
CHANNEL_MENTIONS_NOTIFY_PROP = "channel"
|
||||
COMMENTS_NOTIFY_PROP = "comments"
|
||||
MENTION_KEYS_NOTIFY_PROP = "mention_keys"
|
||||
COMMENTS_NOTIFY_NEVER = "never"
|
||||
COMMENTS_NOTIFY_ROOT = "root"
|
||||
COMMENTS_NOTIFY_ANY = "any"
|
||||
|
||||
DEFAULT_LOCALE = "en"
|
||||
USER_AUTH_SERVICE_EMAIL = "email"
|
||||
|
||||
USER_EMAIL_MAX_LENGTH = 128
|
||||
USER_NICKNAME_MAX_RUNES = 64
|
||||
USER_POSITION_MAX_RUNES = 128
|
||||
USER_FIRST_NAME_MAX_RUNES = 64
|
||||
USER_LAST_NAME_MAX_RUNES = 64
|
||||
USER_AUTH_DATA_MAX_LENGTH = 128
|
||||
USER_NAME_MAX_LENGTH = 64
|
||||
USER_NAME_MIN_LENGTH = 1
|
||||
USER_PASSWORD_MAX_LENGTH = 72
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at,omitempty"`
|
||||
UpdateAt int64 `json:"update_at,omitempty"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password,omitempty"`
|
||||
AuthData *string `json:"auth_data,omitempty"`
|
||||
AuthService string `json:"auth_service"`
|
||||
Email string `json:"email"`
|
||||
EmailVerified bool `json:"email_verified,omitempty"`
|
||||
Nickname string `json:"nickname"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
Position string `json:"position"`
|
||||
Roles string `json:"roles"`
|
||||
AllowMarketing bool `json:"allow_marketing,omitempty"`
|
||||
Props StringMap `json:"props,omitempty"`
|
||||
NotifyProps StringMap `json:"notify_props,omitempty"`
|
||||
LastPasswordUpdate int64 `json:"last_password_update,omitempty"`
|
||||
LastPictureUpdate int64 `json:"last_picture_update,omitempty"`
|
||||
FailedAttempts int `json:"failed_attempts,omitempty"`
|
||||
Locale string `json:"locale"`
|
||||
Timezone StringMap `json:"timezone"`
|
||||
MfaActive bool `json:"mfa_active,omitempty"`
|
||||
MfaSecret string `json:"mfa_secret,omitempty"`
|
||||
LastActivityAt int64 `db:"-" json:"last_activity_at,omitempty"`
|
||||
}
|
||||
|
||||
type UserPatch struct {
|
||||
Username *string `json:"username"`
|
||||
Nickname *string `json:"nickname"`
|
||||
FirstName *string `json:"first_name"`
|
||||
LastName *string `json:"last_name"`
|
||||
Position *string `json:"position"`
|
||||
Email *string `json:"email"`
|
||||
Props StringMap `json:"props,omitempty"`
|
||||
NotifyProps StringMap `json:"notify_props,omitempty"`
|
||||
Locale *string `json:"locale"`
|
||||
Timezone StringMap `json:"timezone"`
|
||||
}
|
||||
|
||||
type UserAuth struct {
|
||||
Password string `json:"password,omitempty"`
|
||||
AuthData *string `json:"auth_data,omitempty"`
|
||||
AuthService string `json:"auth_service,omitempty"`
|
||||
}
|
||||
|
||||
func (u *User) DeepCopy() *User {
|
||||
copyUser := *u
|
||||
if u.AuthData != nil {
|
||||
copyUser.AuthData = NewString(*u.AuthData)
|
||||
}
|
||||
if u.Props != nil {
|
||||
copyUser.Props = CopyStringMap(u.Props)
|
||||
}
|
||||
if u.NotifyProps != nil {
|
||||
copyUser.NotifyProps = CopyStringMap(u.NotifyProps)
|
||||
}
|
||||
if u.Timezone != nil {
|
||||
copyUser.Timezone = CopyStringMap(u.Timezone)
|
||||
}
|
||||
return ©User
|
||||
}
|
||||
|
||||
// IsValid validates the user and returns an error if it isn't configured
|
||||
// correctly.
|
||||
func (u *User) IsValid() *AppError {
|
||||
|
||||
if len(u.Id) != 26 {
|
||||
return InvalidUserError("id", "")
|
||||
}
|
||||
|
||||
if u.CreateAt == 0 {
|
||||
return InvalidUserError("create_at", u.Id)
|
||||
}
|
||||
|
||||
if u.UpdateAt == 0 {
|
||||
return InvalidUserError("update_at", u.Id)
|
||||
}
|
||||
|
||||
if !IsValidUsername(u.Username) {
|
||||
return InvalidUserError("username", u.Id)
|
||||
}
|
||||
|
||||
if len(u.Email) > USER_EMAIL_MAX_LENGTH || len(u.Email) == 0 {
|
||||
return InvalidUserError("email", u.Id)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(u.Nickname) > USER_NICKNAME_MAX_RUNES {
|
||||
return InvalidUserError("nickname", u.Id)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(u.Position) > USER_POSITION_MAX_RUNES {
|
||||
return InvalidUserError("position", u.Id)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(u.FirstName) > USER_FIRST_NAME_MAX_RUNES {
|
||||
return InvalidUserError("first_name", u.Id)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(u.LastName) > USER_LAST_NAME_MAX_RUNES {
|
||||
return InvalidUserError("last_name", u.Id)
|
||||
}
|
||||
|
||||
if u.AuthData != nil && len(*u.AuthData) > USER_AUTH_DATA_MAX_LENGTH {
|
||||
return InvalidUserError("auth_data", u.Id)
|
||||
}
|
||||
|
||||
if u.AuthData != nil && len(*u.AuthData) > 0 && len(u.AuthService) == 0 {
|
||||
return InvalidUserError("auth_data_type", u.Id)
|
||||
}
|
||||
|
||||
if len(u.Password) > 0 && u.AuthData != nil && len(*u.AuthData) > 0 {
|
||||
return InvalidUserError("auth_data_pwd", u.Id)
|
||||
}
|
||||
|
||||
if len(u.Password) > USER_PASSWORD_MAX_LENGTH {
|
||||
return InvalidUserError("password_limit", u.Id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func InvalidUserError(fieldName string, userId string) *AppError {
|
||||
id := fmt.Sprintf("model.user.is_valid.%s.app_error", fieldName)
|
||||
details := ""
|
||||
if userId != "" {
|
||||
details = "user_id=" + userId
|
||||
}
|
||||
return NewAppError("User.IsValid", id, nil, details, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func NormalizeUsername(username string) string {
|
||||
return strings.ToLower(username)
|
||||
}
|
||||
|
||||
func NormalizeEmail(email string) string {
|
||||
return strings.ToLower(email)
|
||||
}
|
||||
|
||||
// PreSave will set the Id and Username if missing. It will also fill
|
||||
// in the CreateAt, UpdateAt times. It will also hash the password. It should
|
||||
// be run before saving the user to the db.
|
||||
func (u *User) PreSave() {
|
||||
if u.Id == "" {
|
||||
u.Id = NewId()
|
||||
}
|
||||
|
||||
if u.Username == "" {
|
||||
u.Username = NewId()
|
||||
}
|
||||
|
||||
if u.AuthData != nil && *u.AuthData == "" {
|
||||
u.AuthData = nil
|
||||
}
|
||||
|
||||
u.Username = NormalizeUsername(u.Username)
|
||||
u.Email = NormalizeEmail(u.Email)
|
||||
|
||||
u.CreateAt = GetMillis()
|
||||
u.UpdateAt = u.CreateAt
|
||||
|
||||
u.LastPasswordUpdate = u.CreateAt
|
||||
|
||||
u.MfaActive = false
|
||||
|
||||
if u.Locale == "" {
|
||||
u.Locale = DEFAULT_LOCALE
|
||||
}
|
||||
|
||||
if u.Props == nil {
|
||||
u.Props = make(map[string]string)
|
||||
}
|
||||
|
||||
if u.NotifyProps == nil || len(u.NotifyProps) == 0 {
|
||||
u.SetDefaultNotifications()
|
||||
}
|
||||
|
||||
if u.Timezone == nil {
|
||||
u.Timezone = DefaultUserTimezone()
|
||||
}
|
||||
|
||||
if len(u.Password) > 0 {
|
||||
u.Password = HashPassword(u.Password)
|
||||
}
|
||||
}
|
||||
|
||||
// PreUpdate should be run before updating the user in the db.
|
||||
func (u *User) PreUpdate() {
|
||||
u.Username = NormalizeUsername(u.Username)
|
||||
u.Email = NormalizeEmail(u.Email)
|
||||
u.UpdateAt = GetMillis()
|
||||
|
||||
if u.AuthData != nil && *u.AuthData == "" {
|
||||
u.AuthData = nil
|
||||
}
|
||||
|
||||
if u.NotifyProps == nil || len(u.NotifyProps) == 0 {
|
||||
u.SetDefaultNotifications()
|
||||
} else if _, ok := u.NotifyProps["mention_keys"]; ok {
|
||||
// Remove any blank mention keys
|
||||
splitKeys := strings.Split(u.NotifyProps["mention_keys"], ",")
|
||||
goodKeys := []string{}
|
||||
for _, key := range splitKeys {
|
||||
if len(key) > 0 {
|
||||
goodKeys = append(goodKeys, strings.ToLower(key))
|
||||
}
|
||||
}
|
||||
u.NotifyProps["mention_keys"] = strings.Join(goodKeys, ",")
|
||||
}
|
||||
}
|
||||
|
||||
func (u *User) SetDefaultNotifications() {
|
||||
u.NotifyProps = make(map[string]string)
|
||||
u.NotifyProps["email"] = "true"
|
||||
u.NotifyProps["push"] = USER_NOTIFY_MENTION
|
||||
u.NotifyProps["desktop"] = USER_NOTIFY_MENTION
|
||||
u.NotifyProps["desktop_sound"] = "true"
|
||||
u.NotifyProps["mention_keys"] = u.Username + ",@" + u.Username
|
||||
u.NotifyProps["channel"] = "true"
|
||||
u.NotifyProps["push_status"] = STATUS_AWAY
|
||||
u.NotifyProps["comments"] = "never"
|
||||
u.NotifyProps["first_name"] = "false"
|
||||
}
|
||||
|
||||
func (user *User) UpdateMentionKeysFromUsername(oldUsername string) {
|
||||
nonUsernameKeys := []string{}
|
||||
splitKeys := strings.Split(user.NotifyProps["mention_keys"], ",")
|
||||
for _, key := range splitKeys {
|
||||
if key != oldUsername && key != "@"+oldUsername {
|
||||
nonUsernameKeys = append(nonUsernameKeys, key)
|
||||
}
|
||||
}
|
||||
|
||||
user.NotifyProps["mention_keys"] = user.Username + ",@" + user.Username
|
||||
if len(nonUsernameKeys) > 0 {
|
||||
user.NotifyProps["mention_keys"] += "," + strings.Join(nonUsernameKeys, ",")
|
||||
}
|
||||
}
|
||||
|
||||
func (u *User) Patch(patch *UserPatch) {
|
||||
if patch.Username != nil {
|
||||
u.Username = *patch.Username
|
||||
}
|
||||
|
||||
if patch.Nickname != nil {
|
||||
u.Nickname = *patch.Nickname
|
||||
}
|
||||
|
||||
if patch.FirstName != nil {
|
||||
u.FirstName = *patch.FirstName
|
||||
}
|
||||
|
||||
if patch.LastName != nil {
|
||||
u.LastName = *patch.LastName
|
||||
}
|
||||
|
||||
if patch.Position != nil {
|
||||
u.Position = *patch.Position
|
||||
}
|
||||
|
||||
if patch.Email != nil {
|
||||
u.Email = *patch.Email
|
||||
}
|
||||
|
||||
if patch.Props != nil {
|
||||
u.Props = patch.Props
|
||||
}
|
||||
|
||||
if patch.NotifyProps != nil {
|
||||
u.NotifyProps = patch.NotifyProps
|
||||
}
|
||||
|
||||
if patch.Locale != nil {
|
||||
u.Locale = *patch.Locale
|
||||
}
|
||||
|
||||
if patch.Timezone != nil {
|
||||
u.Timezone = patch.Timezone
|
||||
}
|
||||
}
|
||||
|
||||
// ToJson convert a User to a json string
|
||||
func (u *User) ToJson() string {
|
||||
b, _ := json.Marshal(u)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (u *UserPatch) ToJson() string {
|
||||
b, _ := json.Marshal(u)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (u *UserAuth) ToJson() string {
|
||||
b, _ := json.Marshal(u)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Generate a valid strong etag so the browser can cache the results
|
||||
func (u *User) Etag(showFullName, showEmail bool) string {
|
||||
return Etag(u.Id, u.UpdateAt, showFullName, showEmail)
|
||||
}
|
||||
|
||||
// Remove any private data from the user object
|
||||
func (u *User) Sanitize(options map[string]bool) {
|
||||
u.Password = ""
|
||||
u.AuthData = NewString("")
|
||||
u.MfaSecret = ""
|
||||
|
||||
if len(options) != 0 && !options["email"] {
|
||||
u.Email = ""
|
||||
}
|
||||
if len(options) != 0 && !options["fullname"] {
|
||||
u.FirstName = ""
|
||||
u.LastName = ""
|
||||
}
|
||||
if len(options) != 0 && !options["passwordupdate"] {
|
||||
u.LastPasswordUpdate = 0
|
||||
}
|
||||
if len(options) != 0 && !options["authservice"] {
|
||||
u.AuthService = ""
|
||||
}
|
||||
}
|
||||
|
||||
func (u *User) ClearNonProfileFields() {
|
||||
u.Password = ""
|
||||
u.AuthData = NewString("")
|
||||
u.MfaSecret = ""
|
||||
u.EmailVerified = false
|
||||
u.AllowMarketing = false
|
||||
u.NotifyProps = StringMap{}
|
||||
u.LastPasswordUpdate = 0
|
||||
u.FailedAttempts = 0
|
||||
}
|
||||
|
||||
func (u *User) SanitizeProfile(options map[string]bool) {
|
||||
u.ClearNonProfileFields()
|
||||
|
||||
u.Sanitize(options)
|
||||
}
|
||||
|
||||
func (u *User) MakeNonNil() {
|
||||
if u.Props == nil {
|
||||
u.Props = make(map[string]string)
|
||||
}
|
||||
|
||||
if u.NotifyProps == nil {
|
||||
u.NotifyProps = make(map[string]string)
|
||||
}
|
||||
}
|
||||
|
||||
func (u *User) AddNotifyProp(key string, value string) {
|
||||
u.MakeNonNil()
|
||||
|
||||
u.NotifyProps[key] = value
|
||||
}
|
||||
|
||||
func (u *User) GetFullName() string {
|
||||
if len(u.FirstName) > 0 && len(u.LastName) > 0 {
|
||||
return u.FirstName + " " + u.LastName
|
||||
} else if len(u.FirstName) > 0 {
|
||||
return u.FirstName
|
||||
} else if len(u.LastName) > 0 {
|
||||
return u.LastName
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (u *User) GetDisplayName(nameFormat string) string {
|
||||
displayName := u.Username
|
||||
|
||||
if nameFormat == SHOW_NICKNAME_FULLNAME {
|
||||
if len(u.Nickname) > 0 {
|
||||
displayName = u.Nickname
|
||||
} else if fullName := u.GetFullName(); len(fullName) > 0 {
|
||||
displayName = fullName
|
||||
}
|
||||
} else if nameFormat == SHOW_FULLNAME {
|
||||
if fullName := u.GetFullName(); len(fullName) > 0 {
|
||||
displayName = fullName
|
||||
}
|
||||
}
|
||||
|
||||
return displayName
|
||||
}
|
||||
|
||||
func (u *User) GetRoles() []string {
|
||||
return strings.Fields(u.Roles)
|
||||
}
|
||||
|
||||
func (u *User) GetRawRoles() string {
|
||||
return u.Roles
|
||||
}
|
||||
|
||||
func IsValidUserRoles(userRoles string) bool {
|
||||
|
||||
roles := strings.Fields(userRoles)
|
||||
|
||||
for _, r := range roles {
|
||||
if !IsValidRoleName(r) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Exclude just the system_admin role explicitly to prevent mistakes
|
||||
if len(roles) == 1 && roles[0] == "system_admin" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Make sure you acually want to use this function. In context.go there are functions to check permissions
|
||||
// This function should not be used to check permissions.
|
||||
func (u *User) IsInRole(inRole string) bool {
|
||||
return IsInRole(u.Roles, inRole)
|
||||
}
|
||||
|
||||
// Make sure you acually want to use this function. In context.go there are functions to check permissions
|
||||
// This function should not be used to check permissions.
|
||||
func IsInRole(userRoles string, inRole string) bool {
|
||||
roles := strings.Split(userRoles, " ")
|
||||
|
||||
for _, r := range roles {
|
||||
if r == inRole {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *User) IsSSOUser() bool {
|
||||
return u.AuthService != "" && u.AuthService != USER_AUTH_SERVICE_EMAIL
|
||||
}
|
||||
|
||||
func (u *User) IsOAuthUser() bool {
|
||||
return u.AuthService == USER_AUTH_SERVICE_GITLAB
|
||||
}
|
||||
|
||||
func (u *User) IsLDAPUser() bool {
|
||||
return u.AuthService == USER_AUTH_SERVICE_LDAP
|
||||
}
|
||||
|
||||
func (u *User) IsSAMLUser() bool {
|
||||
return u.AuthService == USER_AUTH_SERVICE_SAML
|
||||
}
|
||||
|
||||
func (u *User) GetPreferredTimezone() string {
|
||||
if u.Timezone["useAutomaticTimezone"] == "true" {
|
||||
return u.Timezone["automaticTimezone"]
|
||||
}
|
||||
|
||||
return u.Timezone["manualTimezone"]
|
||||
}
|
||||
|
||||
// UserFromJson will decode the input and return a User
|
||||
func UserFromJson(data io.Reader) *User {
|
||||
var user *User
|
||||
json.NewDecoder(data).Decode(&user)
|
||||
return user
|
||||
}
|
||||
|
||||
func UserPatchFromJson(data io.Reader) *UserPatch {
|
||||
var user *UserPatch
|
||||
json.NewDecoder(data).Decode(&user)
|
||||
return user
|
||||
}
|
||||
|
||||
func UserAuthFromJson(data io.Reader) *UserAuth {
|
||||
var user *UserAuth
|
||||
json.NewDecoder(data).Decode(&user)
|
||||
return user
|
||||
}
|
||||
|
||||
func UserMapToJson(u map[string]*User) string {
|
||||
b, _ := json.Marshal(u)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func UserMapFromJson(data io.Reader) map[string]*User {
|
||||
var users map[string]*User
|
||||
json.NewDecoder(data).Decode(&users)
|
||||
return users
|
||||
}
|
||||
|
||||
func UserListToJson(u []*User) string {
|
||||
b, _ := json.Marshal(u)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func UserListFromJson(data io.Reader) []*User {
|
||||
var users []*User
|
||||
json.NewDecoder(data).Decode(&users)
|
||||
return users
|
||||
}
|
||||
|
||||
// HashPassword generates a hash using the bcrypt.GenerateFromPassword
|
||||
func HashPassword(password string) string {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), 10)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return string(hash)
|
||||
}
|
||||
|
||||
// ComparePassword compares the hash
|
||||
func ComparePassword(hash string, password string) bool {
|
||||
|
||||
if len(password) == 0 || len(hash) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
var validUsernameChars = regexp.MustCompile(`^[a-z0-9\.\-_]+$`)
|
||||
|
||||
var restrictedUsernames = []string{
|
||||
"all",
|
||||
"channel",
|
||||
"matterbot",
|
||||
"system",
|
||||
}
|
||||
|
||||
func IsValidUsername(s string) bool {
|
||||
if len(s) < USER_NAME_MIN_LENGTH || len(s) > USER_NAME_MAX_LENGTH {
|
||||
return false
|
||||
}
|
||||
|
||||
if !validUsernameChars.MatchString(s) {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, restrictedUsername := range restrictedUsernames {
|
||||
if s == restrictedUsername {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func CleanUsername(s string) string {
|
||||
s = NormalizeUsername(strings.Replace(s, " ", "-", -1))
|
||||
|
||||
for _, value := range reservedName {
|
||||
if s == value {
|
||||
s = strings.Replace(s, value, "", -1)
|
||||
}
|
||||
}
|
||||
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
for _, c := range s {
|
||||
char := fmt.Sprintf("%c", c)
|
||||
if !validUsernameChars.MatchString(char) {
|
||||
s = strings.Replace(s, char, "-", -1)
|
||||
}
|
||||
}
|
||||
|
||||
s = strings.Trim(s, "-")
|
||||
|
||||
if !IsValidUsername(s) {
|
||||
s = "a" + NewId()
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func IsValidUserNotifyLevel(notifyLevel string) bool {
|
||||
return notifyLevel == CHANNEL_NOTIFY_ALL ||
|
||||
notifyLevel == CHANNEL_NOTIFY_MENTION ||
|
||||
notifyLevel == CHANNEL_NOTIFY_NONE
|
||||
}
|
||||
|
||||
func IsValidPushStatusNotifyLevel(notifyLevel string) bool {
|
||||
return notifyLevel == STATUS_ONLINE ||
|
||||
notifyLevel == STATUS_AWAY ||
|
||||
notifyLevel == STATUS_OFFLINE
|
||||
}
|
||||
|
||||
func IsValidCommentsNotifyLevel(notifyLevel string) bool {
|
||||
return notifyLevel == COMMENTS_NOTIFY_ANY ||
|
||||
notifyLevel == COMMENTS_NOTIFY_ROOT ||
|
||||
notifyLevel == COMMENTS_NOTIFY_NEVER
|
||||
}
|
65
build/manifest/vendor/github.com/mattermost/mattermost-server/model/user_access_token.go
generated
vendored
Normal file
65
build/manifest/vendor/github.com/mattermost/mattermost-server/model/user_access_token.go
generated
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UserAccessToken struct {
|
||||
Id string `json:"id"`
|
||||
Token string `json:"token,omitempty"`
|
||||
UserId string `json:"user_id"`
|
||||
Description string `json:"description"`
|
||||
IsActive bool `json:"is_active"`
|
||||
}
|
||||
|
||||
func (t *UserAccessToken) IsValid() *AppError {
|
||||
if len(t.Id) != 26 {
|
||||
return NewAppError("UserAccessToken.IsValid", "model.user_access_token.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(t.Token) != 26 {
|
||||
return NewAppError("UserAccessToken.IsValid", "model.user_access_token.is_valid.token.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(t.UserId) != 26 {
|
||||
return NewAppError("UserAccessToken.IsValid", "model.user_access_token.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(t.Description) > 255 {
|
||||
return NewAppError("UserAccessToken.IsValid", "model.user_access_token.is_valid.description.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *UserAccessToken) PreSave() {
|
||||
t.Id = NewId()
|
||||
t.IsActive = true
|
||||
}
|
||||
|
||||
func (t *UserAccessToken) ToJson() string {
|
||||
b, _ := json.Marshal(t)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func UserAccessTokenFromJson(data io.Reader) *UserAccessToken {
|
||||
var t *UserAccessToken
|
||||
json.NewDecoder(data).Decode(&t)
|
||||
return t
|
||||
}
|
||||
|
||||
func UserAccessTokenListToJson(t []*UserAccessToken) string {
|
||||
b, _ := json.Marshal(t)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func UserAccessTokenListFromJson(data io.Reader) []*UserAccessToken {
|
||||
var t []*UserAccessToken
|
||||
json.NewDecoder(data).Decode(&t)
|
||||
return t
|
||||
}
|
35
build/manifest/vendor/github.com/mattermost/mattermost-server/model/user_access_token_search.go
generated
vendored
Normal file
35
build/manifest/vendor/github.com/mattermost/mattermost-server/model/user_access_token_search.go
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type UserAccessTokenSearch struct {
|
||||
Term string `json:"term"`
|
||||
}
|
||||
|
||||
// ToJson convert a UserAccessTokenSearch to json string
|
||||
func (c *UserAccessTokenSearch) ToJson() string {
|
||||
b, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// UserAccessTokenSearchJson decodes the input and returns a UserAccessTokenSearch
|
||||
func UserAccessTokenSearchFromJson(data io.Reader) *UserAccessTokenSearch {
|
||||
decoder := json.NewDecoder(data)
|
||||
var cs UserAccessTokenSearch
|
||||
err := decoder.Decode(&cs)
|
||||
if err == nil {
|
||||
return &cs
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
61
build/manifest/vendor/github.com/mattermost/mattermost-server/model/user_autocomplete.go
generated
vendored
Normal file
61
build/manifest/vendor/github.com/mattermost/mattermost-server/model/user_autocomplete.go
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type UserAutocompleteInChannel struct {
|
||||
InChannel []*User `json:"in_channel"`
|
||||
OutOfChannel []*User `json:"out_of_channel"`
|
||||
}
|
||||
|
||||
type UserAutocompleteInTeam struct {
|
||||
InTeam []*User `json:"in_team"`
|
||||
}
|
||||
|
||||
type UserAutocomplete struct {
|
||||
Users []*User `json:"users"`
|
||||
OutOfChannel []*User `json:"out_of_channel,omitempty"`
|
||||
}
|
||||
|
||||
func (o *UserAutocomplete) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func UserAutocompleteFromJson(data io.Reader) *UserAutocomplete {
|
||||
decoder := json.NewDecoder(data)
|
||||
autocomplete := new(UserAutocomplete)
|
||||
err := decoder.Decode(&autocomplete)
|
||||
if err == nil {
|
||||
return autocomplete
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o *UserAutocompleteInChannel) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func UserAutocompleteInChannelFromJson(data io.Reader) *UserAutocompleteInChannel {
|
||||
var o *UserAutocompleteInChannel
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *UserAutocompleteInTeam) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func UserAutocompleteInTeamFromJson(data io.Reader) *UserAutocompleteInTeam {
|
||||
var o *UserAutocompleteInTeam
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
32
build/manifest/vendor/github.com/mattermost/mattermost-server/model/user_search.go
generated
vendored
Normal file
32
build/manifest/vendor/github.com/mattermost/mattermost-server/model/user_search.go
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type UserSearch struct {
|
||||
Term string `json:"term"`
|
||||
TeamId string `json:"team_id"`
|
||||
NotInTeamId string `json:"not_in_team_id"`
|
||||
InChannelId string `json:"in_channel_id"`
|
||||
NotInChannelId string `json:"not_in_channel_id"`
|
||||
AllowInactive bool `json:"allow_inactive"`
|
||||
WithoutTeam bool `json:"without_team"`
|
||||
}
|
||||
|
||||
// ToJson convert a User to a json string
|
||||
func (u *UserSearch) ToJson() string {
|
||||
b, _ := json.Marshal(u)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// UserSearchFromJson will decode the input and return a User
|
||||
func UserSearchFromJson(data io.Reader) *UserSearch {
|
||||
var us *UserSearch
|
||||
json.NewDecoder(data).Decode(&us)
|
||||
return us
|
||||
}
|
24
build/manifest/vendor/github.com/mattermost/mattermost-server/model/users_stats.go
generated
vendored
Normal file
24
build/manifest/vendor/github.com/mattermost/mattermost-server/model/users_stats.go
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type UsersStats struct {
|
||||
TotalUsersCount int64 `json:"total_users_count"`
|
||||
}
|
||||
|
||||
func (o *UsersStats) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func UsersStatsFromJson(data io.Reader) *UsersStats {
|
||||
var o *UsersStats
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
538
build/manifest/vendor/github.com/mattermost/mattermost-server/model/utils.go
generated
vendored
Normal file
538
build/manifest/vendor/github.com/mattermost/mattermost-server/model/utils.go
generated
vendored
Normal file
|
@ -0,0 +1,538 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/base32"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/mail"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||
"github.com/pborman/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
LOWERCASE_LETTERS = "abcdefghijklmnopqrstuvwxyz"
|
||||
UPPERCASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
NUMBERS = "0123456789"
|
||||
SYMBOLS = " !\"\\#$%&'()*+,-./:;<=>?@[]^_`|~"
|
||||
)
|
||||
|
||||
type StringInterface map[string]interface{}
|
||||
type StringMap map[string]string
|
||||
type StringArray []string
|
||||
|
||||
var translateFunc goi18n.TranslateFunc = nil
|
||||
|
||||
func AppErrorInit(t goi18n.TranslateFunc) {
|
||||
translateFunc = t
|
||||
}
|
||||
|
||||
type AppError struct {
|
||||
Id string `json:"id"`
|
||||
Message string `json:"message"` // Message to be display to the end user without debugging information
|
||||
DetailedError string `json:"detailed_error"` // Internal error string to help the developer
|
||||
RequestId string `json:"request_id,omitempty"` // The RequestId that's also set in the header
|
||||
StatusCode int `json:"status_code,omitempty"` // The http status code
|
||||
Where string `json:"-"` // The function where it happened in the form of Struct.Func
|
||||
IsOAuth bool `json:"is_oauth,omitempty"` // Whether the error is OAuth specific
|
||||
params map[string]interface{}
|
||||
}
|
||||
|
||||
func (er *AppError) Error() string {
|
||||
return er.Where + ": " + er.Message + ", " + er.DetailedError
|
||||
}
|
||||
|
||||
func (er *AppError) Translate(T goi18n.TranslateFunc) {
|
||||
if T == nil {
|
||||
er.Message = er.Id
|
||||
return
|
||||
}
|
||||
|
||||
if er.params == nil {
|
||||
er.Message = T(er.Id)
|
||||
} else {
|
||||
er.Message = T(er.Id, er.params)
|
||||
}
|
||||
}
|
||||
|
||||
func (er *AppError) SystemMessage(T goi18n.TranslateFunc) string {
|
||||
if er.params == nil {
|
||||
return T(er.Id)
|
||||
} else {
|
||||
return T(er.Id, er.params)
|
||||
}
|
||||
}
|
||||
|
||||
func (er *AppError) ToJson() string {
|
||||
b, _ := json.Marshal(er)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// AppErrorFromJson will decode the input and return an AppError
|
||||
func AppErrorFromJson(data io.Reader) *AppError {
|
||||
str := ""
|
||||
bytes, rerr := ioutil.ReadAll(data)
|
||||
if rerr != nil {
|
||||
str = rerr.Error()
|
||||
} else {
|
||||
str = string(bytes)
|
||||
}
|
||||
|
||||
decoder := json.NewDecoder(strings.NewReader(str))
|
||||
var er AppError
|
||||
err := decoder.Decode(&er)
|
||||
if err == nil {
|
||||
return &er
|
||||
} else {
|
||||
return NewAppError("AppErrorFromJson", "model.utils.decode_json.app_error", nil, "body: "+str, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func NewAppError(where string, id string, params map[string]interface{}, details string, status int) *AppError {
|
||||
ap := &AppError{}
|
||||
ap.Id = id
|
||||
ap.params = params
|
||||
ap.Message = id
|
||||
ap.Where = where
|
||||
ap.DetailedError = details
|
||||
ap.StatusCode = status
|
||||
ap.IsOAuth = false
|
||||
ap.Translate(translateFunc)
|
||||
return ap
|
||||
}
|
||||
|
||||
var encoding = base32.NewEncoding("ybndrfg8ejkmcpqxot1uwisza345h769")
|
||||
|
||||
// NewId is a globally unique identifier. It is a [A-Z0-9] string 26
|
||||
// characters long. It is a UUID version 4 Guid that is zbased32 encoded
|
||||
// with the padding stripped off.
|
||||
func NewId() string {
|
||||
var b bytes.Buffer
|
||||
encoder := base32.NewEncoder(encoding, &b)
|
||||
encoder.Write(uuid.NewRandom())
|
||||
encoder.Close()
|
||||
b.Truncate(26) // removes the '==' padding
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func NewRandomString(length int) string {
|
||||
var b bytes.Buffer
|
||||
str := make([]byte, length+8)
|
||||
rand.Read(str)
|
||||
encoder := base32.NewEncoder(encoding, &b)
|
||||
encoder.Write(str)
|
||||
encoder.Close()
|
||||
b.Truncate(length) // removes the '==' padding
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// GetMillis is a convience method to get milliseconds since epoch.
|
||||
func GetMillis() int64 {
|
||||
return time.Now().UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
func CopyStringMap(originalMap map[string]string) map[string]string {
|
||||
copyMap := make(map[string]string)
|
||||
for k, v := range originalMap {
|
||||
copyMap[k] = v
|
||||
}
|
||||
return copyMap
|
||||
}
|
||||
|
||||
// MapToJson converts a map to a json string
|
||||
func MapToJson(objmap map[string]string) string {
|
||||
b, _ := json.Marshal(objmap)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// MapToJson converts a map to a json string
|
||||
func MapBoolToJson(objmap map[string]bool) string {
|
||||
b, _ := json.Marshal(objmap)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// MapFromJson will decode the key/value pair map
|
||||
func MapFromJson(data io.Reader) map[string]string {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap map[string]string
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
return make(map[string]string)
|
||||
} else {
|
||||
return objmap
|
||||
}
|
||||
}
|
||||
|
||||
// MapFromJson will decode the key/value pair map
|
||||
func MapBoolFromJson(data io.Reader) map[string]bool {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap map[string]bool
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
return make(map[string]bool)
|
||||
} else {
|
||||
return objmap
|
||||
}
|
||||
}
|
||||
|
||||
func ArrayToJson(objmap []string) string {
|
||||
b, _ := json.Marshal(objmap)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ArrayFromJson(data io.Reader) []string {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap []string
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
return make([]string, 0)
|
||||
} else {
|
||||
return objmap
|
||||
}
|
||||
}
|
||||
|
||||
func ArrayFromInterface(data interface{}) []string {
|
||||
stringArray := []string{}
|
||||
|
||||
dataArray, ok := data.([]interface{})
|
||||
if !ok {
|
||||
return stringArray
|
||||
}
|
||||
|
||||
for _, v := range dataArray {
|
||||
if str, ok := v.(string); ok {
|
||||
stringArray = append(stringArray, str)
|
||||
}
|
||||
}
|
||||
|
||||
return stringArray
|
||||
}
|
||||
|
||||
func StringInterfaceToJson(objmap map[string]interface{}) string {
|
||||
b, _ := json.Marshal(objmap)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func StringInterfaceFromJson(data io.Reader) map[string]interface{} {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap map[string]interface{}
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
return make(map[string]interface{})
|
||||
} else {
|
||||
return objmap
|
||||
}
|
||||
}
|
||||
|
||||
func StringToJson(s string) string {
|
||||
b, _ := json.Marshal(s)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func StringFromJson(data io.Reader) string {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var s string
|
||||
if err := decoder.Decode(&s); err != nil {
|
||||
return ""
|
||||
} else {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
func GetServerIpAddress() string {
|
||||
if addrs, err := net.InterfaceAddrs(); err != nil {
|
||||
return ""
|
||||
} else {
|
||||
for _, addr := range addrs {
|
||||
|
||||
if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() {
|
||||
if ip.IP.To4() != nil {
|
||||
return ip.IP.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func IsLower(s string) bool {
|
||||
return strings.ToLower(s) == s
|
||||
}
|
||||
|
||||
func IsValidEmail(email string) bool {
|
||||
|
||||
if !IsLower(email) {
|
||||
return false
|
||||
}
|
||||
|
||||
if _, err := mail.ParseAddress(email); err == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
var reservedName = []string{
|
||||
"signup",
|
||||
"login",
|
||||
"admin",
|
||||
"channel",
|
||||
"post",
|
||||
"api",
|
||||
"oauth",
|
||||
}
|
||||
|
||||
func IsValidChannelIdentifier(s string) bool {
|
||||
|
||||
if !IsValidAlphaNumHyphenUnderscore(s, true) {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(s) < CHANNEL_NAME_MIN_LENGTH {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func IsValidAlphaNum(s string) bool {
|
||||
validAlphaNum := regexp.MustCompile(`^[a-z0-9]+([a-z\-0-9]+|(__)?)[a-z0-9]+$`)
|
||||
|
||||
return validAlphaNum.MatchString(s)
|
||||
}
|
||||
|
||||
func IsValidAlphaNumHyphenUnderscore(s string, withFormat bool) bool {
|
||||
if withFormat {
|
||||
validAlphaNumHyphenUnderscore := regexp.MustCompile(`^[a-z0-9]+([a-z\-\_0-9]+|(__)?)[a-z0-9]+$`)
|
||||
return validAlphaNumHyphenUnderscore.MatchString(s)
|
||||
}
|
||||
|
||||
validSimpleAlphaNumHyphenUnderscore := regexp.MustCompile(`^[a-zA-Z0-9\-_]+$`)
|
||||
return validSimpleAlphaNumHyphenUnderscore.MatchString(s)
|
||||
}
|
||||
|
||||
func Etag(parts ...interface{}) string {
|
||||
|
||||
etag := CurrentVersion
|
||||
|
||||
for _, part := range parts {
|
||||
etag += fmt.Sprintf(".%v", part)
|
||||
}
|
||||
|
||||
return etag
|
||||
}
|
||||
|
||||
var validHashtag = regexp.MustCompile(`^(#\pL[\pL\d\-_.]*[\pL\d])$`)
|
||||
var puncStart = regexp.MustCompile(`^[^\pL\d\s#]+`)
|
||||
var hashtagStart = regexp.MustCompile(`^#{2,}`)
|
||||
var puncEnd = regexp.MustCompile(`[^\pL\d\s]+$`)
|
||||
|
||||
func ParseHashtags(text string) (string, string) {
|
||||
words := strings.Fields(text)
|
||||
|
||||
hashtagString := ""
|
||||
plainString := ""
|
||||
for _, word := range words {
|
||||
// trim off surrounding punctuation
|
||||
word = puncStart.ReplaceAllString(word, "")
|
||||
word = puncEnd.ReplaceAllString(word, "")
|
||||
|
||||
// and remove extra pound #s
|
||||
word = hashtagStart.ReplaceAllString(word, "#")
|
||||
|
||||
if validHashtag.MatchString(word) {
|
||||
hashtagString += " " + word
|
||||
} else {
|
||||
plainString += " " + word
|
||||
}
|
||||
}
|
||||
|
||||
if len(hashtagString) > 1000 {
|
||||
hashtagString = hashtagString[:999]
|
||||
lastSpace := strings.LastIndex(hashtagString, " ")
|
||||
if lastSpace > -1 {
|
||||
hashtagString = hashtagString[:lastSpace]
|
||||
} else {
|
||||
hashtagString = ""
|
||||
}
|
||||
}
|
||||
|
||||
return strings.TrimSpace(hashtagString), strings.TrimSpace(plainString)
|
||||
}
|
||||
|
||||
func IsFileExtImage(ext string) bool {
|
||||
ext = strings.ToLower(ext)
|
||||
for _, imgExt := range IMAGE_EXTENSIONS {
|
||||
if ext == imgExt {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func GetImageMimeType(ext string) string {
|
||||
ext = strings.ToLower(ext)
|
||||
if len(IMAGE_MIME_TYPES[ext]) == 0 {
|
||||
return "image"
|
||||
} else {
|
||||
return IMAGE_MIME_TYPES[ext]
|
||||
}
|
||||
}
|
||||
|
||||
func ClearMentionTags(post string) string {
|
||||
post = strings.Replace(post, "<mention>", "", -1)
|
||||
post = strings.Replace(post, "</mention>", "", -1)
|
||||
return post
|
||||
}
|
||||
|
||||
func IsValidHttpUrl(rawUrl string) bool {
|
||||
if strings.Index(rawUrl, "http://") != 0 && strings.Index(rawUrl, "https://") != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if _, err := url.ParseRequestURI(rawUrl); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func IsValidTurnOrStunServer(rawUri string) bool {
|
||||
if strings.Index(rawUri, "turn:") != 0 && strings.Index(rawUri, "stun:") != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if _, err := url.ParseRequestURI(rawUri); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func IsSafeLink(link *string) bool {
|
||||
if link != nil {
|
||||
if IsValidHttpUrl(*link) {
|
||||
return true
|
||||
} else if strings.HasPrefix(*link, "/") {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func IsValidWebsocketUrl(rawUrl string) bool {
|
||||
if strings.Index(rawUrl, "ws://") != 0 && strings.Index(rawUrl, "wss://") != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if _, err := url.ParseRequestURI(rawUrl); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func IsValidTrueOrFalseString(value string) bool {
|
||||
return value == "true" || value == "false"
|
||||
}
|
||||
|
||||
func IsValidNumberString(value string) bool {
|
||||
if _, err := strconv.Atoi(value); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func IsValidId(value string) bool {
|
||||
if len(value) != 26 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, r := range value {
|
||||
if !unicode.IsLetter(r) && !unicode.IsNumber(r) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// checkNowhereNil checks that the given interface value is not nil, and if a struct, that all of
|
||||
// its public fields are also nowhere nil
|
||||
func checkNowhereNil(t *testing.T, name string, value interface{}) bool {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(value)
|
||||
switch v.Type().Kind() {
|
||||
case reflect.Ptr:
|
||||
if v.IsNil() {
|
||||
t.Logf("%s was nil", name)
|
||||
return false
|
||||
}
|
||||
|
||||
return checkNowhereNil(t, fmt.Sprintf("(*%s)", name), v.Elem().Interface())
|
||||
|
||||
case reflect.Map:
|
||||
if v.IsNil() {
|
||||
t.Logf("%s was nil", name)
|
||||
return false
|
||||
}
|
||||
|
||||
// Don't check map values
|
||||
return true
|
||||
|
||||
case reflect.Struct:
|
||||
nowhereNil := true
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
f := v.Field(i)
|
||||
// Ignore unexported fields
|
||||
if v.Type().Field(i).PkgPath != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
nowhereNil = nowhereNil && checkNowhereNil(t, fmt.Sprintf("%s.%s", name, v.Type().Field(i).Name), f.Interface())
|
||||
}
|
||||
|
||||
return nowhereNil
|
||||
|
||||
case reflect.Array:
|
||||
fallthrough
|
||||
case reflect.Chan:
|
||||
fallthrough
|
||||
case reflect.Func:
|
||||
fallthrough
|
||||
case reflect.Interface:
|
||||
fallthrough
|
||||
case reflect.UnsafePointer:
|
||||
t.Logf("unhandled field %s, type: %s", name, v.Type().Kind())
|
||||
return false
|
||||
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
152
build/manifest/vendor/github.com/mattermost/mattermost-server/model/version.go
generated
vendored
Normal file
152
build/manifest/vendor/github.com/mattermost/mattermost-server/model/version.go
generated
vendored
Normal file
|
@ -0,0 +1,152 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// This is a list of all the current versions including any patches.
|
||||
// It should be maintained in chronological order with most current
|
||||
// release at the front of the list.
|
||||
var versions = []string{
|
||||
"5.1.0",
|
||||
"5.0.0",
|
||||
"4.10.0",
|
||||
"4.9.0",
|
||||
"4.8.1",
|
||||
"4.8.0",
|
||||
"4.7.2",
|
||||
"4.7.1",
|
||||
"4.7.0",
|
||||
"4.6.0",
|
||||
"4.5.0",
|
||||
"4.4.0",
|
||||
"4.3.0",
|
||||
"4.2.0",
|
||||
"4.1.0",
|
||||
"4.0.0",
|
||||
"3.10.0",
|
||||
"3.9.0",
|
||||
"3.8.0",
|
||||
"3.7.0",
|
||||
"3.6.0",
|
||||
"3.5.0",
|
||||
"3.4.0",
|
||||
"3.3.0",
|
||||
"3.2.0",
|
||||
"3.1.0",
|
||||
"3.0.0",
|
||||
"2.2.0",
|
||||
"2.1.0",
|
||||
"2.0.0",
|
||||
"1.4.0",
|
||||
"1.3.0",
|
||||
"1.2.1",
|
||||
"1.2.0",
|
||||
"1.1.0",
|
||||
"1.0.0",
|
||||
"0.7.1",
|
||||
"0.7.0",
|
||||
"0.6.0",
|
||||
"0.5.0",
|
||||
}
|
||||
|
||||
var CurrentVersion string = versions[0]
|
||||
var BuildNumber string
|
||||
var BuildDate string
|
||||
var BuildHash string
|
||||
var BuildHashEnterprise string
|
||||
var BuildEnterpriseReady string
|
||||
var versionsWithoutHotFixes []string
|
||||
|
||||
func init() {
|
||||
versionsWithoutHotFixes = make([]string, 0, len(versions))
|
||||
seen := make(map[string]string)
|
||||
|
||||
for _, version := range versions {
|
||||
maj, min, _ := SplitVersion(version)
|
||||
verStr := fmt.Sprintf("%v.%v.0", maj, min)
|
||||
|
||||
if seen[verStr] == "" {
|
||||
versionsWithoutHotFixes = append(versionsWithoutHotFixes, verStr)
|
||||
seen[verStr] = verStr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func SplitVersion(version string) (int64, int64, int64) {
|
||||
parts := strings.Split(version, ".")
|
||||
|
||||
major := int64(0)
|
||||
minor := int64(0)
|
||||
patch := int64(0)
|
||||
|
||||
if len(parts) > 0 {
|
||||
major, _ = strconv.ParseInt(parts[0], 10, 64)
|
||||
}
|
||||
|
||||
if len(parts) > 1 {
|
||||
minor, _ = strconv.ParseInt(parts[1], 10, 64)
|
||||
}
|
||||
|
||||
if len(parts) > 2 {
|
||||
patch, _ = strconv.ParseInt(parts[2], 10, 64)
|
||||
}
|
||||
|
||||
return major, minor, patch
|
||||
}
|
||||
|
||||
func GetPreviousVersion(version string) string {
|
||||
verMajor, verMinor, _ := SplitVersion(version)
|
||||
verStr := fmt.Sprintf("%v.%v.0", verMajor, verMinor)
|
||||
|
||||
for index, v := range versionsWithoutHotFixes {
|
||||
if v == verStr && len(versionsWithoutHotFixes) > index+1 {
|
||||
return versionsWithoutHotFixes[index+1]
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func IsCurrentVersion(versionToCheck string) bool {
|
||||
currentMajor, currentMinor, _ := SplitVersion(CurrentVersion)
|
||||
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
|
||||
|
||||
if toCheckMajor == currentMajor && toCheckMinor == currentMinor {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func IsPreviousVersionsSupported(versionToCheck string) bool {
|
||||
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
|
||||
versionToCheckStr := fmt.Sprintf("%v.%v.0", toCheckMajor, toCheckMinor)
|
||||
|
||||
// Current Supported
|
||||
if versionsWithoutHotFixes[0] == versionToCheckStr {
|
||||
return true
|
||||
}
|
||||
|
||||
// Current - 1 Supported
|
||||
if versionsWithoutHotFixes[1] == versionToCheckStr {
|
||||
return true
|
||||
}
|
||||
|
||||
// Current - 2 Supported
|
||||
if versionsWithoutHotFixes[2] == versionToCheckStr {
|
||||
return true
|
||||
}
|
||||
|
||||
// Current - 3 Supported
|
||||
if versionsWithoutHotFixes[3] == versionToCheckStr {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
39
build/manifest/vendor/github.com/mattermost/mattermost-server/model/webrtc.go
generated
vendored
Normal file
39
build/manifest/vendor/github.com/mattermost/mattermost-server/model/webrtc.go
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type WebrtcInfoResponse struct {
|
||||
Token string `json:"token"`
|
||||
GatewayUrl string `json:"gateway_url"`
|
||||
StunUri string `json:"stun_uri,omitempty"`
|
||||
TurnUri string `json:"turn_uri,omitempty"`
|
||||
TurnPassword string `json:"turn_password,omitempty"`
|
||||
TurnUsername string `json:"turn_username,omitempty"`
|
||||
}
|
||||
|
||||
type GatewayResponse struct {
|
||||
Status string `json:"janus"`
|
||||
}
|
||||
|
||||
func GatewayResponseFromJson(data io.Reader) *GatewayResponse {
|
||||
var o *GatewayResponse
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *WebrtcInfoResponse) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func WebrtcInfoResponseFromJson(data io.Reader) *WebrtcInfoResponse {
|
||||
var o *WebrtcInfoResponse
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
195
build/manifest/vendor/github.com/mattermost/mattermost-server/model/websocket_client.go
generated
vendored
Normal file
195
build/manifest/vendor/github.com/mattermost/mattermost-server/model/websocket_client.go
generated
vendored
Normal file
|
@ -0,0 +1,195 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
const (
|
||||
SOCKET_MAX_MESSAGE_SIZE_KB = 8 * 1024 // 8KB
|
||||
PING_TIMEOUT_BUFFER_SECONDS = 5
|
||||
)
|
||||
|
||||
type WebSocketClient struct {
|
||||
Url string // The location of the server like "ws://localhost:8065"
|
||||
ApiUrl string // The api location of the server like "ws://localhost:8065/api/v3"
|
||||
ConnectUrl string // The websocket URL to connect to like "ws://localhost:8065/api/v3/path/to/websocket"
|
||||
Conn *websocket.Conn // The WebSocket connection
|
||||
AuthToken string // The token used to open the WebSocket
|
||||
Sequence int64 // The ever-incrementing sequence attached to each WebSocket action
|
||||
PingTimeoutChannel chan bool // The channel used to signal ping timeouts
|
||||
EventChannel chan *WebSocketEvent
|
||||
ResponseChannel chan *WebSocketResponse
|
||||
ListenError *AppError
|
||||
pingTimeoutTimer *time.Timer
|
||||
}
|
||||
|
||||
// NewWebSocketClient constructs a new WebSocket client with convenience
|
||||
// methods for talking to the server.
|
||||
func NewWebSocketClient(url, authToken string) (*WebSocketClient, *AppError) {
|
||||
return NewWebSocketClientWithDialer(websocket.DefaultDialer, url, authToken)
|
||||
}
|
||||
|
||||
// NewWebSocketClientWithDialer constructs a new WebSocket client with convenience
|
||||
// methods for talking to the server using a custom dialer.
|
||||
func NewWebSocketClientWithDialer(dialer *websocket.Dialer, url, authToken string) (*WebSocketClient, *AppError) {
|
||||
conn, _, err := dialer.Dial(url+API_URL_SUFFIX+"/websocket", nil)
|
||||
if err != nil {
|
||||
return nil, NewAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
client := &WebSocketClient{
|
||||
url,
|
||||
url + API_URL_SUFFIX,
|
||||
url + API_URL_SUFFIX + "/websocket",
|
||||
conn,
|
||||
authToken,
|
||||
1,
|
||||
make(chan bool, 1),
|
||||
make(chan *WebSocketEvent, 100),
|
||||
make(chan *WebSocketResponse, 100),
|
||||
nil,
|
||||
nil,
|
||||
}
|
||||
|
||||
client.configurePingHandling()
|
||||
|
||||
client.SendMessage(WEBSOCKET_AUTHENTICATION_CHALLENGE, map[string]interface{}{"token": authToken})
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// NewWebSocketClient4 constructs a new WebSocket client with convenience
|
||||
// methods for talking to the server. Uses the v4 endpoint.
|
||||
func NewWebSocketClient4(url, authToken string) (*WebSocketClient, *AppError) {
|
||||
return NewWebSocketClient4WithDialer(websocket.DefaultDialer, url, authToken)
|
||||
}
|
||||
|
||||
// NewWebSocketClient4WithDialer constructs a new WebSocket client with convenience
|
||||
// methods for talking to the server using a custom dialer. Uses the v4 endpoint.
|
||||
func NewWebSocketClient4WithDialer(dialer *websocket.Dialer, url, authToken string) (*WebSocketClient, *AppError) {
|
||||
return NewWebSocketClientWithDialer(dialer, url, authToken)
|
||||
}
|
||||
|
||||
func (wsc *WebSocketClient) Connect() *AppError {
|
||||
return wsc.ConnectWithDialer(websocket.DefaultDialer)
|
||||
}
|
||||
|
||||
func (wsc *WebSocketClient) ConnectWithDialer(dialer *websocket.Dialer) *AppError {
|
||||
var err error
|
||||
wsc.Conn, _, err = dialer.Dial(wsc.ConnectUrl, nil)
|
||||
if err != nil {
|
||||
return NewAppError("Connect", "model.websocket_client.connect_fail.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
wsc.configurePingHandling()
|
||||
|
||||
wsc.EventChannel = make(chan *WebSocketEvent, 100)
|
||||
wsc.ResponseChannel = make(chan *WebSocketResponse, 100)
|
||||
|
||||
wsc.SendMessage(WEBSOCKET_AUTHENTICATION_CHALLENGE, map[string]interface{}{"token": wsc.AuthToken})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wsc *WebSocketClient) Close() {
|
||||
wsc.Conn.Close()
|
||||
}
|
||||
|
||||
func (wsc *WebSocketClient) Listen() {
|
||||
go func() {
|
||||
defer func() {
|
||||
wsc.Conn.Close()
|
||||
close(wsc.EventChannel)
|
||||
close(wsc.ResponseChannel)
|
||||
}()
|
||||
|
||||
for {
|
||||
var rawMsg json.RawMessage
|
||||
var err error
|
||||
if _, rawMsg, err = wsc.Conn.ReadMessage(); err != nil {
|
||||
if !websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) {
|
||||
wsc.ListenError = NewAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var event WebSocketEvent
|
||||
if err := json.Unmarshal(rawMsg, &event); err == nil && event.IsValid() {
|
||||
wsc.EventChannel <- &event
|
||||
continue
|
||||
}
|
||||
|
||||
var response WebSocketResponse
|
||||
if err := json.Unmarshal(rawMsg, &response); err == nil && response.IsValid() {
|
||||
wsc.ResponseChannel <- &response
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (wsc *WebSocketClient) SendMessage(action string, data map[string]interface{}) {
|
||||
req := &WebSocketRequest{}
|
||||
req.Seq = wsc.Sequence
|
||||
req.Action = action
|
||||
req.Data = data
|
||||
|
||||
wsc.Sequence++
|
||||
|
||||
wsc.Conn.WriteJSON(req)
|
||||
}
|
||||
|
||||
// UserTyping will push a user_typing event out to all connected users
|
||||
// who are in the specified channel
|
||||
func (wsc *WebSocketClient) UserTyping(channelId, parentId string) {
|
||||
data := map[string]interface{}{
|
||||
"channel_id": channelId,
|
||||
"parent_id": parentId,
|
||||
}
|
||||
|
||||
wsc.SendMessage("user_typing", data)
|
||||
}
|
||||
|
||||
// GetStatuses will return a map of string statuses using user id as the key
|
||||
func (wsc *WebSocketClient) GetStatuses() {
|
||||
wsc.SendMessage("get_statuses", nil)
|
||||
}
|
||||
|
||||
// GetStatusesByIds will fetch certain user statuses based on ids and return
|
||||
// a map of string statuses using user id as the key
|
||||
func (wsc *WebSocketClient) GetStatusesByIds(userIds []string) {
|
||||
data := map[string]interface{}{
|
||||
"user_ids": userIds,
|
||||
}
|
||||
wsc.SendMessage("get_statuses_by_ids", data)
|
||||
}
|
||||
|
||||
func (wsc *WebSocketClient) configurePingHandling() {
|
||||
wsc.Conn.SetPingHandler(wsc.pingHandler)
|
||||
wsc.pingTimeoutTimer = time.NewTimer(time.Second * (60 + PING_TIMEOUT_BUFFER_SECONDS))
|
||||
go wsc.pingWatchdog()
|
||||
}
|
||||
|
||||
func (wsc *WebSocketClient) pingHandler(appData string) error {
|
||||
if !wsc.pingTimeoutTimer.Stop() {
|
||||
<-wsc.pingTimeoutTimer.C
|
||||
}
|
||||
|
||||
wsc.pingTimeoutTimer.Reset(time.Second * (60 + PING_TIMEOUT_BUFFER_SECONDS))
|
||||
wsc.Conn.WriteMessage(websocket.PongMessage, []byte{})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wsc *WebSocketClient) pingWatchdog() {
|
||||
<-wsc.pingTimeoutTimer.C
|
||||
wsc.PingTimeoutChannel <- true
|
||||
}
|
165
build/manifest/vendor/github.com/mattermost/mattermost-server/model/websocket_message.go
generated
vendored
Normal file
165
build/manifest/vendor/github.com/mattermost/mattermost-server/model/websocket_message.go
generated
vendored
Normal file
|
@ -0,0 +1,165 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
WEBSOCKET_EVENT_TYPING = "typing"
|
||||
WEBSOCKET_EVENT_POSTED = "posted"
|
||||
WEBSOCKET_EVENT_POST_EDITED = "post_edited"
|
||||
WEBSOCKET_EVENT_POST_DELETED = "post_deleted"
|
||||
WEBSOCKET_EVENT_CHANNEL_CONVERTED = "channel_converted"
|
||||
WEBSOCKET_EVENT_CHANNEL_CREATED = "channel_created"
|
||||
WEBSOCKET_EVENT_CHANNEL_DELETED = "channel_deleted"
|
||||
WEBSOCKET_EVENT_CHANNEL_UPDATED = "channel_updated"
|
||||
WEBSOCKET_EVENT_CHANNEL_MEMBER_UPDATED = "channel_member_updated"
|
||||
WEBSOCKET_EVENT_DIRECT_ADDED = "direct_added"
|
||||
WEBSOCKET_EVENT_GROUP_ADDED = "group_added"
|
||||
WEBSOCKET_EVENT_NEW_USER = "new_user"
|
||||
WEBSOCKET_EVENT_ADDED_TO_TEAM = "added_to_team"
|
||||
WEBSOCKET_EVENT_LEAVE_TEAM = "leave_team"
|
||||
WEBSOCKET_EVENT_UPDATE_TEAM = "update_team"
|
||||
WEBSOCKET_EVENT_DELETE_TEAM = "delete_team"
|
||||
WEBSOCKET_EVENT_USER_ADDED = "user_added"
|
||||
WEBSOCKET_EVENT_USER_UPDATED = "user_updated"
|
||||
WEBSOCKET_EVENT_USER_ROLE_UPDATED = "user_role_updated"
|
||||
WEBSOCKET_EVENT_MEMBERROLE_UPDATED = "memberrole_updated"
|
||||
WEBSOCKET_EVENT_USER_REMOVED = "user_removed"
|
||||
WEBSOCKET_EVENT_PREFERENCE_CHANGED = "preference_changed"
|
||||
WEBSOCKET_EVENT_PREFERENCES_CHANGED = "preferences_changed"
|
||||
WEBSOCKET_EVENT_PREFERENCES_DELETED = "preferences_deleted"
|
||||
WEBSOCKET_EVENT_EPHEMERAL_MESSAGE = "ephemeral_message"
|
||||
WEBSOCKET_EVENT_STATUS_CHANGE = "status_change"
|
||||
WEBSOCKET_EVENT_HELLO = "hello"
|
||||
WEBSOCKET_EVENT_WEBRTC = "webrtc"
|
||||
WEBSOCKET_AUTHENTICATION_CHALLENGE = "authentication_challenge"
|
||||
WEBSOCKET_EVENT_REACTION_ADDED = "reaction_added"
|
||||
WEBSOCKET_EVENT_REACTION_REMOVED = "reaction_removed"
|
||||
WEBSOCKET_EVENT_RESPONSE = "response"
|
||||
WEBSOCKET_EVENT_EMOJI_ADDED = "emoji_added"
|
||||
WEBSOCKET_EVENT_CHANNEL_VIEWED = "channel_viewed"
|
||||
WEBSOCKET_EVENT_PLUGIN_STATUSES_CHANGED = "plugin_statuses_changed"
|
||||
WEBSOCKET_EVENT_PLUGIN_ENABLED = "plugin_enabled"
|
||||
WEBSOCKET_EVENT_PLUGIN_DISABLED = "plugin_disabled"
|
||||
WEBSOCKET_EVENT_ROLE_UPDATED = "role_updated"
|
||||
WEBSOCKET_EVENT_LICENSE_CHANGED = "license_changed"
|
||||
WEBSOCKET_EVENT_CONFIG_CHANGED = "config_changed"
|
||||
)
|
||||
|
||||
type WebSocketMessage interface {
|
||||
ToJson() string
|
||||
IsValid() bool
|
||||
EventType() string
|
||||
}
|
||||
|
||||
type WebsocketBroadcast struct {
|
||||
OmitUsers map[string]bool `json:"omit_users"` // broadcast is omitted for users listed here
|
||||
UserId string `json:"user_id"` // broadcast only occurs for this user
|
||||
ChannelId string `json:"channel_id"` // broadcast only occurs for users in this channel
|
||||
TeamId string `json:"team_id"` // broadcast only occurs for users in this team
|
||||
ContainsSanitizedData bool `json:"-"`
|
||||
ContainsSensitiveData bool `json:"-"`
|
||||
}
|
||||
|
||||
type precomputedWebSocketEventJSON struct {
|
||||
Event json.RawMessage
|
||||
Data json.RawMessage
|
||||
Broadcast json.RawMessage
|
||||
}
|
||||
|
||||
type WebSocketEvent struct {
|
||||
Event string `json:"event"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
Broadcast *WebsocketBroadcast `json:"broadcast"`
|
||||
Sequence int64 `json:"seq"`
|
||||
|
||||
precomputedJSON *precomputedWebSocketEventJSON
|
||||
}
|
||||
|
||||
// PrecomputeJSON precomputes and stores the serialized JSON for all fields other than Sequence.
|
||||
// This makes ToJson much more efficient when sending the same event to multiple connections.
|
||||
func (m *WebSocketEvent) PrecomputeJSON() {
|
||||
event, _ := json.Marshal(m.Event)
|
||||
data, _ := json.Marshal(m.Data)
|
||||
broadcast, _ := json.Marshal(m.Broadcast)
|
||||
m.precomputedJSON = &precomputedWebSocketEventJSON{
|
||||
Event: json.RawMessage(event),
|
||||
Data: json.RawMessage(data),
|
||||
Broadcast: json.RawMessage(broadcast),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *WebSocketEvent) Add(key string, value interface{}) {
|
||||
m.Data[key] = value
|
||||
}
|
||||
|
||||
func NewWebSocketEvent(event, teamId, channelId, userId string, omitUsers map[string]bool) *WebSocketEvent {
|
||||
return &WebSocketEvent{Event: event, Data: make(map[string]interface{}),
|
||||
Broadcast: &WebsocketBroadcast{TeamId: teamId, ChannelId: channelId, UserId: userId, OmitUsers: omitUsers}}
|
||||
}
|
||||
|
||||
func (o *WebSocketEvent) IsValid() bool {
|
||||
return o.Event != ""
|
||||
}
|
||||
|
||||
func (o *WebSocketEvent) EventType() string {
|
||||
return o.Event
|
||||
}
|
||||
|
||||
func (o *WebSocketEvent) ToJson() string {
|
||||
if o.precomputedJSON != nil {
|
||||
return fmt.Sprintf(`{"event": %s, "data": %s, "broadcast": %s, "seq": %d}`, o.precomputedJSON.Event, o.precomputedJSON.Data, o.precomputedJSON.Broadcast, o.Sequence)
|
||||
}
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func WebSocketEventFromJson(data io.Reader) *WebSocketEvent {
|
||||
var o *WebSocketEvent
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
type WebSocketResponse struct {
|
||||
Status string `json:"status"`
|
||||
SeqReply int64 `json:"seq_reply,omitempty"`
|
||||
Data map[string]interface{} `json:"data,omitempty"`
|
||||
Error *AppError `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (m *WebSocketResponse) Add(key string, value interface{}) {
|
||||
m.Data[key] = value
|
||||
}
|
||||
|
||||
func NewWebSocketResponse(status string, seqReply int64, data map[string]interface{}) *WebSocketResponse {
|
||||
return &WebSocketResponse{Status: status, SeqReply: seqReply, Data: data}
|
||||
}
|
||||
|
||||
func NewWebSocketError(seqReply int64, err *AppError) *WebSocketResponse {
|
||||
return &WebSocketResponse{Status: STATUS_FAIL, SeqReply: seqReply, Error: err}
|
||||
}
|
||||
|
||||
func (o *WebSocketResponse) IsValid() bool {
|
||||
return o.Status != ""
|
||||
}
|
||||
|
||||
func (o *WebSocketResponse) EventType() string {
|
||||
return WEBSOCKET_EVENT_RESPONSE
|
||||
}
|
||||
|
||||
func (o *WebSocketResponse) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func WebSocketResponseFromJson(data io.Reader) *WebSocketResponse {
|
||||
var o *WebSocketResponse
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
34
build/manifest/vendor/github.com/mattermost/mattermost-server/model/websocket_request.go
generated
vendored
Normal file
34
build/manifest/vendor/github.com/mattermost/mattermost-server/model/websocket_request.go
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||
)
|
||||
|
||||
type WebSocketRequest struct {
|
||||
// Client-provided fields
|
||||
Seq int64 `json:"seq"`
|
||||
Action string `json:"action"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
|
||||
// Server-provided fields
|
||||
Session Session `json:"-"`
|
||||
T goi18n.TranslateFunc `json:"-"`
|
||||
Locale string `json:"-"`
|
||||
}
|
||||
|
||||
func (o *WebSocketRequest) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func WebSocketRequestFromJson(data io.Reader) *WebSocketRequest {
|
||||
var o *WebSocketRequest
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
Reference in a new issue