ckan / ckanapi

A command line interface and Python module for accessing the CKAN Action API
Other
178 stars 74 forks source link

Argument to Inlude Group/Org Users in Dump and Load (+ fixed tests) #208

Closed JVickery-TBS closed 1 year ago

JVickery-TBS commented 1 year ago

feat(cli): added include-users option for group and org dump/load;

JVickery-TBS commented 1 year ago

Working on fixing the tests currently.

Python 2.7 support has been removed fully from actions/python-versions so we can no longer use that. I have also updated the base image of test workflow to use ubuntu-latest.

JVickery-TBS commented 1 year ago

Okay I also fixed the tests. Sadly python 2 is no longer supported in actions/setup-python but I was able to get around this by just using the docker python images for the respective versions.

There was also a reported possible memory leak when running the tests due to unclosed files from the dump and search subcommands when not using stdout. I have added a closing call to those files. Let me know if this is not necessary or bad to do.

wardi commented 1 year ago

IIUC include_users=True would only do something on sites where ckan.auth.public_user_details = False, and only when dumping groups/orgs, right? This change provides the option for the load command too which doesn't look like it will do anything.

JVickery-TBS commented 1 year ago

@wardi Yeah, so it would really only be a thing for ckan.auth.public_user_details = False, which is False by default.

https://github.com/ckan/ckanapi/blob/master/ckanapi/cli/load.py#L267

def _copy_from_existing_for_update(obj, existing, thing):
    """
    modifies obj dict in place, copying values from existing.

    the id is alwasys copied from existing to make sure update updates
    the correct object.

    users lists for groups and orgs are maintained if not present in obj
    """
    if 'id' in existing:
        obj['id'] = existing['id']

    if thing in ('organizations', 'groups'):
        if 'users' not in obj and 'users' in existing:
            obj['users'] = existing['users']

There is code which copies over the users in the above function. So if the users are not available, it will use the ones from the load method (if the load is called with --include-users).