[ckan-changes] commit/ckan: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Tue Oct 18 14:41:52 UTC 2011


2 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/cf5f536e06ea/
changeset:   cf5f536e06ea
branch:      feature-1381-manage-groups-via-package-api
user:        amercader
date:        2011-10-18 10:53:40
summary:     [api, logic] #1381 - Allow group management from package entity API
affected #:  3 files (-1 bytes)

--- a/ckan/lib/dictization/model_save.py	Mon Oct 17 15:07:58 2011 +0100
+++ b/ckan/lib/dictization/model_save.py	Tue Oct 18 09:53:40 2011 +0100
@@ -357,10 +357,11 @@
                 else:
                     new_value.append({"key": extras_key,
                                       "value": None})
+        if key == 'groups':
+             new_value = [{"name": item} for item in value] 
 
         dictized[key] = new_value
 
-    groups = dictized.pop('groups', None)
     download_url = dictized.pop('download_url', None)
     if download_url and not dictized.get('resources'):
         dictized["resources"] = [{'url': download_url}]


--- a/ckan/logic/auth/create.py	Mon Oct 17 15:07:58 2011 +0100
+++ b/ckan/logic/auth/create.py	Tue Oct 18 09:53:40 2011 +0100
@@ -87,9 +87,12 @@
     group_dicts = data_dict.get("groups", [])
     groups = set()
     for group_dict in group_dicts:
-        id = group_dict.get('id')
-        if not id:
-            continue
+        if isinstance(group_dict,dict):
+            id = group_dict.get('id')
+            if not id:
+                continue
+        else:
+            id = group_dict
         grp = model.Group.get(id)
         if grp is None:
             raise NotFound(_('Group was not found.'))


--- a/ckan/logic/schema.py	Mon Oct 17 15:07:58 2011 +0100
+++ b/ckan/logic/schema.py	Tue Oct 18 09:53:40 2011 +0100
@@ -104,6 +104,7 @@
         'relationships_as_subject': default_relationship_schema(),
         'groups': {
             'id': [ignore_missing, unicode],
+            'name': [ignore_missing, unicode],
             '__extras': [ignore],
         }
     }


http://bitbucket.org/okfn/ckan/changeset/edf632c72f3b/
changeset:   edf632c72f3b
branch:      feature-1381-manage-groups-via-package-api
user:        amercader
date:        2011-10-18 15:22:39
summary:     [tests] Add tests for #1381
affected #:  2 files (-1 bytes)

--- a/ckan/tests/functional/api/model/test_package.py	Tue Oct 18 09:53:40 2011 +0100
+++ b/ckan/tests/functional/api/model/test_package.py	Tue Oct 18 14:22:39 2011 +0100
@@ -3,9 +3,9 @@
 from nose.tools import assert_equal, assert_raises
 
 from ckan.tests.functional.api.base import BaseModelApiTestCase
-from ckan.tests.functional.api.base import Api1TestCase as Version1TestCase 
-from ckan.tests.functional.api.base import Api2TestCase as Version2TestCase 
-from ckan.tests.functional.api.base import ApiUnversionedTestCase as UnversionedTestCase 
+from ckan.tests.functional.api.base import Api1TestCase as Version1TestCase
+from ckan.tests.functional.api.base import Api2TestCase as Version2TestCase
+from ckan.tests.functional.api.base import ApiUnversionedTestCase as UnversionedTestCase
 from ckan import plugins
 import ckan.lib.search as search
 
@@ -39,7 +39,7 @@
         res = self.app.post(offset, params=postparams,
                             status=self.STATUS_201_CREATED,
                             extra_environ=self.extra_environ)
-        
+
         # Check the returned package is as expected
         pkg = self.loads(res.body)
         assert_equal(pkg['name'], self.package_fixture_data['name'])
@@ -50,7 +50,7 @@
 
         # Check the value of the Location header.
         location = res.header('Location')
-        
+
         assert offset in location
         res = self.app.get(location, status=self.STATUS_200_OK)
         # Check the database record.
@@ -95,15 +95,71 @@
         assert '"extras": {' in res, res
         for key, value in self.package_fixture_data['extras'].items():
             assert '"%s": "%s"' % (key, value) in res, res
-        
+
         self.remove()
-        
+
         # Test Packages Register Post 409 (conflict - create duplicate package).
         offset = self.package_offset()
         postparams = '%s=1' % self.dumps(self.package_fixture_data)
         res = self.app.post(offset, params=postparams, status=self.STATUS_409_CONFLICT,
                 extra_environ=self.extra_environ)
-        self.remove()        
+        self.remove()
+
+    def test_register_post_with_group(self):
+        assert not self.get_package_by_name(self.package_fixture_data['name'])
+        offset = self.package_offset()
+
+        groups = [u'david']
+        user = model.User.by_name(u'russianfan')
+        for grp in groups:
+            group = model.Group.get(grp)
+            model.setup_default_user_roles(group, [user])
+
+
+
+        package_fixture_data = self.package_fixture_data
+        package_fixture_data['groups'] = groups
+        data = self.dumps(package_fixture_data)
+        res = self.post_json(offset, data, status=self.STATUS_201_CREATED,
+                             extra_environ={'Authorization':str(user.apikey)})
+
+        # Check the database record.
+        self.remove()
+        package = self.get_package_by_name(self.package_fixture_data['name'])
+        assert package
+        self.assert_equal([g.name for g in package.groups], groups)
+        del package_fixture_data['groups']
+
+    def test_register_post_with_group_not_authorized(self):
+        assert not self.get_package_by_name(self.package_fixture_data['name'])
+        offset = self.package_offset()
+
+        groups = [u'david']
+
+        package_fixture_data = self.package_fixture_data
+        package_fixture_data['groups'] = groups
+        data = self.dumps(package_fixture_data)
+        res = self.post_json(offset, data, status=self.STATUS_403_ACCESS_DENIED,
+                             extra_environ=self.extra_environ)
+        del package_fixture_data['groups']
+
+    def test_register_post_with_group_sysadmin(self):
+        assert not self.get_package_by_name(self.package_fixture_data['name'])
+        offset = self.package_offset()
+        user = model.User.by_name(u'testsysadmin')
+        groups = [u'david']
+
+        package_fixture_data = self.package_fixture_data
+        package_fixture_data['groups'] = groups
+        data = self.dumps(package_fixture_data)
+        res = self.post_json(offset, data, status=self.STATUS_201_CREATED,
+                              extra_environ={'Authorization':str(user.apikey)})
+        # Check the database record.
+        self.remove()
+        package = self.get_package_by_name(self.package_fixture_data['name'])
+        assert package
+        self.assert_equal([g.name for g in package.groups], groups)
+        del package_fixture_data['groups']
 
     def test_register_post_json(self):
         assert not self.get_package_by_name(self.package_fixture_data['name'])
@@ -116,7 +172,7 @@
         package = self.get_package_by_name(self.package_fixture_data['name'])
         assert package
         self.assert_equal(package.title, self.package_fixture_data['title'])
-        
+
     def test_register_post_bad_content_type(self):
         assert not self.get_package_by_name(self.package_fixture_data['name'])
         offset = self.package_offset()
@@ -134,7 +190,7 @@
             # Check there is no database record.
             assert not package
         else:
-            assert package        
+            assert package
 
     def test_register_post_bad_request(self):
         test_params = {
@@ -282,7 +338,7 @@
                 u'size_extra':u'400',
             }],
             'extras': {
-                u'key3': u'val3', 
+                u'key3': u'val3',
                 u'key4': u'',
                 u'key2': None,
                 u'key7': ['a','b'],
@@ -377,7 +433,7 @@
         new_fixture_data = {
             'name':u'somethingnew',
             'extras': {
-                u'key1': None, 
+                u'key1': None,
                 },
         }
         self.create_package_roles_revision(old_fixture_data)
@@ -572,7 +628,7 @@
             }
         offset = self.package_offset()
         postparams = '%s=1' % self.dumps(test_params)
-        res = self.app.post(offset, params=postparams, 
+        res = self.app.post(offset, params=postparams,
                             extra_environ=self.extra_environ)
         model.Session.remove()
         pkg = self.get_package_by_name(test_params['name'])


--- a/ckan/tests/lib/test_dictization_schema.py	Tue Oct 18 09:53:40 2011 +0100
+++ b/ckan/tests/lib/test_dictization_schema.py	Tue Oct 18 14:22:39 2011 +0100
@@ -68,7 +68,7 @@
         pprint(errors)
         assert converted_data == {'extras': [{'key': u'genre', 'value': u'"romantic novel"'},
                                             {'key': u'original media', 'value': u'"book"'}],
-#                                 'groups': [{'name': u'david'}, {'name': u'roger'}],
+                                 'groups': [{'name': u'david'}, {'name': u'roger'}],
                                  'license_id': u'other-open',
                                  'name': u'anna2',
                                  'notes': u'Some test notes\n\n### A 3rd level heading\n\n**Some bolded text.**\n\n*Some italicized text.*\n\nForeign characters:\nu with umlaut \xfc\n66-style quote \u201c\nforeign word: th\xfcmb\n \nNeeds escaping:\nleft arrow <\n\n<http://ckan.net/>\n\n',

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list