32 lines
2.2 KiB
Python
32 lines
2.2 KiB
Python
|
|
"""Add only barcode navigation and administrator permissions; preserve existing menus and roles."""
|
||
|
|
def ensure_barcode_navigation(cursor):
|
||
|
|
menus = [
|
||
|
|
(20140, '扫码识别', 'lab:barcode:query', 2, 4, 20100, 'barcode', 'ep:aim', 'lab/barcode/index', 'LabBarcodeWorkbench'),
|
||
|
|
(20141, '条码登记', 'lab:barcode:register', 3, 1, 20140, '', '', '', ''),
|
||
|
|
(20142, '条码关联任务', 'lab:barcode:bind', 3, 2, 20140, '', '', '', ''),
|
||
|
|
(20143, '条码管理', 'lab:barcode:rebind', 3, 3, 20140, '', '', '', ''),
|
||
|
|
]
|
||
|
|
cursor.execute('SELECT id FROM system_menu WHERE id=20100 AND deleted=0')
|
||
|
|
if not cursor.fetchone():
|
||
|
|
raise ValueError('Task center menu is missing; barcode navigation cannot be installed')
|
||
|
|
for menu in menus:
|
||
|
|
cursor.execute('SELECT permission,component,parent_id FROM system_menu WHERE id=%s', (menu[0],))
|
||
|
|
existing = cursor.fetchone()
|
||
|
|
if existing:
|
||
|
|
if tuple(existing) != (menu[2], menu[8], menu[5]):
|
||
|
|
raise ValueError('Barcode menu ID conflicts with an existing menu: '+str(menu[0]))
|
||
|
|
continue
|
||
|
|
cursor.execute('INSERT INTO system_menu (id,name,permission,type,sort,parent_id,path,icon,component,component_name,status,visible,keep_alive,always_show,creator,updater,deleted) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,0,1,1,1,\'1\',\'1\',0)', menu)
|
||
|
|
# New write permissions are not silently granted to task readers or other existing roles.
|
||
|
|
cursor.execute("SELECT id,tenant_id FROM system_role WHERE code IN ('super_admin','admin') AND deleted=0 AND status=0")
|
||
|
|
roles = list(cursor.fetchall())
|
||
|
|
cursor.execute('SELECT COALESCE(MAX(id),100000) FROM system_role_menu')
|
||
|
|
next_id = cursor.fetchone()[0]
|
||
|
|
for role, tenant in roles:
|
||
|
|
for menu in menus:
|
||
|
|
cursor.execute('SELECT id FROM system_role_menu WHERE role_id=%s AND menu_id=%s AND tenant_id=%s AND deleted=0', (role,menu[0],tenant))
|
||
|
|
if cursor.fetchone():
|
||
|
|
continue
|
||
|
|
next_id += 1
|
||
|
|
cursor.execute('INSERT INTO system_role_menu (id,role_id,menu_id,creator,updater,deleted,tenant_id) VALUES (%s,%s,%s,\'1\',\'1\',0,%s)', (next_id,role,menu[0],tenant))
|