model

package
v0.0.0-...-3b47b55 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Model

	// ActionID  string     `gorm:"size:64" json:"actionID"` // TODO
	Name      string      `gorm:"size:256" json:"name"`
	Describe  string      `gorm:"size:256" json:"describe"`
	Resources []*Resource `gorm:"many2many:action_resources;" json:"resources"`
}

Action

type ActionService

type ActionService interface {
	// Find returns a action from the datastore.
	Find(context.Context, uint64) (*Action, error)

	// List returns a list of actions from the datastore.
	List(context.Context) ([]*Action, error)

	// Update persists a action to the datastore.
	Update(context.Context, *Action) error

	// Delete deletes a action from the datastore.
	Delete(context.Context, uint64) error

	// Create persists a new action to the datastore.
	Create(context.Context, *Action) error
}

ActionService defines operations for working with system actions.

type AdmissionService

type AdmissionService interface {
	// LoadAllPolicy returns all policy from the datastore.
	LoadAllPolicy(context.Context, []*Role) error

	// DeleteAllPolicy deletes policy from the datastore.
	DeleteAllPolicy(context.Context) error

	// Admit can be used to restrict access to authorized users, such as
	// members of an organization in your source control management system.
	Admit(ctx context.Context, user *User, subject string, action string) (bool, error)
}

RoleService defines operations for working with system roles.

type Model

type Model struct {
	ID        uint64     `gorm:"primary_key" json:"id"`
	CreatedAt time.Time  `sql:"index" json:"createdAt"`
	UpdatedAt time.Time  `json:"updatedAt"`
	DeletedAt *time.Time `json:"deletedAt"`
}

Model represents meta data of entity.

type PageQuery

type PageQuery struct {
	Where     string
	WhereArgs []interface{}
	PageNo    int
	PageSize  int
}

func NewPageQuery

func NewPageQuery(pageNo int, pageSize int) PageQuery

type Permission

type Permission struct {
	Model

	Name         string    `gorm:"size:64;unique_index" json:"name"`
	Label        string    `gorm:"size:64" json:"label"`
	Describe     string    `gorm:"size:256" json:"describe"`
	Icon         string    `gorm:"size:64" json:"icon"`
	Path         string    `gorm:"size:256" json:"path"`
	Actions      []*Action `gorm:"many2many:permission_actions;" json:"actions"`
	DefaultCheck bool      `gorm:"default:false" json:"defaultCheck"`
	Status       int       `gorm:"default:1" json:"status"`
	Deleted      int       `gorm:"default:0" json:"deleted"`

	Selected []interface{} `gorm:"-" json:"selected"` //selected actions
}

permission.

func (*Permission) GetActionIds

func (p *Permission) GetActionIds() mapset.Set

type PermissionService

type PermissionService interface {
	// Find returns a permission from the datastore.
	Find(context.Context, uint64) (*Permission, error)

	// FindWhere returns a list of users from the datastore.
	FindWhere(PageQuery) ([]*Permission, pagination.Pagination)

	// List returns a list of permissions from the datastore.
	List(context.Context) ([]*Permission, error)

	// Update persists a permission to the datastore.
	Update(context.Context, *Permission) error

	// Delete deletes a permission from the datastore.
	Delete(context.Context, uint64) error

	// Create persists a new permission to the datastore.
	Create(context.Context, *Permission) error
}

PermissionService defines operations for working with system permissions.

type Resource

type Resource struct {
	Model

	ActionID uint64 `json:"actionID"`
	// Name     string `gorm:"size:64" json:"name"`
	// Describe string `gorm:"size:256" json:"describe"`
	Method string `gorm:"size:64" json:"method"`
	Path   string `gorm:"size:256" json:"path"`
}

Permission represents an auth request of the system. Resource

type ResourceService

type ResourceService interface {
	// Find returns a resource from the datastore.
	Find(context.Context, uint64) (*Resource, error)

	// List returns a list of resources from the datastore.
	List(context.Context) ([]*Resource, error)

	// Update persists a resource to the datastore.
	Update(context.Context, *Resource) error

	// Delete deletes a resource from the datastore.
	Delete(context.Context, uint64) error

	// Create persists a new resource to the datastore.
	Create(context.Context, *Resource) error
}

ResourceService defines operations for working with system resource.

type Role

type Role struct {
	Model

	Name        string        `gorm:"size:64;unique_index" json:"name"`
	Label       string        `gorm:"size:64" json:"label"`
	Describe    string        `gorm:"size:256" json:"describe"`
	CreateBy    string        `gorm:"size:64" json:"createBy"`
	Status      int           `gorm:"default:1" json:"status"`
	Deleted     int           `gorm:"default:0" json:"deleted"`
	Permissions []*Permission `gorm:"many2many:role_permissions;" json:"permissions"`
	Actions     []*Action     `gorm:"many2many:role_actions;" json:"actions"`
}

Role represents a user role of the system. Role

func (*Role) GetActionIds

func (u *Role) GetActionIds() mapset.Set

type RoleAction

type RoleAction struct {
	RoleID   uint64 `sql:"index"`
	ActionID uint64 `sql:"index"`
}

type RoleService

type RoleService interface {
	// Find returns a role from the datastore.
	Find(context.Context, uint64) (*Role, error)

	// FindName returns a role from the datastore.
	FindName(context.Context, string) (*Role, error)

	// List returns a list of roles from the datastore.
	List(context.Context) ([]*Role, error)

	// Clear Related persists a role to the datastore.
	RelatedClear(context.Context, *Role)

	// Update persists a role to the datastore.
	Update(ctx context.Context, role *Role, actionIDs []interface{}) error

	// Delete deletes a role from the datastore.
	Delete(context.Context, uint64) error

	// Create persists a new role to the datastore.
	Create(context.Context, *Role) error
}

RoleService defines operations for working with system roles.

type SessionData

type SessionData struct {
	UID       uint64 // user ID
	Username  string // username
	Roles     string // user roles
	Token     string // user token
	Anonymous bool   // Anonymous user
}

SessionData represents the session.

func (*SessionData) Delete

func (sd *SessionData) Delete(c *gin.Context, user *User, users UserService) error

func (*SessionData) Get

func (sd *SessionData) Get(c *gin.Context, users UserService) (*User, error)

func (*SessionData) Save

func (sd *SessionData) Save(c *gin.Context) error

Save saves the current session of the specified context.

type Setting

type Setting struct {
	Model

	Name     string `sql:"index" gorm:"size:64;unique_index" json:"name"`
	Value    string `gorm:"type:text" json:"value"`
	Describe string `gorm:"size:text" json:"describe"`
}

Setting represents a user setting of the system. Setting

type SettingService

type SettingService interface {
	// Find returns a setting from the datastore.
	Find(context.Context, uint64) (*Setting, error)

	// Find returns a setting from the datastore.
	FindName(context.Context, string) (*Setting, error)

	// Find returns a setting from the datastore.
	FindLike(context.Context, string) ([]*Setting, error)

	// List returns a list of settings from the datastore.
	List(context.Context) ([]*Setting, error)

	// Update persists a setting to the datastore.
	Update(context.Context, *Setting) error

	// Updates persists a setting to the datastore.
	Updates(context.Context, []*Setting) error

	// Delete deletes a setting from the datastore.
	Delete(context.Context, uint64) error

	// Create persists a new setting to the datastore.
	Create(context.Context, *Setting) error
}

SettingService defines operations for working with system settings.

type User

type User struct {
	Model

	Username     string     `gorm:"size:64" json:"username"`
	Nickname     string     `gorm:"size:64" json:"nickname"`
	Avatar       string     `gorm:"size:255" json:"avatar"`
	BIO          string     `gorm:"size:512" json:"bio"`
	Locale       string     `gorm:"size:64" json:"locale"`
	Password     string     `gorm:"-" json:"password,omitempty"`
	PasswordHash string     `gorm:"size:64" json:"-"`
	Email        string     `gorm:"size:64" json:"email"`
	Phone        string     `gorm:"size:16" json:"phone"`
	Status       int        `gorm:"default:1" json:"status"`
	LoginIP      string     `gorm:"size:32" json:"loginIP"`
	LoginAt      *time.Time `json:"loginAt"`
	Token        string     `gorm:"size:255" json:"-"`
	Refresh      string     `gorm:"size:255" json:"-"`
	Expiry       int64      `gorm:"size:255" json:"-"`
	Hash         string     `gorm:"size:64" json:"-"`
	Roles        []*Role    `gorm:"many2many:user_roles;association_jointable_foreignkey:role_id" json:"roles"`
	RoleList     []uint64   `gorm:"-" json:"roleList" `
}

User represents a user of the system.

func (*User) FillRoleList

func (u *User) FillRoleList()

func (*User) FillRolePermissionList

func (u *User) FillRolePermissionList()

func (*User) Validate

func (u *User) Validate() error

Validate the user and returns an error if the validation fails.

type UserRole

type UserRole struct {
	UserID uint64 `sql:"index"`
	RoleID uint64 `sql:"index"`
}

type UserService

type UserService interface {
	// Find returns a user from the datastore.
	Find(context.Context, uint64) (*User, error)

	// FindName returns a user from the datastore by username.
	FindName(context.Context, string) (*User, error)

	// FindToken returns a user from the datastore by token.
	FindToken(context.Context, string) (*User, error)

	// FindWhere returns a list of users from the datastore.
	FindWhere(PageQuery, []string) ([]*User, pagination.Pagination)

	// List returns a list of users from the datastore.
	List(context.Context) ([]*User, error)

	// Create persists a new user to the datastore.
	Create(context.Context, *User) error

	// Update persists an updated user to the datastore.
	Update(context.Context, *User) error

	// Update columns persists an updated user to the datastore.
	Updates(context.Context, *User, interface{}) error

	// Delete deletes a user from the datastore.
	Delete(context.Context, uint64) error

	// Count returns a count of users.
	Count(context.Context) (int, error)

	// RelatedClear returns a user from the datastore by token.
	RelatedClear(context.Context, *User)
}

UserService defines operations for working with users.

Jump to

Keyboard shortcuts

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