You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 line
1.5 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import webnotes
  5. import webnotes.model.doc
  6. import webnotes.model.code
  7. @webnotes.whitelist()
  8. def get(name):
  9. """
  10. Return the :term:`doclist` of the `Page` specified by `name`
  11. """
  12. page = webnotes.bean("Page", name)
  13. page.run_method("get_from_files")
  14. return page.doclist
  15. @webnotes.whitelist(allow_guest=True)
  16. def getpage():
  17. """
  18. Load the page from `webnotes.form` and send it via `webnotes.response`
  19. """
  20. page = webnotes.form_dict.get('name')
  21. doclist = get(page)
  22. if has_permission(doclist):
  23. # load translations
  24. if webnotes.lang != "en":
  25. from webnotes.modules import get_doc_path
  26. from webnotes.translate import get_lang_data
  27. d = doclist[0]
  28. messages = get_lang_data(get_doc_path(d.module, d.doctype, d.name),
  29. webnotes.lang, 'js')
  30. webnotes.response["__messages"] = messages
  31. webnotes.response['docs'] = doclist
  32. else:
  33. webnotes.response['403'] = 1
  34. raise webnotes.PermissionError, 'No read permission for Page %s' % \
  35. (doclist[0].title or page, )
  36. def has_permission(page_doclist):
  37. if webnotes.user.name == "Administrator" or "System Manager" in webnotes.user.get_roles():
  38. return True
  39. page_roles = [d.role for d in page_doclist if d.fields.get("doctype")=="Page Role"]
  40. if webnotes.user.name == "Guest" and not (page_roles and "Guest" in page_roles):
  41. return False
  42. elif page_roles and not (set(page_roles) & set(webnotes.user.get_roles())):
  43. return False
  44. return True