Ejemplo n.º 1
0
	def test_user_permissions_in_doc(self):
		add_user_permission("Blog Category", "-test-blog-category-1", "*****@*****.**")

		frappe.set_user("*****@*****.**")

		post = frappe.get_doc("Blog Post", "-test-blog-post")
		self.assertFalse(post.has_permission("read"))
		self.assertFalse(get_doc_permissions(post).get("read"))

		post1 = frappe.get_doc("Blog Post", "-test-blog-post-1")
		self.assertTrue(post1.has_permission("read"))
		self.assertTrue(get_doc_permissions(post1).get("read"))
Ejemplo n.º 2
0
	def test_user_permissions_in_doc(self):
		add_user_permission("Blog Category", "_Test Blog Category 1",
			"*****@*****.**")

		frappe.set_user("*****@*****.**")

		post = frappe.get_doc("Blog Post", "-test-blog-post")
		self.assertFalse(post.has_permission("read"))
		self.assertFalse(get_doc_permissions(post).get("read"))

		post1 = frappe.get_doc("Blog Post", "-test-blog-post-1")
		self.assertTrue(post1.has_permission("read"))
		self.assertTrue(get_doc_permissions(post1).get("read"))
Ejemplo n.º 3
0
def get_docinfo(doc):
    frappe.response["docinfo"] = {
        "attachments": get_attachments(doc.doctype, doc.name),
        "comments": get_comments(doc.doctype, doc.name),
        "assignments": get_assignments(doc.doctype, doc.name),
        "permissions": get_doc_permissions(doc)
    }
Ejemplo n.º 4
0
def get_docinfo(doc=None, doctype=None, name=None):
    if not doc:
        doc = frappe.get_doc(doctype, name)
        if not doc.has_permission("read"):
            raise frappe.PermissionError
    frappe.response["docinfo"] = {
        "attachments":
        get_attachments(doc.doctype, doc.name),
        "communications":
        _get_communications(doc.doctype, doc.name),
        'comments':
        get_comments(doc.doctype, doc.name),
        'total_comments':
        len(json.loads(doc.get('_comments') or '[]')),
        'versions':
        get_versions(doc),
        "assignments":
        get_assignments(doc.doctype, doc.name),
        "permissions":
        get_doc_permissions(doc),
        "shared":
        frappe.share.get_users(doc.doctype, doc.name),
        "views":
        get_view_logs(doc.doctype, doc.name),
        "energy_point_logs":
        get_point_logs(doc.doctype, doc.name),
        "milestones":
        get_milestones(doc.doctype, doc.name),
        "is_document_followed":
        is_document_followed(doc.doctype, doc.name, frappe.session.user)
    }
Ejemplo n.º 5
0
def get_docinfo(doc):
	frappe.response["docinfo"] = {
		"attachments": get_attachments(doc.doctype, doc.name),
		"comments": get_comments(doc.doctype, doc.name),
		"assignments": get_assignments(doc.doctype, doc.name),
		"permissions": get_doc_permissions(doc)
	}
Ejemplo n.º 6
0
def get_docinfo(doc=None, doctype=None, name=None):
    if not doc:
        doc = frappe.get_doc(doctype, name)
        if not doc.has_permission("read"):
            raise frappe.PermissionError

    all_communications = _get_communications(doc.doctype, doc.name)
    automated_messages = filter(
        lambda x: x['communication_type'] == 'Automated Message',
        all_communications)
    communications_except_auto_messages = filter(
        lambda x: x['communication_type'] != 'Automated Message',
        all_communications)

    frappe.response["docinfo"] = {
        "attachments":
        get_attachments(doc.doctype, doc.name),
        "attachment_logs":
        get_comments(doc.doctype, doc.name, 'attachment'),
        "communications":
        communications_except_auto_messages,
        "automated_messages":
        automated_messages,
        'comments':
        get_comments(doc.doctype, doc.name),
        'total_comments':
        len(json.loads(doc.get('_comments') or '[]')),
        'versions':
        get_versions(doc),
        "assignments":
        get_assignments(doc.doctype, doc.name),
        "assignment_logs":
        get_comments(doc.doctype, doc.name, 'assignment'),
        "permissions":
        get_doc_permissions(doc),
        "shared":
        frappe.share.get_users(doc.doctype, doc.name),
        "info_logs":
        get_comments(doc.doctype, doc.name, 'Info'),
        "share_logs":
        get_comments(doc.doctype, doc.name, 'share'),
        "like_logs":
        get_comments(doc.doctype, doc.name, 'Like'),
        "views":
        get_view_logs(doc.doctype, doc.name),
        "energy_point_logs":
        get_point_logs(doc.doctype, doc.name),
        "additional_timeline_content":
        get_additional_timeline_content(doc.doctype, doc.name),
        "milestones":
        get_milestones(doc.doctype, doc.name),
        "is_document_followed":
        is_document_followed(doc.doctype, doc.name, frappe.session.user),
        "tags":
        get_tags(doc.doctype, doc.name),
        "document_email":
        get_document_email(doc.doctype, doc.name)
    }
Ejemplo n.º 7
0
def get_docinfo(doc=None, doctype=None, name=None):
    if not doc:
        doc = frappe.get_doc(doctype, name)
        if not doc.has_permission("read"):
            raise frappe.PermissionError

    frappe.response["docinfo"] = {
        "attachments": get_attachments(doc.doctype, doc.name),
        "communications": _get_communications(doc.doctype, doc.name),
        "assignments": get_assignments(doc.doctype, doc.name),
        "permissions": get_doc_permissions(doc),
        "shared": frappe.share.get_users(doc.doctype, doc.name)
    }
Ejemplo n.º 8
0
def get_docinfo(doc=None, doctype=None, name=None):
	if not doc:
		doc = frappe.get_doc(doctype, name)
		if not doc.has_permission("read"):
			raise frappe.PermissionError

	frappe.response["docinfo"] = {
		"attachments": get_attachments(doc.doctype, doc.name),
		"communications": _get_communications(doc.doctype, doc.name),
		"assignments": get_assignments(doc.doctype, doc.name),
		"permissions": get_doc_permissions(doc),
		"shared": frappe.share.get_users(doc.doctype, doc.name)
	}
Ejemplo n.º 9
0
def get_docinfo(doc=None, doctype=None, name=None):
	if not doc:
		doc = frappe.get_doc(doctype, name)
		if not doc.has_permission("read"):
			raise frappe.PermissionError

	frappe.response["docinfo"] = {
		"attachments": get_attachments(doc.doctype, doc.name),
		"comments": get_comments(doc.doctype, doc.name),
		"assignments": get_assignments(doc.doctype, doc.name),
		"permissions": get_doc_permissions(doc),
		"shared": frappe.share.get_users(doc.doctype, doc.name,
			fields=["user", "read", "write", "share", "everyone"])
	}
Ejemplo n.º 10
0
def get_docinfo(doc=None, doctype=None, name=None):
	if not doc:
		doc = frappe.get_doc(doctype, name)
		if not doc.has_permission("read"):
			raise frappe.PermissionError

	frappe.response["docinfo"] = {
		"attachments": get_attachments(doc.doctype, doc.name),
		"comments": get_comments(doc.doctype, doc.name),
		"assignments": get_assignments(doc.doctype, doc.name),
		"permissions": get_doc_permissions(doc),
		"shared": frappe.share.get_users(doc.doctype, doc.name,
			fields=["user", "read", "write", "share", "everyone"])
	}
Ejemplo n.º 11
0
def get_docinfo(doc=None, doctype=None, name=None):
	if not doc:
		doc = frappe.get_doc(doctype, name)
		if not doc.has_permission("read"):
			raise frappe.PermissionError

	frappe.response["docinfo"] = {
		"attachments": get_attachments(doc.doctype, doc.name),
		"communications": _get_communications(doc.doctype, doc.name),
		'total_comments': len(json.loads(doc.get('_comments') or '[]')),
		'versions': get_versions(doc),
		"assignments": get_assignments(doc.doctype, doc.name),
		"permissions": get_doc_permissions(doc),
		"shared": frappe.share.get_users(doc.doctype, doc.name),
		"rating": get_feedback_rating(doc.doctype, doc.name)
	}
Ejemplo n.º 12
0
def get_docinfo(doc=None, doctype=None, name=None):
	if not doc:
		doc = frappe.get_doc(doctype, name)
		if not doc.has_permission("read"):
			raise frappe.PermissionError

	all_communications = _get_communications(doc.doctype, doc.name)
	automated_messages = filter(
		lambda x: x["communication_type"] == "Automated Message", all_communications
	)
	communications_except_auto_messages = filter(
		lambda x: x["communication_type"] != "Automated Message", all_communications
	)

	frappe.response["docinfo"] = {
		"attachments": get_attachments(doc.doctype, doc.name),
		"attachment_logs": get_comments(doc.doctype, doc.name, "attachment"),
		"communications": communications_except_auto_messages,
		"automated_messages": automated_messages,
		"comments": get_comments(doc.doctype, doc.name),
		"total_comments": len(json.loads(doc.get("_comments") or "[]")),
		"versions": get_versions(doc),
		"assignments": get_assignments(doc.doctype, doc.name),
		"assignment_logs": get_comments(doc.doctype, doc.name, "assignment"),
		"permissions": get_doc_permissions(doc),
		"shared": frappe.share.get_users(doc.doctype, doc.name),
		"info_logs": get_comments(doc.doctype, doc.name, comment_type=["Info", "Edit", "Label"]),
		"share_logs": get_comments(doc.doctype, doc.name, "share"),
		"like_logs": get_comments(doc.doctype, doc.name, "Like"),
		"workflow_logs": get_comments(doc.doctype, doc.name, comment_type="Workflow"),
		"views": get_view_logs(doc.doctype, doc.name),
		"energy_point_logs": get_point_logs(doc.doctype, doc.name),
		"additional_timeline_content": get_additional_timeline_content(doc.doctype, doc.name),
		"milestones": get_milestones(doc.doctype, doc.name),
		"is_document_followed": is_document_followed(doc.doctype, doc.name, frappe.session.user),
		"tags": get_tags(doc.doctype, doc.name),
		"document_email": get_document_email(doc.doctype, doc.name),
	}
Ejemplo n.º 13
0
def has_upload_permission(doc, ptype='read', user=None):
	if not user:
		user = frappe.session.user
	if get_doc_permissions(doc, user=user, ptype=ptype).get(ptype):
		return True
	return doc.user_id == user