Browse Source

#477: groundwork for private threads

Rafał Pitoń 10 years ago
parent
commit
5346f35a90

+ 23 - 1
misago/acl/migrations/0003_default_roles.py

@@ -161,8 +161,8 @@ def create_default_roles(apps, schema_editor):
                 'max_lifted_ban_length': 14,
             },
         })
-
     role.save()
+
     role = Role(name=_("Deleting users"))
     pickle_permissions(role,
         {
@@ -184,6 +184,28 @@ def create_default_roles(apps, schema_editor):
         })
     role.save()
 
+    role = Role(name=_("Private threads"))
+    pickle_permissions(role,
+        {
+            # delete users perms
+            'misago.users.permissions.delete': {
+                'can_delete_users_newer_than': 3,
+                'can_delete_users_with_less_posts_than': 7,
+            },
+        })
+    role.save()
+
+    role = Role(name=_("Private threads moderator"))
+    pickle_permissions(role,
+        {
+            # delete users perms
+            'misago.users.permissions.delete': {
+                'can_delete_users_newer_than': 3,
+                'can_delete_users_with_less_posts_than': 7,
+            },
+        })
+    role.save()
+
 
 class Migration(migrations.Migration):
 

+ 2 - 1
misago/conf/defaults.py

@@ -181,7 +181,8 @@ MISAGO_ACL_EXTENSIONS = (
     'misago.users.permissions.moderation',
     'misago.users.permissions.delete',
     'misago.forums.permissions',
-    'misago.threads.permissions',
+    'misago.threads.permissions.privatethreads',
+    'misago.threads.permissions.threads',
 )
 
 MISAGO_MARKUP_EXTENSIONS = ()

+ 5 - 5
misago/forums/migrations/0003_forums_roles.py

@@ -38,7 +38,7 @@ def create_default_forums_roles(apps, schema_editor):
             },
 
             # threads perms
-            'misago.threads.permissions': {
+            'misago.threads.permissions.threads': {
                 'can_see_all_threads': 1,
             },
         })
@@ -54,7 +54,7 @@ def create_default_forums_roles(apps, schema_editor):
             },
 
             # threads perms
-            'misago.threads.permissions': {
+            'misago.threads.permissions.threads': {
                 'can_see_all_threads': 1,
                 'can_reply_threads': 1,
                 'can_edit_posts': 1,
@@ -72,7 +72,7 @@ def create_default_forums_roles(apps, schema_editor):
             },
 
             # threads perms
-            'misago.threads.permissions': {
+            'misago.threads.permissions.threads': {
                 'can_see_all_threads': 1,
                 'can_start_threads': 1,
                 'can_reply_threads': 1,
@@ -93,7 +93,7 @@ def create_default_forums_roles(apps, schema_editor):
             },
 
             # threads perms
-            'misago.threads.permissions': {
+            'misago.threads.permissions.threads': {
                 'can_see_all_threads': 1,
                 'can_start_threads': 1,
                 'can_reply_threads': 1,
@@ -113,7 +113,7 @@ def create_default_forums_roles(apps, schema_editor):
             },
 
             # threads perms
-            'misago.threads.permissions': {
+            'misago.threads.permissions.threads': {
                 'can_see_all_threads': 1,
                 'can_start_threads': 1,
                 'can_reply_threads': 1,

+ 2 - 0
misago/threads/permissions/__init__.py

@@ -0,0 +1,2 @@
+from misago.threads.permissions.privatethreads import *
+from misago.threads.permissions.threads import *

+ 69 - 0
misago/threads/permissions/privatethreads.py

@@ -0,0 +1,69 @@
+from django.utils.translation import ugettext_lazy as _
+
+from misago.acl import add_acl, algebra
+from misago.acl.decorators import return_boolean
+from misago.acl.models import Role
+from misago.core import forms
+
+
+__all__ = [
+]
+
+
+"""
+Admin Permissions Form
+"""
+class PermissionsForm(forms.Form):
+    legend = _("Private threads")
+    can_use_private_threads = forms.YesNoSwitch(
+        label=_("Can use private threads"))
+    can_start_private_threads = forms.YesNoSwitch(
+        label=_("Can start private threads"))
+    max_private_thread_participants = forms.IntegerField(
+        label=_("Max number of users invited to private thread"),
+        help_text=_("Enter 0 to don't limit number of participants."),
+        initial=3,
+        min_value=0)
+    can_add_everyone_to_private_threads = forms.YesNoSwitch(
+        label=_("Can add everyone to threads"),
+        help_text=_("Allows user to add users that are "
+                    "blocking him to private threads."))
+    can_report_private_threads = forms.YesNoSwitch(
+        label=_("Can report private threads"),
+        help_text=_("Allows user to report private threads they are "
+                    "participating in, making them accessible to moderators."))
+    can_moderate_private_threads = forms.YesNoSwitch(
+        label=_("Allows user to read, reply, edit and delete "
+                "content in reported private threads."))
+
+
+def change_permissions_form(role):
+    if isinstance(role, Role) and role.special_role != 'anonymous':
+        return PermissionsForm
+    else:
+        return None
+
+
+"""
+ACL Builder
+"""
+def build_acl(acl, roles, key_name):
+    new_acl = {
+        'can_use_private_threads': 0,
+        'can_start_private_threads': 0,
+        'max_private_thread_participants': 3,
+        'can_add_everyone_to_private_threads': 0,
+        'can_report_private_threads': 0,
+        'can_moderate_private_threads': 0,
+    }
+
+    new_acl.update(acl)
+
+    acl = algebra.sum_acls(new_acl, roles=roles, key=key_name,
+        can_use_private_threads=algebra.greater,
+        can_start_private_threads=algebra.greater,
+        max_private_thread_participants=algebra.greater_or_zero,
+        can_add_everyone_to_private_threads=algebra.greater,
+        can_report_private_threads=algebra.greater,
+        can_moderate_private_threads=algebra.greater
+    )

+ 25 - 0
misago/threads/permissions.py → misago/threads/permissions/threads.py

@@ -13,6 +13,31 @@ from misago.forums.permissions import get_forums_roles
 from misago.threads.models import Thread, Post, Event
 
 
+__all__ = [
+    'add_acl_to_target',
+    'allow_see_thread',
+    'can_see_thread',
+    'allow_start_thread',
+    'can_start_thread',
+    'allow_reply_thread',
+    'can_reply_thread',
+    'allow_edit_thread',
+    'can_edit_thread',
+    'allow_see_post',
+    'can_see_post',
+    'allow_edit_post',
+    'can_edit_post',
+    'allow_unhide_post',
+    'can_unhide_post',
+    'allow_hide_post',
+    'can_hide_post',
+    'allow_delete_post',
+    'can_delete_post',
+    'exclude_invisible_threads',
+    'exclude_invisible_posts'
+]
+
+
 """
 Admin Permissions Form
 """