0003_categories_roles.py 4.8 KB

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