Compare commits

..
Author SHA1 Message Date
aios a4e20f1bc8 Create V1R2C0 user portal RBAC ops dashboard patch branch 2026-07-08 09:55:30 +08:00
5 changed files with 9 additions and 126 deletions
-66
View File
@@ -1,66 +0,0 @@
"""V1R3C0 User Portal RBAC Ops core services.
Pure application layer: no secrets, no external credentials.
"""
from dataclasses import dataclass, field
from datetime import datetime, timezone
ROLES = {"user", "group_admin", "owner"}
@dataclass
class PortalContext:
user_id: str
group_id: str | None
role: str
def scope(self):
if self.role == "owner":
return "global"
if self.role == "group_admin":
return "group"
return "self"
@dataclass
class Approval:
request_id: str
request_type: str
state: str = "pending"
@dataclass
class Alert:
alert_id: str
level: str
state: str = "open"
@dataclass
class AuditEvent:
action: str
actor: str
created_at: str = field(default_factory=lambda: datetime.now(timezone.utc).isoformat())
class PortalRBACService:
def authorize(self, ctx: PortalContext, target_scope: str):
if ctx.role not in ROLES:
return False
if ctx.scope() == "global":
return True
return ctx.scope() == target_scope
def navigation(self, role: str):
common = ["/", "/me", "/model", "/usage", "/quota", "/tasks", "/alerts", "/approvals", "/audit"]
if role == "owner":
return common + ["/owner/system", "/owner/gitops", "/owner/runtime", "/owner/security"]
if role == "group_admin":
return common + ["/group", "/group/users", "/group/quota", "/group/audit"]
return common
class PortalAuditService:
def append(self, action: str, actor: str):
return AuditEvent(action=action, actor=actor)
class SecretPolicy:
@staticmethod
def redact(value: str):
return "***REDACTED***" if value else value
__all__ = ["PortalContext", "PortalRBACService", "PortalAuditService", "SecretPolicy", "Approval", "Alert"]
@@ -1,27 +0,0 @@
CREATE TABLE IF NOT EXISTS portal_approvals (
id TEXT PRIMARY KEY,
request_type TEXT NOT NULL,
state TEXT NOT NULL DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS portal_alerts (
id TEXT PRIMARY KEY,
level TEXT NOT NULL,
state TEXT NOT NULL DEFAULT 'open',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS portal_audit_logs (
id TEXT PRIMARY KEY,
actor TEXT NOT NULL,
action TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS portal_notifications (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
message TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
@@ -1,9 +0,0 @@
{
"type": "branch",
"branch": "patch/v1r3c0-user-portal-rbac-ops-20260708",
"base": "main",
"created_by": "chatgpt-gitops-bot",
"created_at": "2026-07-07T18:32:29Z",
"direct_main_push": false,
"owner_approval_required": true
}
@@ -0,0 +1,9 @@
{
"id": "patch-1783475730122-9eb60075",
"patch_name": "user-portal-rbac-ops-dashboard-v1r2c0",
"branch": "patch/user-portal-rbac-ops-dashboard-v1r2c0",
"risk": "high",
"description": "Implement V1R2C0 user.cnnetmkt.top three-role portal end-to-end: user/group_admin/owner pages, Portal API, approvals, alerts, audit, RBAC, Owner system cockpit, OpenAPI operationId coverage, and self-loop tests. Handoff to Hermes/OpenClaw multi-agent implementation; no secrets in Git.",
"created_by": "chatgpt-gitops-bot",
"created_at": "2026-07-08T01:55:30Z"
}
-24
View File
@@ -1,24 +0,0 @@
from active_runtime.app.portal_rbac_ops import PortalContext, PortalRBACService, PortalAuditService, SecretPolicy
def test_user_scope():
ctx = PortalContext('u1', 'g1', 'user')
assert PortalRBACService().authorize(ctx, 'self')
def test_owner_scope():
ctx = PortalContext('o1', None, 'owner')
assert PortalRBACService().authorize(ctx, 'global')
def test_navigation():
assert '/owner/system' in PortalRBACService().navigation('owner')
def test_audit_append():
event = PortalAuditService().append('login', 'u1')
assert event.action == 'login'
def test_secret_redaction():
assert SecretPolicy.redact('secret') == '***REDACTED***'