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.
 
 
 
 
 
 

56 lines
1.6 KiB

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