You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2012/09/19 20:43:27 UTC

[4/50] git commit: [#3027] ticket:165 Validate SVN checkout url if it's changed

[#3027] ticket:165 Validate SVN checkout url if it's changed


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

Branch: refs/heads/master
Commit: 6d0994850573e34ece2004959dc1ea10865928b0
Parents: 6ee82a2
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Thu Sep 13 01:06:27 2012 +0400
Committer: Cory Johns <jo...@geek.net>
Committed: Tue Sep 18 22:07:05 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/validators.py                    |   11 +++++++++++
 ForgeSVN/forgesvn/svn_main.py                      |   11 ++++++++++-
 ForgeSVN/forgesvn/templates/svn/checkout_url.html  |    4 +++-
 .../forgesvn/tests/functional/test_controllers.py  |   11 +++++++++++
 4 files changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6d099485/Allura/allura/lib/validators.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/validators.py b/Allura/allura/lib/validators.py
index 5bab308..de3d517 100644
--- a/Allura/allura/lib/validators.py
+++ b/Allura/allura/lib/validators.py
@@ -3,6 +3,7 @@ from bson import ObjectId
 import formencode as fe
 from formencode import validators as fev
 from . import helpers as h
+import pysvn
 
 class Ming(fev.FancyValidator):
 
@@ -61,3 +62,13 @@ class JsonValidator(fev.FancyValidator):
         except ValueError, e:
             raise fe.Invalid('Invalid JSON: ' + str(e), value, state)
         return value
+
+
+class CheckoutUrlValidator(fev.FancyValidator):
+    def _to_python(self, value, state):
+        svn = pysvn.Client()
+        try:
+            svn.info2(value)
+        except pysvn.ClientError, e:
+            raise  fe.Invalid(str(e), value, state)
+        return value

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6d099485/ForgeSVN/forgesvn/svn_main.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/svn_main.py b/ForgeSVN/forgesvn/svn_main.py
index 45bd189..ec8b899 100644
--- a/ForgeSVN/forgesvn/svn_main.py
+++ b/ForgeSVN/forgesvn/svn_main.py
@@ -1,6 +1,7 @@
 #-*- python -*-
 import logging
 from pylons import c, request
+import pylons
 
 # Non-stdlib imports
 from ming.utils import LazyProperty
@@ -17,6 +18,7 @@ from allura.lib.repository import RepositoryApp, RepoAdminController
 from allura.app import SitemapEntry, ConfigOption
 from allura.lib import helpers as h
 from allura import model as M
+from allura.lib import validators as V
 
 # Local imports
 from . import model as SM
@@ -97,8 +99,15 @@ class SVNRepoAdminController(RepoAdminController):
     @without_trailing_slash
     @expose()
     @require_post()
+    @validate(dict(checkout_url=V.CheckoutUrlValidator()))
     def set_checkout_url(self, **post_data):
-        self.app.config.options['checkout_url'] = post_data['checkout_url']
+        if not pylons.c.form_errors:
+            url = post_data['checkout_url'].replace(
+                self.app.repo.clone_url('ro', self.app), "")
+            self.app.config.options['checkout_url'] = url
+        else:
+            flash(pylons.c.form_errors["checkout_url"], "error")
+
 
 class SVNImportController(BaseController):
     import_form=widgets.ImportForm()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6d099485/ForgeSVN/forgesvn/templates/svn/checkout_url.html
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/templates/svn/checkout_url.html b/ForgeSVN/forgesvn/templates/svn/checkout_url.html
index 1d575b0..2283a5d 100644
--- a/ForgeSVN/forgesvn/templates/svn/checkout_url.html
+++ b/ForgeSVN/forgesvn/templates/svn/checkout_url.html
@@ -1,3 +1,4 @@
+{% block content %}
 <form>
   <label class="grid-13" for="checkout_url">Checkout url:</label>
   <div class="grid-13">
@@ -25,7 +26,7 @@
     function save_checkout_url() {
         var cval = $.cookie('_session_id');
         $.post('{{c.project.url()}}admin/{{app.config.options.mount_point}}/set_checkout_url', {
-            checkout_url: $('#checkout_url').val(),
+            checkout_url: "{{app.repo.clone_url('ro', app)}}" + $('#checkout_url').val(),
             _session_id:cval
         },
         function () {
@@ -34,3 +35,4 @@
     }
   </script>
 {% endif %}
+{% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6d099485/ForgeSVN/forgesvn/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/functional/test_controllers.py b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
index ad9d41e..c0dc4b1 100644
--- a/ForgeSVN/forgesvn/tests/functional/test_controllers.py
+++ b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
@@ -8,6 +8,7 @@ from pylons import c
 from ming.orm import ThreadLocalORMSession
 
 from allura.lib import helpers as h
+from allura.lib import validators as V
 from allura.tests import decorators as td
 from alluratest.controller import TestController
 
@@ -105,6 +106,16 @@ class TestRootController(SVNTestController):
         assert 'This is readme' in resp, resp.showbrowser()
         assert '+++' in resp, resp.showbrowser()
 
+    def test_checkout_svn(self):
+        self.app.post('/p/test/admin/src/set_checkout_url',
+                      {"checkout_url": "badurl"})
+        r = self.app.get('/p/test/admin/src/checkout_url')
+        assert "trunk" in r
+
+    def test_validator(self):
+        v_svn = V.CheckoutUrlValidator()
+        v_svn.to_python("file:///" + c.app.repo.fs_path + c.app.repo.name)
+
 
 class TestImportController(SVNTestController):
     def test_index(self):