Merge pull request #1065 from trheyi/main

Add user_oauth_account, user_type, user_role
This commit is contained in:
Max 2025-08-02 10:54:52 +08:00 committed by GitHub
commit 4701f07c34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 854 additions and 138 deletions

File diff suppressed because one or more lines are too long

View file

@ -20,15 +20,18 @@ import (
// SystemModels system models
var systemModels = map[string]string{
"__yao.assistant": "yao/models/assistant.mod.yao",
"__yao.attachment": "yao/models/attachment.mod.yao",
"__yao.audit": "yao/models/audit.mod.yao",
"__yao.chat": "yao/models/chat.mod.yao",
"__yao.config": "yao/models/config.mod.yao",
"__yao.dsl": "yao/models/dsl.mod.yao",
"__yao.history": "yao/models/history.mod.yao",
"__yao.kb": "yao/models/kb.mod.yao",
"__yao.user": "yao/models/user.mod.yao",
"__yao.assistant": "yao/models/assistant.mod.yao",
"__yao.attachment": "yao/models/attachment.mod.yao",
"__yao.audit": "yao/models/audit.mod.yao",
"__yao.chat": "yao/models/chat.mod.yao",
"__yao.config": "yao/models/config.mod.yao",
"__yao.dsl": "yao/models/dsl.mod.yao",
"__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",
}
// Load load models

View file

@ -36,15 +36,18 @@ var testServer *http.Server = nil
// SystemModels system models for testing
var testSystemModels = map[string]string{
"__yao.assistant": "yao/models/assistant.mod.yao",
"__yao.attachment": "yao/models/attachment.mod.yao",
"__yao.audit": "yao/models/audit.mod.yao",
"__yao.chat": "yao/models/chat.mod.yao",
"__yao.config": "yao/models/config.mod.yao",
"__yao.dsl": "yao/models/dsl.mod.yao",
"__yao.history": "yao/models/history.mod.yao",
"__yao.kb": "yao/models/kb.mod.yao",
"__yao.user": "yao/models/user.mod.yao",
"__yao.assistant": "yao/models/assistant.mod.yao",
"__yao.attachment": "yao/models/attachment.mod.yao",
"__yao.audit": "yao/models/audit.mod.yao",
"__yao.chat": "yao/models/chat.mod.yao",
"__yao.config": "yao/models/config.mod.yao",
"__yao.dsl": "yao/models/dsl.mod.yao",
"__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",
}
var testSystemStores = map[string]string{

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,255 @@
{
"name": "User OAuth Account",
"label": "User OAuth Account",
"description": "User's third-party OAuth account information storage",
"tags": ["user", "oauth", "social", "external", "provider"],
"table": {
"name": "user_oauth_account",
"comment": "User's third-party OAuth account information storage"
},
"columns": [
// ============================================================================
// Basic Fields
// ============================================================================
{
"name": "id",
"type": "ID",
"label": "ID",
"comment": "Primary key identifier",
"primary": true
},
{
"name": "user_id",
"type": "string",
"label": "User ID",
"comment": "Reference to main user account",
"length": 255,
"nullable": false,
"index": true
},
{
"name": "provider",
"type": "string",
"label": "Provider",
"comment": "OAuth provider name (google, apple, github, etc.)",
"length": 50,
"nullable": false,
"index": true
},
// ============================================================================
// OIDC Standard Claims from Provider
// Reference: https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
// ============================================================================
{
"name": "sub",
"type": "string",
"label": "Subject",
"comment": "OIDC subject identifier (sub claim) from provider",
"length": 255,
"nullable": false,
"index": true
},
{
"name": "preferred_username",
"type": "string",
"label": "Preferred Username",
"comment": "OIDC preferred username from provider",
"length": 100,
"nullable": true
},
{
"name": "email",
"type": "string",
"label": "Email",
"comment": "OIDC email address from provider",
"length": 255,
"nullable": true,
"index": true
},
{
"name": "email_verified",
"type": "boolean",
"label": "Email Verified",
"comment": "OIDC email verification status from provider",
"default": false,
"nullable": true
},
{
"name": "name",
"type": "string",
"label": "Full Name",
"comment": "OIDC full name from provider",
"length": 200,
"nullable": true
},
{
"name": "given_name",
"type": "string",
"label": "Given Name",
"comment": "OIDC given name(s) or first name(s) from provider",
"length": 100,
"nullable": true
},
{
"name": "family_name",
"type": "string",
"label": "Family Name",
"comment": "OIDC surname(s) or last name(s) from provider",
"length": 100,
"nullable": true
},
{
"name": "middle_name",
"type": "string",
"label": "Middle Name",
"comment": "OIDC middle name(s) from provider",
"length": 100,
"nullable": true
},
{
"name": "nickname",
"type": "string",
"label": "Nickname",
"comment": "OIDC casual name from provider",
"length": 100,
"nullable": true
},
{
"name": "profile",
"type": "string",
"label": "Profile",
"comment": "OIDC profile page URL from provider",
"length": 500,
"nullable": true
},
{
"name": "picture",
"type": "string",
"label": "Picture",
"comment": "OIDC profile picture URL from provider",
"length": 500,
"nullable": true
},
{
"name": "website",
"type": "string",
"label": "Website",
"comment": "OIDC web page or blog URL from provider",
"length": 500,
"nullable": true
},
{
"name": "gender",
"type": "string",
"label": "Gender",
"comment": "OIDC gender from provider",
"length": 20,
"nullable": true
},
{
"name": "birthdate",
"type": "string",
"label": "Birthdate",
"comment": "OIDC birthday from provider (YYYY-MM-DD format)",
"length": 10,
"nullable": true
},
{
"name": "zoneinfo",
"type": "string",
"label": "Zone Info",
"comment": "OIDC time zone info from provider",
"length": 50,
"nullable": true
},
{
"name": "locale",
"type": "string",
"label": "Locale",
"comment": "OIDC locale from provider (language-country)",
"length": 20,
"nullable": true
},
{
"name": "phone_number",
"type": "string",
"label": "Phone Number",
"comment": "OIDC phone number from provider",
"length": 50,
"nullable": true
},
{
"name": "phone_number_verified",
"type": "boolean",
"label": "Phone Number Verified",
"comment": "OIDC phone verification status from provider",
"default": false,
"nullable": true
},
{
"name": "address",
"type": "json",
"label": "Address",
"comment": "OIDC physical mailing address from provider (structured)",
"nullable": true
},
{
"name": "raw",
"type": "json",
"label": "Raw",
"comment": "OIDC original user info response from provider",
"nullable": true
},
// ============================================================================
// Account Management Fields
// ============================================================================
{
"name": "last_login_at",
"type": "timestamp",
"label": "Last Login At",
"comment": "Last login via this OAuth provider",
"nullable": true,
"index": true
},
{
"name": "is_active",
"type": "boolean",
"label": "Is Active",
"comment": "Whether this OAuth account is still active",
"default": true,
"index": true
}
],
"indexes": [
{
"name": "idx_user_oauth_user_provider",
"columns": ["user_id", "provider"],
"type": "unique",
"comment": "Unique constraint: one account per provider per user"
},
{
"name": "idx_user_oauth_provider_sub",
"columns": ["provider", "sub"],
"type": "unique",
"comment": "Unique constraint: one record per provider sub claim"
},
{
"name": "idx_user_oauth_email",
"columns": ["provider", "email"],
"type": "index",
"comment": "Index for email lookups by provider"
},
{
"name": "idx_user_oauth_active",
"columns": ["is_active", "last_login_at"],
"type": "index",
"comment": "Index for active account queries"
}
],
"relations": {},
"values": [],
"option": { "timestamps": true, "soft_deletes": 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 }
}