Skip to content

Commit

Permalink
group_patch does not reset packages
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk authored and tino097 committed Dec 4, 2018
1 parent 6342799 commit b2bcd87
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ckan/logic/action/update.py
Expand Up @@ -522,8 +522,12 @@ def _group_or_org_update(context, data_dict, is_org=False):
else:
rev.message = _(u'REST API: Update object %s') % data.get("name")

group = model_save.group_dict_save(data, context,
prevent_packages_update=is_org)
contains_packages = 'packages' in data_dict

group = model_save.group_dict_save(
data, context,
prevent_packages_update=is_org or not contains_packages
)

if is_org:
plugin_type = plugins.IOrganizationController
Expand Down
31 changes: 31 additions & 0 deletions ckan/tests/logic/action/test_patch.py
Expand Up @@ -75,6 +75,37 @@ def test_group_patch_updating_single_field(self):
assert_equals(group2['name'], 'economy')
assert_equals(group2['description'], 'somethingnew')

def test_group_patch_preserve_datasets(self):
user = factories.User()
group = factories.Group(
name='economy',
description='some test now',
user=user)
factories.Dataset(groups=[{'name': group['name']}])

group2 = helpers.call_action('group_show', id=group['id'])
assert_equals(1, group2['package_count'])

group = helpers.call_action(
'group_patch',
id=group['id'],
context={'user': user['name']})

group3 = helpers.call_action('group_show', id=group['id'])
assert_equals(1, group3['package_count'])

group = helpers.call_action(
'group_patch',
id=group['id'],
packages=[],
context={'user': user['name']})

group4 = helpers.call_action(
'group_show', id=group['id'], include_datasets=True
)
assert_equals(0, group4['package_count'])


def test_organization_patch_updating_single_field(self):
user = factories.User()
organization = factories.Organization(
Expand Down

0 comments on commit b2bcd87

Please sign in to comment.