72 lines
2.5 KiB
Go
72 lines
2.5 KiB
Go
package usecase
|
|
|
|
import (
|
|
"context"
|
|
"permission/reborn/domain/entity"
|
|
)
|
|
|
|
// PermissionUseCase 權限業務邏輯介面
|
|
type PermissionUseCase interface {
|
|
// GetAll 取得所有權限
|
|
GetAll(ctx context.Context) ([]*PermissionResponse, error)
|
|
|
|
// GetTree 取得權限樹
|
|
GetTree(ctx context.Context) (*PermissionTreeNode, error)
|
|
|
|
// GetByHTTP 根據 HTTP 資訊取得權限
|
|
GetByHTTP(ctx context.Context, path, method string) (*PermissionResponse, error)
|
|
|
|
// ExpandPermissions 展開權限 (包含父權限)
|
|
ExpandPermissions(ctx context.Context, permissions entity.Permissions) (entity.Permissions, error)
|
|
|
|
// GetUsersByPermission 取得擁有指定權限的所有使用者
|
|
GetUsersByPermission(ctx context.Context, permissionNames []string) ([]string, error)
|
|
}
|
|
|
|
// PermissionResponse 權限回應
|
|
type PermissionResponse struct {
|
|
ID int64 `json:"id"`
|
|
ParentID int64 `json:"parent_id"`
|
|
Name string `json:"name"`
|
|
HTTPPath string `json:"http_path,omitempty"`
|
|
HTTPMethod string `json:"http_method,omitempty"`
|
|
Status entity.PermissionStatus `json:"status"`
|
|
Type entity.PermissionType `json:"type"`
|
|
}
|
|
|
|
// PermissionTreeNode 權限樹節點
|
|
type PermissionTreeNode struct {
|
|
*PermissionResponse
|
|
Children []*PermissionTreeNode `json:"children,omitempty"`
|
|
}
|
|
|
|
// RolePermissionUseCase 角色權限業務邏輯介面
|
|
type RolePermissionUseCase interface {
|
|
// GetByRoleUID 取得角色的所有權限
|
|
GetByRoleUID(ctx context.Context, roleUID string) (entity.Permissions, error)
|
|
|
|
// GetByUserUID 取得使用者的所有權限
|
|
GetByUserUID(ctx context.Context, userUID string) (*UserPermissionResponse, error)
|
|
|
|
// UpdateRolePermissions 更新角色權限
|
|
UpdateRolePermissions(ctx context.Context, roleUID string, permissions entity.Permissions) error
|
|
|
|
// CheckPermission 檢查角色是否有權限
|
|
CheckPermission(ctx context.Context, roleUID, path, method string) (*PermissionCheckResponse, error)
|
|
}
|
|
|
|
// UserPermissionResponse 使用者權限回應
|
|
type UserPermissionResponse struct {
|
|
UserUID string `json:"user_uid"`
|
|
RoleUID string `json:"role_uid"`
|
|
RoleName string `json:"role_name"`
|
|
Permissions entity.Permissions `json:"permissions"`
|
|
}
|
|
|
|
// PermissionCheckResponse 權限檢查回應
|
|
type PermissionCheckResponse struct {
|
|
Allowed bool `json:"allowed"`
|
|
PermissionName string `json:"permission_name,omitempty"`
|
|
PlainCode bool `json:"plain_code"`
|
|
}
|