Ralfp 12 лет назад
Родитель
Сommit
a042745aab

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

@@ -29,6 +29,9 @@ def make_form(request, role, form):
 
 
 class PrivateThreadsACL(BaseACL):
+    def can_participate(self):
+        return self.acl['can_use_private_threads']
+        
     def is_mod(self):
         return self.acl['private_threads_mod']
 

+ 24 - 1
misago/apps/privatethreads/jumps.py

@@ -46,7 +46,29 @@ class DownvotePostView(DownvotePostBaseView, TypeMixin):
 
 class InviteUserView(JumpView, TypeMixin):
     def make_jump(self):
-        print 'ZOMG INVITING USER'
+        username = self.request.POST.get('username', '').strip()
+        if not username:
+            self.request.messages.set_flash(Message(_('You have to enter name of user you want to invite to thread.')), 'error', 'threads')
+            return self.retreat_redirect()
+        try:
+            user = User.objects.get(username=username)
+            acl = user.acl(self.request)
+            if user in self.thread.participants.all():
+                if user.pk == self.request.user.pk:
+                    self.request.messages.set_flash(Message(_('You cannot add yourself to this thread.')), 'error', 'threads')
+                else:
+                    self.request.messages.set_flash(Message(_('%(user)s is already participating in this thread.') % {'user': user.username}), 'info', 'threads')
+            if not acl.private_threads.can_participate():
+                    self.request.messages.set_flash(Message(_('%(user)s cannot participate in private threads.') % {'user': user.username}), 'info', 'threads')
+            else:
+                self.thread.participants.add(user)
+                self.thread.last_post.set_checkpoint(self.request, 'invited', user)
+                self.thread.last_post.save(force_update=True)
+                self.request.messages.set_flash(Message(_('%(user)s has been added to this thread.') % {'user': user.username}), 'success', 'threads')
+            return self.retreat_redirect()
+        except User.DoesNotExist:
+            self.request.messages.set_flash(Message(_('User with requested username could not be found.')), 'error', 'threads')
+            return self.retreat_redirect()
 
 
 class RemoveUserView(JumpView, TypeMixin):
@@ -69,6 +91,7 @@ class RemoveUserView(JumpView, TypeMixin):
             # Nope, see if we removed ourselves
             if user.pk == self.request.user.pk:
                 self.thread.last_post.set_checkpoint(self.request, 'left')
+                self.thread.last_post.save(force_update=True)
                 self.request.messages.set_flash(Message(_('You have left the "%(thread)s" thread.') % {'thread': self.thread.name}), 'info', 'threads')
                 return self.threads_list_redirect()
             # Nope, somebody else removed user

+ 4 - 1
templates/cranefly/private_threads/thread.html

@@ -321,6 +321,8 @@
               <i class="icon-trash"></i> {% trans user=checkpoint_user(checkpoint), date=checkpoint.date|reltimesince|low %}{{ user }} deleted this thread {{ date }}{% endtrans %}
               {%- elif checkpoint.action == 'undeleted' -%}
               <i class="icon-trash"></i> {% trans user=checkpoint_user(checkpoint), date=checkpoint.date|reltimesince|low %}{{ user }} restored this thread {{ date }}{% endtrans %}
+              {%- elif checkpoint.action == 'invited' -%}
+              <i class="icon-plus-sign"></i> {% trans user=checkpoint_user(checkpoint), invited=checkpoint_target(checkpoint), date=checkpoint.date|reltimesince|low %}{{ user }} added {{ invited }} to thread {{ date }}{% endtrans %}
               {%- elif checkpoint.action == 'removed' -%}
               <i class="icon-remove-sign"></i> {% trans user=checkpoint_user(checkpoint), removed=checkpoint_target(checkpoint), date=checkpoint.date|reltimesince|low %}{{ user }} removed {{ removed }} from thread {{ date }}{% endtrans %}
               {%- elif checkpoint.action == 'left' -%}
@@ -405,8 +407,9 @@
 
         <h4>{% trans %}Invite User{% endtrans %}</h4>
         <div class="invite-participant">
-          <form class="form-inline">
+          <form class="form-inline" action="{% url 'private_thread_invite_user' thread=thread.pk, slug=thread.slug %}" method="post">
             <input type="hidden" name="{{ csrf_id }}" value="{{ csrf_token }}">
+            <input type="hidden" name="retreat" value="{{ request_path }}">
             {{ form_theme.input_text(invite_form.fields.username, width="2", attrs={'placeholder':_("User to invite...")}) }}
             <button class="btn" type="submit"><i class="icon-plus"></i></button>
           </form>