Skip to content

Commit

Permalink
[#2389,#2472] Remove datastore enabled checks from controller
Browse files Browse the repository at this point in the history
Datastore is now enabled by default for all resources. When something is
posted to the datastore, the 'webstore_url' extra is set to 'active'.

Also replaced model calls with logic functions.
  • Loading branch information
amercader committed Jun 27, 2012
1 parent d8734c0 commit 8ebf311
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions ckan/controllers/datastore.py
@@ -1,9 +1,9 @@
from ckan.lib.base import BaseController, abort, _, c, response, request, g
import ckan.model as model
from ckan.lib.helpers import json
from ckan.lib.jsonp import jsonpify
from ckan.logic import get_action, check_access
from ckan.logic import NotFound, NotAuthorized, ValidationError
from ckan.logic import NotFound, NotAuthorized


class DatastoreController(BaseController):
def _make_redirect(self, id, url=''):
Expand All @@ -20,10 +20,6 @@ def read(self, id, url=''):

try:
resource = get_action('resource_show')(context, {'id': id})
if not resource.get('webstore_url', ''):
return {
'error': 'DataStore is disabled for this resource'
}
self._make_redirect(id, url)
return ''
except NotFound:
Expand All @@ -36,19 +32,15 @@ def write(self, id, url):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author}
try:
resource = model.Resource.get(id)
if not resource:
abort(404, _('Resource not found'))
if not resource.webstore_url:
return {
'error': 'DataStore is disabled for this resource'
}
context["resource"] = resource
check_access('resource_update', context, {'id': id})
resource_dict = get_action('resource_show')(context,{'id':id})
if not resource_dict['webstore_url']:
resource_dict['webstore_url'] = u'active'
get_action('resource_update')(context,resource_dict)

self._make_redirect(id, url)
return ''
except NotFound:
abort(404, _('Resource not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read resource %s') % id)

0 comments on commit 8ebf311

Please sign in to comment.