def add(doctype, name, user=None, read=1, write=0, share=0, everyone=0, flags=None): """Share the given document with a user.""" if not user: user = frappe.session.user if not (flags or {}).get("ignore_share_permission"): check_share_permission(doctype, name) share_name = get_share_name(doctype, name, user, everyone) if share_name: doc = frappe.get_doc("DocShare", share_name) else: doc = frappe.new_doc("DocShare") doc.update({ "user": user, "share_doctype": doctype, "share_name": name, "everyone": cint(everyone) }) if flags: doc.flags.update(flags) doc.update({ # always add read, since you are adding! "read": 1, "write": cint(write), "share": cint(share) }) doc.save(ignore_permissions=True) notify_assignment(user, doctype, name, everyone) follow_document(doctype, name, user) return doc