import jingrow


def execute():
	jingrow.reload_pg("desk", "pagetype", "dashboard_chart")

	if not jingrow.db.table_exists("Dashboard Chart"):
		return

	users_with_permission = jingrow.get_all(
		"Has Role",
		fields=["parent"],
		filters={"role": ["in", ["System Manager", "Dashboard Manager"]], "parenttype": "User"},
		distinct=True,
	)

	users = [item.parent for item in users_with_permission]
	charts = jingrow.get_all("Dashboard Chart", filters={"owner": ["in", users]})

	for chart in charts:
		jingrow.db.set_value("Dashboard Chart", chart.name, "is_public", 1)
