Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

Fix policy for storage.objects to include users/groups from document.readGroups (#46)

Brad Barbin58be7aa44010
diff --git a/apps/carbon/app/hooks/usePermissions.tsx b/apps/carbon/app/hooks/usePermissions.tsx
index 09514f16ed..046c9eb85d 100644
--- a/apps/carbon/app/hooks/usePermissions.tsx
+++ b/apps/carbon/app/hooks/usePermissions.tsx
@@ -17,8 +17,6 @@ export function usePermissions() {
);
}
- console.log(data?.permissions);
-
const can = useCallback(
(action: "view" | "create" | "update" | "delete", feature: string) => {
return data?.permissions[feature]?.[action] ?? false;
diff --git a/apps/carbon/app/root.tsx b/apps/carbon/app/root.tsx
index 5cb8de0688..64de0efd23 100644
--- a/apps/carbon/app/root.tsx
+++ b/apps/carbon/app/root.tsx
@@ -5,13 +5,13 @@ import { SkipNavLink } from "@chakra-ui/skip-nav";
import type { MetaFunction } from "@remix-run/node";
import { json } from "@remix-run/node";
import {
- isRouteErrorResponse,
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
+ isRouteErrorResponse,
useLoaderData,
useRouteError,
} from "@remix-run/react";
diff --git a/packages/database/SCHEMA.md b/packages/database/SCHEMA.md
index b7bb3d8a0d..546d55c3e3 100644
--- a/packages/database/SCHEMA.md
+++ b/packages/database/SCHEMA.md
@@ -4026,8 +4026,8 @@ FOR SELECT USING (
AND coalesce(get_my_claim('documents_view')::boolean, false) = true
AND (
(storage.foldername(name))[1] = auth.uid()::text
- OR storage.filename(name) IN (
- SELECT "path" FROM public.document WHERE "readGroups" && groups_for_user(auth.uid()::text)
+ OR "name" IN (
+ SELECT "path" FROM public.document WHERE (groups_for_user(auth.uid()::text) && "readGroups") = true
)
)
);
@@ -4039,8 +4039,8 @@ FOR INSERT WITH CHECK (
AND coalesce(get_my_claim('documents_create')::boolean, false) = true
AND (
(storage.foldername(name))[1] = auth.uid()::text
- OR storage.filename(name) IN (
- SELECT "path" FROM public.document WHERE "writeGroups" && groups_for_user(auth.uid()::text)
+ OR "name" IN (
+ SELECT "path" FROM public.document WHERE (groups_for_user(auth.uid()::text) && "writeGroups") = true
)
)
);
@@ -4052,8 +4052,8 @@ FOR UPDATE USING (
AND coalesce(get_my_claim('documents_update')::boolean, false) = true
AND (
(storage.foldername(name))[1] = auth.uid()::text
- OR storage.filename(name) IN (
- SELECT "path" FROM public.document WHERE "readGroups" && groups_for_user(auth.uid()::text)
+ OR "name" IN (
+ SELECT "path" FROM public.document WHERE (groups_for_user(auth.uid()::text) && "writeGroups") = true
)
)
);
@@ -4065,8 +4065,8 @@ FOR DELETE USING (
AND coalesce(get_my_claim('documents_delete')::boolean, false) = true
AND (
(storage.foldername(name))[1] = auth.uid()::text
- OR storage.filename(name) IN (
- SELECT "path" FROM public.document WHERE "readGroups" && groups_for_user(auth.uid()::text)
+ OR "name" IN (
+ SELECT "path" FROM public.document WHERE (groups_for_user(auth.uid()::text) && "writeGroups") = true
)
)
);
diff --git a/packages/database/supabase/migrations/20230423023136_documents.sql b/packages/database/supabase/migrations/20230423023136_documents.sql
index 8b3821d665..08ea1656f9 100644
--- a/packages/database/supabase/migrations/20230423023136_documents.sql
+++ b/packages/database/supabase/migrations/20230423023136_documents.sql
@@ -54,8 +54,8 @@ FOR SELECT USING (
AND coalesce(get_my_claim('documents_view')::boolean, false) = true
AND (
(storage.foldername(name))[1] = auth.uid()::text
- OR storage.filename(name) IN (
- SELECT "path" FROM public.document WHERE "readGroups" && groups_for_user(auth.uid()::text)
+ OR "name" IN (
+ SELECT "path" FROM public.document WHERE (groups_for_user(auth.uid()::text) && "readGroups") = true
)
)
);
@@ -67,8 +67,8 @@ FOR INSERT WITH CHECK (
AND coalesce(get_my_claim('documents_create')::boolean, false) = true
AND (
(storage.foldername(name))[1] = auth.uid()::text
- OR storage.filename(name) IN (
- SELECT "path" FROM public.document WHERE "writeGroups" && groups_for_user(auth.uid()::text)
+ OR "name" IN (
+ SELECT "path" FROM public.document WHERE (groups_for_user(auth.uid()::text) && "writeGroups") = true
)
)
);
@@ -80,8 +80,8 @@ FOR UPDATE USING (
AND coalesce(get_my_claim('documents_update')::boolean, false) = true
AND (
(storage.foldername(name))[1] = auth.uid()::text
- OR storage.filename(name) IN (
- SELECT "path" FROM public.document WHERE "readGroups" && groups_for_user(auth.uid()::text)
+ OR "name" IN (
+ SELECT "path" FROM public.document WHERE (groups_for_user(auth.uid()::text) && "writeGroups") = true
)
)
);
@@ -93,8 +93,8 @@ FOR DELETE USING (
AND coalesce(get_my_claim('documents_delete')::boolean, false) = true
AND (
(storage.foldername(name))[1] = auth.uid()::text
- OR storage.filename(name) IN (
- SELECT "path" FROM public.document WHERE "readGroups" && groups_for_user(auth.uid()::text)
+ OR "name" IN (
+ SELECT "path" FROM public.document WHERE (groups_for_user(auth.uid()::text) && "writeGroups") = true
)
)
);
diff --git a/packages/react/src/Theme/ThemeProvider.tsx b/packages/react/src/Theme/ThemeProvider.tsx
index b7af8a7e8e..6e3164a934 100644
--- a/packages/react/src/Theme/ThemeProvider.tsx
+++ b/packages/react/src/Theme/ThemeProvider.tsx
@@ -1,6 +1,6 @@
-import { useMemo } from "react";
-import type { ReactNode } from "react";
import { ChakraProvider, extendTheme } from "@chakra-ui/react";
+import type { ReactNode } from "react";
+import { useMemo } from "react";
import { theme as carbonTheme } from "./theme";
export enum Mode {