-- Slice 7C · Notifications perms — every role gets their own inbox
INSERT INTO user_groups_perms (user_group_id, controller_allowed, action_allowed, created_by, created_on)
SELECT g.c0d, 'Notifications', a.act, 0, NOW()
FROM (
    SELECT 'index'          AS act UNION ALL
    SELECT 'unreadCountAj'         UNION ALL
    SELECT 'recentAj'              UNION ALL
    SELECT 'markReadAj'            UNION ALL
    SELECT 'markAllReadAj'
) a
CROSS JOIN user_groups g
WHERE g.user_group_name IN (
    'Executive','Finance Manager','Accountant','Project Manager','Projects Coordinator',
    'Field Supervisor','Procurement','Administrator','CRM','Stores'
)
  AND NOT EXISTS (
    SELECT 1 FROM user_groups_perms p
     WHERE p.user_group_id = g.c0d
       AND p.controller_allowed = 'Notifications'
       AND p.action_allowed = a.act
  );
