<commit_before># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, print_function
from six import string_types
import frappe, copy, json
from frappe import _, msgprint
from frappe.utils import cint
import frappe.share
rights = ("read", "write", "create", "delete", "submit", "cancel", "amend",
	"print", "email", "report", "import", "export", "set_user_permissions", "share")

# TODO:

# optimize: meta.get_link_map (check if the doctype link exists for the given permission type)

def check_admin_or_system_manager(user=None):
	if not user: user = frappe.session.user

	if ("System Manager" not in frappe.get_roles(user)) and (user!="Administrator"):
		frappe.throw(_("Not permitted"), frappe.PermissionError)

def print_has_permission_check_logs(func):
	def inner(*args, **kwargs):
		frappe.flags['has_permission_check_logs'] = []
		result = func(*args, **kwargs)
		self_perm_check = True if not kwargs.get('user') else kwargs.get('user') == frappe.session.user
		# print only if access denied
		# and if user is checking his own permission
		if not result and self_perm_check:
			msgprint(('<br>').join(frappe.flags['has_permission_check_logs']))
		frappe.flags.pop('has_permission_check_logs', None)
		return result
	return inner

@print_has_permission_check_logs
def has_permission(doctype, ptype="read", doc=None, verbose=False, user=None):
	"""Returns True if user has permission `ptype` for given `doctype`.
	If `doc` is passed, it also checks user, share and owner permissions.

	Note: if Table DocType is passed, it always returns True.
	"""
	if not user: user = frappe.session.user

	if not doc and hasattr(doctype, 'doctype'):<commit_msg>fix(permission): use .get to avoid key error (#7187)<commit_after># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, print_function
from six import string_types
import frappe, copy, json
from frappe import _, msgprint
from frappe.utils import cint
import frappe.share
rights = ("read", "write", "create", "delete", "submit", "cancel", "amend",
	"print", "email", "report", "import", "export", "set_user_permissions", "share")

# TODO:

# optimize: meta.get_link_map (check if the doctype link exists for the given permission type)

def check_admin_or_system_manager(user=None):
	if not user: user = frappe.session.user

	if ("System Manager" not in frappe.get_roles(user)) and (user!="Administrator"):
		frappe.throw(_("Not permitted"), frappe.PermissionError)

def print_has_permission_check_logs(func):
	def inner(*args, **kwargs):
		frappe.flags['has_permission_check_logs'] = []
		result = func(*args, **kwargs)
		self_perm_check = True if not kwargs.get('user') else kwargs.get('user') == frappe.session.user
		# print only if access denied
		# and if user is checking his own permission
		if not result and self_perm_check:
			msgprint(('<br>').join(frappe.flags.get('has_permission_check_logs')))
		frappe.flags.pop('has_permission_check_logs', None)
		return result
	return inner

@print_has_permission_check_logs
def has_permission(doctype, ptype="read", doc=None, verbose=False, user=None):
	"""Returns True if user has permission `ptype` for given `doctype`.
	If `doc` is passed, it also checks user, share and owner permissions.

	Note: if Table DocType is passed, it always returns True.
	"""
	if not user: user = frappe.session.user

	if not doc and hasattr(doctype, 'doctype'):
{'fraction_non_alphanumeric': 0.12091967073516889, 'fraction_numerical': 0.0034061879080329264, 'mean_word_length': 5.7251908396946565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5177761', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1126, 'n_words': 358}