Skip to content

Commit

Permalink
Merge pull request #1711 from wardi/1711-organization-update-notfound…
Browse files Browse the repository at this point in the history
…-package

 prevent packages update in organization_update
  • Loading branch information
David Read committed May 20, 2014
2 parents 3f09acd + 8df3d43 commit 15a71ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
19 changes: 9 additions & 10 deletions ckan/lib/dictization/model_save.py
Expand Up @@ -381,14 +381,13 @@ def group_member_save(context, group_dict, member_table_name):
return processed


def group_dict_save(group_dict, context):
def group_dict_save(group_dict, context, prevent_packages_update=False):
from ckan.lib.search import rebuild

model = context["model"]
session = context["session"]
group = context.get("group")
allow_partial_update = context.get("allow_partial_update", False)
prevent_packages_update = context.get("prevent_packages_update", False)

Group = model.Group
if group:
Expand Down Expand Up @@ -418,14 +417,6 @@ def group_dict_save(group_dict, context):
'Groups: %r Tags: %r', pkgs_edited, group_users_changed,
group_groups_changed, group_tags_changed)

# We will get a list of packages that we have either added or
# removed from the group, and trigger a re-index.
package_ids = pkgs_edited['removed']
package_ids.extend( pkgs_edited['added'] )
if package_ids:
session.commit()
map( rebuild, package_ids )

extras = group_extras_save(group_dict.get("extras", {}), context)
if extras or not allow_partial_update:
old_extras = set(group.extras.keys())
Expand All @@ -435,6 +426,14 @@ def group_dict_save(group_dict, context):
for key in new_extras:
group.extras[key] = extras[key]

# We will get a list of packages that we have either added or
# removed from the group, and trigger a re-index.
package_ids = pkgs_edited['removed']
package_ids.extend( pkgs_edited['added'] )
if package_ids:
session.commit()
map( rebuild, package_ids )

return group


Expand Down
13 changes: 5 additions & 8 deletions ckan/logic/action/update.py
Expand Up @@ -523,14 +523,8 @@ def _group_or_org_update(context, data_dict, is_org=False):
else:
rev.message = _(u'REST API: Update object %s') % data.get("name")

# when editing an org we do not want to update the packages if using the
# new templates.
if ((not is_org)
and not converters.asbool(
config.get('ckan.legacy_templates', False))
and 'api_version' not in context):
context['prevent_packages_update'] = True
group = model_save.group_dict_save(data, context)
group = model_save.group_dict_save(data, context,
prevent_packages_update=is_org)

if is_org:
plugin_type = plugins.IOrganizationController
Expand Down Expand Up @@ -617,6 +611,9 @@ def organization_update(context, data_dict):
:param id: the name or id of the organization to update
:type id: string
:param packages: ignored. use
:py:func:`~ckan.logic.action.update.package_owner_org_update`
to change package ownership
:returns: the updated organization
:rtype: dictionary
Expand Down

0 comments on commit 15a71ab

Please sign in to comment.