def METHOD_NAME(doctype):
	links = get_permitted_and_not_permitted_links(doctype)
	if not links.get("not_permitted_links"):
		# when everything is permitted, don't add additional condition
		return ""
	elif not links.get("permitted_links"):
		# when everything is not permitted
		conditions = [
			f"ifnull(`tab{doctype}`.`{df.fieldname}`, '')=''" for df in links.get("not_permitted_links")
		]
		return "( " + " and ".join(conditions) + " )"
	else:
		conditions = [
			f"ifnull(`tab{doctype}`.`{df.fieldname}`, '')!=''" for df in links.get("permitted_links")
		]
		return "( " + " or ".join(conditions) + " )"