allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [04/17] allura git commit: [#7999] ticket:861 Add confirmation step
Date Wed, 25 Nov 2015 19:37:58 GMT
[#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/f32163ce
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/f32163ce
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/f32163ce

Branch: refs/heads/master
Commit: f32163ce34e02348280282c722aa894ea4788486
Parents: 9fd62fb
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed Nov 18 15:46:24 2015 +0200
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Wed Nov 25 14:37:42 2015 -0500

----------------------------------------------------------------------
 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/f32163ce/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/f32163ce/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/f32163ce/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>


Mime
View raw message