mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 22:04:56 +00:00
- Added type annotations and class definitions in the dashboard layout, stats, and data table modules for improved type safety and documentation. - Introduced new classes for UI components, props, and configuration in the form builder, navigation menu, notification center, and UI dialogs packages. - Implemented detailed type definitions for actions, fields, and pagination components to streamline usage and enhance clarity. - Updated initialization functions in multiple packages to include versioning and installation context. - Improved structure and readability of the codebase by organizing and documenting component properties and methods.
50 lines
1.1 KiB
Lua
50 lines
1.1 KiB
Lua
local check = require("check")
|
|
|
|
---@class AuthGate
|
|
local M = {}
|
|
|
|
---@class User
|
|
---@field id string
|
|
---@field level? number
|
|
|
|
---@class GateContext
|
|
---@field user? User
|
|
---@field requiredLevel? number
|
|
---@field children? table
|
|
|
|
---@class CheckResult
|
|
---@field allowed boolean
|
|
---@field reason? string
|
|
---@field redirect? string
|
|
|
|
---@class UIComponent
|
|
---@field type string
|
|
---@field props? table
|
|
|
|
---@param ctx GateContext
|
|
---@return CheckResult
|
|
function M.check(ctx)
|
|
if not ctx.user then
|
|
return { allowed = false, reason = "not_authenticated", redirect = "/login" }
|
|
end
|
|
if ctx.requiredLevel and not check.can_access(ctx.user, ctx.requiredLevel) then
|
|
return { allowed = false, reason = "insufficient_permission" }
|
|
end
|
|
return { allowed = true }
|
|
end
|
|
|
|
---@param ctx GateContext
|
|
---@return UIComponent|table
|
|
function M.wrap(ctx)
|
|
local result = M.check(ctx)
|
|
if not result.allowed then
|
|
if result.redirect then
|
|
return { type = "Redirect", props = { to = result.redirect } }
|
|
end
|
|
return { type = "AccessDenied", props = { reason = result.reason } }
|
|
end
|
|
return ctx.children
|
|
end
|
|
|
|
return M
|