mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
config: social,packages,lua (2 files)
This commit is contained in:
@@ -1,112 +1,13 @@
|
||||
-- Formatting helpers for audit log display
|
||||
local M = {}
|
||||
-- Audit log formatting module
|
||||
-- DEPRECATED: This file redirects to formatting/init.lua
|
||||
-- Individual functions are now in separate files under formatting/
|
||||
--
|
||||
-- Migration guide:
|
||||
-- Old: local formatting = require("formatting")
|
||||
-- New: local formatting = require("formatting.init")
|
||||
-- Or import individual functions:
|
||||
-- local formatTimestamp = require("formatting.format_timestamp")
|
||||
--
|
||||
-- Types are defined in formatting/types.lua
|
||||
|
||||
---@class AuditLog
|
||||
---@field id string
|
||||
---@field operation string
|
||||
---@field resource string
|
||||
---@field resourceId string
|
||||
---@field username string
|
||||
---@field timestamp number
|
||||
---@field ipAddress string
|
||||
---@field success boolean
|
||||
---@field errorMessage string?
|
||||
|
||||
---@class FormattedLogEntry
|
||||
---@field id string
|
||||
---@field operation string
|
||||
---@field operationColor string
|
||||
---@field resource string
|
||||
---@field resourceId string
|
||||
---@field resourceIcon string
|
||||
---@field username string
|
||||
---@field timestamp string
|
||||
---@field ipAddress string
|
||||
---@field success boolean
|
||||
---@field errorMessage string?
|
||||
---@field rowClass string
|
||||
|
||||
--- Operation type to color mapping
|
||||
M.operationColors = {
|
||||
CREATE = "bg-green-500",
|
||||
READ = "bg-blue-500",
|
||||
UPDATE = "bg-yellow-500",
|
||||
DELETE = "bg-red-500"
|
||||
}
|
||||
|
||||
--- Resource type to icon mapping
|
||||
M.resourceIcons = {
|
||||
user = "User",
|
||||
credential = "ShieldCheck",
|
||||
default = "ChartLine"
|
||||
}
|
||||
|
||||
--- Get color class for operation
|
||||
---@param operation string
|
||||
---@return string
|
||||
function M.getOperationColor(operation)
|
||||
return M.operationColors[operation] or "bg-gray-500"
|
||||
end
|
||||
|
||||
--- Get icon name for resource
|
||||
---@param resource string
|
||||
---@return string
|
||||
function M.getResourceIcon(resource)
|
||||
return M.resourceIcons[resource] or M.resourceIcons.default
|
||||
end
|
||||
|
||||
--- Format timestamp for display (assumes input in milliseconds)
|
||||
---@param timestamp number?
|
||||
---@return string
|
||||
function M.formatTimestamp(timestamp)
|
||||
if not timestamp then
|
||||
return "Unknown"
|
||||
end
|
||||
|
||||
-- Assuming timestamp is in milliseconds
|
||||
local seconds = math.floor(timestamp / 1000)
|
||||
return os.date("%Y-%m-%d %H:%M:%S", seconds)
|
||||
end
|
||||
|
||||
--- Format a log entry for display
|
||||
---@param log AuditLog
|
||||
---@return FormattedLogEntry
|
||||
function M.formatLogEntry(log)
|
||||
return {
|
||||
id = log.id,
|
||||
operation = log.operation,
|
||||
operationColor = M.getOperationColor(log.operation),
|
||||
resource = log.resource,
|
||||
resourceId = log.resourceId,
|
||||
resourceIcon = M.getResourceIcon(log.resource),
|
||||
username = log.username,
|
||||
timestamp = M.formatTimestamp(log.timestamp),
|
||||
ipAddress = log.ipAddress,
|
||||
success = log.success,
|
||||
errorMessage = log.errorMessage,
|
||||
rowClass = log.success and "bg-card" or "bg-destructive/5 border-destructive/20"
|
||||
}
|
||||
end
|
||||
|
||||
--- Format all logs for display
|
||||
---@param logs AuditLog[] | nil
|
||||
---@return FormattedLogEntry[]
|
||||
function M.formatAllLogs(logs)
|
||||
local result = {}
|
||||
for i, log in ipairs(logs or {}) do
|
||||
result[i] = M.formatLogEntry(log)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
--- Get status badge text for a log
|
||||
---@param log AuditLog
|
||||
---@return string | nil
|
||||
function M.getStatusBadge(log)
|
||||
if log.success then
|
||||
return nil
|
||||
end
|
||||
return "Failed"
|
||||
end
|
||||
|
||||
return M
|
||||
return require("formatting.init")
|
||||
|
||||
32
packages/social_hub/seed/scripts/tests/social.cases.json
Normal file
32
packages/social_hub/seed/scripts/tests/social.cases.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"validate_content": [
|
||||
{ "input": null, "valid": false, "error": "Post cannot be empty", "desc": "null content" },
|
||||
{ "input": "", "valid": false, "error": "Post cannot be empty", "desc": "empty string" },
|
||||
{ "input": "Hello world!", "valid": true, "error": null, "desc": "normal content" },
|
||||
{ "input": "x", "valid": true, "error": null, "desc": "single char" },
|
||||
{ "input": "12345678901234567890123456789012345678901234567890", "valid": true, "error": null, "desc": "50 chars" },
|
||||
{ "input": "Hello\nWorld\n123", "valid": true, "error": null, "desc": "multiline content" },
|
||||
{ "input": "Special chars: !@#$%^&*()_+", "valid": true, "error": null, "desc": "special chars" }
|
||||
],
|
||||
"validate_content_length": [
|
||||
{ "length": 499, "valid": true, "desc": "just under limit" },
|
||||
{ "length": 500, "valid": true, "desc": "at limit" },
|
||||
{ "length": 501, "valid": false, "desc": "just over limit" },
|
||||
{ "length": 1000, "valid": false, "desc": "way over limit" }
|
||||
],
|
||||
"submit_post": [
|
||||
{ "content": "Hello!", "media": null, "expected_media": [], "desc": "no media" },
|
||||
{ "content": "Photo post", "media": ["http://img.com/a.jpg"], "expected_media": ["http://img.com/a.jpg"], "desc": "single image" },
|
||||
{ "content": "Multi", "media": ["a.jpg", "b.png", "c.gif"], "expected_media": ["a.jpg", "b.png", "c.gif"], "desc": "multiple media" }
|
||||
],
|
||||
"render_post": [
|
||||
{ "id": "p1", "author": "Alice", "content": "Hello", "likes": 5, "comments": 2, "desc": "basic post" },
|
||||
{ "id": "p2", "author": "Bob", "content": "Test", "likes": 0, "comments": 0, "desc": "no engagement" },
|
||||
{ "id": "p3", "author": "Carol", "content": "Popular!", "likes": 1000, "comments": 50, "desc": "popular post" }
|
||||
],
|
||||
"render_stat": [
|
||||
{ "label": "Posts", "value": 42, "icon": "article", "desc": "posts stat" },
|
||||
{ "label": "Followers", "value": 1000, "icon": "people", "desc": "followers stat" },
|
||||
{ "label": "Likes", "value": 0, "icon": "heart", "desc": "zero likes" }
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user