0003_categories_roles.py 5.6 KB

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