incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [06/50] git commit: [#3154] ticket:386 Notify user when export finished
Date Wed, 21 Aug 2013 20:12:22 GMT
[#3154] ticket:386 Notify user when export finished


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

Branch: refs/heads/db/3154b
Commit: 01390e5ed0d736c63976eacd597cd7113d90b938
Parents: 845e642
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Jul 4 17:28:24 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Aug 21 18:12:22 2013 +0000

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py         |  2 +-
 Allura/allura/tasks/export_tasks.py           | 29 +++++++++++++++++++++-
 Allura/allura/templates/mail/bulk_export.html | 29 ++++++++++++++++++++++
 Allura/allura/tests/functional/test_admin.py  | 15 ++++++++---
 Allura/allura/tests/test_tasks.py             | 21 ++++++++++++----
 Allura/development.ini                        |  1 +
 Allura/test.ini                               |  1 +
 7 files changed, 87 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/01390e5e/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index ee59e1d..ca55645 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -649,7 +649,7 @@ class ProjectAdminController(BaseController):
             if c.project.bulk_export_status() == 'busy':
                 flash('Export for project %s already running' % c.project.shortname, 'info')
                 redirect('export')
-            export_tasks.bulk_export.post(c.project.shortname, tools)
+            export_tasks.bulk_export.post(c.project.shortname, tools, c.user.username)
             flash('Export scheduled', 'ok')
             redirect('export')
         return {

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/01390e5e/Allura/allura/tasks/export_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py
index 64aee3f..d097205 100644
--- a/Allura/allura/tasks/export_tasks.py
+++ b/Allura/allura/tasks/export_tasks.py
@@ -19,8 +19,13 @@ import os
 import logging
 import shutil
 
+import tg
+from pylons import app_globals as g
+
 from allura import model as M
+from allura.tasks import mail_tasks
 from allura.lib.decorators import task
+from allura.lib import helpers as h
 from allura.model.repository import zipdir
 
 
@@ -28,7 +33,7 @@ log = logging.getLogger(__name__)
 
 
 @task
-def bulk_export(project_shortname, tools):
+def bulk_export(project_shortname, tools, username):
     project = M.Project.query.get(shortname=project_shortname)
     if not project:
         log.error('Project %s not found' % project_shortname)
@@ -58,6 +63,28 @@ def bulk_export(project_shortname, tools):
     except:
         log.error('Something went wrong during zipping exported data.', exc_info=True)
 
+    user = M.User.by_username(username)
+    if not user:
+        log.info('Can not find user %s. Skipping notification.' % username)
+        return
+    tmpl = g.jinja2_env.get_template('allura:templates/mail/bulk_export.html')
+    instructions = tg.config.get('bulk_export_download_instructions', '')
+    instructions = instructions.format(project=project.shortname)
+    tmpl_context = {
+        'instructions': instructions,
+        'project': project,
+        'tools': tools,
+    }
+    email = {
+        'fromaddr': unicode(user.email_address_header()),
+        'reply_to': unicode(user.email_address_header()),
+        'message_id': h.gen_message_id(),
+        'destinations': [unicode(user._id)],
+        'subject': u'Bulk export for project %s completed' % project_shortname,
+        'text': tmpl.render(tmpl_context),
+    }
+    mail_tasks.sendmail.post(**email)
+
 
 def create_export_dir(project):
     """Create temporary directory for export files"""

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/01390e5e/Allura/allura/templates/mail/bulk_export.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/mail/bulk_export.html b/Allura/allura/templates/mail/bulk_export.html
new file mode 100644
index 0000000..420848f
--- /dev/null
+++ b/Allura/allura/templates/mail/bulk_export.html
@@ -0,0 +1,29 @@
+{#
+       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.
+#}
+
+Bulk export for project {{ project.shortname }} is completed.
+
+Following tools was exported:
+{% for tool in tools %}
+- {{ tool }}
+{% endfor %}
+
+Follow instructions below to get exported data.
+
+{{ instructions }}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/01390e5e/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 8e205b5..774fd36 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -820,26 +820,33 @@ class TestExport(TestController):
         r = self.app.post('/admin/export', {'tools': u'wiki'})
         assert_in('ok', self.webflash(r))
         export_tasks.bulk_export.post.assert_called_once_with(
-            'test', [u'wiki'])
+            'test', [u'wiki'], u'test-admin')
 
     @mock.patch('allura.ext.admin.admin_main.export_tasks')
     def test_selected_multiple_tools(self, export_tasks):
         r = self.app.post('/admin/export', {'tools': [u'wiki', u'wiki2']})
         assert_in('ok', self.webflash(r))
         export_tasks.bulk_export.post.assert_called_once_with(
-            'test', [u'wiki', u'wiki2'])
+            'test', [u'wiki', u'wiki2'], u'test-admin')
 
     @patch('allura.ext.admin.admin_main.export_tasks')
     def test_export_in_progress(self, export_tasks):
         p = M.Project.query.get(shortname='test')
         tmpdir = os.path.join(p.bulk_export_path(), p.shortname)
-        shutil.rmtree(tmpdir, ignore_errors=True)
+        shutil.rmtree(p.bulk_export_path(), ignore_errors=True)
         os.makedirs(tmpdir)
         r = self.app.post('/admin/export', {'tools': [u'wiki', u'wiki2']})
         assert_in('info', self.webflash(r))
         assert_equals(export_tasks.bulk_export.post.call_count, 0)
-        shutil.rmtree(tmpdir, ignore_errors=True)
+        shutil.rmtree(p.bulk_export_path(), ignore_errors=True)
 
     def test_export_done(self):
+        p = M.Project.query.get(shortname='test')
+        shutil.rmtree(p.bulk_export_path(), ignore_errors=True)
+        os.makedirs(p.bulk_export_path())
+        fn = os.path.join(p.bulk_export_path(), p.bulk_export_filename())
+        with open(fn, 'w') as f:
+            f.write('Pretending I am zip archive')
         r = self.app.get('/admin/export')
         assert_in('<h2>Careful!</h2>', r)
+        shutil.rmtree(p.bulk_export_path(), ignore_errors=True)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/01390e5e/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 5f2e44c..39c3397 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -342,12 +342,12 @@ class TestExportTasks(unittest.TestCase):
 
     @mock.patch('allura.tasks.export_tasks.log')
     def test_bulk_export_invalid_project(self, log):
-        export_tasks.bulk_export('bad', [u'wiki'])
+        export_tasks.bulk_export('bad', [u'wiki'], 'test-admin')
         log.error.assert_called_once_with('Project bad not found')
 
     @mock.patch('allura.tasks.export_tasks.log')
     def test_bulk_export_invalid_tool(self, log):
-        export_tasks.bulk_export('test', [u'bugs', u'blog'])
+        export_tasks.bulk_export('test', [u'bugs', u'blog'], 'test-admin')
         assert_equal(log.info.call_count, 2)
         assert_equal(log.info.call_args_list, [
             mock.call('Can not load app for bugs mount point. Skipping.'),
@@ -357,7 +357,7 @@ class TestExportTasks(unittest.TestCase):
     @td.with_tool('test', 'Tickets', 'bugs')
     @td.with_tool('test', 'Blog', 'blog')
     def test_bulk_export_not_exportable_tool(self, log):
-        export_tasks.bulk_export('test', [u'bugs', u'blog'])
+        export_tasks.bulk_export('test', [u'bugs', u'blog'], 'test-admin')
         assert_equal(log.info.call_count, 2)
         assert_equal(log.info.call_args_list, [
             mock.call('Tool bugs is not exportable. Skipping.'),
@@ -369,7 +369,8 @@ class TestExportTasks(unittest.TestCase):
     @mock.patch('allura.tasks.export_tasks.log')
     @td.with_wiki
     def test_bulk_export(self, log, wiki_bulk_export, zipdir, shutil):
-        export_tasks.bulk_export('test', [u'wiki'])
+        M.MonQTask.query.remove()
+        export_tasks.bulk_export('test', [u'wiki'], 'test-admin')
         assert_equal(log.info.call_count, 1)
         assert_equal(log.info.call_args_list, [
             mock.call('Exporting wiki...')])
@@ -379,6 +380,16 @@ class TestExportTasks(unittest.TestCase):
         zipdir.assert_caled_once_with(temp, temp + '/test.zip')
         shutil.move.assert_called_once_with(temp + '/test.zip',  zipfn)
         shutil.rmtree.assert_called_once_with(temp)
+        # check notification
+        M.MonQTask.run_ready()
+        tasks = M.MonQTask.query.find(
+            dict(task_name='allura.tasks.mail_tasks.sendmail')).all()
+        assert_equal(len(tasks), 1)
+        assert_equal(tasks[0].kwargs['subject'], 'Bulk export for project test completed')
+        text = tasks[0].kwargs['text']
+        assert_in('Bulk export for project test is completed.', text)
+        assert_in('Following tools was exported:\n\n- wiki', text)
+        assert_in('Sample instructions for test', text)
 
     @mock.patch('forgewiki.wiki_main.ForgeWikiApp.bulk_export')
     @mock.patch('allura.tasks.export_tasks.log')
@@ -387,7 +398,7 @@ class TestExportTasks(unittest.TestCase):
         project = M.Project.query.get(shortname='test')
         export_tasks.create_export_dir(project)
         assert_equal(project.bulk_export_status(), 'busy')
-        export_tasks.bulk_export('test', [u'wiki'])
+        export_tasks.bulk_export('test', [u'wiki'], 'test-admin')
         log.info.assert_called_once_with('Another export is running for project test. Skipping.')
         assert_equal(wiki_bulk_export.call_count, 0)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/01390e5e/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index 6fe2e6e..0d3386b 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -143,6 +143,7 @@ scm.repos.tarball.url_prefix = http://localhost/
 scm.repos.tarball.zip_binary = /usr/bin/zip
 
 bulk_export_path = /tmp/bulk_export/{nbhd}/{project}
+bulk_export_download_instructions = Sample instructions for {project}
 
 # space-separated list of tool names that are valid options
 # for project admins to set for their 'support_page' field

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/01390e5e/Allura/test.ini
----------------------------------------------------------------------
diff --git a/Allura/test.ini b/Allura/test.ini
index 6babfaf..9ce586e 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -103,6 +103,7 @@ scm.repos.tarball.root = /tmp/tarball
 scm.repos.tarball.url_prefix = file://
 
 bulk_export_path = /tmp/bulk_export/{nbhd}/{project}
+bulk_export_download_instructions = Sample instructions for {project}
 
 support_tool_choices = wiki tickets discussion
 


Mime
View raw message