From 5593cef462f2fb894ccde1264c613e779654de52 Mon Sep 17 00:00:00 2001 From: mahmood Date: Thu, 26 Nov 2026 13:31:00 +0330 Subject: [PATCH] feat(survey): show the design survey to every admin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The survey screen, its nav item, route guard and API were gated on the product.survey rid, which only the super admin held in practice. Grant 'product' and 'product.survey' to every user type (migration for existing databases, seed for fresh ones). 'product' only opens the products menu group — its other children keep their own rids — so nothing else new becomes visible. Co-Authored-By: Claude Sonnet 5.5 --- .../migration.sql | 19 +++++++++++++++++++ apps/api/prisma/seed.ts | 11 +++++++++++ 2 files changed, 30 insertions(+) create mode 100644 apps/api/prisma/migrations/20261126120000_survey_visible_to_all_admins/migration.sql 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, + }); } /**