Documentation
¶
Index ¶
- Constants
- Variables
- func AllMy(q *pop.Query, m *Member, b Belonging, all ...bool) error
- func AllMyOwn(q *pop.Query, m *Member, b Belonging, all ...bool) error
- func FindMy(q *pop.Query, m *Member, b Belonging, id interface{}) error
- func FindMyOwn(q *pop.Query, m *Member, b Belonging, id interface{}) error
- func Logger(logger buffalo.Logger)
- func Marshal(m Object) string
- func SelectByAttrs(m interface{}, attrs map[string]interface{}) error
- type AccessGrant
- type AccessGrants
- type App
- func (a *App) AccessibleBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (a *App) AddRole(tx *pop.Connection, n, c, d string, r int, o bool) error
- func (a *App) GenerateKeyPair()
- func (a *App) GetRole(tx *pop.Connection, code string) *Role
- func (a App) GetRoles() *Roles
- func (a App) GrantsCount() int
- func (a *App) OwnedBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (a *App) QueryParams() QueryParams
- func (a App) Requests() *[]RoleMap
- func (a App) RequestsCount() int
- func (a App) String() string
- func (a *App) Validate(tx *pop.Connection) (*validate.Errors, error)
- func (a *App) ValidateSave(tx *pop.Connection) (*validate.Errors, error)
- func (a *App) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error)
- type Apps
- type Belonging
- type Credential
- func (c *Credential) AccessibleBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (c *Credential) OwnedBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (c Credential) Owner() *Member
- func (c Credential) OwnerID() uuid.UUID
- func (c *Credential) QueryParams() QueryParams
- func (c *Credential) Save()
- func (c Credential) String() string
- type Credentials
- type Doc
- func (d *Doc) AccessibleBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (d Doc) AuthorName() string
- func (d *Doc) OwnedBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (d *Doc) QueryParams() QueryParams
- func (d Doc) String() string
- func (d *Doc) Validate(tx *pop.Connection) (*validate.Errors, error)
- func (d *Doc) ValidateSave(tx *pop.Connection) (*validate.Errors, error)
- func (d *Doc) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error)
- type Docs
- type Member
- func (m Member) AccessGrantCount() int
- func (m *Member) AccessibleBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (m *Member) AddRole(tx *pop.Connection, r *Role, active ...bool) error
- func (m Member) AppRoles(appID uuid.UUID, flag ...bool) *Roles
- func (m Member) CredentialCount() int
- func (m Member) Credentials() *Credentials
- func (m Member) GetAppRoleCodes(appCode string) []string
- func (m *Member) GetID() interface{}
- func (m Member) Grant(tx *pop.Connection, app *App, scope string) error
- func (m Member) Granted(appID uuid.UUID, scope string) bool
- func (m Member) GrantedApps() *Apps
- func (m Member) Grants() *AccessGrants
- func (m Member) HasRole(roleID uuid.UUID) bool
- func (m *Member) IsNil() bool
- func (m *Member) MessageMarkAsSent(id uuid.UUID) error
- func (m *Member) Messengers(args ...int) *Messengers
- func (m *Member) OwnedBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (m *Member) PrimaryAlert() *Messenger
- func (m *Member) PrimaryNotifier() *Messenger
- func (m *Member) QueryParams() QueryParams
- func (m *Member) RemoveRole(tx *pop.Connection, r *Role) error
- func (m Member) Revoke(tx *pop.Connection, app *App) error
- func (m Member) Roles() *Roles
- func (m *Member) Save()
- func (m Member) String() string
- func (m *Member) Validate(tx *pop.Connection) (*validate.Errors, error)
- func (m *Member) ValidateSave(tx *pop.Connection) (*validate.Errors, error)
- func (m *Member) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error)
- type Members
- type Message
- func (m *Message) AccessibleBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (m Message) AppName() string
- func (m Message) MemberMap(memberID interface{}) *MessageMap
- func (m *Message) OwnedBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (m Message) Owner() *Member
- func (m Message) PriorityString() string
- func (m *Message) QueryParams() QueryParams
- func (m Message) String() string
- func (m *Message) Validate(tx *pop.Connection) (*validate.Errors, error)
- type MessageMap
- type MessageMaps
- type Messages
- type MessagingLog
- type MessagingLogs
- type Messenger
- func (m *Messenger) AccessibleBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (m *Messenger) OwnedBy(q *pop.Query, o Owner, f ...bool) *pop.Query
- func (m *Messenger) QueryParams() QueryParams
- func (m Messenger) String() string
- func (m *Messenger) Validate(tx *pop.Connection) (*validate.Errors, error)
- func (m *Messenger) ValidateSave(tx *pop.Connection) (*validate.Errors, error)
- func (m *Messenger) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error)
- type Messengers
- type Object
- type Owner
- type QueryParams
- type Role
- func (r Role) App() *App
- func (r Role) MemberCount(isActive bool) int
- func (r Role) Members(flag ...bool) *Members
- func (r Role) String() string
- func (r *Role) Validate(tx *pop.Connection) (*validate.Errors, error)
- func (r *Role) ValidateSave(tx *pop.Connection) (*validate.Errors, error)
- func (r *Role) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error)
- type RoleMap
- type Roles
Constants ¶
const ( ACUART = "uart" AppDefaultAdminScope = "all:all" AppDefaultScope = "profile, auth:all" DefaultSortApps = "name" )
default values
const ( MsgFacCore = "core" MsgFacAuth = "auth" MsgFacApp = "app" MsgFacUser = "user" MsgFacMesg = "messaging" MsgFacCron = "scheduler" MsgFacSecu = "security" MsgPriEmerg = 0 // RESERVED MsgPriAlert = 1 // for alert MsgPriCrit = 2 // FATAL MsgPriErr = 3 MsgPriWarn = 4 MsgPriNote = 5 // for notification MsgPriInfo = 6 MsgPriDebug = 7 )
constants for messaging/logging subsystem
const ( RCAdmin = "admin" RCUser = "user" RCAppMan = "appman" RCUserMan = "userman" RCLeader = "leader" )
standard role codes
const (
DefaultSortCredentials = "created_at"
)
common constants
const (
DefaultSortMembers = "created_at"
)
common constants
const (
DefaultSortMessages = "created_at desc"
)
common constants
Variables ¶
var DB *pop.Connection
DB and others: shared variables for models
var MessengerMethod = map[string]string{
"Email": "mail",
}
MessengerMethod is a map for method name to code string.
var MessengerMethodReverse = map[string]string{
"mail": "Email",
}
MessengerMethodReverse is a reverse map for method code to name.
var MessengerPriority = map[string]int{
"Alert": 1,
"Notification": 5,
"Disabled": 8,
}
MessengerPriority is a map for priority string to code.
var MsgPri = map[string]int{
"Emerg": 0,
"Alert": 1,
"Crit": 2,
"Err": 3,
"Warn": 4,
"Note": 5,
"Info": 6,
"Debug": 7,
}
MsgPri is a map for name to code referencing of message priority
var MsgPriReverse = map[int]string{
0: "Emerg",
1: "Alert",
2: "Crit",
3: "Err",
4: "Warn",
5: "Note",
6: "Info",
7: "Debug",
}
MsgPriReverse is a map for code to name referencing of message priority
Functions ¶
func SelectByAttrs ¶
SelectByAttrs find and store models with given search attributes
Types ¶
type AccessGrant ¶
type AccessGrant struct { ID uuid.UUID `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` AppID uuid.UUID `json:"app_id" db:"app_id"` MemberID uuid.UUID `json:"member_id" db:"member_id"` Scope string `json:"scope" db:"scope"` AccessCount int `json:"access_count" db:"access_count"` }
AccessGrant is the linkage between Member and App.
func (AccessGrant) Description ¶
func (g AccessGrant) Description() template.HTML
Description returns formatted description of the access grant
func (AccessGrant) Member ¶
func (g AccessGrant) Member() *Member
Member returns the associcated member instance
func (AccessGrant) String ¶
func (g AccessGrant) String() string
String returns pretty printable string of this model.
func (*AccessGrant) Validate ¶
func (g *AccessGrant) Validate(tx *pop.Connection) (*validate.Errors, error)
Validate gets run every time you call a "pop.Validate" method.
type App ¶
type App struct { ID uuid.UUID `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` Name string `json:"name" db:"name"` Code string `json:"code" db:"code"` Description string `json:"description" db:"description"` AppKey string `json:"app_key" db:"app_key"` AppSecret string `json:"app_secret" db:"app_secret"` SiteURL string `json:"site_url" db:"site_url"` CallbackURL string `json:"callback_url" db:"callback_url"` AppIcon string `json:"app_icon" db:"app_icon"` }
App is model for application which can be authenticated with uart.
func GetAppByCode ¶
GetAppByCode search and returns an app instance by given code, or nil
func GetAppByKey ¶
GetAppByKey returns an app instance has given app_key or nil.
func (*App) AccessibleBy ¶
AccessibleBy implements Belonging interface
func (*App) GenerateKeyPair ¶
func (a *App) GenerateKeyPair()
GenerateKeyPair generates key and secret for the app.
func (*App) GetRole ¶
func (a *App) GetRole(tx *pop.Connection, code string) *Role
GetRole returns a role with given code of the app or nil.
func (App) GrantsCount ¶
GrantsCount returns count of access grant for the app
func (*App) QueryParams ¶
func (a *App) QueryParams() QueryParams
QueryParams implements Belonging interface
func (App) RequestsCount ¶
RequestsCount returns count of role requests for the app
func (*App) ValidateSave ¶
ValidateSave gets run every time you call "pop.ValidateSave" method.
func (*App) ValidateUpdate ¶
ValidateUpdate gets run every time you call "pop.ValidateUpdate" method.
type Apps ¶
type Apps []App
Apps is array of App.
func (*Apps) AccessibleBy ¶
AccessibleBy implements Belonging interface
func (*Apps) QueryParams ¶
func (a *Apps) QueryParams() QueryParams
QueryParams implements Belonging interface
type Belonging ¶
type Belonging interface { QueryParams() QueryParams OwnedBy(*pop.Query, Owner, ...bool) *pop.Query AccessibleBy(*pop.Query, Owner, ...bool) *pop.Query }
Belonging is an interface for model which have foreign reference.
type Credential ¶
type Credential struct { ID uuid.UUID `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` MemberID uuid.UUID `json:"member_id" db:"member_id"` Provider string `json:"provider" db:"provider"` UserID string `json:"user_id" db:"user_id"` Name string `json:"name" db:"name"` Email string `json:"email" db:"email"` AvatarURL string `json:"avatar_url" db:"avatar_url"` IsAuthorized bool `json:"is_authorized" db:"is_authorized"` IsPrimary bool `json:"is_primary" db:"is_primary"` }
Credential is the model for oauth2 information from 3rd party providers
func (*Credential) AccessibleBy ¶
AccessibleBy implements Belonging interface
func (Credential) Owner ¶
func (c Credential) Owner() *Member
Owner find and return associated member instance
func (Credential) OwnerID ¶
func (c Credential) OwnerID() uuid.UUID
OwnerID returns id of associated member
func (*Credential) QueryParams ¶
func (c *Credential) QueryParams() QueryParams
QueryParams implements Belonging interface
func (Credential) String ¶
func (c Credential) String() string
String returns pretty printable string of this model.
type Credentials ¶
type Credentials []Credential
Credentials is an array of Credentials.
func (*Credentials) AccessibleBy ¶
AccessibleBy implements Belonging interface
func (*Credentials) QueryParams ¶
func (c *Credentials) QueryParams() QueryParams
QueryParams implements Belonging interface
type Doc ¶
type Doc struct { ID uuid.UUID `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` MemberID uuid.UUID `json:"member_id" db:"member_id"` Type string `json:"type" db:"type"` Category string `json:"category" db:"category"` Subject string `json:"subject" db:"subject"` Slug string `json:"slug" db:"slug"` Title string `json:"title" db:"title"` Content string `json:"content" db:"content"` IsPublished bool `json:"is_published" db:"is_published"` NewCategory string `json:"new_category" db:"-"` NewSubject string `json:"new_subject" db:"-"` }
Doc is a structure for documentations
func (*Doc) AccessibleBy ¶
AccessibleBy implements Belonging interface
func (Doc) AuthorName ¶
AuthorName returns name of the author associated to the doc.
func (*Doc) QueryParams ¶
func (d *Doc) QueryParams() QueryParams
QueryParams implements Belonging interface
func (*Doc) ValidateSave ¶
ValidateSave gets run every time you call "pop.ValidateSave" method.
func (*Doc) ValidateUpdate ¶
ValidateUpdate gets run every time you call "pop.ValidateUpdate" method.
type Member ¶
type Member struct { ID uuid.UUID `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` Name string `json:"name" db:"name"` Email string `json:"email" db:"email"` Mobile string `json:"mobile" db:"mobile"` Icon string `json:"icon" db:"icon"` IsActive bool `json:"is_active" db:"is_active"` Note string `json:"note" db:"note"` APIKey string `json:"api_key" db:"api_key"` }
Member is the main model which presents the user.
func CreateMember ¶
func CreateMember(cred *Credential) (*Member, error)
CreateMember creates a member with an associated credential
func GetMember ¶
func GetMember(id interface{}) *Member
GetMember picks a member instance with given id.
func (Member) AccessGrantCount ¶
AccessGrantCount returns count of associated access grants
func (*Member) AccessibleBy ¶
AccessibleBy implements Belonging interface
func (Member) CredentialCount ¶
CredentialCount returns count of associated credentials
func (Member) Credentials ¶
func (m Member) Credentials() *Credentials
Credentials returns the member's associated credentials
func (Member) GetAppRoleCodes ¶
GetAppRoleCodes returns the member's active role codes of given app.
func (Member) Granted ¶
Granted checks if the member have granted for given app. additionally it increase reference count as access count.
func (Member) GrantedApps ¶
GrantedApps returns the member's associcated granted apps
func (Member) Grants ¶
func (m Member) Grants() *AccessGrants
Grants returns all grants of the member.
func (*Member) MessageMarkAsSent ¶
MessageMarkAsSent marks given message's message map for the member.
func (*Member) Messengers ¶
func (m *Member) Messengers(args ...int) *Messengers
Messengers returns messengers belonging to the member.
func (*Member) PrimaryAlert ¶
PrimaryAlert returns primary messenger of the member.
func (*Member) PrimaryNotifier ¶
PrimaryNotifier returns primary messenger of the member.
func (*Member) QueryParams ¶
func (m *Member) QueryParams() QueryParams
QueryParams implements Belonging interface
func (*Member) RemoveRole ¶
func (m *Member) RemoveRole(tx *pop.Connection, r *Role) error
RemoveRole remove rolemap between the member and given role.
func (Member) Revoke ¶
func (m Member) Revoke(tx *pop.Connection, app *App) error
Revoke decouples the app and given member, returns database status Revoke does not consider scope.
func (*Member) ValidateSave ¶
ValidateSave gets run every time you call "pop.ValidateSave" method.
func (*Member) ValidateUpdate ¶
ValidateUpdate gets run every time you call "pop.ValidateUpdate" method.
type Members ¶
type Members []Member
Members is an array of Members.
func (*Members) AccessibleBy ¶
AccessibleBy implements Belonging interface
func (*Members) QueryParams ¶
func (m *Members) QueryParams() QueryParams
QueryParams implements Belonging interface
type Message ¶
type Message struct { ID uuid.UUID `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` MemberID uuid.UUID `json:"member_id" db:"member_id"` Subject string `json:"subject" db:"subject"` Content string `json:"content" db:"content"` AppCode string `json:"app_code" db:"app_code"` Facility string `json:"facility" db:"facility"` Priority int `json:"priority" db:"priority"` IsLog bool `json:"is_log" db:"is_log"` }
Message is a structure for messaging/logging subsystem
func NewMessage ¶
func NewMessage(tx *pop.Connection, sndrID interface{}, rcpts, bccs *Members, subj, cont, ac, fac string, pri int, isLog bool) *Message
NewMessage creates new message with given parameters
func (*Message) AccessibleBy ¶
AccessibleBy implements Belonging interface
func (Message) MemberMap ¶
func (m Message) MemberMap(memberID interface{}) *MessageMap
MemberMap returns message map for the message and given member. This method will be called directly from template(index, show)
func (Message) PriorityString ¶
PriorityString returns human readable string of the message's priority
func (*Message) QueryParams ¶
func (m *Message) QueryParams() QueryParams
QueryParams implements Belonging interface
type MessageMap ¶
type MessageMap struct { ID uuid.UUID `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` MemberID uuid.UUID `json:"member_id" db:"member_id"` MessageID uuid.UUID `json:"message_id" db:"message_id"` IsSent bool `json:"is_sent" db:"is_sent"` IsRead bool `json:"is_read" db:"is_read"` IsBCC bool `json:"is_bcc" db:"is_bcc"` }
MessageMap is structure for connection messages and members
func (MessageMap) String ¶
func (m MessageMap) String() string
String returns human readable string of model message map.
type Messages ¶
type Messages []Message
Messages is an array of Messages
func (*Messages) AccessibleBy ¶
AccessibleBy implements Belonging interface
func (*Messages) QueryParams ¶
func (m *Messages) QueryParams() QueryParams
QueryParams implements Belonging interface
type MessagingLog ¶
type MessagingLog struct { ID uuid.UUID `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` Status string `json:"status" db:"status"` QueueID string `json:"queue_id" db:"queue_id"` Response string `json:"response" db:"response"` Method string `json:"method" db:"method"` SentFor string `json:"sent_for" db:"sent_for"` SentTo string `json:"sent_to" db:"sent_to"` Subject string `json:"subject" db:"subject"` Notes string `json:"notes" db:"notes"` }
MessagingLog is a structure for log of messaging.
func (MessagingLog) String ¶
func (m MessagingLog) String() string
String returns representation of the log
type Messenger ¶
type Messenger struct { ID uuid.UUID `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` MemberID uuid.UUID `json:"member_id" db:"member_id"` Priority int `json:"priority" db:"priority"` Method string `json:"method" db:"method"` Value string `json:"value" db:"value"` IsPrimary bool `json:"is_primary" db:"is_primary"` }
Messenger is a structure for messaging methods
func (*Messenger) AccessibleBy ¶
AccessibleBy implements Belonging interface
func (*Messenger) QueryParams ¶
func (m *Messenger) QueryParams() QueryParams
QueryParams implements Belonging interface
func (*Messenger) ValidateSave ¶
ValidateSave gets run every time you call "pop.ValidateSave" method.
func (*Messenger) ValidateUpdate ¶
ValidateUpdate gets run every time you call "pop.ValidateUpdate" method.
type Owner ¶
type Owner interface {
GetID() interface{}
}
Owner is an interface for model which have belongings
type QueryParams ¶
QueryParams is structure contains query parameters
type Role ¶
type Role struct { ID uuid.UUID `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` AppID uuid.UUID `json:"app_id" db:"app_id"` Name string `json:"name" db:"name"` Code string `json:"code" db:"code"` Description string `json:"description" db:"description"` Rank int `json:"rank" db:"rank"` IsReadonly bool `json:"is_readonly" db:"is_readonly"` }
Role is used to set member's privilege for each apps.
func GetAppRole ¶
GetAppRole returns role instance found by given app code and role code.
func (Role) MemberCount ¶
MemberCount returns count of members who has the role
func (Role) Members ¶
Members returns members have the role. if optional flag is true, only active members are returned.
func (*Role) ValidateSave ¶
ValidateSave gets run every time you call "pop.ValidateSave" method.
func (*Role) ValidateUpdate ¶
ValidateUpdate gets run every time you call "pop.ValidateUpdate" method.
type RoleMap ¶
type RoleMap struct { ID int `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` RoleID uuid.UUID `json:"role_id" db:"role_id"` MemberID uuid.UUID `json:"member_id" db:"member_id"` IsActive bool `json:"is_active" db:"is_active"` }
RoleMap is a mapping object for role and member.