incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [7/9] git commit: [#6456] Fixed GC project importer being tied to Projects nbhd and added security check
Date Tue, 23 Jul 2013 02:52:50 GMT
[#6456] Fixed GC project importer being tied to Projects nbhd and added security check

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


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

Branch: refs/heads/master
Commit: 22c7f7012fadca27b1ffce67428bfa254b180a3a
Parents: 788e9e4
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Mon Jul 22 22:32:02 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Tue Jul 23 02:45:42 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py                  |  2 +-
 ForgeImporters/forgeimporters/base.py                 |  6 +++++-
 ForgeImporters/forgeimporters/google/project.py       | 14 ++++++++++----
 .../forgeimporters/google/templates/project.html      |  2 +-
 .../forgeimporters/templates/project_base.html        |  2 +-
 5 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/22c7f701/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index a407bba..91d5a4f 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -74,7 +74,7 @@ class NeighborhoodController(object):
         self.browse = NeighborhoodProjectBrowseController(neighborhood=self.neighborhood)
         self._admin = NeighborhoodAdminController(self.neighborhood)
         self._moderate = NeighborhoodModerateController(self.neighborhood)
-        self.import_project = ProjectImporterDispatcher()
+        self.import_project = ProjectImporterDispatcher(self.neighborhood)
 
     def _check_security(self):
         require_access(self.neighborhood, 'read')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/22c7f701/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index 6632f37..334b89a 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -26,10 +26,14 @@ from allura.controllers import BaseController
 
 
 class ProjectImporterDispatcher(BaseController):
+    def __init__(self, neighborhood, *a, **kw):
+        super(ProjectImporterDispatcher, self).__init__(*a, **kw)
+        self.neighborhood = neighborhood
+
     @expose()
     def _lookup(self, source, *rest):
         for ep in iter_entry_points('allura.project_importers', source):
-            return ep.load()(), rest
+            return ep.load()(self.neighborhood), rest
 
 
 class ProjectImporter(BaseController):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/22c7f701/ForgeImporters/forgeimporters/google/project.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/project.py b/ForgeImporters/forgeimporters/google/project.py
index 057115f..678f16d 100644
--- a/ForgeImporters/forgeimporters/google/project.py
+++ b/ForgeImporters/forgeimporters/google/project.py
@@ -23,6 +23,7 @@ from formencode import validators as fev, schema
 from allura import model as M
 from allura.lib.decorators import require_post
 from allura.lib.widgets.forms import NeighborhoodProjectShortNameValidator
+from allura.lib.security import require_access
 from allura.lib import helpers as h
 from allura.lib import exceptions
 
@@ -41,22 +42,27 @@ class GoogleCodeProjectForm(schema.Schema):
 class GoogleCodeProjectImporter(base.ProjectImporter):
     source = 'Google Code'
 
+    def __init__(self, neighborhood, *a, **kw):
+        super(GoogleCodeProjectImporter, self).__init__(*a, **kw)
+        self.neighborhood = neighborhood
+
+    def _check_security(self):
+        require_access(self.neighborhood, 'register')
+
     @with_trailing_slash
     @expose('jinja:forgeimporters.google:templates/project.html')
     def index(self, **kw):
-        neighborhood = M.Neighborhood.query.get(url_prefix='/p/')
-        return {'importer': self, 'neighborhood': neighborhood}
+        return {'importer': self}
 
     @require_post()
     @expose()
     @validate(GoogleCodeProjectForm(), error_handler=index)
     def process(self, project_name=None, project_shortname=None, tools=None, **kw):
-        neighborhood = M.Neighborhood.query.get(url_prefix='/p/')
         project_name = h.really_unicode(project_name).encode('utf-8')
         project_shortname = h.really_unicode(project_shortname).encode('utf-8').lower()
 
         try:
-            c.project = neighborhood.register_project(project_shortname,
+            c.project = self.neighborhood.register_project(project_shortname,
                     project_name=project_name)
         except exceptions.ProjectOverlimitError:
             flash("You have exceeded the maximum number of projects you are allowed to create",
'error')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/22c7f701/ForgeImporters/forgeimporters/google/templates/project.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/templates/project.html b/ForgeImporters/forgeimporters/google/templates/project.html
index a98d5ef..614e1cb 100644
--- a/ForgeImporters/forgeimporters/google/templates/project.html
+++ b/ForgeImporters/forgeimporters/google/templates/project.html
@@ -98,7 +98,7 @@
             {{c.form_errors['project_shortname']}}
         </div>
         <div id="project-url">
-            http://{{request.environ['HTTP_HOST']}}{{neighborhood.url()}}<span id="url-fragment">{{c.form_values['project_shortname']}}</span>
+            http://{{request.environ['HTTP_HOST']}}{{importer.neighborhood.url()}}<span
id="url-fragment">{{c.form_values['project_shortname']}}</span>
         </div>
     </div>
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/22c7f701/ForgeImporters/forgeimporters/templates/project_base.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/templates/project_base.html b/ForgeImporters/forgeimporters/templates/project_base.html
index d42954f..bd37665 100644
--- a/ForgeImporters/forgeimporters/templates/project_base.html
+++ b/ForgeImporters/forgeimporters/templates/project_base.html
@@ -26,7 +26,7 @@
 {% block content %}
 
 <form id="project-import-form" method="POST" action="process">
-    <input type="hidden" id="neighborhood" name="neighborhood" value="Projects"/>
+    <input type="hidden" id="neighborhood" name="neighborhood" value="{{importer.neighborhood.name}}"/>
 
     <fieldset id="project-fields">
         {% block project_fields %}{% endblock %}


Mime
View raw message