allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [6/8] allura git commit: [#7999] ticket:856 Include reason
Date Wed, 04 Nov 2015 17:20:24 GMT
[#7999] ticket:856 Include reason


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

Branch: refs/heads/ib/7999
Commit: 805aac258348453f16ed48d9070caef279bd3d1f
Parents: e38fa84
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Nov 2 18:21:48 2015 +0200
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Wed Nov 4 11:30:39 2015 +0200

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py           |  8 ++++++--
 Allura/allura/scripts/delete_projects.py          |  7 +++++--
 .../templates/site_admin_delete_projects.html     | 13 +++++++++----
 Allura/allura/tests/functional/test_site_admin.py | 18 ++++++++++++++++++
 Allura/allura/tests/test_delete_projects.py       | 15 ++++++++++++++-
 5 files changed, 52 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/805aac25/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 5587148..cec6b3a 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -18,6 +18,7 @@
 import re
 import logging
 from datetime import datetime, timedelta
+import pipes
 
 from tg import expose, validate, flash, config, redirect
 from tg.decorators import with_trailing_slash, without_trailing_slash
@@ -320,8 +321,9 @@ class SiteAdminController(object):
 
     @without_trailing_slash
     @expose('jinja:allura:templates/site_admin_delete_projects.html')
-    @validate(validators=dict(projects=validators.UnicodeString(if_empty=None)))
-    def delete_projects(self, projects=None, **kw):
+    @validate(validators=dict(projects=validators.UnicodeString(if_empty=None),
+                              reason=validators.UnicodeString(if_empty=None)))
+    def delete_projects(self, projects=None, reason=None, **kw):
         if request.method == "POST":
             if not projects:
                 flash(u'No projects specified', 'warning')
@@ -334,6 +336,8 @@ class SiteAdminController(object):
             log.info('Parsed projects: %s', projects)
             task_params = [u'{}/{}'.format(n.strip('/'), p) for (n, p) in projects]
             task_params = u' '.join(task_params)
+            if reason:
+                task_params = u'-r {} {}'.format(pipes.quote(reason), task_params)
             DeleteProjects.post(task_params)
             flash(u'Delete scheduled for %s' % projects, 'ok')
             redirect('delete_projects')

http://git-wip-us.apache.org/repos/asf/allura/blob/805aac25/Allura/allura/scripts/delete_projects.py
----------------------------------------------------------------------
diff --git a/Allura/allura/scripts/delete_projects.py b/Allura/allura/scripts/delete_projects.py
index 23b144a..0cd1ca8 100644
--- a/Allura/allura/scripts/delete_projects.py
+++ b/Allura/allura/scripts/delete_projects.py
@@ -36,8 +36,10 @@ class DeleteProjects(ScriptTask):
         for proj in options.projects:
             proj = cls.get_project(proj)
             if proj:
-                log.info('Purging %s%s', proj.neighborhood.url_prefix, proj.shortname)
+                log.info('Purging %s%s. Reason: %s', proj.neighborhood.url_prefix, proj.shortname,
options.reason)
+                pid = proj._id
                 cls.purge_project(proj)
+                g.post_event('project_deleted', project_id=pid, reason=options.reason)
 
     @classmethod
     def get_project(cls, proj):
@@ -67,13 +69,14 @@ class DeleteProjects(ScriptTask):
                 cls.query.remove(dict(app_config_id={'$in': app_config_ids}))
         project.delete()
         session(project).flush()
-        g.post_event('project_deleted', project_id=pid)
 
     @classmethod
     def parser(cls):
         parser = argparse.ArgumentParser(description='Completely delete projects')
         parser.add_argument('projects', metavar='nbhd/project', type=str, nargs='+',
                             help='Project to delete in a form nbhd_prefix/shortname')
+        parser.add_argument('-r', '--reason', type=str,
+                            help='Reason why these projects being deleted')
         return parser
 
 

http://git-wip-us.apache.org/repos/asf/allura/blob/805aac25/Allura/allura/templates/site_admin_delete_projects.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_delete_projects.html b/Allura/allura/templates/site_admin_delete_projects.html
index ddf85b9..bae6a05 100644
--- a/Allura/allura/templates/site_admin_delete_projects.html
+++ b/Allura/allura/templates/site_admin_delete_projects.html
@@ -26,11 +26,16 @@
 
 {% block content %}
   <div class="grid-19">
-    <p>Put project URLs separated by newline or whitespace</p>
+    <p>Put project URLs separated by newline or whitespace below</p>
     <p class="warning">Be carefull. This will delete all projects data!</p>
-    <form action="delete_projects" method="POST">
+    <form action="delete_projects" method="POST" id="delete_projects">
       <div class="grid-18">
-        <textarea id="projects-to-delete" name="projects">{{ projects }}</textarea>
+        <label for="projects">Projects:</label><br>
+        <textarea name="projects">{{ projects }}</textarea>
+      </div>
+      <div class="grid-18">
+        <label for="reason">Reason:</label><br>
+        <textarea name="reason"></textarea>
       </div>
       <div class="grid-18">
         <input type="submit" value="Delete">
@@ -42,7 +47,7 @@
 
 {% block extra_css %}
 <style>
-#projects-to-delete {
+#delete_projects textarea {
   width: 90%;
   height: 100px;
 }

http://git-wip-us.apache.org/repos/asf/allura/blob/805aac25/Allura/allura/tests/functional/test_site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_site_admin.py b/Allura/allura/tests/functional/test_site_admin.py
index 0918a0f..f6c1a31 100644
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -577,6 +577,24 @@ class TestDeleteProjects(TestController):
         assert_equal(self.form(r)['projects'].value, u'/p/test/\n/adobe/adobe-1/\n/p/test2/')
 
     @patch('allura.controllers.site_admin.DeleteProjects', autospec=True)
+    def test_reason_passed_to_task(self, dp):
+        r = self.app.get('/nf/admin/delete_projects')
+        form = self.form(r)
+        form['projects'] = 'p/test2'
+        form['reason'] = 'Because "I can and want"'
+        form.submit()
+        dp.post.assert_called_once_with('-r \'Because "I can and want"\' p/test2')
+
+    @patch('allura.controllers.site_admin.DeleteProjects', autospec=True)
+    def test_multiline_reason_passed_to_task(self, dp):
+        r = self.app.get('/nf/admin/delete_projects')
+        form = self.form(r)
+        form['projects'] = 'p/test2'
+        form['reason'] = 'Because\nI want'
+        form.submit()
+        dp.post.assert_called_once_with('-r \'Because\nI want\' p/test2')
+
+    @patch('allura.controllers.site_admin.DeleteProjects', autospec=True)
     def test_task_fires(self, dp):
         r = self.app.get('/nf/admin/delete_projects')
         form = self.form(r)

http://git-wip-us.apache.org/repos/asf/allura/blob/805aac25/Allura/allura/tests/test_delete_projects.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_delete_projects.py b/Allura/allura/tests/test_delete_projects.py
index 466fe80..f8cc62e 100644
--- a/Allura/allura/tests/test_delete_projects.py
+++ b/Allura/allura/tests/test_delete_projects.py
@@ -78,4 +78,17 @@ class TestDeleteProjects(TestController):
     def test_event_is_fired(self, post_event):
         pid = M.Project.query.get(shortname=self.p_shortname)._id
         self.run_script(['p/{}'.format(self.p_shortname)])
-        post_event.assert_called_once_with('project_deleted', project_id=pid)
+        post_event.assert_called_once_with('project_deleted', project_id=pid, reason=None)
+
+    @patch.object(delete_projects.g, 'post_event', autospec=True)
+    @patch('allura.scripts.delete_projects.log', autospec=True)
+    def test_delete_with_reason(self, log, post_event):
+        p = M.Project.query.get(shortname=self.p_shortname)
+        pid = p._id
+        assert p is not None, 'Can not find project to delete'
+        self.run_script(['-r', 'The Reason', 'p/{}'.format(p.shortname)])
+        session(p).expunge(p)
+        p = M.Project.query.get(shortname=p.shortname)
+        assert p is None, 'Project is not deleted'
+        log.info.assert_called_once_with('Purging %s%s. Reason: %s', '/p/', 'test-delete',
'The Reason')
+        post_event.assert_called_once_with('project_deleted', project_id=pid, reason='The
Reason')


Mime
View raw message