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:05 UTC
[06/16] allura git commit: [#7999] ticket:854 Add delete projects
page to nf admin
[#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/d457e586
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/d457e586
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/d457e586
Branch: refs/heads/ib/7999a
Commit: d457e586bf59b4b4c85d496d47d0c99eb7d44cee
Parents: 96657d1
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Oct 29 15:02:33 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon Nov 16 14:18:35 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/d457e586/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/d457e586/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/d457e586/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/d457e586/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):