Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

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