| 37779 |
amit |
1 |
-- Migration: Demo partner access (2026-09-25)
|
|
|
2 |
--
|
|
|
3 |
-- Lets an admin tag any partner to a Sales person purely so they can open that partner's
|
|
|
4 |
-- dashboard / Franchise App for a demo. The binding lives ONLY in cs.demo_partner_access and is
|
|
|
5 |
-- read ONLY at the partner-view entry points (fofo Partner access dropdown, login-as-partner-readonly,
|
|
|
6 |
-- /mobileapp token; web /getPartners, /getPartnersList, /impersonate). The position mappings
|
|
|
7 |
-- (cs.position / cs.partner_position and CsService.getAuthUser*Mapping) are NOT touched, so no
|
|
|
8 |
-- performance, target, report or cron figure changes.
|
|
|
9 |
--
|
|
|
10 |
-- A grant is active while revoked_at IS NULL. Revoke stamps revoked_at/revoked_by (history kept);
|
|
|
11 |
-- re-granting after a revoke inserts a new row.
|
|
|
12 |
|
|
|
13 |
CREATE TABLE IF NOT EXISTS cs.demo_partner_access (
|
|
|
14 |
id INT NOT NULL AUTO_INCREMENT,
|
|
|
15 |
auth_user_id INT NOT NULL,
|
|
|
16 |
fofo_id INT NOT NULL,
|
|
|
17 |
created_by INT NOT NULL,
|
|
|
18 |
created_at DATETIME NOT NULL,
|
|
|
19 |
revoked_by INT NULL,
|
|
|
20 |
revoked_at DATETIME NULL,
|
|
|
21 |
PRIMARY KEY (id),
|
|
|
22 |
KEY idx_demo_partner_access_auth_user (auth_user_id, revoked_at),
|
|
|
23 |
KEY idx_demo_partner_access_fofo (fofo_id)
|
|
|
24 |
) ENGINE = InnoDB DEFAULT CHARSET = utf8;
|
|
|
25 |
|
|
|
26 |
-- Menu "Demo Partner Access" under Admin Control (id=176), next to "Partner access" (92).
|
|
|
27 |
-- Deliberately NOT copied from menu 92: that one is visible to Sales, who must not grant to themselves.
|
|
|
28 |
INSERT INTO auth.menu (display_text, description, parent_menu_id, sequence, action_class, icon_class)
|
|
|
29 |
SELECT 'Demo Partner Access',
|
|
|
30 |
'Grant / revoke demo dashboard access to partners for Sales team',
|
|
|
31 |
176,
|
|
|
32 |
COALESCE((SELECT MAX(sequence) FROM auth.menu WHERE parent_menu_id = 176), 0) + 1,
|
|
|
33 |
'demo-partner-access',
|
|
|
34 |
NULL
|
|
|
35 |
WHERE NOT EXISTS (SELECT 1 FROM auth.menu WHERE action_class = 'demo-partner-access');
|
|
|
36 |
|
|
|
37 |
-- Who sees it (same rule as the sidebar, AdminUser.adminPanel, and the server guard DemoPartnerAccessService.canManage):
|
|
|
38 |
-- AdminUser.ALL_MENU_EMAILS and every L5 position holder see all menus anyway; beyond them, the
|
|
|
39 |
-- menu_category rows below. escalation_type here is the EscalationType ORDINAL ('3' = L4), the same
|
|
|
40 |
-- Business Intelligence mapping 70 other menus use. Add rows to widen who can manage grants.
|
|
|
41 |
INSERT INTO auth.menu_category (menu_id, category_id, escalation_type)
|
|
|
42 |
SELECT m.id, 19, '3'
|
|
|
43 |
FROM auth.menu m
|
|
|
44 |
WHERE m.action_class = 'demo-partner-access'
|
|
|
45 |
AND NOT EXISTS (SELECT 1 FROM auth.menu_category mc WHERE mc.menu_id = m.id AND mc.category_id = 19 AND mc.escalation_type = '3');
|
|
|
46 |
|
|
|
47 |
-- Verify
|
|
|
48 |
-- SELECT * FROM auth.menu WHERE action_class = 'demo-partner-access';
|
|
|
49 |
-- SELECT mc.* FROM auth.menu_category mc JOIN auth.menu m ON m.id = mc.menu_id WHERE m.action_class = 'demo-partner-access';
|
|
|
50 |
|
|
|
51 |
-- Rollback
|
|
|
52 |
-- DELETE mc FROM auth.menu_category mc JOIN auth.menu m ON m.id = mc.menu_id WHERE m.action_class = 'demo-partner-access';
|
|
|
53 |
-- DELETE FROM auth.menu WHERE action_class = 'demo-partner-access';
|
|
|
54 |
-- DROP TABLE cs.demo_partner_access;
|