CKAN在扩展IPackageController after_update中使包变为私有

时间:2015-04-27 13:13:58

标签: ckan

在CKAN中,我尝试将所有数据集设置为“私有”,因此只有特定用户才能发布数据集。我创建了一个扩展并实现了IPackageController方法after_update - 如果需要,这将再次调用package_update将数据集设置为private:

class SetStateForPendingValidationPlugin(plugins.SingletonPlugin):
   plugins.implements(plugins.IPackageController, inherit=True)

   def after_update(self, context, data_dict):
    log.debug("CKAN after_update context: %r", context)
    log.debug("CKAN after_update data_dict: %r", data_dict)

    # Check if the user is the one who is allowed to publish datasets 

    # Only do this for active datasets, and not ones in draft or deleted state
    # it is also not needed if the dataset is already private
    if 'state' not in data_dict or ( 'state' in data_dict and data_dict['state'] == 'active'):
        if 'private' not in data_dict or ( 'private' in data_dict and data_dict['private'] == False):
            data_dict['private'] = True
            log.info("CKAN to send %r: ", data_dict)
            toolkit.get_action('package_update')(context, data_dict)

不幸的是,在启用FileStore的情况下执行此操作会导致网站崩溃,并且该用户不是管理员。数据集已正确保存,但系统在保存后尝试加载页面时会抱怨。它似乎与文件有关,因为当以管理员身份查看数据集时,似乎没有资源,并且作为普通用户,系统崩溃。

[Mon Apr 27 11:45:52 2015] [error] 2015-04-27 11:45:52,079 DEBUG [ckan.logic] check access - user u'nonamin', action resource_create
[Mon Apr 27 11:45:53 2015] [error] [client 127.0.0.1] Error - <class 'ckan.logic.NotFound'>:
[Mon Apr 27 11:45:53 2015] [error] [client 127.0.0.1] URL: http://10.11.98.85/dataset/newweekfilepublic
[Mon Apr 27 11:45:53 2015] [error] [client 127.0.0.1] File '/usr/lib/ckan/default/lib/python2.7/site-packages/weberror/errormiddleware.py', line 162 in __call__
[Mon Apr 27 11:45:53 2015] [error] [client 127.0.0.1]   app_iter = self.application(environ, sr_checker)
[Mon Apr 27 11:45:53 2015] [error] [client 127.0.0.1] File '/usr/lib/ckan/default/lib/python2.7/site-packages/webob/dec.py', line 147 in __call__

我已经使用IAuthFunction扩展了插件,它总是授予用户resource_create,然后它会停止崩溃。但文件/资源​​仍然不可见。

这似乎只在创建数据集时才有意义。之后添加资源/文件似乎按预期工作。

0 个答案:

没有答案