25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

102 lines
3.6 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. from webnotes.website.permissions import get_access, clear_permissions
  6. from webnotes.templates.generators.website_group import get_pathname
  7. from webnotes.utils.email_lib.bulk import send
  8. @webnotes.whitelist()
  9. def suggest_user(term, group):
  10. pathname = get_pathname(group)
  11. if not get_access(pathname).get("admin"):
  12. raise webnotes.PermissionError
  13. profiles = webnotes.conn.sql("""select pr.name, pr.first_name, pr.last_name,
  14. pr.user_image, pr.location
  15. from `tabProfile` pr
  16. where (pr.first_name like %(term)s or pr.last_name like %(term)s)
  17. and pr.user_type = "Website User"
  18. and pr.user_image is not null and pr.enabled=1
  19. and not exists(select wsp.name from `tabWebsite Sitemap Permission` wsp
  20. where wsp.website_sitemap=%(group)s and wsp.profile=pr.name)""",
  21. {"term": "%{}%".format(term), "group": pathname}, as_dict=True)
  22. template = webnotes.get_template("templates/includes/profile_display.html")
  23. return [{
  24. "value": "{} {}".format(pr.first_name or "", pr.last_name or ""),
  25. "profile_html": template.render({"profile": pr}),
  26. "profile": pr.name
  27. } for pr in profiles]
  28. @webnotes.whitelist()
  29. def add_sitemap_permission(group, profile):
  30. pathname = get_pathname(group)
  31. if not get_access(pathname).get("admin"):
  32. raise webnotes.PermissionError
  33. permission = webnotes.bean({
  34. "doctype": "Website Sitemap Permission",
  35. "website_sitemap": pathname,
  36. "profile": profile,
  37. "read": 1
  38. })
  39. permission.insert(ignore_permissions=True)
  40. profile = permission.doc.fields
  41. profile.update(webnotes.conn.get_value("Profile", profile.profile,
  42. ["name", "first_name", "last_name", "user_image", "location"], as_dict=True))
  43. return webnotes.get_template("templates/includes/sitemap_permission.html").render({
  44. "profile": profile
  45. })
  46. @webnotes.whitelist()
  47. def update_permission(group, profile, perm, value):
  48. pathname = get_pathname(group)
  49. if not get_access(pathname).get("admin"):
  50. raise webnotes.PermissionError
  51. permission = webnotes.bean("Website Sitemap Permission", {"website_sitemap": pathname, "profile": profile})
  52. permission.doc.fields[perm] = int(value)
  53. permission.save(ignore_permissions=True)
  54. # send email
  55. if perm=="admin" and int(value):
  56. group_title = webnotes.conn.get_value("Website Sitemap", pathname, "page_title")
  57. subject = "You have been made Administrator of Group " + group_title
  58. send(recipients=[profile],
  59. subject= subject, add_unsubscribe_link=False,
  60. message="""<h3>Group Notification<h3>\
  61. <p>%s</p>\
  62. <p style="color: #888">This is just for your information.</p>""" % subject)
  63. @webnotes.whitelist()
  64. def update_description(group, description):
  65. if not get_access(get_pathname(group)).get("admin"):
  66. raise webnotes.PermissionError
  67. group = webnotes.bean("Website Group", group)
  68. group.doc.group_description = description
  69. group.save(ignore_permissions=True)
  70. @webnotes.whitelist()
  71. def add_website_group(group, new_group, public_read, public_write, group_type="Forum"):
  72. if not get_access(get_pathname(group)).get("admin"):
  73. raise webnotes.PermissionError
  74. parent_website_sitemap = webnotes.conn.get_value("Website Sitemap",
  75. {"ref_doctype": "Website Group", "docname": group})
  76. webnotes.bean({
  77. "doctype": "Website Group",
  78. "group_name": group + "-" + new_group,
  79. "group_title": new_group,
  80. "parent_website_sitemap": parent_website_sitemap,
  81. "group_type": group_type,
  82. "public_read": int(public_read),
  83. "public_write": int(public_write)
  84. }).insert(ignore_permissions=True)