You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by he...@apache.org on 2015/04/01 23:10:22 UTC

[05/45] allura git commit: [#7833] ticket:741 Added script for trimming user emails

[#7833] ticket:741 Added script for trimming user emails


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/27f9c9ff
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/27f9c9ff
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/27f9c9ff

Branch: refs/heads/hss/7072
Commit: 27f9c9fff47dd4ff9bca68198d93a8c32270ab88
Parents: c2673b6
Author: Aleksey 'LXj' Alekseyev <go...@gmail.com>
Authored: Wed Mar 11 23:28:02 2015 +0200
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Thu Mar 19 18:37:45 2015 +0000

----------------------------------------------------------------------
 Allura/allura/scripts/trim_emails.py | 44 +++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/27f9c9ff/Allura/allura/scripts/trim_emails.py
----------------------------------------------------------------------
diff --git a/Allura/allura/scripts/trim_emails.py b/Allura/allura/scripts/trim_emails.py
new file mode 100644
index 0000000..0ce4caa
--- /dev/null
+++ b/Allura/allura/scripts/trim_emails.py
@@ -0,0 +1,44 @@
+#       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.
+
+import logging
+
+from allura.scripts import ScriptTask
+from allura import model as M
+from allura.lib.utils import chunked_find
+
+
+log = logging.getLogger(__name__)
+
+
+class TrimEmails(ScriptTask):
+
+    @classmethod
+    def execute(cls, options):
+        for chunk in chunked_find(M.User, {}):
+            for u in chunk:
+                log.info('Trimming emails for user %s', u.username)
+                new_addresses = [M.EmailAddress.canonical(addr) for addr in u.email_addresses]
+                u.email_addresses = new_addresses
+                if u.preferences.email_address is not None:
+                    u.preferences.email_address = M.EmailAddress.canonical(
+                        u.preferences.email_address)
+        log.info('Finished trimming emails')
+
+
+if __name__ == '__main__':
+    TrimEmails.main()