Commits

Anonymous committed 42c6282 Merge

[merge] (cset:15566874efe7, and maybe others?)

Comments (0)

Files changed (19)

         assert isinstance(username, unicode), type(username)
         assert model.Action.is_valid(action), action
 
+        # sysadmins can do everything
         from pylons import config
-        # sysadmins can do everything
         admins_string = config.get('auth.sysadmins', '')
         admins = admins_string.split()
         if username in admins:
             return True
 
+        # check not blacklisted
         if action is not model.Action.READ:
             if cls.blacklister.is_blacklisted(username):
                 return False
 
+        # check this user's roles for this object
         roles = cls.get_roles(username, domain_object)
         if not roles:
             return False
-
         # print '%r has roles %s on object %s. Checking permission to %s' % (username, roles, domain_object.name, action)
+        
         if model.Role.ADMIN in roles:
             return True
+
+        # check it's active
+        if hasattr(domain_object, 'state'):
+            active = model.State.query.filter_by(name='active').one()
+            if domain_object.state != active:
+                return False
+
+        # check if any of the roles allows the action requested
         for role in roles:
             action_query = model.RoleAction.query.filter_by(role=role,
                                                             action=action)

ckan/controllers/base.py

         try:
             current_page = int(id)
         except:
-            current_page = 0
+            current_page = 1
 
         register = getattr(model, register_name.capitalize())
         query = register.query
             list_value = [{'id': i.name} for i in collection]
             return simplejson.dumps({list_name: list_value})
         else:
-            import paginate
+            from ckan.lib.helpers import paginate
             c.page = paginate.Page(
                 collection=collection,
-                current_page=current_page,
+                page=current_page,
                 items_per_page=50,
                 item_count=item_count,
             )

ckan/lib/helpers.py

 from webhelpers.html import escape, HTML, literal, url_escape
 from webhelpers.html.tags import *
 from webhelpers.markdown import markdown
+from webhelpers import paginate
 from routes import url_for, redirect_to
-import paginate
+from ckan.lib.helpers import paginate
 
 class TextFormat(object):
 

ckan/templates/paginated_list_contents.html

   <div class="pagination">
     <py:if test="c.page.page_count > 1">
       <ul>
-      <py:if test="c.page.current_page > 1">
+      <py:if test="c.page.page > 1">
         <li>
             <a 
-              href="${h.url_for(action='list', id=c.page.current_page - 1)}"
+              href="${h.url_for(action='list', id=c.page.page - 1)}"
               onclick="return updatePaginatedListHTML(
-                '${h.url_for(action='list',id=c.page.current_page - 1)}')
+                '${h.url_for(action='list',id=c.page.page - 1)}')
             ">Previous</a>
         </li>
       </py:if>
       <py:for each="number in range(1, c.page.page_count + 1)">
         <li>
-        <py:choose test="number == c.page.current_page">
+        <py:choose test="number == c.page.page">
           <py:when test="True">
             <span class="pagination-current">
             <a 
         </py:choose>
         </li>
       </py:for>
-      <py:if test="c.page.page_count > c.page.current_page">
+      <py:if test="c.page.page_count > c.page.page">
         <li>
             <a 
-              href="${h.url_for(action='list', id=c.page.current_page + 1)}"
+              href="${h.url_for(action='list', id=c.page.page + 1)}"
             >Next</a>
         </li>
       </py:if>
       </py:if>
     </py:if>
     <py:if test="c.page.page_count > 1">
-    Displaying ${c.register_name} ${c.page.first_item + 1} - ${c.page.last_item + 1} of ${c.page.item_count}.
+    Displaying ${c.register_name} ${c.page.first_item} - ${c.page.last_item} of ${c.page.item_count}.
     </py:if>
     </p>
 

ckan/tests/__init__.py

 from ckan.lib.cli import CreateTestData, CreateSearchTestData
 
 __all__ = ['url_for',
-        'TestController2',
+        'TestController',
         'CreateTestData',
         'CreateSearchTestData',
         ]
 import ckan.model as model
 model.repo.rebuild_db()
 
-class TestController2(object):
+class TestController(object):
 
     def __init__(self, *args, **kwargs):
         wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)

ckan/tests/functional/test_admin.py

 from ckan.tests import *
 
-class TestAdminController(TestController2):
+class TestAdminController(TestController):
 
     def test_index(self):
         response = self.app.get(url_for(controller='admin'))

ckan/tests/functional/test_authz.py

 from ckan.lib.base import *
 import ckan.authz as authz
 
-class TestUsage(TestController2):
+class TestUsage(TestController):
     @classmethod
     def _create_test_data(self):
         self.modes = ('--', 'r-', 'w-', 'rr', 'wr', 'ww') #  logged-in, visitor

ckan/tests/functional/test_group.py

 from ckan.tests import *
 import ckan.model as model
 
-class TestGroup(TestController2):
+class TestGroup(TestController):
 
     @classmethod
     def setup_class(self):
         assert name in res
 
 
-class TestEdit(TestController2):
+class TestEdit(TestController):
     groupname = u'david'
 
     @classmethod

ckan/tests/functional/test_group_edit_authz.py

 from ckan.lib.base import *
 import ckan.authz as authz
 
-class TestGroupEditAuthz(TestController2):
+class TestGroupEditAuthz(TestController):
     @classmethod
     def setup_class(self):
         model.repo.rebuild_db()

ckan/tests/functional/test_home.py

 from ckan.tests import *
 
-class TestHomeController(TestController2):
+class TestHomeController(TestController):
 
     def test_home_page(self):
         offset = url_for('home')

ckan/tests/functional/test_package.py

 import cgi
 from paste.fixture import AppError
 
-class TestPackageController(TestController2):
+class TestPackageController(TestController):
 
     @classmethod
     def setup_class(self):
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     def test_index(self):
         offset = url_for(controller='package')
         assert 'Revisions' in res
         assert name in res
 
-class TestPackageControllerEdit(TestController2):
+class TestPackageControllerEdit(TestController):
     def setup_method(self, method):
         self.setUp()
 
         # assert rev.message == exp_log_message
 
 
-class TestPackageControllerNew(TestController2):
+class TestPackageControllerNew(TestController):
     pkgname = u'testpkg'
     pkgtitle = u'mytesttitle'
 
         assert 'value="test tags"' in res, res
 #        assert 'value="test groups"' in res, res
 
+class TestNonActivePackages(TestController):
+
+    @classmethod
+    def setup_class(self):
+        CreateTestData.create()
+        self.non_active_name = u'test_nonactive'
+        model.Package(name=self.non_active_name)
+        model.repo.new_revision()
+        model.repo.commit_and_remove()
+
+        pkg = model.Package.query.filter_by(name=self.non_active_name).one()
+        admin = model.User.by_name('joeadmin')
+        model.setup_default_user_roles(pkg, [admin])
+        
+        pkg = model.Package.query.filter_by(name=self.non_active_name).one()
+        pkg.delete() # becomes non active
+        model.repo.new_revision()
+        model.repo.commit_and_remove()
+        
+
+    @classmethod
+    def teardown_class(self):
+        model.repo.rebuild_db()
+
+    def test_list(self):
+        offset = url_for(controller='package', action='list')
+        res = self.app.get(offset)
+        assert 'Packages - List' in res
+        assert 'annakarenina' in res
+        assert self.non_active_name not in res
+
+    def test_read(self):
+        offset = url_for(controller='package', action='read', id=self.non_active_name)
+        res = self.app.get(offset, status=[302, 401])
+
+
+    def test_read_as_admin(self):
+        offset = url_for(controller='package', action='read', id=self.non_active_name)
+        res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER':'joeadmin'})
+
+    def test_search(self):
+        offset = url_for(controller='package', action='search')
+        res = self.app.get(offset)
+        assert 'Packages - Search' in res
+        form = res.forms[0]
+        form['q'] =  str(self.non_active_name)
+        results_page = form.submit()
+        assert 'Packages - Search' in results_page, results_page
+        print results_page
+        assert '0 packages found' in results_page, (self.non_active_name, results_page)
+
+
+        

ckan/tests/functional/test_package_edit_authz.py

 from ckan.lib.base import *
 import ckan.authz as authz
 
-class TestPackageEditAuthz(TestController2):
+class TestPackageEditAuthz(TestController):
     @classmethod
     def setup_class(self):
         model.repo.rebuild_db()

ckan/tests/functional/test_rest.py

     return model.Session.get(model.License, id).name
 
 
-class TestRestController(TestController2):
+class TestRestController(TestController):
 
     @classmethod
     def setup_class(self):
         res = self.app.delete(offset, status=[404],
                               extra_environ=self.extra_environ)
 
-class TestSearch(TestController2):
+class TestSearch(TestController):
     @classmethod
     def setup_class(self):
         try:

ckan/tests/functional/test_revision.py

 import ckan.model as model
 
 # TODO: purge revisions after creating them
-class TestRevisionController(TestController2):
+class TestRevisionController(TestController):
 
     @classmethod
     def setup_class(self):

ckan/tests/functional/test_tag.py

 from ckan.tests import *
 import ckan.model as model
 
-class TestTagController(TestController2):
+class TestTagController(TestController):
 
     @classmethod
     def setup_class(self):

ckan/tests/functional/test_user.py

 from ckan.tests import *
 import ckan.model as model
 
-class TestUserController(TestController2):
+class TestUserController(TestController):
 
     def test_user_not_logged_in(self):
         offset = url_for(controller='user')

ckan/tests/misc/test_paginate.py

 
 # TODO: (?) remove as we do not use our own paginate system but 3rd party one
 # Disable for time being
-class _TestPaginate(TestController2):
+class _TestPaginate(TestController):
 
     def setup_method(self, method):
         if method.__name__ == 'test_page_multi':
         'SQLAlchemy>=0.4.8,<=0.4.99',
         'repoze.who>=1.0.0,<1.0.99',
         'repoze.who.plugins.openid>=0.5,<0.5.99',
-        'paginate==0.3.2',
         'uuid>=1.0', # in python 2.5 but not before
         # for open licenses
         'licenses',