share_5.py 770 B

1234567891011121314151617181920212223242526
  1. def get_shared(doctype, user=None, rights=None):
  2. """Get list of shared document names for given user and DocType.
  3. :param doctype: DocType of which shared names are queried.
  4. :param user: User for which shared names are queried.
  5. :param rights: List of rights for which the document is shared. List of `read`, `write`, `share`"""
  6. if not user:
  7. user = frappe.session.user
  8. if not rights:
  9. rights = ["read"]
  10. filters = [[right, '=', 1] for right in rights]
  11. filters += [['share_doctype', '=', doctype]]
  12. or_filters = [['user', '=', user]]
  13. if user != 'Guest':
  14. or_filters += [['everyone', '=', 1]]
  15. shared_docs = frappe.db.get_all('DocShare',
  16. fields=['share_name'],
  17. filters=filters,
  18. or_filters=or_filters)
  19. return [doc.share_name for doc in shared_docs]