<commit_before>import frappe
import frappe.share

def execute():
	frappe.reload_doc("core", "doctype", "docperm")
	frappe.reload_doc("core", "doctype", "docshare")

	# default share to all writes
	frappe.db.sql("""update tabDocPerm set `share`=1 where ifnull(`write`,0)=1 and ifnull(`permlevel`,0)=0""")

	# every user must have access to his / her own detail
	for user in frappe.get_all("User", filters={"user_type": "System User"}):
		frappe.share.add("User", user.name, user.name, share=1)

	# move event user to shared
	if frappe.db.exists("DocType", "Event User"):
		for event in frappe.get_all("Event User", fields=["parent", "person"]):
			frappe.share.add("Event", event.parent, event.person, write=1)

		frappe.delete_doc("DocType", "Event User")

	# move note user to shared
	if frappe.db.exists("DocType", "Note User"):
		for note in frappe.get_all("Note User", fields=["parent", "user", "permission"]):
			perm = {"read": 1} if note.permission=="Read" else {"write": 1}
			frappe.share.add("Note", note.parent, note.user, **perm)

		frappe.delete_doc("DocType", "Note User")<commit_msg>[patch] skip sharing for users that do not exist<commit_after>import frappe
import frappe.share

def execute():
	frappe.reload_doc("core", "doctype", "docperm")
	frappe.reload_doc("core", "doctype", "docshare")

	# default share to all writes
	frappe.db.sql("""update tabDocPerm set `share`=1 where ifnull(`write`,0)=1 and ifnull(`permlevel`,0)=0""")

	# every user must have access to his / her own detail
	users = frappe.get_all("User", filters={"user_type": "System User"})
	usernames = [user.name for user in users]
	for user in usernames:
		frappe.share.add("User", user, user, share=1)

	# move event user to shared
	if frappe.db.exists("DocType", "Event User"):
		for event in frappe.get_all("Event User", fields=["parent", "person"]):
			if event.person in usernames:
				frappe.share.add("Event", event.parent, event.person, write=1)

		frappe.delete_doc("DocType", "Event User")

	# move note user to shared
	if frappe.db.exists("DocType", "Note User"):
		for note in frappe.get_all("Note User", fields=["parent", "user", "permission"]):
			perm = {"read": 1} if note.permission=="Read" else {"write": 1}
			if note.user in usernames:
				frappe.share.add("Note", note.parent, note.user, **perm)

		frappe.delete_doc("DocType", "Note User")
{'fraction_non_alphanumeric': 0.17078364565587734, 'fraction_numerical': 0.007666098807495741, 'mean_word_length': 5.214285714285714, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4722130', 'n_tokens_mistral': 843, 'n_tokens_neox': 829, 'n_words': 225}