Beispiel #1
0
def resource_delete(context, data_dict):
    '''
    This runs the 'resource_delete' action from core ckan's delete.py
    It allows us to do some minor changes and wrap it.
    '''
    process_batch_mode(context, data_dict)

    result_dict = core_delete.resource_delete(context, data_dict)

    return result_dict
def resource_delete(context, data_dict):
  ''' Delete a resource.
    .. seealso https://github.com/ckan/ckan/blob/master/ckan/logic/action/delete.py
  '''
  model = context['model']
  user = context['user']
  id = _get_or_bust(data_dict, "id")
  log.debug(id)
  resource = model.Resource.get(id)
  previous_s3_object_url =   resource.url
  ################################################################################################################
  if tk.asbool(config.get('ckanext.cloud_storage.enable')) and previous_s3_object_url.startswith("https://s3.amazonaws.com/") :
    log.debug('Deleting Remote Resource')
    log.debug(previous_s3_object_url)
    context["resource"] = resource

    if not resource:
      log.error('Could not find resource ' + id)
      raise NotFound(_('Resource was not found.'))

    _check_access('resource_delete', context, data_dict)
    package_id = resource.package.id
    pkg_dict = _get_action('package_show')(context, {'id': package_id})

    for n, p in enumerate(pkg_dict['resources']):
      if p['id'] == id:
          break
    else:
      log.error('Could not find resource ' + id)
      raise NotFound(_('Resource was not found.'))

    upload = uploader.get_resource_uploader(data_dict)
    upload.delete(previous_s3_object_url)
  else:
    log.debug('Plugin Not Enabled or External Link')
  ################################################################################################################
  return origin.resource_delete(context, data_dict)
Beispiel #3
0
def resource_delete(context, data_dict):
    _clear_get_resource_data_cache()
    return delete_core.resource_delete(context, data_dict)
Beispiel #4
0
def resource_delete(context, data_dict):
    delete.resource_delete(context, data_dict)
    send_resource_log(context, data_dict, 'Resource removed',
                      'ResourceRemoved')