diff --git a/apps/api/prisma/migrations/20261126120000_survey_visible_to_all_admins/migration.sql b/apps/api/prisma/migrations/20261126120000_survey_visible_to_all_admins/migration.sql new file mode 100644 index 00000000..17cc4ca3 --- /dev/null +++ b/apps/api/prisma/migrations/20261126120000_survey_visible_to_all_admins/migration.sql @@ -0,0 +1,19 @@ +-- Product design survey visible to EVERY admin user, whatever their user type. +-- +-- Before this, the survey screen (nav item, route guard, in-view check and the +-- API's @RequirePermission('product.survey')) only appeared for admins whose +-- user type had been granted `product.survey` — in practice the super admin. +-- +-- Granting both rids to every existing user type fixes that: +-- `product` - the «محصولات» menu group itself (children are still +-- gated by their own rids, so nothing else new appears) +-- `product.survey` - the «نظرسنجی طرح» item and its API endpoints +-- +-- Idempotent: re-running adds nothing. User types created later are granted +-- through the normal permission screen, and the seed does the same for fresh +-- databases. +INSERT INTO "permission" ("rid", "userTypeId") +SELECT r.rid, ut.id +FROM (VALUES ('product'), ('product.survey')) AS r(rid) +CROSS JOIN "user_type" AS ut +ON CONFLICT ("rid", "userTypeId") DO NOTHING; diff --git a/apps/api/prisma/seed.ts b/apps/api/prisma/seed.ts index b0bb1385..7a66d092 100644 --- a/apps/api/prisma/seed.ts +++ b/apps/api/prisma/seed.ts @@ -88,6 +88,17 @@ async function seedAccessControl() { skipDuplicates: true, }); } + + // The design survey is for every admin, not only the super admin — see the + // 20261126120000_survey_visible_to_all_admins migration. `product` opens the + // «محصولات» menu group; its other children stay gated by their own rids. + const allTypes = await prisma.userType.findMany({ select: { id: true } }); + await prisma.permission.createMany({ + data: allTypes.flatMap((ut) => + ['product', 'product.survey'].map((rid) => ({ rid, userTypeId: ut.id })), + ), + skipDuplicates: true, + }); } /**