You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/12/13 06:08:14 UTC
[28/45] git commit: [#6888] ticket:495 option to disable the send
message form
[#6888] ticket:495 option to disable the send message form
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/19b00b3b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/19b00b3b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/19b00b3b
Branch: refs/heads/tv/6942
Commit: 19b00b3b4e76dd1df5caef17da306c5b9c481cf7
Parents: 2426f03
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Mon Nov 25 13:00:08 2013 +0400
Committer: Cory Johns <ad...@users.sf.net>
Committed: Thu Dec 12 15:41:40 2013 +0000
----------------------------------------------------------------------
Allura/allura/controllers/auth.py | 6 ++++++
.../ext/user_profile/templates/user_index.html | 2 +-
Allura/allura/ext/user_profile/user_main.py | 4 ++++
Allura/allura/model/auth.py | 1 +
Allura/allura/templates/user_prefs.html | 12 ++++++++++++
Allura/allura/tests/functional/test_auth.py | 8 ++++++++
Allura/allura/tests/functional/test_user_profile.py | 16 ++++++++++++++++
7 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19b00b3b/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index d945394..7a58eda 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -507,6 +507,12 @@ class PreferencesController(BaseController):
flash('Key uploaded')
redirect('.')
+ @expose()
+ @require_post()
+ def user_message(self, allow_user_message=None):
+ c.user.allow_user_message = allow_user_message is not None
+ redirect(request.referer)
+
class UserInfoController(BaseController):
def __init__(self, *args, **kwargs):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19b00b3b/Allura/allura/ext/user_profile/templates/user_index.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/user_profile/templates/user_index.html b/Allura/allura/ext/user_profile/templates/user_index.html
index e3f2833..f3639d1 100644
--- a/Allura/allura/ext/user_profile/templates/user_index.html
+++ b/Allura/allura/ext/user_profile/templates/user_index.html
@@ -229,7 +229,7 @@
</div>
{% endif %}
- {% if user.get_pref('email_address') and c.user.get_pref('email_address') %}
+ {% if user.get_pref('email_address') and c.user.get_pref('email_address') and user.allow_user_message %}
<div class="grid-24">
<b><a href="send_message">Send me a message</a></b>
</div>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19b00b3b/Allura/allura/ext/user_profile/user_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/user_profile/user_main.py b/Allura/allura/ext/user_profile/user_main.py
index 4666e35..c57fb60 100644
--- a/Allura/allura/ext/user_profile/user_main.py
+++ b/Allura/allura/ext/user_profile/user_main.py
@@ -107,6 +107,10 @@ class UserProfileController(BaseController, FeedController):
'an email address associated with their account.', 'info')
redirect(request.referer)
+ if not to_user.allow_user_message:
+ flash('This user has disabled user message', 'info')
+ redirect(request.referer)
+
@expose('jinja:allura.ext.user_profile:templates/user_index.html')
def index(self, **kw):
user = c.project.user_project_of
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19b00b3b/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index d1f5b7f..f7a8705 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -353,6 +353,7 @@ class User(MappedClass, ActivityNode, ActivityObject):
#Statistics
stats_id = FieldProperty(S.ObjectId, if_missing=None)
+ allow_user_message = FieldProperty(bool, if_missing=True)
def can_send_user_message(self):
"""Return true if User is permitted to send a mesage to another user.
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19b00b3b/Allura/allura/templates/user_prefs.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_prefs.html b/Allura/allura/templates/user_prefs.html
index 3185747..6f9e155 100644
--- a/Allura/allura/templates/user_prefs.html
+++ b/Allura/allura/templates/user_prefs.html
@@ -158,4 +158,16 @@
</form>
</div>
{% endif %}
+<div class="grid-20">
+ <h2>User Messages</h2>
+ <form method="POST" action="user_message">
+ <div class="grid-19">
+ <input type="checkbox" id="allow_user_message" name="allow_user_message" {% if c.user.allow_user_message %} checked {% endif %}>
+ <label for="allow_user_message">Allow user messages</label>
+ </div>
+ <label class="grid-4"> </label>
+ <div class="grid-19">
+ <input class="submit" type="submit" value="Save">
+ </div>
+</div>
{% endblock %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19b00b3b/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 4bb106d..cad16dd 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -712,6 +712,14 @@ class TestPreferences(TestController):
user = M.User.query.get(username='test-admin')
assert len(user.skills) == 0
+ @td.with_user_project('test-admin')
+ def test_user_message(self):
+ assert M.User.query.get(username='test-admin').allow_user_message
+ self.app.post('/auth/preferences/user_message')
+ assert not M.User.query.get(username='test-admin').allow_user_message
+ self.app.post('/auth/preferences/user_message', params={'allow_user_message': 'on'})
+ assert M.User.query.get(username='test-admin').allow_user_message
+
class TestPasswordReset(TestController):
@patch('allura.tasks.mail_tasks.sendmail')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19b00b3b/Allura/allura/tests/functional/test_user_profile.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_user_profile.py b/Allura/allura/tests/functional/test_user_profile.py
index 5fb23cd..fae35e5 100644
--- a/Allura/allura/tests/functional/test_user_profile.py
+++ b/Allura/allura/tests/functional/test_user_profile.py
@@ -132,3 +132,19 @@ class TestUserProfile(TestController):
status=200)
assert '<a href="send_message">Send me a message</a>' not in r
+
+ @td.with_user_project('test-user')
+ def test_allow_user_message(self):
+ User.by_username('test-admin').set_pref('email_address', 'admin@example.com')
+ test_user = User.by_username('test-user')
+ test_user.set_pref('email_address', 'user@example.com')
+ test_user.allow_user_message = False
+ r = self.app.get('/u/test-user/profile')
+ assert '<a href="send_message">Send me a message</a>' not in r
+ r = self.app.get('/u/test-user/profile/send_message', status=302)
+ assert 'This user has disabled user message' in self.webflash(r)
+
+
+
+
+