def set_permission(doctype, name, user, permission_to, value=1, everyone=0): """Set share permission.""" check_share_permission(doctype, name) share_name = get_share_name(doctype, name, user, everyone) value = int(value) if not share_name: if value: share = add(doctype, name, user, everyone=everyone, **{permission_to: 1}) else: # no share found, nothing to remove share = {} pass else: share = frappe.get_doc("DocShare", share_name) share.flags.ignore_permissions = True share.set(permission_to, value) if not value: # un-set higher-order permissions too if permission_to=="read": share.read = share.write = share.share = 0 share.save() if not (share.read or share.write or share.share): share.delete() share = {} return share