helpers

package
v0.0.0-...-a33bf99 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2015 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BrandNameMaxLength = 20
	BrandAPIKeyLength  = 16
)
View Source
const (
	FileTokenType          = "file"
	FileTokenExpirationSec = 60 * 30
	FileTokenExpiration    = FileTokenExpirationSec * time.Second
)
View Source
const (
	FocusMessageMaxLength = 140

	FocusTypeReminder     = "REMINDER"
	FocusTypeNotification = "NOTIFICATION"
)
View Source
const (
	JSONTypeNameId     = "objectId"
	JSONTypeNameString = "string"
	JSONTypeNameNumber = "number"
	JSONTypeNameArray  = "array"
	JSONTypeNameObject = "object"
	JSONTypeNameBoolen = "boolen"
)
View Source
const (
	TicketSubjectMaxLength     = 20
	TicketContentMinLength     = 15
	TicketExtendFieldMaxLength = 100

	TicketStatusDefault = models.TicketStatusPending

	TicketChannelWeb   = "_WEB"
	TicketChannelEmail = "_EMAIL"
)
View Source
const (
	TokenType                 = "token"
	TokenDefaultExpirationSec = 3600 * 24 * 30
	TokenDefaultExpiration    = TokenDefaultExpirationSec * time.Second
)
View Source
const (
	UserChannelAgent = "_AGENT"
	UserChannelEmail = "_EMAIL"

	UserNameMaxLength     = 20
	UserPasswordMinLength = 6

	UserRandNameLength = 6
)
View Source
const (
	CommentContentMinLength = 5
)
View Source
const (
	LimitedDataFieldMaxLength = 200
)

Variables

View Source
var (
	EmptyId     = mgoutils.EmptyObjectId
	ErrNotFound = mgoutils.ErrNotFound
)
View Source
var (
	CommentTypeOptionsForNonAgentView = []interface{}{
		models.CommentTypeQuestion,
		models.CommentTypePublic,
		models.CommentTypeFeedback,
	}

	CommentTypeOptionsForCreate = []interface{}{
		models.CommentTypeFeedback,
		models.CommentTypePublic,
		models.CommentTypeInternal,
	}

	CommentTypeOptionsForUpdate = []interface{}{
		models.CommentTypePublic,
	}
)
View Source
var (
	FilterFieldValueOptions = map[string][]interface{}{
		"status":   TicketStatusOptionsForList,
		"priority": TicketPriorityOptions,
	}

	FilterFieldNameOptions = []interface{}{
		"creatorId",
		"priority",
		"status",
		"created",
		"updated",
		"sort",
	}

	FilterTimeFieldOptions = []interface{}{
		"1day",
		"2days",
		"3days",
		"7days",
		"14days",
		"30days",
	}

	FilterTimeFieldDurationMap = map[string]time.Duration{
		"1day":   oneDay,
		"2days":  2 * oneDay,
		"3days":  3 * oneDay,
		"7days":  7 * oneDay,
		"14days": 14 * oneDay,
		"30days": 30 * oneDay,
	}
)
View Source
var (
	FocusPriorityOptions = []interface{}{
		models.PriorityLow,
		models.PriorityNormal,
		models.PriorityHign,
		models.PriorityUrgent,
	}

	FocusStatusOptionForList = []interface{}{
		models.FocusStatusPending,
		models.FocusStatusHandled,
	}
)
View Source
var (
	TicketPriorityOptions = []interface{}{
		models.PriorityLow,
		models.PriorityNormal,
		models.PriorityHign,
		models.PriorityUrgent,
	}

	TicketStatusOptionsForList = []interface{}{
		models.TicketStatusPending,
		models.TicketStatusReplied,
		models.TicketStatusResubmitted,
		models.TicketStatusSolved,
	}

	TicketSortOptionsForList = []interface{}{
		"-updated",
		"updated",
		"-priority",
		"priority",
	}

	TicketStatusOptionsForCreate = []interface{}{
		models.TicketStatusPending,
		models.TicketStatusSolved,
	}

	TicketStatusOptionsForUpdate = []interface{}{
		models.TicketStatusSolved,
	}

	TicketRankOptions = []interface{}{0, 1, 2, 3, 4, 5}

	TicketChannelOptionsForCreate = []interface{}{
		TicketChannelWeb,
		TicketChannelEmail,
	}
)
View Source
var (
	ErrTokenNotFound = fmt.Errorf("token not found")

	ErrInvalidTokenExpired             = newErrInvalidToken("token expired")
	ErrInvalidTokenParseFailed         = newErrInvalidToken("failed to parse")
	ErrInvalidTokenInvalidType         = newErrInvalidToken("invalid type")
	ErrInvalidTokenInvalidUserId       = newErrInvalidToken("invalid userId")
	ErrInvalidTokenUserNotFound        = newErrInvalidToken("user not found")
	ErrInvalidTokenChannelInfoRequired = newErrInvalidToken("channel info required")
	ErrInvalidTokenInvalidChannelName  = newErrInvalidToken("invalid channel name")
	ErrInvalidTokenInvalidEmail        = newErrInvalidToken("invalid email")
)
View Source
var (
	UserImportanceOptions = []interface{}{
		models.UserImportanceNormal,
		models.UserImportanceImportant,
		models.UserImportanceVIP,
	}

	UserSortOptionsForList = []interface{}{
		"created",
		"-created",
		"-business.importance",
		"business.importance",
	}
)
View Source
var (
	ResourceTypeOptions = []interface{}{
		models.ResourceTypeTicket,
		models.ResourceTypeComment,
	}
)

Functions

func AgentFind

func AgentFind() (*models.User, error)

func AgentInit

func AgentInit(email, name, password, salt string) (*models.User, error)

func BrandFindOne

func BrandFindOne(query map[string]interface{}) (*models.Brand, error)

func BrandInit

func BrandInit(name string) (*models.Brand, error)

func BrandNewAPIKey

func BrandNewAPIKey() string

func BrandUpdateCurrent

func BrandUpdateCurrent(change map[string]interface{}) error

func ClientCount

func ClientCount(query map[string]interface{}) (int, error)

func ClientFindById

func ClientFindById(id interface{}) (*models.User, error)

func ClientListAfter

func ClientListAfter(query map[string]interface{}, lastId bson.ObjectId, limit int, sort []string) ([]*models.User, error)

func CommentFindAllByTicketId

func CommentFindAllByTicketId(ticketId interface{}, query map[string]interface{}, sort []string) ([]*models.Comment, error)

func CommentFindAndModify

func CommentFindAndModify(comment *models.Comment, change map[string]interface{}) error

func CommentFindById

func CommentFindById(commentId interface{}) (*models.Comment, error)

func CommentFindByTicketIdAndCommentId

func CommentFindByTicketIdAndCommentId(ticketId, commentId interface{}) (*models.Comment, error)

func CommentInsertForTicket

func CommentInsertForTicket(ticket *models.Ticket, creator *models.User, typ, content string, attachments []*models.File) (*models.Comment, error)

func CurrentBrand

func CurrentBrand() *models.Brand

func FilterParseFromRequest

func FilterParseFromRequest(req *http.Request, query map[string]interface{}, isAgent bool) map[string]interface{}

func FocusCount

func FocusCount(query map[string]interface{}) (int, error)

func FocusFindById

func FocusFindById(focusId interface{}) (*models.Focus, error)

func FocusHandled

func FocusHandled(focus *models.Focus) error

func FocusListAfter

func FocusListAfter(query map[string]interface{}, lastId bson.ObjectId, limit int, sort []string) ([]*models.Focus, error)

func FocusNew

func FocusNew(typ, message string, durSec int64, priority models.TypePriority, resource *models.Resource) *models.Focus

func FocusReminderInsert

func FocusReminderInsert(message string, durSec int64, priority models.TypePriority, resource *models.Resource) (*models.Focus, error)

func IdFromString

func IdFromString(s string) (bson.ObjectId, bool)

func InitWithStorage

func InitWithStorage(stg *mgoutils.MgoPool) error

func InternalFileTokenValid

func InternalFileTokenValid(userId, s, key string) bool

func IsDup

func IsDup(err error) bool

func IsEmptyId

func IsEmptyId(id bson.ObjectId) bool

func IsInvalidToken

func IsInvalidToken(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func LoadCurrentBrand

func LoadCurrentBrand() error

func NewInternalFileToken

func NewInternalFileToken(userId, key string, expiration time.Duration) string

func ResourceByComment

func ResourceByComment(comment *models.Comment) *models.Resource

func ResourceByCommentId

func ResourceByCommentId(commentId interface{}) (*models.Resource, error)

func ResourceByTicket

func ResourceByTicket(ticket *models.Ticket) *models.Resource

func ResourceByTicketId

func ResourceByTicketId(ticketId interface{}) (*models.Resource, error)

func ResourceByTypeAndId

func ResourceByTypeAndId(typ string, id interface{}) (*models.Resource, error)

func TicketCount

func TicketCount(query map[string]interface{}) (int, error)

func TicketFindAndModify

func TicketFindAndModify(ticket *models.Ticket, change map[string]interface{}) error

func TicketFindById

func TicketFindById(ticketId interface{}) (*models.Ticket, error)

func TicketGetValidSubject

func TicketGetValidSubject(s string) string

func TicketInit

func TicketInit(ticket *models.Ticket, content string, attachments []*models.File) error

func TicketListAfter

func TicketListAfter(query map[string]interface{}, lastId bson.ObjectId, limit int, sort []string) ([]*models.Ticket, error)

func TicketNewWithChannelName

func TicketNewWithChannelName(creator *models.User, chName, subject string, extend map[string]string) *models.Ticket

func TicketParseExtendFromPreSet

func TicketParseExtendFromPreSet(extend map[string]string) map[string]string

func TokenForUser

func TokenForUser(user *models.User, key string) string

func UserCheckPassword

func UserCheckPassword(user *models.User, password, salt string) bool

func UserCount

func UserCount(query map[string]interface{}) (int, error)

func UserFindAndModify

func UserFindAndModify(user *models.User, change map[string]interface{}) error

func UserFindByChannel

func UserFindByChannel(chName, chId string) (*models.User, error)

func UserFindById

func UserFindById(id interface{}) (*models.User, error)

func UserFromRequest

func UserFromRequest(r *http.Request, key string) (*models.User, bool, error)

func UserFromToken

func UserFromToken(t string, key []byte) (*models.User, bool, error)

func UserGetValidName

func UserGetValidName(name string) string

func UserGetValidNameFromEmail

func UserGetValidNameFromEmail(email string) string

func UserIsAgent

func UserIsAgent(user *models.User) bool

func UserListAfter

func UserListAfter(query map[string]interface{}, lastId bson.ObjectId, limit int, sort []string) ([]*models.User, error)

func UserMustByChannel

func UserMustByChannel(chName, chId, email, name string) (*models.User, bool, error)

func UserMustForChannelEmail

func UserMustForChannelEmail(email, name string) (*models.User, bool, error)

func ValidationForBrandName

func ValidationForBrandName(v *validation.Validation, key, name string) *validation.Validation

brand

func ValidationForCommentContent

func ValidationForCommentContent(v *validation.Validation, key, content string) *validation.Validation

func ValidationForCommentTypeOnCreate

func ValidationForCommentTypeOnCreate(v *validation.Validation, key, typeName string) *validation.Validation

comment

func ValidationForCommentTypeOnUpdate

func ValidationForCommentTypeOnUpdate(v *validation.Validation, key, typeName string) *validation.Validation

func ValidationForEmail

func ValidationForEmail(v *validation.Validation, key, email string) *validation.Validation

email

func ValidationForFocusPriority

func ValidationForFocusPriority(v *validation.Validation, key string, priority models.TypePriority) *validation.Validation

func ValidationForFocusResourceId

func ValidationForFocusResourceId(v *validation.Validation, key string, resourceId bson.ObjectId) *validation.Validation

resource

func ValidationForFocusResourceType

func ValidationForFocusResourceType(v *validation.Validation, key, resourceType string) *validation.Validation

func ValidationForFocusStatusOnList

func ValidationForFocusStatusOnList(v *validation.Validation, key, status string) *validation.Validation

func ValidationForFoucsMessage

func ValidationForFoucsMessage(v *validation.Validation, key, message string) *validation.Validation

focus

func ValidationForTicektListSort

func ValidationForTicektListSort(v *validation.Validation, key, sort string) *validation.Validation

func ValidationForTicketChannel

func ValidationForTicketChannel(v *validation.Validation, key, channel string) *validation.Validation

func ValidationForTicketContent

func ValidationForTicketContent(v *validation.Validation, key, content string) *validation.Validation

func ValidationForTicketExtendField

func ValidationForTicketExtendField(v *validation.Validation, extend map[string]string) *validation.Validation

func ValidationForTicketPriority

func ValidationForTicketPriority(v *validation.Validation, key string, priority models.TypePriority) *validation.Validation

func ValidationForTicketStatusOnCreate

func ValidationForTicketStatusOnCreate(v *validation.Validation, key, status string) *validation.Validation

func ValidationForTicketStatusOnUpdate

func ValidationForTicketStatusOnUpdate(v *validation.Validation, key, status string) *validation.Validation

func ValidationForTicketSubject

func ValidationForTicketSubject(v *validation.Validation, key, subject string) *validation.Validation

ticket

func ValidationForUserImportance

func ValidationForUserImportance(v *validation.Validation, key string, importance models.TypeUserImportance) *validation.Validation

func ValidationForUserListSort

func ValidationForUserListSort(v *validation.Validation, key, sort string) *validation.Validation

func ValidationForUserName

func ValidationForUserName(v *validation.Validation, key, name string) *validation.Validation

func ValidationForUserPassword

func ValidationForUserPassword(v *validation.Validation, key, password string) *validation.Validation

user

func ValidationNew

func ValidationNew() *validation.Validation

Types

type M

type M bson.M

type OutputBrandKey

type OutputBrandKey struct {
	Key string `json:"key"`
}

func OutputBrandAPIKey

func OutputBrandAPIKey(key string) *OutputBrandKey

type OutputComment

type OutputComment struct {
	Id      bson.ObjectId `json:"id"`
	Creator *OutputUser   `json:"creator"`
	Type    string        `json:"type"`
	Content string        `json:"content"`
	Created int64         `json:"created"`
	Updated int64         `json:"updated"`
}

func OutputCommentInfo

func OutputCommentInfo(comment *models.Comment) (*OutputComment, error)

func OutputCommentInfos

func OutputCommentInfos(comments []*models.Comment) ([]*OutputComment, error)

type OutputTicket

type OutputTicket struct {
	Id       bson.ObjectId       `json:"id"`
	Creator  *OutputUser         `json:"creator"`
	Channel  *models.ChannelInfo `json:"channel,omitempty"`
	Subject  string              `json:"subject"`
	Content  string              `json:"content"`
	Priority models.TypePriority `json:"priority,omitempty"`
	IsPublic bool                `json:"isPublic"`
	Created  int64               `json:"created"`
	Updated  int64               `json:"updated"`
	Status   string              `json:"status"`
	Rank     int                 `json:"rank,omitempty"`
	Extend   map[string]string   `json:"extend,omitempty"`
	Comments []*OutputComment    `json:"comments,omitempty"`
}

func OutputTicketDetailInfo

func OutputTicketDetailInfo(ticket *models.Ticket) (*OutputTicket, error)

func OutputTicketDetailInfoForList

func OutputTicketDetailInfoForList(ticket *models.Ticket) (*OutputTicket, error)

func OutputTicketPublicInfo

func OutputTicketPublicInfo(ticket *models.Ticket) (*OutputTicket, error)

func OutputTicketPublicInfoForList

func OutputTicketPublicInfoForList(ticket *models.Ticket) (*OutputTicket, error)

func (*OutputTicket) GetComments

func (this *OutputTicket) GetComments(query map[string]interface{}, sort []string) error

type OutputToken

type OutputToken struct {
	Token      string `json:"token"`
	Expiration int64  `json:"expiration"`
}

func OutputTokenInfo

func OutputTokenInfo(token string, expirationSec int64) *OutputToken

type OutputUser

type OutputUser struct {
	Id       bson.ObjectId            `json:"id"`
	Channel  *models.ChannelInfo      `json:"channel,omitempty"`
	Base     *models.UserBaseInfo     `json:"base,omitempty"`
	Personal *models.UserPersonalInfo `json:"personal,omitempty"`
	Business *models.UserBusinessInfo `json:"business,omitempty"`
	Created  int64                    `json:"created,omitempty"`
	Updated  int64                    `json:"updated,omitempty"`
}

func OutputUserBaseInfo

func OutputUserBaseInfo(user *models.User) *OutputUser

func OutputUserBaseInfoByUserId

func OutputUserBaseInfoByUserId(userId interface{}) (*OutputUser, error)

func OutputUserDetailInfo

func OutputUserDetailInfo(user *models.User) *OutputUser

func OutputUserProfileInfo

func OutputUserProfileInfo(user *models.User) *OutputUser

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL