0003_categories_roles.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.db import migrations
  4. _ = lambda s: s
  5. def create_default_categories_roles(apps, schema_editor):
  6. CategoryRole = apps.get_model('misago_categories', 'CategoryRole')
  7. CategoryRole.objects.create(
  8. name=_("See only"),
  9. permissions={
  10. # categories perms
  11. 'misago.categories.permissions': {
  12. 'can_see': 1,
  13. 'can_browse': 0
  14. },
  15. }
  16. )
  17. read_only = CategoryRole.objects.create(
  18. name=_("Read only"),
  19. permissions={
  20. # categories perms
  21. 'misago.categories.permissions': {
  22. 'can_see': 1,
  23. 'can_browse': 1
  24. },
  25. # threads perms
  26. 'misago.threads.permissions.threads': {
  27. 'can_see_all_threads': 1,
  28. 'can_see_posts_likes': 1,
  29. 'can_download_other_users_attachments': 1,
  30. 'can_like_posts': 1
  31. },
  32. }
  33. )
  34. CategoryRole.objects.create(
  35. name=_("Reply to threads"),
  36. permissions={
  37. # categories perms
  38. 'misago.categories.permissions': {
  39. 'can_see': 1,
  40. 'can_browse': 1
  41. },
  42. # threads perms
  43. 'misago.threads.permissions.threads': {
  44. 'can_see_all_threads': 1,
  45. 'can_reply_threads': 1,
  46. 'can_edit_posts': 1,
  47. 'can_download_other_users_attachments': 1,
  48. 'max_attachment_size': 500,
  49. 'can_see_posts_likes': 2,
  50. 'can_like_posts': 1
  51. },
  52. }
  53. )
  54. standard = CategoryRole.objects.create(
  55. name=_("Start and reply threads"),
  56. permissions={
  57. # categories perms
  58. 'misago.categories.permissions': {
  59. 'can_see': 1,
  60. 'can_browse': 1
  61. },
  62. # threads perms
  63. 'misago.threads.permissions.threads': {
  64. 'can_see_all_threads': 1,
  65. 'can_start_threads': 1,
  66. 'can_reply_threads': 1,
  67. 'can_edit_threads': 1,
  68. 'can_edit_posts': 1,
  69. 'can_download_other_users_attachments': 1,
  70. 'max_attachment_size': 500,
  71. 'can_see_posts_likes': 2,
  72. 'can_like_posts': 1
  73. },
  74. }
  75. )
  76. moderator = CategoryRole.objects.create(
  77. name=_("Moderator"),
  78. permissions={
  79. # categories perms
  80. 'misago.categories.permissions': {
  81. 'can_see': 1,
  82. 'can_browse': 1
  83. },
  84. # threads perms
  85. 'misago.threads.permissions.threads': {
  86. 'can_see_all_threads': 1,
  87. 'can_start_threads': 1,
  88. 'can_reply_threads': 1,
  89. 'can_edit_threads': 2,
  90. 'can_edit_posts': 2,
  91. 'can_hide_own_threads': 2,
  92. 'can_hide_own_posts': 2,
  93. 'thread_edit_time': 0,
  94. 'post_edit_time': 0,
  95. 'can_hide_threads': 2,
  96. 'can_hide_posts': 2,
  97. 'can_protect_posts': 1,
  98. 'can_move_posts': 1,
  99. 'can_merge_posts': 1,
  100. 'can_announce_threads': 1,
  101. 'can_pin_threads': 2,
  102. 'can_close_threads': 1,
  103. 'can_move_threads': 1,
  104. 'can_merge_threads': 1,
  105. 'can_approve_content': 1,
  106. 'can_download_other_users_attachments': 1,
  107. 'max_attachment_size': 2500,
  108. 'can_delete_other_users_attachments': 1,
  109. 'can_see_posts_likes': 2,
  110. 'can_like_posts': 1,
  111. 'can_report_content': 1,
  112. 'can_see_reports': 1,
  113. 'can_hide_events': 2
  114. },
  115. }
  116. )
  117. # assign category roles to roles
  118. Category = apps.get_model('misago_categories', 'Category')
  119. Role = apps.get_model('misago_acl', 'Role')
  120. RoleCategoryACL = apps.get_model('misago_categories', 'RoleCategoryACL')
  121. category = Category.objects.get(tree_id=1, level=1)
  122. RoleCategoryACL.objects.create(
  123. role=Role.objects.get(name=_("Moderator")), category=category, category_role=moderator
  124. )
  125. RoleCategoryACL.objects.create(
  126. role=Role.objects.get(special_role='authenticated'),
  127. category=category,
  128. category_role=standard
  129. )
  130. RoleCategoryACL.objects.create(
  131. role=Role.objects.get(special_role='anonymous'),
  132. category=category,
  133. category_role=read_only
  134. )
  135. class Migration(migrations.Migration):
  136. dependencies = [
  137. ('misago_categories', '0002_default_categories'),
  138. ('misago_acl', '0003_default_roles'),
  139. ]
  140. operations = [
  141. migrations.RunPython(create_default_categories_roles),
  142. ]