This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 1311bcadc40643cbe79236aa8ae430e08a6caa3c
Author: Shalitha Suranga <shalithasuranga@gmail.com>
AuthorDate: Tue Aug 6 21:44:42 2019 +0530
[#8285] Add script for notification defaults and other improvements
---
Allura/allura/model/auth.py | 1 +
.../scripts/set_default_user_notifications.py | 56 ++++++++++++++++++++++
Allura/allura/tasks/notification_tasks.py | 3 +-
3 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index e85850f..7188e20 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -690,6 +690,7 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
auth_provider = plugin.AuthenticationProvider.get(request)
user = auth_provider.register_user(doc)
+ user.set_pref('mention_notifications', True)
if user and 'display_name' in doc:
user.set_pref('display_name', doc['display_name'])
if user:
diff --git a/Allura/allura/scripts/set_default_user_notifications.py b/Allura/allura/scripts/set_default_user_notifications.py
new file mode 100644
index 0000000..90bd063
--- /dev/null
+++ b/Allura/allura/scripts/set_default_user_notifications.py
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import absolute_import, division, print_function, unicode_literals
+
+import logging
+import argparse
+
+from ming.orm import session
+from allura.model import main_orm_session, main_explicitflush_orm_session
+
+from allura.scripts import ScriptTask
+from allura import model as M
+from allura.lib.utils import chunked_find
+
+log = logging.getLogger('allura.scripts.set_default_user_notifications')
+
+
+class SetDefaultUserMentions(ScriptTask):
+
+ @classmethod
+ def parser(cls):
+ return argparse.ArgumentParser(description="Set default user notifications option
for existing users. ")
+
+ @classmethod
+ def execute(cls, options):
+ for i, chunk in enumerate(chunked_find(M.User, {})):
+ log.info('Adding default setting for chunk #%s', i)
+ for u in chunk:
+ try:
+ u.set_pref('mention_notifications', True)
+ session(u).flush(u)
+ except Exception:
+ log.exception('Error processing on user %s', u)
+
+ main_orm_session.clear() # AuditLog and User objs
+ main_explicitflush_orm_session.clear() # UserLoginDetails objs, already flushed
individually
+
+ log.info('Finished adding default user notification setting')
+
+
+if __name__ == '__main__':
+ SetDefaultUserMentions.main()
diff --git a/Allura/allura/tasks/notification_tasks.py b/Allura/allura/tasks/notification_tasks.py
index 58a1ab5..e5280b6 100644
--- a/Allura/allura/tasks/notification_tasks.py
+++ b/Allura/allura/tasks/notification_tasks.py
@@ -35,4 +35,5 @@ def send_usermentions_notification(artifact, text, old_text=None):
for username in list(usernames):
u = M.User.by_username(username)
- u.send_user_mention_notification(c.user, artifact)
+ if u.get_pref('mention_notifications'):
+ u.send_user_mention_notification(c.user, artifact)
|