升级 AppStore 缓存 Key 并在覆盖安装时强制重新登录。
统一账号作用域 Key 对齐 Android,新增缓存 schema 迁移清理旧数据,并同步更新相关模块与单元测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -26,8 +26,14 @@ final class AppPermissionStore {
|
||||
|
||||
/// 旧版 role_id,用于权限匹配兜底。
|
||||
var legacyRoleId: Int {
|
||||
get { defaults.integer(forKey: scopedKey(.legacyRoleId)) }
|
||||
set { defaults.set(newValue, forKey: scopedKey(.legacyRoleId)) }
|
||||
get {
|
||||
guard let key = scopedKey(.legacyRoleId) else { return 0 }
|
||||
return defaults.integer(forKey: key)
|
||||
}
|
||||
set {
|
||||
guard let key = scopedKey(.legacyRoleId) else { return }
|
||||
defaults.set(newValue, forKey: key)
|
||||
}
|
||||
}
|
||||
|
||||
/// 保存完整 role-permission 列表。
|
||||
@ -71,21 +77,24 @@ final class AppPermissionStore {
|
||||
}
|
||||
|
||||
/// 清除当前账号的全部权限缓存。
|
||||
func clear() {
|
||||
Key.allCases.forEach { defaults.removeObject(forKey: scopedKey($0)) }
|
||||
func clear(accountScope: String) {
|
||||
guard !accountScope.isEmpty else { return }
|
||||
Key.allCases.forEach { defaults.removeObject(forKey: "\(accountScope)_\($0.rawValue)") }
|
||||
}
|
||||
|
||||
private func save<Value: Encodable>(_ value: Value, for key: Key) {
|
||||
guard let data = try? JSONEncoder().encode(value) else { return }
|
||||
defaults.set(data, forKey: scopedKey(key))
|
||||
guard let scopedKey = scopedKey(key),
|
||||
let data = try? JSONEncoder().encode(value) else { return }
|
||||
defaults.set(data, forKey: scopedKey)
|
||||
}
|
||||
|
||||
private func load<Value: Decodable>(_ type: Value.Type, for key: Key) -> Value? {
|
||||
guard let data = defaults.data(forKey: scopedKey(key)) else { return nil }
|
||||
guard let scopedKey = scopedKey(key),
|
||||
let data = defaults.data(forKey: scopedKey) else { return nil }
|
||||
return try? JSONDecoder().decode(type, from: data)
|
||||
}
|
||||
|
||||
private func scopedKey(_ key: Key) -> String {
|
||||
"\(session.accountCachePrefix)_\(key.rawValue)"
|
||||
private func scopedKey(_ key: Key) -> String? {
|
||||
session.accountScopedKey(key.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user