Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
12 лет назад
12 лет назад
12 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. from __future__ import unicode_literals
  23. import webnotes
  24. import webnotes.model.doc
  25. import webnotes.model.code
  26. conn = webnotes.conn
  27. @webnotes.whitelist()
  28. def get(name):
  29. """
  30. Return the :term:`doclist` of the `Page` specified by `name`
  31. """
  32. from webnotes.model.code import get_obj
  33. page = get_obj('Page', name, with_children=1)
  34. page.get_from_files()
  35. return page.doclist
  36. @webnotes.whitelist(allow_guest=True)
  37. def getpage():
  38. """
  39. Load the page from `webnotes.form` and send it via `webnotes.response`
  40. """
  41. page = webnotes.form_dict.get('name')
  42. doclist = get(page)
  43. if has_permission(doclist):
  44. # load translations
  45. if webnotes.lang != "en":
  46. from webnotes.modules import get_doc_path
  47. from webnotes.translate import get_lang_data
  48. d = doclist[0]
  49. messages = get_lang_data(get_doc_path(d.module, d.doctype, d.name),
  50. webnotes.lang, 'js')
  51. webnotes.response["__messages"] = messages
  52. webnotes.response['docs'] = doclist
  53. else:
  54. webnotes.response['403'] = 1
  55. raise webnotes.PermissionError, 'No read permission for Page %s' % \
  56. (doclist[0].title or page, )
  57. def has_permission(page_doclist):
  58. if webnotes.user.name == "Administrator" or "System Manager" in webnotes.user.get_roles():
  59. return True
  60. page_roles = [d.role for d in page_doclist if d.fields.get("doctype")=="Page Role"]
  61. if webnotes.user.name == "Guest" and not (page_roles and "Guest" in page_roles):
  62. return False
  63. elif page_roles and not (set(page_roles) & set(webnotes.user.get_roles())):
  64. return False
  65. return True