コード例 #1
0
def package_show_release(context, data_dict):
    """Wrapper for package_show with some additional release related info

    This works just like package_show but also optionally accepts `release_id`
    as a parameter; Providing it means that the returned data will show the
    package metadata from the specified release, and also include the
    release_metadata key with some release metadata.

    If release_id is not provided, package data will include a `releases` key
    with a list of releases for this package.
    """
    release = data_dict.get('release', None)
    dataset_name = data_dict.get('dataset', None)
    if release and dataset_name:
        release_dict = dataset_release_show(context, {
            'release': release,
            'dataset': dataset_name
        })
        package_dict = _get_package_in_revision(context, data_dict,
                                                release_dict['name'])
        package_dict['release_metadata'] = release_dict
    else:
        package_dict = core_package_show(context, data_dict)
        releases = dataset_release_list(context,
                                        {'dataset': package_dict['id']})
        package_dict['releases'] = releases

    return package_dict
コード例 #2
0
    def test_package_patch_for_update(self):

        dataset = factories.Dataset()

        mock_package_show = mock.MagicMock()
        mock_package_show.side_effect = lambda context, data_dict: core_package_show(
            context, data_dict)

        with mock.patch.dict('ckan.logic._actions',
                             {'package_show': mock_package_show}):
            helpers.call_action('package_patch', id=dataset['id'], notes='hey')
            assert mock_package_show.call_args_list[0][0][0].get(
                'for_update') is True
コード例 #3
0
def package_show(context, data_dict):
    '''Override core ckan package_show.
    '''
    package = core_package_show(context, data_dict)
    # User with less perms then creator should not be able to access pending dataset
    approval_pending = package.get('approval_state') == 'approval_pending'
    try:
        toolkit.check_access('package_update', context, data_dict)
        can_edit = True
    except toolkit.NotAuthorized:
        can_edit = False
    if not can_edit and approval_pending:
        raise toolkit.ObjectNotFound
    return package
コード例 #4
0
    def test_resource_delete_for_delete(self):

        dataset = factories.Dataset()
        resource = factories.Resource(package_id=dataset['id'])

        mock_package_show = mock.MagicMock()
        mock_package_show.side_effect = lambda context, data_dict: core_package_show(
            context, data_dict)

        with mock.patch.dict('ckan.logic._actions',
                             {'package_show': mock_package_show}):
            helpers.call_action('resource_delete',
                                id=resource['id'],
                                description='hey')
            assert mock_package_show.call_args_list[1][0][0].get(
                'for_update') is True
コード例 #5
0
def package_show_revision(context, data_dict):
    """Show a package from a specified revision

    Takes the same arguments as 'package_show' but with an additional
    revision ID parameter

    :param id: the id of the package
    :type id: string
    :param revision_ref: the ID of the revision
    :type revision_ref: string
    :returns: A package dict
    :rtype: dict
    """
    revision_ref = _get_revision_ref(data_dict)
    if revision_ref is None:
        result = core_package_show(context, data_dict)
    else:
        result = _get_package_in_revision(context, data_dict, revision_ref)

    return result
コード例 #6
0
def _get_package_in_revision(context, data_dict, revision_id):
    """Internal implementation of package_show_revision
    """
    result = core_package_show(context, data_dict)
    if revision_id:
        backend = get_metastore_backend()
        dataset_name = _get_dataset_name(data_dict.get('id'))
        pkg_info = backend.fetch(dataset_name, revision_id)
        dataset = frictionless_to_dataset(pkg_info.package)
        result = update_ckan_dict(result, dataset)
        for resource in result.get('resources', []):
            resource['datastore_active'] = False
            _fix_resource_data(resource, revision_id)

    # Fetching the license_url, title from the license registry and validate
    if 'license_id' in result and result['license_id']:
        license_data = h.get_license(result['license_id'])
        # Validate license has url and title both
        result['license_url'] = license_data.url if license_data.url else ''
        result['license_title'] = license_data.title if license_data.title \
            else ''
    return result