allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [1/8] allura git commit: [#7999] ticket:854 Add delete projects page to nf admin
Date Wed, 04 Nov 2015 17:20:19 GMT
Repository: allura
Updated Branches:
  refs/heads/ib/7999 [created] 094140500


[#7999] ticket:854 Add delete projects page to nf admin


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

Branch: refs/heads/ib/7999
Commit: a184530a4f6ef0bfb4f0bf9557fb5d72f34912f6
Parents: f510201
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Oct 29 15:02:33 2015 +0200
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Mon Nov 2 12:26:33 2015 +0200

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py         | 20 ++++++++
 Allura/allura/lib/plugin.py                     | 15 ++++++
 .../templates/site_admin_delete_projects.html   | 51 ++++++++++++++++++++
 Allura/allura/tests/test_plugin.py              | 10 ++++
 4 files changed, 96 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/a184530a/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 8bcd192..621963c 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -87,6 +87,7 @@ class SiteAdminController(object):
             SitemapEntry('Reclone Repo', base_url + 'reclone_repo', ui_icon=g.icons['admin']),
             SitemapEntry('Task Manager', base_url + 'task_manager?state=busy', ui_icon=g.icons['stats']),
             SitemapEntry('Search Projects', base_url + 'search_projects', ui_icon=g.icons['search']),
+            SitemapEntry('Delete Projects', base_url + 'delete_projects', ui_icon=g.icons['delete']),
             SitemapEntry('Search Users', base_url + 'search_users', ui_icon=g.icons['search']),
         ]
         for ep_name in sorted(g.entry_points['site_admin']):
@@ -317,6 +318,25 @@ 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)))
+    def delete_projects(self, projects=None, **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)
+            # TODO: fire delete project task
+            flash(u'Delete scheduled for %s' % projects, 'ok')
+            redirect('delete_projects')
+        return {}
+
+    @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),

http://git-wip-us.apache.org/repos/asf/allura/blob/a184530a/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 46cd3e8..eb19152 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -26,6 +26,7 @@ import string
 import crypt
 import random
 from urllib2 import urlopen
+from urlparse import urlparse
 from cStringIO import StringIO
 from random import randint
 from hashlib import sha256
@@ -1009,6 +1010,20 @@ class ProjectRegistrationProvider(object):
             (project.url() + 'admin/audit/', 'Audit Trail'),
         ]
 
+    def project_from_url(self, url):
+        '''Return pair where (n, p) parsed from project url
+        where n is neighborhood's url_prefix and p is project's shortname
+
+        Return None if url can't be parsed
+        '''
+        if url is None:
+            return None
+        url = urlparse(url)
+        url = [u for u in url.path.split('/') if u]
+        if len(url) < 2:
+            return None
+        return (u'/{}/'.format(url[0]), url[1])
+
 
 class ThemeProvider(object):
 

http://git-wip-us.apache.org/repos/asf/allura/blob/a184530a/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
new file mode 100644
index 0000000..4b92892
--- /dev/null
+++ b/Allura/allura/templates/site_admin_delete_projects.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.
+-#}
+
+{% set page = 'delete_projects' %}
+
+{% extends 'allura:templates/site_admin.html' %}
+
+{% block title %}Delete Projects{% endblock %}
+{% block header %}Delete Projects{% endblock %}
+
+{% block content %}
+  <div class="grid-19">
+    <p>Put project URLs separated by newline or whitespace</p>
+    <p class="warning">Be carefull. This will delete all projects data!</p>
+    <form action="delete_projects" method="POST">
+      <div class="grid-18">
+        <textarea id="projects-to-delete" name="projects"></textarea>
+      </div>
+      <div class="grid-18">
+        <input type="submit" value="Delete">
+      </div>
+      {{lib.csrf_token()}}
+    </form>
+  </div>
+{% endblock %}
+
+{% block extra_css %}
+<style>
+#projects-to-delete {
+  width: 90%;
+  height: 100px;
+}
+.warning { color: red; }
+</style>
+{% endblock %}

http://git-wip-us.apache.org/repos/asf/allura/blob/a184530a/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 2b8b039..ec20288 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -89,6 +89,16 @@ class TestProjectRegistrationProvider(object):
         Project.query.get.return_value = Mock()
         assert_raises(ProjectConflict, v, 'thisislegit', neighborhood=nbhd)
 
+    def test_project_from_url(self):
+        parse = self.provider.project_from_url
+        assert_is_none(parse(None))
+        assert_is_none(parse(''))
+        assert_is_none(parse('/p/'))
+        assert_equal(('/p/', 'test'), parse('/p/test/'))
+        assert_equal(('/p/', 'test'), parse('/p/test/tickets/1'))
+        assert_equal(('/adobe/', 'adobe-1'), parse('/adobe/adobe-1'))
+        assert_equal(('/p/', 'test'), parse('http://localhost:8080/p/test/wiki'))
+
 
 class UserMock(object):
     def __init__(self):


Mime
View raw message