You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/11/18 17:06:11 UTC

[12/16] allura git commit: [#7999] ticket:861 Add confirmation step

[#7999] ticket:861 Add confirmation step


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

Branch: refs/heads/ib/7999a
Commit: 283d525bb1054612e3005ca61609cb7f7aa05170
Parents: 3b99161
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Nov 18 15:46:24 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Wed Nov 18 15:46:24 2015 +0200

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py         | 42 +++++++++++++++-----
 .../templates/site_admin_delete_projects.html   |  1 +
 .../site_admin_delete_projects_confirm.html     | 26 +++++++++++-
 3 files changed, 57 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/283d525b/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 52b3405..4776dd5 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -347,21 +347,32 @@ class DeleteProjectsController(object):
         return [l.split('#', 1)[0] for l in lines]
 
     def parse_projects(self, projects):
+        """Takes projects from user input and returns a list of tuples (input, project, error)"""
         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''
+        parsed_projects = []
+        for input in projects:
+            if input.strip():
+                p, error = provider.project_from_url(input.strip())
+                parsed_projects.append((input, p, error))
+        return parsed_projects
+
+    def format_parsed_projects(self, projects):
+        template = u'{}    # {}'
+        lines = []
+        for input, p, error in projects:
+            comment = u'OK: {}'.format(p.url()) if p else error
+            lines.append(template.format(input, comment))
+        return u'\n'.join(lines)
 
     @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)}
+        return {'projects': projects,
+                'reason': reason,
+                'disable_users': disable_users}
 
     @expose('jinja:allura:templates/site_admin_delete_projects_confirm.html')
     @require_post()
@@ -371,7 +382,15 @@ class DeleteProjectsController(object):
         if not projects:
             flash(u'No projects specified', 'warning')
             redirect('.')
-        return {'projects': self.format_projects(projects),
+        parsed_projects = self.parse_projects(projects)
+        projects = self.format_parsed_projects(parsed_projects)
+        edit_link = u'./?projects={}&reason={}&disable_users={}'.format(
+            h.urlquoteplus(projects),
+            h.urlquoteplus(reason),
+            h.urlquoteplus(disable_users))
+        return {'projects': projects,
+                'parsed_projects': parsed_projects,
+                'edit_link': edit_link,
                 'reason': reason,
                 'disable_users': disable_users}
 
@@ -384,14 +403,17 @@ class DeleteProjectsController(object):
             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'{}/{}'.format(p.neighborhood.url_prefix.strip('/'), p.shortname) for (_, p, _) in projects if p]
+        if not task_params:
+            flash(u'Unable to parse at least one project from your input', 'warning')
+            redirect('.')
         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')
+        flash(u'Delete scheduled', 'ok')
         redirect('.')
 
 

http://git-wip-us.apache.org/repos/asf/allura/blob/283d525b/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 428ea6e..1b1db94 100644
--- a/Allura/allura/templates/site_admin_delete_projects.html
+++ b/Allura/allura/templates/site_admin_delete_projects.html
@@ -39,5 +39,6 @@
   height: 100px;
 }
 .warning { color: red; }
+.pad table { width: 98%; }
 </style>
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/allura/blob/283d525b/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
index 97360f0..628028e 100644
--- a/Allura/allura/templates/site_admin_delete_projects_confirm.html
+++ b/Allura/allura/templates/site_admin_delete_projects_confirm.html
@@ -21,8 +21,30 @@
 
 {% 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
+    <p class="warning">Be careful. This will delete all projects data!</p>
+    <p>You're trying to delete the following projects {% if disable_users %} and <strong>disable all projects' users</strong>{% endif %}</p>
+    <p>Because of: {{ reason }}</p>
+    <p><a href="{{ edit_link }}">Edit</a></p>
+    <table>
+      <thead>
+      <tr>
+        <th>Your input</th>
+        <th>Parsed project</th>
+      </tr>
+      </thead>
+      {% for input, p, error in parsed_projects %}
+      <tr>
+        <td>{{ input }}</td>
+        <td>
+          {% if p %}
+            <a href="{{ p.url() }}">{{ p.url() }}</a>
+          {% else %}
+            {{ error }}
+          {% endif %}
+        </td>
+      </tr>
+      {% endfor %}
+    </table>
     {% set form_step = 'confirm' %}
     {% include 'allura:templates/site_admin_delete_projects_form.html' %}
   </div>