|
|
@@ -19,6 +19,32 @@ function shouldAutoAccept(perm: PermissionRequest) {
|
|
|
return perm.permission === "edit"
|
|
|
}
|
|
|
|
|
|
+function isNonAllowRule(rule: unknown) {
|
|
|
+ if (!rule) return false
|
|
|
+ if (typeof rule === "string") return rule !== "allow"
|
|
|
+ if (typeof rule !== "object") return false
|
|
|
+ if (Array.isArray(rule)) return false
|
|
|
+
|
|
|
+ for (const action of Object.values(rule)) {
|
|
|
+ if (action !== "allow") return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+function hasAutoAcceptPermissionConfig(permission: unknown) {
|
|
|
+ if (!permission) return false
|
|
|
+ if (typeof permission === "string") return permission !== "allow"
|
|
|
+ if (typeof permission !== "object") return false
|
|
|
+ if (Array.isArray(permission)) return false
|
|
|
+
|
|
|
+ const config = permission as Record<string, unknown>
|
|
|
+ if (isNonAllowRule(config.edit)) return true
|
|
|
+ if (isNonAllowRule(config.write)) return true
|
|
|
+
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
export const { use: usePermission, provider: PermissionProvider } = createSimpleContext({
|
|
|
name: "Permission",
|
|
|
init: () => {
|
|
|
@@ -27,9 +53,10 @@ export const { use: usePermission, provider: PermissionProvider } = createSimple
|
|
|
const globalSync = useGlobalSync()
|
|
|
|
|
|
const permissionsEnabled = createMemo(() => {
|
|
|
- if (!params.dir || !base64Decode(params.dir)) return false
|
|
|
- const [store] = globalSync.child(base64Decode(params.dir))
|
|
|
- return store.config.permission !== undefined
|
|
|
+ const directory = params.dir ? base64Decode(params.dir) : undefined
|
|
|
+ if (!directory) return false
|
|
|
+ const [store] = globalSync.child(directory)
|
|
|
+ return hasAutoAcceptPermissionConfig(store.config.permission)
|
|
|
})
|
|
|
|
|
|
const [store, setStore, _, ready] = persisted(
|