Browse Source

Start private thread from user profile.

Ralfp 12 years ago
parent
commit
5692658129

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

@@ -29,6 +29,10 @@ def make_form(request, role, form):
 
 
 class PrivateThreadsACL(BaseACL):
+    def can_start(self):
+        return (self.acl['can_use_private_threads'] and
+                self.acl['can_start_private_threads'])
+
     def can_participate(self):
         return self.acl['can_use_private_threads']
         

+ 17 - 1
misago/apps/privatethreads/posting.py

@@ -1,9 +1,10 @@
 from django.core.urlresolvers import reverse
 from django.shortcuts import redirect
 from django.utils.translation import ugettext as _
+from misago.acl.exceptions import ACLError403, ACLError404
 from misago.apps.threadtype.posting import NewThreadBaseView, EditThreadBaseView, NewReplyBaseView, EditReplyBaseView
 from misago.messages import Message
-from misago.models import Forum, Thread, Post
+from misago.models import Forum, Thread, Post, User
 from misago.apps.privatethreads.forms import (NewThreadForm, EditThreadForm,
                                               NewReplyForm, EditReplyForm)
 from misago.apps.privatethreads.mixins import TypeMixin
@@ -14,6 +15,21 @@ class NewThreadView(NewThreadBaseView, TypeMixin):
     def set_forum_context(self):
         self.forum = Forum.objects.get(special='private_threads')
 
+    def form_initial_data(self):
+        if self.kwargs.get('user'):
+            try:
+                user = User.objects.get(id=self.kwargs.get('user'))
+                acl = user.acl(self.request)
+                if not acl.private_threads.can_participate():
+                    raise ACLError403(_("This member can not participate in private threads."))
+                if (not self.request.acl.private_threads.can_invite_ignoring() and
+                        not user.allow_pd_invite(self.request.user)):
+                    raise ACLError403(_('%(user)s restricts who can invite him to private threads.') % {'user': user.username})
+                return {'invite_users': user.username}
+            except User.DoesNotExist:
+                raise ACLError404()
+        return {}
+
     def after_form(self, form):
         self.thread.participants.add(self.request.user)
         self.invite_users(form.invite_users)

+ 1 - 0
misago/apps/privatethreads/urls.py

@@ -4,6 +4,7 @@ urlpatterns = patterns('misago.apps.privatethreads',
     url(r'^$', 'list.ThreadsListView', name="private_threads"),
     url(r'^(?P<page>\d+)/$', 'list.ThreadsListView', name="private_threads"),
     url(r'^start/$', 'posting.NewThreadView', name="private_thread_start"),
+    url(r'^start/(?P<username>\w+)-(?P<user>\d+)/$', 'posting.NewThreadView', name="private_thread_start_with"),
     url(r'^(?P<slug>(\w|-)+)-(?P<thread>\d+)/edit/$', 'posting.EditThreadView', name="private_thread_edit"),
     url(r'^(?P<slug>(\w|-)+)-(?P<thread>\d+)/reply/$', 'posting.NewReplyView', name="private_thread_reply"),
     url(r'^(?P<slug>(\w|-)+)-(?P<thread>\d+)/(?P<quote>\d+)/reply/$', 'posting.NewReplyView', name="private_thread_reply"),

+ 0 - 1
misago/models/usermodel.py

@@ -321,7 +321,6 @@ class User(models.Model):
         self.username_slug = slugify(username)
 
     def sync_username(self):
-        print 'SYNCING NAME CACHES!'
         rename_user.send(sender=self)
 
     def is_username_valid(self, e):

+ 2 - 0
static/cranefly/css/cranefly.css

@@ -860,6 +860,8 @@ a.label:hover,a.label:focus,a.badge:hover,a.badge:focus{color:#ffffff;text-decor
 .header-primary .header-tabs li.active a:link,.header-primary .header-tabs li.active a:visited,.header-primary .header-tabs li.active a:hover,.header-primary .header-tabs li.active a:active{background:none;border-bottom:4px solid #cf402e;margin-bottom:0px;color:#333333;}
 .header-primary .header-tabs li .form-inline{margin:0px;margin-left:14px;margin-bottom:7px;}.header-primary .header-tabs li .form-inline .btn-icon{padding-left:7px;padding-right:7px;}
 .header-primary .header-tabs li .form-inline i{position:relative;top:0px;}
+.header-primary .header-tabs li a.btn{border:1px solid #cccccc;*border:0;border-radius:3px;margin:0px;padding:4px 12px;color:#333333;}.header-primary .header-tabs li a.btn i{position:relative;top:0px;}
+.header-primary .header-tabs li a.btn:visited,.header-primary .header-tabs li a.btn:hover{background-color:#ffffff;border-color:#a6a6a6;}
 html,body{height:100%;}
 #wrap{min-height:100%;height:auto !important;height:100%;margin:0 auto -100px;}#wrap .container-primary{padding-top:20px;padding-bottom:120px;}#wrap .container-primary .page-description{margin-bottom:20px;}
 #wrap .container-primary hr{border:none;border-top:1px solid #eeeeee;}

+ 22 - 0
static/cranefly/css/cranefly/header.less

@@ -144,6 +144,28 @@
           top: 0px;
         }
       }
+
+      & {
+        a.btn {
+          border: 1px solid @btnBorder;
+          *border: 0; // Remove the border to prevent IE7's black border on input:focus
+          border-radius: @baseBorderRadius;
+          margin: 0px;
+          padding: 4px 12px;
+
+          color: @textColor;
+
+          i {
+            position: relative;
+            top: 0px;
+          }
+
+          &:visited, &:hover {
+            background-color: @white;
+            border-color: lighten(@grayLight, 5%);
+          }
+        }
+      }
     }
   }
 }

+ 5 - 0
templates/cranefly/profiles/profile.html

@@ -57,6 +57,11 @@
                 </button>
               </form>
             </li>
+            {% if acl.private_threads.can_start() %}
+            <li class="pull-right">
+              <a href="{% url 'private_thread_start_with' username=profile.username_slug, user=profile.pk %}" class="btn"><i class="icon-envelope"></i> {% trans %}Message{% endtrans %}</a>
+            </li>
+            {% endif %}
             {% endif %}
           </ul>
         </div>