Documentation
¶
Index ¶
- Variables
- func MemberTableName() string
- type AccountBase
- func (acc *AccountBase) CheckPermissions(ctx context.Context, resource any, patterns ...string) bool
- func (acc *AccountBase) CheckedPermissions(ctx context.Context, resource any, patterns ...string) rbac.Permission
- func (acc *AccountBase) ExtendAdminUsers(ids ...uint64)
- func (acc *AccountBase) ExtendPermissions(perm PermissionChecker)
- func (acc *AccountBase) GetApprove() pkgModels.ApproveStatus
- func (acc *AccountBase) GetCreatedAt() time.Time
- func (acc *AccountBase) GetID() uint64
- func (acc *AccountBase) GetUpdatedAt() time.Time
- func (acc *AccountBase) HasPermission(patterns ...string) bool
- func (acc *AccountBase) IsAdminUser(userID uint64) bool
- func (acc *AccountBase) IsAnonymous() bool
- func (acc *AccountBase) IsNil() bool
- func (acc *AccountBase) IsOwnerUser(userID uint64) bool
- func (acc *AccountBase) ListPermissions(patterns ...string) []rbac.Permission
- func (acc *AccountBase) OwnerAccountID() uint64
- func (acc *AccountBase) PermissionsChecker() PermissionChecker
- func (acc *AccountBase) RBACResourceName() string
- func (acc *AccountBase) SetApprove(status pkgModels.ApproveStatus)
- func (acc *AccountBase) SetID(id uint64)
- func (acc *AccountBase) SetPermissions(perm PermissionChecker)
- func (acc *AccountBase) TableName() string
- type M2MAccountMemberRole
- type MemberBase
- type PermissionChecker
Constants ¶
This section is empty.
Variables ¶
var CtxPermissionCheckAccount = &struct{ s string }{s: "permc:account"}
CtxPermissionCheckAccount is the context key used to store the account for permission checks.
Functions ¶
func MemberTableName ¶ added in v0.5.0
func MemberTableName() string
MemberTableName returns the default member join table name (nil-safe for query builders).
Types ¶
type AccountBase ¶ added in v0.5.0
type AccountBase struct {
ID uint64 `json:"id" gorm:"primaryKey"`
Approve pkgModels.ApproveStatus `json:"approved" db:"approve_status" gorm:"column:approve_status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"deleted_at"`
Permissions PermissionChecker `json:"-" gorm:"-"`
Admins []uint64 `json:"-" gorm:"-"`
}
AccountBase is the minimal embeddable account (tenant anchor for Members).
func (*AccountBase) CheckPermissions ¶ added in v0.5.0
func (acc *AccountBase) CheckPermissions(ctx context.Context, resource any, patterns ...string) bool
CheckPermissions for some specific resource.
func (*AccountBase) CheckedPermissions ¶ added in v0.5.0
func (acc *AccountBase) CheckedPermissions(ctx context.Context, resource any, patterns ...string) rbac.Permission
CheckedPermissions for some specific resource.
func (*AccountBase) ExtendAdminUsers ¶ added in v0.5.0
func (acc *AccountBase) ExtendAdminUsers(ids ...uint64)
ExtendAdminUsers to the account.
func (*AccountBase) ExtendPermissions ¶ added in v0.5.0
func (acc *AccountBase) ExtendPermissions(perm PermissionChecker)
ExtendPermissions of the account for the user.
func (*AccountBase) GetApprove ¶ added in v0.5.0
func (acc *AccountBase) GetApprove() pkgModels.ApproveStatus
GetApprove returns approval status.
func (*AccountBase) GetCreatedAt ¶ added in v0.5.0
func (acc *AccountBase) GetCreatedAt() time.Time
GetCreatedAt returns created timestamp.
func (*AccountBase) GetID ¶ added in v0.5.0
func (acc *AccountBase) GetID() uint64
GetID returns account ID.
func (*AccountBase) GetUpdatedAt ¶ added in v0.5.0
func (acc *AccountBase) GetUpdatedAt() time.Time
GetUpdatedAt returns updated timestamp.
func (*AccountBase) HasPermission ¶ added in v0.5.0
func (acc *AccountBase) HasPermission(patterns ...string) bool
HasPermission for the account.
func (*AccountBase) IsAdminUser ¶ added in v0.5.0
func (acc *AccountBase) IsAdminUser(userID uint64) bool
IsAdminUser reports whether userID is an admin of this account.
func (*AccountBase) IsAnonymous ¶ added in v0.5.0
func (acc *AccountBase) IsAnonymous() bool
IsAnonymous account.
func (*AccountBase) IsNil ¶ added in v0.5.0
func (acc *AccountBase) IsNil() bool
IsNil checks if the account is nil.
func (*AccountBase) IsOwnerUser ¶ added in v0.5.0
func (acc *AccountBase) IsOwnerUser(userID uint64) bool
IsOwnerUser of the account.
func (*AccountBase) ListPermissions ¶ added in v0.5.0
func (acc *AccountBase) ListPermissions(patterns ...string) []rbac.Permission
ListPermissions for the account.
func (*AccountBase) OwnerAccountID ¶ added in v0.5.0
func (acc *AccountBase) OwnerAccountID() uint64
OwnerAccountID returns the account ID which belongs the object.
func (*AccountBase) PermissionsChecker ¶ added in v0.5.0
func (acc *AccountBase) PermissionsChecker() PermissionChecker
PermissionsChecker returns the account permission checker.
func (*AccountBase) RBACResourceName ¶ added in v0.5.0
func (acc *AccountBase) RBACResourceName() string
RBACResourceName returns the default RBAC resource name (override on consumer type).
func (*AccountBase) SetApprove ¶ added in v0.5.0
func (acc *AccountBase) SetApprove(status pkgModels.ApproveStatus)
SetApprove sets approval status.
func (*AccountBase) SetID ¶ added in v0.5.0
func (acc *AccountBase) SetID(id uint64)
SetID sets account primary key.
func (*AccountBase) SetPermissions ¶ added in v0.5.0
func (acc *AccountBase) SetPermissions(perm PermissionChecker)
SetPermissions of the account for the user.
func (*AccountBase) TableName ¶ added in v0.5.0
func (acc *AccountBase) TableName() string
TableName returns the default database table (override on consumer type).
type M2MAccountMemberRole ¶
type M2MAccountMemberRole struct {
MemberID uint64 `db:"member_id" gorm:"primaryKey"`
RoleID uint64 `db:"role_id" gorm:"primaryKey"`
CreatedAt time.Time `db:"created_at"`
}
M2MAccountMemberRole m2m link between members and roles|permissions.
func (*M2MAccountMemberRole) TableName ¶
func (member *M2MAccountMemberRole) TableName() string
TableName of the model in the database.
type MemberBase ¶ added in v0.5.0
type MemberBase struct {
ID uint64 `db:"id" gorm:"primaryKey"`
Approve pkgModels.ApproveStatus `db:"approve_status" gorm:"column:approve_status"`
AccountID uint64 `db:"account_id"`
UserID uint64 `db:"user_id"`
IsAdmin bool `db:"is_admin"`
Roles []*rbacModels.Role `gorm:"many2many:m2m_account_member_role;foreignKey:ID;joinForeignKey:MemberID;references:ID;joinReferences:RoleID"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
DeletedAt gorm.DeletedAt `db:"deleted_at"`
}
MemberBase is the embeddable account-member join (Account ↔ User + RBAC).
func (*MemberBase) GetID ¶ added in v0.5.0
func (m *MemberBase) GetID() uint64
GetID returns member ID.
func (*MemberBase) OwnerAccountID ¶ added in v0.5.0
func (m *MemberBase) OwnerAccountID() uint64
OwnerAccountID returns the account this member belongs to.
func (*MemberBase) RBACResourceName ¶ added in v0.5.0
func (m *MemberBase) RBACResourceName() string
RBACResourceName returns the default RBAC resource name (override on consumer type).
func (*MemberBase) TableName ¶ added in v0.5.0
func (m *MemberBase) TableName() string
TableName returns the default database table (override on consumer type).
type PermissionChecker ¶
type PermissionChecker interface {
// CheckPermissions verifies if the given patterns are permitted for a resource in the context.
CheckPermissions(ctx context.Context, resource any, patterns ...string) bool
// CheckedPermissions returns the permission object if patterns are permitted, nil otherwise.
CheckedPermissions(ctx context.Context, resource any, patterns ...string) rbac.Permission
// ChildRoles returns all child roles associated with this permission checker.
ChildRoles() []rbac.Role
// ChildPermissions returns all child permissions associated with this permission checker.
ChildPermissions() []rbac.Permission
// Permissions returns all permissions matching the given patterns.
Permissions(patterns ...string) []rbac.Permission
// HasPermission checks if any of the given permission patterns exist.
HasPermission(patterns ...string) bool
}
PermissionChecker describes the interface for checking permissions for account members.