Spaces:
Sleeping
Sleeping
File size: 3,271 Bytes
6ea020b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | import sqlite3
import json
import os
def set_perms():
project_root = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(project_root, 'lab_database.db')
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Get admin ID
cursor.execute("SELECT id FROM user WHERE username='admin'")
row = cursor.fetchone()
if not row:
print("Admin user not found")
return
admin_id = row[0]
# Complete list of all pages and their buttons
pages = {
'dashboard': [],
'patient_registration': ["save_registration", "discount", "print_barcode", "print_receipt"],
'patients': ["edit", "delete", "print_barcode", "result_entry"],
'patient_edit': ["save", "print_barcode", "print_receipt", "discount"],
'deleted_patients': ["restore", "view"],
'deleted_tests': [],
'patient_history': [],
'patient_status': [],
'result_entry': ["save", "authorize", "duplicate", "rerun", "no_sample"],
'double_auth': ["double_authorize", "rerun", "unauthorize"],
'no_sample': ["mark_no_sample", "receive_sample"],
'print_barcode': ["print"],
'barcode_designer': ["save"],
'print_receipt': ["print"],
'receipt_designer': ["save"],
'print_results': ["print", "view"],
'call_centre': ["mark_called", "send_whatsapp"],
'result_designer': ["save"],
'departments': ["create", "edit", "delete"],
'sample_types': ["create", "edit", "delete"],
'devices': ["create", "edit", "delete"],
'parameters': ["create", "edit", "delete"],
'report_notes': ["create", "edit", "delete"],
'supplies': ["create", "edit", "delete"],
'inventory': ["create", "edit", "delete"],
'tests': ["create", "edit", "delete"],
'formulas': ["create", "edit", "delete"],
'test_ranges': ["create", "edit", "delete"],
'test_result_types': ["create", "edit", "delete"],
'packages': ["create", "edit", "delete"],
'expenses_types': ["create", "edit", "delete"],
'expenses_entry': ["create", "edit", "delete"],
'discount_report': ["view"],
'detailed_income': ["view"],
'net_amounts': ["view"],
'payment_records': ["view"],
'patients_number': ["view"],
'tests_number': ["view"],
'expenses_report': ["view", "edit", "delete"],
'remain_report': ["view"],
'partners': ["create", "edit", "delete"],
'provinces': ["create", "edit", "delete"],
'regions': ["create", "edit", "delete"],
'lab_info': ["edit", "save"],
'user_management': ["create", "edit", "delete"],
'activity_logs': ["view"],
}
# Delete existing admin permissions and re-insert all
cursor.execute("DELETE FROM userpermission WHERE user_id = ?", (admin_id,))
for page, perms in pages.items():
cursor.execute("INSERT INTO userpermission (user_id, page_key, allowed_buttons) VALUES (?, ?, ?)",
(admin_id, page, json.dumps(perms)))
conn.commit()
conn.close()
print(f"Successfully updated admin permissions for {len(pages)} pages")
if __name__ == "__main__":
set_perms()
|