半中间的 rule
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// 管理员权限检查函数
function isAdmin() {
return request.auth != null && request.auth.token.admin == true;
}
// 验证用户是否已认证
function isAuthenticated() {
return request.auth != null;
}
// 验证是否是自动通过白名单地址
function isAutoApprover(address) {
let settings = get(/databases/$(database)/documents/admin_settings/auto_approval).data;
return settings != null &&
settings.enabled == true &&
settings.approverAddresses.hasAny([address]);
}
// 用户集合规则
match /users/{userId} {
allow read, write: if true; // 保持原有的开放访问权限
}
// 访问日志集合规则
match /access_logs/{logId} {
allow read, create: if true; // 保持原有的访问权限
allow update, delete: if false; // 禁止修改和删除日志
}
// 申请集合规则
match /applications/{applicationId} {
allow read: if true; // 保持原有的读取权限
allow create: if true; // 允许创建新申请
allow update: if true || isAutoApprover(request.resource.data.submitter_address); // 允许更新,包括自动通过
allow delete: if false; // 禁止删除申请记录
}
// 管理员日志集合规则
match /admin_logs/{logId} {
allow read: if true; // 保持原有的读取权限
allow create: if true; // 允许创建日志
allow update, delete: if false; // 禁止修改和删除日志
}
// 申请历史记录集合规则
match /application_history/{historyId} {
allow read: if true; // 允许读取历史记录
allow create: if true; // 允许创建历史记录
allow update: if true; // 允许更新历史记录(例如标记归档)
allow delete: if false; // 禁止删除历史记录
}
// 自动通过设置集合规则
match /admin_settings/auto_approval {
allow read: if true; // 允许读取自动通过设置
allow write: if true; // 允许更新自动通过设置
}
// 自动通过白名单集合规则
match /auto_approval_whitelist/{address} {
allow read: if true; // 允许读取白名单
allow write: if true; // 允许更新白名单
}
}
}