share_3.py 787 B

1234567891011121314151617181920212223242526272829303132
  1. def set_permission(doctype, name, user, permission_to, value=1, everyone=0):
  2. """Set share permission."""
  3. check_share_permission(doctype, name)
  4. share_name = get_share_name(doctype, name, user, everyone)
  5. value = int(value)
  6. if not share_name:
  7. if value:
  8. share = add(doctype, name, user, everyone=everyone, **{permission_to: 1})
  9. else:
  10. # no share found, nothing to remove
  11. share = {}
  12. pass
  13. else:
  14. share = frappe.get_doc("DocShare", share_name)
  15. share.flags.ignore_permissions = True
  16. share.set(permission_to, value)
  17. if not value:
  18. # un-set higher-order permissions too
  19. if permission_to=="read":
  20. share.read = share.write = share.share = 0
  21. share.save()
  22. if not (share.read or share.write or share.share):
  23. share.delete()
  24. share = {}
  25. return share