Browse Source

#477: display "message" button in user profile.

Rafał Pitoń 10 years ago
parent
commit
868c47ebea
2 changed files with 22 additions and 0 deletions
  1. 13 0
      misago/templates/misago/profile/header.html
  2. 9 0
      misago/users/views/profile.py

+ 13 - 0
misago/templates/misago/profile/header.html

@@ -14,6 +14,18 @@
 
 {% if user.is_authenticated %}
 <div class="page-actions">
+  {% if can_message %}
+  <button class="btn btn-default btn-message pull-left">
+    <span class="fa fa-envelope-o"></span>
+    {% trans "Message" %}
+  </button>
+  {% elif not is_authenticated_user %}
+  <button class="btn btn-default tooltip-bottom" disabled="disabled" title="{{ cant_message_reason }}">
+    <span class="fa fa-envelope-o"></span>
+    {% trans "Message" %}
+  </button>
+  {% endif %}
+
   {% if profile.acl_.can_follow %}
   <form action="{% url 'misago:follow_user' user_slug=profile.slug user_id=profile.id %}" method="POST" class="pull-left dynamic-button">
     {% csrf_token %}
@@ -23,6 +35,7 @@
     </button>
   </form>
   {% endif %}
+
   {% if profile.acl_.can_block %}
   <form action="{% url 'misago:block_user' user_slug=profile.slug user_id=profile.id %}" method="POST" class="pull-left dynamic-button">
     {% csrf_token %}

+ 9 - 0
misago/users/views/profile.py

@@ -1,5 +1,6 @@
 from django.contrib import messages
 from django.contrib.auth import get_user_model
+from django.core.exceptions import PermissionDenied
 from django.core.urlresolvers import reverse
 from django.db.transaction import atomic
 from django.http import Http404, JsonResponse
@@ -11,6 +12,7 @@ from misago.core.decorators import require_POST
 from misago.core.shortcuts import get_object_or_404, paginate, validate_slug
 from misago.core.utils import clean_return_path
 from misago.notifications import notify_user, read_user_notification
+from misago.threads.permissions import allow_message_user
 
 from misago.users.bans import get_user_ban
 from misago.users.decorators import deny_guests
@@ -104,6 +106,13 @@ def render(request, template, context):
 
     context['state'] = get_user_state(context['profile'], user_acl)
 
+    if request.user.is_authenticated():
+        try:
+            context['can_message'] = True
+        except PermissionDenied as e:
+            context['can_message'] = False
+            context['cant_message_reason'] = unicode(e)
+
     return django_render(request, template, context)