Browse Source

Changed way Private Threads permissions are managed.

Ralfp 12 years ago
parent
commit
6bfb1fca4a

+ 91 - 0
misago/acl/permissions/privatethreads.py

@@ -0,0 +1,91 @@
+from django.utils.translation import ugettext_lazy as _
+from django import forms
+from misago.acl.builder import BaseACL
+from misago.acl.exceptions import ACLError403, ACLError404
+from misago.forms import YesNoSwitch
+from misago.models import Forum
+
+def make_form(request, role, form):
+    if role.special != 'guest':
+        form.base_fields['can_use_private_threads'] = forms.BooleanField(widget=YesNoSwitch, initial=False, required=False)
+        form.base_fields['can_start_private_threads'] = forms.BooleanField(widget=YesNoSwitch, initial=False, required=False)
+        form.base_fields['can_upload_attachments_in_private_threads'] = forms.BooleanField(widget=YesNoSwitch, initial=False, required=False)
+        form.base_fields['private_thread_attachment_size'] = forms.IntegerField(min_value=0, initial=100, required=False)
+        form.base_fields['private_thread_attachments_limit'] = forms.IntegerField(min_value=0, initial=3, required=False)
+        form.base_fields['can_invite_ignoring'] = forms.BooleanField(widget=YesNoSwitch, initial=False, required=False)
+        form.base_fields['private_threads_mod'] = forms.BooleanField(widget=YesNoSwitch, initial=False, required=False)
+        form.layout.append((
+                            _("Private Threads"),
+                            (
+                             ('can_use_private_threads', {'label': _("Can participate in private threads")}),
+                             ('can_start_private_threads', {'label': _("Can start private threads")}),
+                             ('can_upload_attachments_in_private_threads', {'label': _("Can upload files in attachments")}),
+                             ('private_thread_attachment_size', {'label': _("Max. size of single attachment (in KB)")}),
+                             ('private_thread_attachments_limit', {'label': _("Max. number of attachments per post")}),
+                             ('can_invite_ignoring', {'label': _("Can invite users that ignore him")}),
+                             ('private_threads_mod', {'label': _("Can moderate threads"), 'help_text': _("Makes user with this role Private Threads moderator capable of closing, deleting and editing all private threads he participates in at will.")}),
+                             ),
+                            ))
+
+
+def cleanup(acl, perms, forums):
+    forum = Forum.objects.special_pk('private_threads')
+    acl.threads.acl[forum] = {
+                              'can_read_threads': 2,
+                              'can_start_threads': 0,
+                              'can_edit_own_threads': True,
+                              'can_soft_delete_own_threads': False,
+                              'can_write_posts': 2,
+                              'can_edit_own_posts': True,
+                              'can_soft_delete_own_posts': True,
+                              'can_upvote_posts': False,
+                              'can_downvote_posts': False,
+                              'can_see_posts_scores': 0,
+                              'can_see_votes': False,
+                              'can_make_polls': False,
+                              'can_vote_in_polls': False,
+                              'can_see_poll_votes': False,
+                              'can_see_attachments': True,
+                              'can_upload_attachments': False,
+                              'can_download_attachments': True,
+                              'attachment_size': 100,
+                              'attachment_limit': 3,
+                              'can_approve': False,
+                              'can_edit_labels': False,
+                              'can_see_changelog': False,
+                              'can_pin_threads': 0,
+                              'can_edit_threads_posts': False,
+                              'can_move_threads_posts': False,
+                              'can_close_threads': False,
+                              'can_protect_posts': False,
+                              'can_delete_threads': 0,
+                              'can_delete_posts': 0,
+                              'can_delete_polls': 0,
+                              'can_delete_attachments': False,
+                              'can_invite_ignoring': False,
+                             }
+
+    for perm in perms:
+        try:
+            if perm['can_use_private_threads']:
+                acl.forums.acl['can_see'].append(forum)
+                acl.forums.acl['can_browse'].append(forum)
+            if perm['can_start_private_threads']:
+                acl.threads.acl[forum]['can_start_threads'] = True
+            if perm['can_upload_attachments_in_private_threads']:
+                acl.threads.acl[forum]['can_upload_attachments'] = True
+            if perm['private_thread_attachment_size']:
+                acl.threads.acl[forum]['attachment_size'] = True
+            if perm['private_thread_attachments_limit']:
+                acl.threads.acl[forum]['attachment_limit'] = True
+            if perm['can_invite_ignoring']:
+                acl.threads.acl[forum]['can_invite_ignoring'] = True
+            if perm['private_threads_mod']:
+                acl.threads.acl[forum]['can_edit_threads_posts'] = True
+                acl.threads.acl[forum]['can_move_threads_posts'] = True
+                acl.threads.acl[forum]['can_see_changelog'] = True
+                acl.threads.acl[forum]['can_delete_threads'] = 2
+                acl.threads.acl[forum]['can_delete_posts'] = 2
+                acl.threads.acl[forum]['can_delete_attachments'] = True
+        except KeyError:
+            pass

+ 1 - 10
misago/apps/admin/roles/views.py

@@ -130,16 +130,7 @@ class Forums(ListWidget):
         return Forum.objects.get(special='root').get_descendants()
     
     def sort_items(self, page_items, sorting_method):
-        final_items = []
-        for forum in Forum.objects.filter(special__in=['reports', 'private_threads']).order_by('special'):
-            if forum.special == 'reports':
-                forum.name = _("Reports")
-            if forum.special == 'private_threads':
-                forum.name = _("Private Threads")
-            final_items.append(forum)
-        for forum in page_items.order_by('lft').all():
-            final_items.append(forum)
-        return final_items
+        return page_items.order_by('lft').all()
 
     def add_template_variables(self, variables):
         variables['target'] = _(self.role.name)

+ 45 - 0
misago/apps/privatethreads/thread.py

@@ -0,0 +1,45 @@
+from django.utils.translation import ugettext as _
+from misago.apps.threadtype.thread import ThreadBaseView, ThreadModeration, PostsModeration
+from misago.models import Forum, Thread
+from misago.apps.privatethreads.mixins import TypeMixin
+
+class ThreadView(ThreadBaseView, ThreadModeration, PostsModeration, TypeMixin):
+    def posts_actions(self):
+        acl = self.request.acl.threads.get_role(self.thread.forum_id)
+        actions = []
+        try:
+            if acl['can_move_threads_posts']:
+                actions.append(('merge', _('Merge posts into one')))
+                actions.append(('split', _('Split posts to new thread')))
+            if acl['can_protect_posts']:
+                actions.append(('protect', _('Protect posts')))
+                actions.append(('unprotect', _('Remove posts protection')))
+            if acl['can_delete_posts']:
+                if self.thread.replies_deleted > 0:
+                    actions.append(('undelete', _('Undelete posts')))
+                actions.append(('soft', _('Soft delete posts')))
+            if acl['can_delete_posts'] == 2:
+                actions.append(('hard', _('Hard delete posts')))
+        except KeyError:
+            pass
+        return actions
+
+    def thread_actions(self):
+        acl = self.request.acl.threads.get_role(self.thread.forum_id)
+        actions = []
+        try:
+            if acl['can_close_threads']:
+                if self.thread.closed:
+                    actions.append(('open', _('Open this thread')))
+                else:
+                    actions.append(('close', _('Close this thread')))
+            if acl['can_delete_threads']:
+                if self.thread.deleted:
+                    actions.append(('undelete', _('Undelete this thread')))
+                else:
+                    actions.append(('soft', _('Soft delete this thread')))
+            if acl['can_delete_threads'] == 2:
+                actions.append(('hard', _('Hard delete this thread')))
+        except KeyError:
+            pass
+        return actions

+ 1 - 0
misago/settings_base.py

@@ -111,6 +111,7 @@ PERMISSION_PROVIDERS = (
     'misago.acl.permissions.users',
     'misago.acl.permissions.forums',
     'misago.acl.permissions.threads',
+    'misago.acl.permissions.privatethreads',
     'misago.acl.permissions.special',
 )