allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shalithasura...@apache.org
Subject [allura] 02/02: [#8285] Implement an option to manage user mention notifications
Date Sun, 28 Jul 2019 15:40:13 GMT
This is an automated email from the ASF dual-hosted git repository.

shalithasuranga pushed a commit to branch ss/8285
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 8b899c691ee9e06d014f9a1a09ec18f305b03723
Author: Shalitha Suranga <shalithasuranga@gmail.com>
AuthorDate: Sun Jul 28 21:08:57 2019 +0530

    [#8285] Implement an option to manage user mention notifications
---
 Allura/allura/controllers/auth.py           |  6 ++++++
 Allura/allura/model/auth.py                 |  1 +
 Allura/allura/templates/user_subs.html      | 12 ++++++++++++
 Allura/allura/tests/functional/test_auth.py | 16 ++++++++++++++++
 4 files changed, 35 insertions(+)

diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index f21b3be..057a8d8 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -1219,6 +1219,12 @@ class SubscriptionsController(BaseController):
 
         redirect(request.referer or '/')
 
+    @expose()
+    @require_post()
+    def update_user_notifications(self, allow_umnotif=False):
+        c.user.set_pref('mention_notifications', allow_umnotif and True or False)
+        redirect(request.referer or '/')
+
 
 class OAuthController(BaseController):
 
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 5df5261..a53f8c6 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -253,6 +253,7 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
         email_address=str,
         email_format=str,
         disable_user_messages=bool,
+        mention_notifications=bool,
         multifactor=bool,
     ))
     # Additional top-level fields can/should be accessed with get/set_pref also
diff --git a/Allura/allura/templates/user_subs.html b/Allura/allura/templates/user_subs.html
index b49e85c..82e7491 100644
--- a/Allura/allura/templates/user_subs.html
+++ b/Allura/allura/templates/user_subs.html
@@ -35,4 +35,16 @@
     <p>No subscriptions.</p>
   {% endif %}
 
+  <h2>User notifications</h2>
+  <form method="POST" action="update_user_notifications">
+  <div class="grid-10">
+      <input type="checkbox" id="allow_umnotif" name="allow_umnotif" {% if c.user.get_pref('mention_notifications')
%} checked {% endif %}>
+      <label for="allow_umnotif">Send a notification via e-mail if my username is mentioned
in somewhere</label>
+  </div>
+  <div class="grid-2">
+      <input class="submit" type="submit" value="Save">
+  </div>
+  {{ lib.csrf_token() }}
+  </form>
+  
 {% endblock %}
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 3578231..b8066b6 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -786,6 +786,22 @@ class TestAuth(TestController):
                     else:
                         assert str(ac._id) in r, "Page doesn't list tool %s" % ac.tool_name
 
+
+    @td.with_user_project('test-admin')
+    def test_update_user_notifications(self):
+        self.app.get('/').follow()  # establish session
+        assert not M.User.query.get(username='test-admin').get_pref('mention_notifications')
+        self.app.post('/auth/subscriptions/update_user_notifications',
+                      params={'_session_id': self.app.cookies['_session_id'],
+                              })
+        assert not M.User.query.get(username='test-admin').get_pref('mention_notifications')
+        self.app.post('/auth/subscriptions/update_user_notifications',
+                      params={'allow_umnotif': 'on',
+                              '_session_id': self.app.cookies['_session_id'],
+                              })
+        assert M.User.query.get(username='test-admin').get_pref('mention_notifications')
+
+
     def _find_subscriptions_form(self, r):
         form = None
         for f in r.forms.itervalues():


Mime
View raw message