Add user role and type models, update user model fields

- Introduced user_role and user_type models to enhance user management capabilities.
- Updated user model fields to reference role and type identifiers, improving clarity and compliance with relational standards.
- Adjusted asset metadata timestamps and system/test model mappings to include new models, ensuring consistency across the application.
This commit is contained in:
Max 2025-08-02 10:53:59 +08:00
parent ea4a492974
commit 6b53086e53
6 changed files with 549 additions and 113 deletions

File diff suppressed because one or more lines are too long

View file

@ -29,6 +29,8 @@ var systemModels = map[string]string{
"__yao.history": "yao/models/history.mod.yao",
"__yao.kb": "yao/models/kb.mod.yao",
"__yao.user": "yao/models/user.mod.yao",
"__yao.user_role": "yao/models/user_role.mod.yao",
"__yao.user_type": "yao/models/user_type.mod.yao",
"__yao.user_oauth_account": "yao/models/user_oauth_account.mod.yao",
}

View file

@ -45,6 +45,8 @@ var testSystemModels = map[string]string{
"__yao.history": "yao/models/history.mod.yao",
"__yao.kb": "yao/models/kb.mod.yao",
"__yao.user": "yao/models/user.mod.yao",
"__yao.user_role": "yao/models/user_role.mod.yao",
"__yao.user_type": "yao/models/user_type.mod.yao",
"__yao.user_oauth_account": "yao/models/user_oauth_account.mod.yao",
}

View file

@ -239,20 +239,20 @@
"nullable": false
},
{
"name": "role",
"name": "role_id",
"type": "string",
"label": "Role",
"comment": "User role for authorization",
"length": 100,
"label": "Role ID",
"comment": "User role identifier (references user_role.role_id)",
"length": 50,
"nullable": true,
"index": true
},
{
"name": "type",
"name": "type_id",
"type": "string",
"label": "Type",
"comment": "User type classification",
"length": 100,
"label": "Type ID",
"comment": "User type identifier (references user_type.type_id)",
"length": 50,
"nullable": true,
"index": true
},

View file

@ -0,0 +1,217 @@
{
"name": "User Role",
"label": "User Role",
"description": "User role and permission management",
"tags": ["user", "role", "permission", "auth"],
"table": {
"name": "user_role",
"comment": "User role and permission management"
},
"columns": [
// ============================================================================
// Basic Fields
// ============================================================================
{
"name": "id",
"type": "ID",
"label": "ID",
"comment": "Primary key identifier",
"primary": true
},
{
"name": "role_id",
"type": "string",
"label": "Role ID",
"comment": "Unique role identifier (admin, user, moderator, etc.)",
"length": 50,
"unique": true,
"index": true,
"nullable": false
},
{
"name": "name",
"type": "string",
"label": "Name",
"comment": "Display name of the role",
"length": 100,
"nullable": false
},
{
"name": "description",
"type": "text",
"label": "Description",
"comment": "Detailed description of the role and its purpose",
"nullable": true
},
// ============================================================================
// Permission Fields
// ============================================================================
{
"name": "permissions",
"type": "json",
"label": "Permissions",
"comment": "JSON object containing all permissions and access rights",
"nullable": true
},
{
"name": "restricted_permissions",
"type": "json",
"label": "Restricted Permissions",
"comment": "JSON array of explicitly denied permissions",
"nullable": true
},
// ============================================================================
// Hierarchy Fields
// ============================================================================
{
"name": "parent_role_id",
"type": "string",
"label": "Parent Role ID",
"comment": "Parent role for inheritance (optional)",
"length": 50,
"nullable": true,
"index": true
},
{
"name": "level",
"type": "integer",
"label": "Level",
"comment": "Role hierarchy level (higher = more permissions)",
"default": 0,
"nullable": true,
"index": true
},
// ============================================================================
// Management Fields
// ============================================================================
{
"name": "is_active",
"type": "boolean",
"label": "Is Active",
"comment": "Whether this role is currently active",
"default": true,
"index": true
},
{
"name": "is_default",
"type": "boolean",
"label": "Is Default",
"comment": "Whether this is the default role for new users",
"default": false,
"index": true
},
{
"name": "is_system",
"type": "boolean",
"label": "Is System",
"comment": "Whether this is a system role (cannot be deleted)",
"default": false,
"index": true
},
{
"name": "sort_order",
"type": "integer",
"label": "Sort Order",
"comment": "Display order for sorting",
"default": 0,
"nullable": true
},
// ============================================================================
// Display Fields
// ============================================================================
{
"name": "color",
"type": "string",
"label": "Color",
"comment": "Color code for UI display (hex format)",
"length": 7,
"nullable": true
},
{
"name": "icon",
"type": "string",
"label": "Icon",
"comment": "Icon identifier for UI display",
"length": 50,
"nullable": true
},
// ============================================================================
// Access Control Fields
// ============================================================================
{
"name": "max_users",
"type": "integer",
"label": "Max Users",
"comment": "Maximum number of users that can have this role (0 = unlimited)",
"default": 0,
"nullable": true
},
{
"name": "requires_approval",
"type": "boolean",
"label": "Requires Approval",
"comment": "Whether assigning this role requires admin approval",
"default": false
},
{
"name": "auto_revoke_days",
"type": "integer",
"label": "Auto Revoke Days",
"comment": "Days after which this role is automatically revoked (0 = never)",
"default": 0,
"nullable": true
},
// ============================================================================
// Extended Configuration
// ============================================================================
{
"name": "metadata",
"type": "json",
"label": "Metadata",
"comment": "Additional role configuration and settings",
"nullable": true
},
{
"name": "conditions",
"type": "json",
"label": "Conditions",
"comment": "Conditions that must be met to assign/maintain this role",
"nullable": true
}
],
"indexes": [
{
"name": "idx_user_role_active",
"columns": ["is_active", "sort_order"],
"type": "index",
"comment": "Index for active roles with ordering"
},
{
"name": "idx_user_role_hierarchy",
"columns": ["parent_role_id", "level"],
"type": "index",
"comment": "Index for role hierarchy queries"
},
{
"name": "idx_user_role_system",
"columns": ["is_system", "is_active"],
"type": "index",
"comment": "Index for system role queries"
},
{
"name": "idx_user_role_default",
"columns": ["is_default", "is_active"],
"type": "index",
"comment": "Index for finding default active role"
}
],
"relations": {},
"values": [],
"option": { "timestamps": true, "soft_deletes": true }
}

View file

@ -0,0 +1,169 @@
{
"name": "User Type",
"label": "User Type",
"description": "User type classification and configuration",
"tags": ["user", "type", "classification", "config"],
"table": {
"name": "user_type",
"comment": "User type classification and configuration"
},
"columns": [
// ============================================================================
// Basic Fields
// ============================================================================
{
"name": "id",
"type": "ID",
"label": "ID",
"comment": "Primary key identifier",
"primary": true
},
{
"name": "type_id",
"type": "string",
"label": "Type ID",
"comment": "Unique type identifier (admin, customer, guest, etc.)",
"length": 50,
"unique": true,
"index": true,
"nullable": false
},
{
"name": "name",
"type": "string",
"label": "Name",
"comment": "Display name of the user type",
"length": 100,
"nullable": false
},
{
"name": "description",
"type": "text",
"label": "Description",
"comment": "Detailed description of the user type",
"nullable": true
},
// ============================================================================
// Configuration Fields
// ============================================================================
{
"name": "default_role_id",
"type": "string",
"label": "Default Role ID",
"comment": "Default role assigned to users of this type",
"length": 50,
"nullable": true,
"index": true
},
{
"name": "schema",
"type": "json",
"label": "Schema",
"comment": "JSON schema defining metadata structure and UI configuration",
"nullable": true
},
{
"name": "metadata",
"type": "json",
"label": "Metadata",
"comment": "Additional configuration and settings for this user type",
"nullable": true
},
// ============================================================================
// Management Fields
// ============================================================================
{
"name": "is_active",
"type": "boolean",
"label": "Is Active",
"comment": "Whether this user type is currently active",
"default": true,
"index": true
},
{
"name": "is_default",
"type": "boolean",
"label": "Is Default",
"comment": "Whether this is the default user type for new registrations",
"default": false,
"index": true
},
{
"name": "sort_order",
"type": "integer",
"label": "Sort Order",
"comment": "Display order for sorting",
"default": 0,
"nullable": true
},
// ============================================================================
// Access Control Fields
// ============================================================================
{
"name": "max_sessions",
"type": "integer",
"label": "Max Sessions",
"comment": "Maximum concurrent sessions allowed for this user type",
"nullable": true
},
{
"name": "session_timeout",
"type": "integer",
"label": "Session Timeout",
"comment": "Session timeout in minutes (0 = no timeout)",
"default": 0,
"nullable": true
},
{
"name": "password_policy",
"type": "json",
"label": "Password Policy",
"comment": "Password requirements and policies for this user type",
"nullable": true
},
// ============================================================================
// Feature Flags
// ============================================================================
{
"name": "features",
"type": "json",
"label": "Features",
"comment": "Feature flags and capabilities available to this user type",
"nullable": true
},
{
"name": "limits",
"type": "json",
"label": "Limits",
"comment": "Usage limits and quotas for this user type",
"nullable": true
}
],
"indexes": [
{
"name": "idx_user_type_active",
"columns": ["is_active", "sort_order"],
"type": "index",
"comment": "Index for active user types with ordering"
},
{
"name": "idx_user_type_default",
"columns": ["is_default", "is_active"],
"type": "index",
"comment": "Index for finding default active user type"
},
{
"name": "idx_user_type_role",
"columns": ["default_role_id"],
"type": "index",
"comment": "Index for role relationships"
}
],
"relations": {},
"values": [],
"option": { "timestamps": true, "soft_deletes": true }
}