5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-25 22:31:35 +00:00

Commit mattermost vendoring

This commit is contained in:
Wim 2016-05-21 14:14:08 +02:00
parent 85faa43145
commit 33844fa60c
10 changed files with 521 additions and 0 deletions

View File

@ -0,0 +1,24 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package einterfaces
import (
"github.com/mattermost/platform/model"
"mime/multipart"
)
type BrandInterface interface {
SaveBrandImage(*multipart.FileHeader) *model.AppError
GetBrandImage() ([]byte, *model.AppError)
}
var theBrandInterface BrandInterface
func RegisterBrandInterface(newInterface BrandInterface) {
theBrandInterface = newInterface
}
func GetBrandInterface() BrandInterface {
return theBrandInterface
}

View File

@ -0,0 +1,23 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package einterfaces
import (
"github.com/mattermost/platform/model"
)
type ComplianceInterface interface {
StartComplianceDailyJob()
RunComplianceJob(job *model.Compliance) *model.AppError
}
var theComplianceInterface ComplianceInterface
func RegisterComplianceInterface(newInterface ComplianceInterface) {
theComplianceInterface = newInterface
}
func GetComplianceInterface() ComplianceInterface {
return theComplianceInterface
}

View File

@ -0,0 +1,25 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package einterfaces
import (
"github.com/mattermost/platform/model"
)
type MfaInterface interface {
GenerateQrCode(user *model.User) ([]byte, *model.AppError)
Activate(user *model.User, token string) *model.AppError
Deactivate(userId string) *model.AppError
ValidateToken(secret, token string) (bool, *model.AppError)
}
var theMfaInterface MfaInterface
func RegisterMfaInterface(newInterface MfaInterface) {
theMfaInterface = newInterface
}
func GetMfaInterface() MfaInterface {
return theMfaInterface
}

View File

@ -0,0 +1,132 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
"encoding/json"
"io"
"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, err := json.Marshal(o)
if err != nil {
return ""
} else {
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 = strings.ToLower(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 NewLocAppError("Compliance.IsValid", "model.compliance.is_valid.id.app_error", nil, "")
}
if me.CreateAt == 0 {
return NewLocAppError("Compliance.IsValid", "model.compliance.is_valid.create_at.app_error", nil, "")
}
if len(me.Desc) > 512 || len(me.Desc) == 0 {
return NewLocAppError("Compliance.IsValid", "model.compliance.is_valid.desc.app_error", nil, "")
}
if me.StartAt == 0 {
return NewLocAppError("Compliance.IsValid", "model.compliance.is_valid.start_at.app_error", nil, "")
}
if me.EndAt == 0 {
return NewLocAppError("Compliance.IsValid", "model.compliance.is_valid.end_at.app_error", nil, "")
}
if me.EndAt <= me.StartAt {
return NewLocAppError("Compliance.IsValid", "model.compliance.is_valid.start_end_at.app_error", nil, "")
}
return nil
}
func ComplianceFromJson(data io.Reader) *Compliance {
decoder := json.NewDecoder(data)
var o Compliance
err := decoder.Decode(&o)
if err == nil {
return &o
} else {
return nil
}
}
func (o Compliances) ToJson() string {
if b, err := json.Marshal(o); err != nil {
return "[]"
} else {
return string(b)
}
}
func CompliancesFromJson(data io.Reader) Compliances {
decoder := json.NewDecoder(data)
var o Compliances
err := decoder.Decode(&o)
if err == nil {
return o
} else {
return nil
}
}

View File

@ -0,0 +1,104 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
"time"
)
type CompliancePost struct {
// From Team
TeamName string
TeamDisplayName string
// From Channel
ChannelName string
ChannelDisplayName 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
PostFilenames string
}
func CompliancePostHeader() []string {
return []string{
"TeamName",
"TeamDisplayName",
"ChannelName",
"ChannelDisplayName",
"UserUsername",
"UserEmail",
"UserNickname",
"PostId",
"PostCreateAt",
"PostUpdateAt",
"PostDeleteAt",
"PostRootId",
"PostParentId",
"PostOriginalId",
"PostMessage",
"PostType",
"PostProps",
"PostHashtags",
"PostFilenames",
}
}
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{
me.TeamName,
me.TeamDisplayName,
me.ChannelName,
me.ChannelDisplayName,
me.UserUsername,
me.UserEmail,
me.UserNickname,
me.PostId,
time.Unix(0, me.PostCreateAt*int64(1000*1000)).Format(time.RFC3339),
postUpdateAt,
postDeleteAt,
me.PostRootId,
me.PostParentId,
me.PostOriginalId,
me.PostMessage,
me.PostType,
me.PostProps,
me.PostHashtags,
me.PostFilenames,
}
}

View File

@ -0,0 +1,8 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
const (
USER_AUTH_SERVICE_GITLAB = "gitlab"
)

View File

@ -0,0 +1,40 @@
// Copyright (c) 2016 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"`
DirectProfiles map[string]*User `json:"direct_profiles"`
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, err := json.Marshal(me)
if err != nil {
return ""
} else {
return string(b)
}
}
func InitialLoadFromJson(data io.Reader) *InitialLoad {
decoder := json.NewDecoder(data)
var o InitialLoad
err := decoder.Decode(&o)
if err == nil {
return &o
} else {
return nil
}
}

8
vendor/github.com/mattermost/platform/model/ldap.go generated vendored Normal file
View File

@ -0,0 +1,8 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
const (
USER_AUTH_SERVICE_LDAP = "ldap"
)

View File

@ -0,0 +1,37 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
const (
PASSWORD_RECOVERY_CODE_SIZE = 128
PASSWORD_RECOVER_EXPIRY_TIME = 1000 * 60 * 60 // 1 hour
)
type PasswordRecovery struct {
UserId string
Code string
CreateAt int64
}
func (p *PasswordRecovery) IsValid() *AppError {
if len(p.UserId) != 26 {
return NewLocAppError("User.IsValid", "model.password_recovery.is_valid.user_id.app_error", nil, "")
}
if len(p.Code) != PASSWORD_RECOVERY_CODE_SIZE {
return NewLocAppError("User.IsValid", "model.password_recovery.is_valid.code.app_error", nil, "")
}
if p.CreateAt == 0 {
return NewLocAppError("User.IsValid", "model.password_recovery.is_valid.create_at.app_error", nil, "")
}
return nil
}
func (p *PasswordRecovery) PreSave() {
p.Code = NewRandomString(PASSWORD_RECOVERY_CODE_SIZE)
p.CreateAt = GetMillis()
}

View File

@ -0,0 +1,120 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
"encoding/json"
"io"
"strings"
)
const (
ROLE_TEAM_ADMIN = "admin"
)
type TeamMember struct {
TeamId string `json:"team_id"`
UserId string `json:"user_id"`
Roles string `json:"roles"`
}
func (o *TeamMember) ToJson() string {
b, err := json.Marshal(o)
if err != nil {
return ""
} else {
return string(b)
}
}
func TeamMemberFromJson(data io.Reader) *TeamMember {
decoder := json.NewDecoder(data)
var o TeamMember
err := decoder.Decode(&o)
if err == nil {
return &o
} else {
return nil
}
}
func TeamMembersToJson(o []*TeamMember) string {
if b, err := json.Marshal(o); err != nil {
return "[]"
} else {
return string(b)
}
}
func TeamMembersFromJson(data io.Reader) []*TeamMember {
decoder := json.NewDecoder(data)
var o []*TeamMember
err := decoder.Decode(&o)
if err == nil {
return o
} else {
return nil
}
}
func IsValidTeamRoles(teamRoles string) bool {
roles := strings.Split(teamRoles, " ")
for _, r := range roles {
if !isValidTeamRole(r) {
return false
}
}
return true
}
func isValidTeamRole(role string) bool {
if role == "" {
return true
}
if role == ROLE_TEAM_ADMIN {
return true
}
return false
}
func IsInTeamRole(teamRoles string, inRole string) bool {
roles := strings.Split(teamRoles, " ")
for _, r := range roles {
if r == inRole {
return true
}
}
return false
}
func (o *TeamMember) IsTeamAdmin() bool {
return IsInTeamRole(o.Roles, ROLE_TEAM_ADMIN)
}
func (o *TeamMember) IsValid() *AppError {
if len(o.TeamId) != 26 {
return NewLocAppError("TeamMember.IsValid", "model.team_member.is_valid.team_id.app_error", nil, "")
}
if len(o.UserId) != 26 {
return NewLocAppError("TeamMember.IsValid", "model.team_member.is_valid.user_id.app_error", nil, "")
}
for _, role := range strings.Split(o.Roles, " ") {
if !(role == "" || role == ROLE_TEAM_ADMIN) {
return NewLocAppError("TeamMember.IsValid", "model.team_member.is_valid.role.app_error", nil, "role="+role)
}
}
return nil
}