allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [10/16] allura git commit: [#7999] ticket:861 Add confirm step UI skeleton and tests changes
Date Wed, 18 Nov 2015 16:06:09 GMT
[#7999] ticket:861 Add confirm step UI skeleton and tests changes


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

Branch: refs/heads/ib/7999a
Commit: c234c65a3584a592322c314029064f4f8ae75582
Parents: df8fdaa
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Nov 16 16:21:45 2015 +0200
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Wed Nov 18 13:18:21 2015 +0200

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py         | 86 ++++++++++++++------
 .../templates/site_admin_delete_projects.html   | 23 +-----
 .../site_admin_delete_projects_confirm.html     | 30 +++++++
 .../site_admin_delete_projects_form.html        | 51 ++++++++++++
 .../allura/tests/functional/test_site_admin.py  | 54 ++++++++----
 5 files changed, 183 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/c234c65a/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index c74203a..52b3405 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -65,6 +65,7 @@ class SiteAdminController(object):
         self.task_manager = TaskManagerController()
         c.site_admin_sidebar_menu = self.sidebar_menu()
         self.user = AdminUserDetailsController()
+        self.delete_projects = DeleteProjectsController()
 
     def _check_security(self):
         with h.push_context(config.get('site_admin_project', 'allura'),
@@ -320,33 +321,6 @@ class SiteAdminController(object):
         return r
 
     @without_trailing_slash
-    @expose('jinja:allura:templates/site_admin_delete_projects.html')
-    @validate(validators=dict(projects=validators.UnicodeString(if_empty=None),
-                              reason=validators.UnicodeString(if_empty=None),
-                              disable_users=validators.StringBool(if_empty=False)))
-    def delete_projects(self, projects=None, reason=None, disable_users=False, **kw):
-        if request.method == "POST":
-            if not projects:
-                flash(u'No projects specified', 'warning')
-                redirect('delete_projects')
-            provider = ProjectRegistrationProvider.get()
-            projects = projects.split()
-            log.info('Got projects for delete: %s', projects)
-            projects = [provider.project_from_url(p.strip()) for p in projects]
-            projects = [p for p in projects if p]
-            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)
-            if disable_users:
-                task_params = u'--disable-users {}'.format(task_params)
-            DeleteProjects.post(task_params)
-            flash(u'Delete scheduled for %s' % projects, 'ok')
-            redirect('delete_projects')
-        return {'projects': u'\n'.join(projects.split()) if projects else u''}
-
-    @without_trailing_slash
     @expose('jinja:allura:templates/site_admin_search.html')
     @validate(validators=dict(q=validators.UnicodeString(if_empty=None),
                               limit=validators.Int(if_invalid=None),
@@ -363,6 +337,64 @@ class SiteAdminController(object):
         return r
 
 
+class DeleteProjectsController(object):
+    delete_form_validators = dict(
+        projects=validators.UnicodeString(if_empty=None),
+        reason=validators.UnicodeString(if_empty=None),
+        disable_users=validators.StringBool(if_empty=False))
+
+    def remove_comments(self, lines):
+        return [l.split('#', 1)[0] for l in lines]
+
+    def parse_projects(self, projects):
+        provider = ProjectRegistrationProvider.get()
+        projects = projects.splitlines()
+        projects = self.remove_comments(projects)
+        projects = [provider.project_from_url(p.strip()) for p in projects]
+        projects = [p for p in projects if p]
+        return projects
+
+    def format_projects(self, projects):
+        return u'\n'.join(projects.split()) if projects else u''
+
+    @with_trailing_slash
+    @expose('jinja:allura:templates/site_admin_delete_projects.html')
+    @validate(validators=delete_form_validators)
+    def index(self, projects=None, reason=None, disable_users=False, **kw):
+        return {'projects': self.format_projects(projects)}
+
+    @expose('jinja:allura:templates/site_admin_delete_projects_confirm.html')
+    @require_post()
+    @without_trailing_slash
+    @validate(validators=delete_form_validators)
+    def confirm(self, projects=None, reason=None, disable_users=False, **kw):
+        if not projects:
+            flash(u'No projects specified', 'warning')
+            redirect('.')
+        return {'projects': self.format_projects(projects),
+                'reason': reason,
+                'disable_users': disable_users}
+
+    @expose()
+    @require_post()
+    @without_trailing_slash
+    @validate(validators=delete_form_validators)
+    def really_delete(self, projects=None, reason=None, disable_users=False, **kw):
+        if not projects:
+            flash(u'No projects specified', 'warning')
+            redirect('.')
+        projects = self.parse_projects(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)
+        if disable_users:
+            task_params = u'--disable-users {}'.format(task_params)
+        DeleteProjects.post(task_params)
+        flash(u'Delete scheduled for %s' % projects, 'ok')
+        redirect('.')
+
+
 class TaskManagerController(object):
 
     def _check_security(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/c234c65a/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 3f15ec1..428ea6e 100644
--- a/Allura/allura/templates/site_admin_delete_projects.html
+++ b/Allura/allura/templates/site_admin_delete_projects.html
@@ -26,26 +26,9 @@
 
 {% block content %}
   <div class="grid-19">
-    <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" id="delete_projects">
-      <div class="grid-18">
-        <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 id="disable_users" name="disable_users" type="checkbox">
-        <label for="disable_users">Disable all project members</label>
-      </div>
-      <div class="grid-18">
-        <input type="submit" value="Delete">
-      </div>
-      {{lib.csrf_token()}}
-    </form>
+    <p>Put project URLs separated by newline (anything after "#" is considered comment
and ignored)</p>
+    {% set form_step = 'delete' %}
+    {% include 'allura:templates/site_admin_delete_projects_form.html' %}
   </div>
 {% endblock %}
 

http://git-wip-us.apache.org/repos/asf/allura/blob/c234c65a/Allura/allura/templates/site_admin_delete_projects_confirm.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_delete_projects_confirm.html b/Allura/allura/templates/site_admin_delete_projects_confirm.html
new file mode 100644
index 0000000..97360f0
--- /dev/null
+++ b/Allura/allura/templates/site_admin_delete_projects_confirm.html
@@ -0,0 +1,30 @@
+{#-
+       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.
+-#}
+
+{% extends 'allura:templates/site_admin_delete_projects.html' %}
+
+{% block content %}
+  <div class="grid-19">
+    <p class="warning">Be carefull. This will delete all projects data!</p>
+    TODO: Add table with parsed projects and edit button
+    {% set form_step = 'confirm' %}
+    {% include 'allura:templates/site_admin_delete_projects_form.html' %}
+  </div>
+{% endblock %}
+

http://git-wip-us.apache.org/repos/asf/allura/blob/c234c65a/Allura/allura/templates/site_admin_delete_projects_form.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_delete_projects_form.html b/Allura/allura/templates/site_admin_delete_projects_form.html
new file mode 100644
index 0000000..40dbd92
--- /dev/null
+++ b/Allura/allura/templates/site_admin_delete_projects_form.html
@@ -0,0 +1,51 @@
+{#-
+       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 'allura:templates/jinja_master/lib.html' as lib with context %}
+
+{% set action = 'confirm' %}
+{% set submit_text = 'Delete' %}
+{% set fields_visible = True %}
+
+{% if form_step == 'confirm' %}
+  {% set action = 'really_delete' %}
+  {% set submit_text = 'Confirm deletion' %}
+  {% set fields_visible = False %}
+{% endif %}
+
+<form action="{{ action }}" method="POST" id="delete_projects">
+  <div class="{{ '' if fields_visible else 'hidden' }}">
+    <div class="grid-18">
+      <label for="projects">Projects:</label><br>
+      <textarea name="projects">{{ projects or '' }}</textarea>
+    </div>
+    <div class="grid-18">
+      <label for="reason">Reason:</label><br>
+      <textarea name="reason">{{ reason or '' }}</textarea>
+    </div>
+    <div class="grid-18">
+      <input id="disable_users" name="disable_users" type="checkbox" {% if disable_users
%}checked{% endif %}>
+      <label for="disable_users">Disable all project members</label>
+    </div>
+  </div>
+  <div class="grid-18">
+    <input type="submit" value="{{ submit_text }}">
+  </div>
+  {{lib.csrf_token()}}
+</form>

http://git-wip-us.apache.org/repos/asf/allura/blob/c234c65a/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 fed8fa4..fa9de1f 100644
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -567,19 +567,36 @@ To reset your password on %s, please visit the following URL:
 
 class TestDeleteProjects(TestController):
 
-    def form(self, r):
-        return self.find_form(r, lambda f: f.action == 'delete_projects')
+    def confirm_form(self, r):
+        return self.find_form(r, lambda f: f.action == 'really_delete')
+
+    def delete_form(self, r):
+        return self.find_form(r, lambda f: f.action == 'confirm')
 
     def test_projects_populated_from_get_params(self):
-        r = self.app.get('/nf/admin/delete_projects')
-        assert_equal(self.form(r)['projects'].value, u'')
-        r = self.app.get('/nf/admin/delete_projects?projects=/p/test/+/adobe/adobe-1/%20/p/test2/')
-        assert_equal(self.form(r)['projects'].value, u'/p/test/\n/adobe/adobe-1/\n/p/test2/')
+        r = self.app.get('/nf/admin/delete_projects/')
+        assert_equal(self.delete_form(r)['projects'].value, u'')
+        r = self.app.get('/nf/admin/delete_projects/?projects=/p/test/+/adobe/adobe-1/%20/p/test2/')
+        assert_equal(self.delete_form(r)['projects'].value, u'/p/test/\n/adobe/adobe-1/\n/p/test2/')
+
+    def test_confirm_step_values(self):
+        r = self.app.get('/nf/admin/delete_projects/')
+        form = self.delete_form(r)
+        form['projects'] = 'p/test\ndne/dne'
+        form['reason'] = 'The Reason'
+        form['disable_users'] = True
+        r = form.submit()
+        confirm_form = self.confirm_form(r)
+        for f in ['projects', 'reason', 'disable_users']:
+            assert_equal(confirm_form[f].value, form[f].value)
+
+    def test_confirm(self):
+        assert False
 
     @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)
+        r = self.app.get('/nf/admin/confirm/')
+        form = self.confirm_form(r)
         form['projects'] = 'p/test2'
         form['reason'] = 'Because "I can and want"'
         form.submit()
@@ -587,8 +604,8 @@ class TestDeleteProjects(TestController):
 
     @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)
+        r = self.app.get('/nf/admin/confirm/')
+        form = self.confirm_form(r)
         form['projects'] = 'p/test2'
         form['reason'] = 'Because\nI want'
         form.submit()
@@ -596,16 +613,25 @@ class TestDeleteProjects(TestController):
 
     @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)
+        r = self.app.get('/nf/admin/confirm/')
+        form = self.confirm_form(r)
         form['projects'] = '/p/test http://localhost:8080/adobe/adobe-1 p/test2'
         form.submit()
         dp.post.assert_called_once_with('p/test adobe/adobe-1 p/test2')
 
     @patch('allura.controllers.site_admin.DeleteProjects', autospec=True)
+    def test_comments_are_ignored(self, dp):
+        r = self.app.get('/nf/admin/confirm/')
+        form = self.confirm_form(r)
+        form['projects'] = '''/p/test    # comment
+                              /p/test2   # comment 2'''
+        form.submit()
+        dp.post.assert_called_once_with('p/test p/test2')
+
+    @patch('allura.controllers.site_admin.DeleteProjects', autospec=True)
     def test_admins_and_devs_are_disabled(self, dp):
-        r = self.app.get('/nf/admin/delete_projects')
-        form = self.form(r)
+        r = self.app.get('/nf/admin/confirm/')
+        form = self.confirm_form(r)
         form['projects'] = 'p/test p/test2'
         form['disable_users'] = True
         form.submit()


Mime
View raw message