Skip to content

Commit

Permalink
Updated the call to match to set the environ on the mapper before we …
Browse files Browse the repository at this point in the history
…call match so that the REQUEST_METHOD is available and can be used to check the conditions set on the cors_options url
  • Loading branch information
rossjones committed Jan 3, 2012
1 parent 4ab76d0 commit b886462
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
5 changes: 2 additions & 3 deletions ckan/config/routing.py
Expand Up @@ -25,6 +25,8 @@ def make_map():
map.connect('/error/{action}', controller='error')
map.connect('/error/{action}/{id}', controller='error')

map.connect('*url', controller='home', action='cors_options', conditions=dict(method=['OPTIONS']))

# CUSTOM ROUTES HERE
for plugin in routing_plugins:
map = plugin.before_map(map)
Expand Down Expand Up @@ -285,9 +287,6 @@ def make_map():
map.connect('ckanadmin_index', '/ckan-admin', controller='admin', action='index')
map.connect('ckanadmin', '/ckan-admin/{action}', controller='admin')

map.connect('*url', controller='home', action='cors_options',
conditions=dict(method=['OPTIONS']))

for plugin in routing_plugins:
map = plugin.after_map(map)

Expand Down
7 changes: 7 additions & 0 deletions ckan/controllers/group.py
Expand Up @@ -45,7 +45,14 @@ def register_pluggable_behaviour(map):
# Create the routes based on group_type here, this will allow us to have top level
# objects that are actually Groups, but first we need to make sure we are not
# clobbering an existing domain

# Our version of routes doesn't allow the environ to be passed into the match call
# and so we have to set it on the map instead. This looks like a threading problem
# waiting to happen but it is executed sequentially from instead the routing setup
e = map.environ
map.environ = {'REQUEST_METHOD': 'GET'}
match = map.match('/%s/new' % (group_type,))
map.environ = e
if match:
raise Exception, "Plugin %r would overwrite existing urls" % plugin

Expand Down
4 changes: 2 additions & 2 deletions ckan/controllers/package.py
Expand Up @@ -148,7 +148,7 @@ def check_data_dict(self, data_dict):
# Resources might not exist yet (eg. Add Dataset)
surplus_keys_schema = ['__extras', '__junk', 'state', 'groups',
'extras_validation', 'save', 'return_to',
'resources']
'resources', 'type']

schema_keys = package_form_schema().keys()
keys_in_schema = set(schema_keys) - set(surplus_keys_schema)
Expand All @@ -158,7 +158,7 @@ def check_data_dict(self, data_dict):
if missing_keys:
#print data_dict
#print missing_keys
log.info('incorrect form fields posted')
log.info('incorrect form fields posted, missing %s' % missing_keys )
raise DataError(data_dict)

def setup_template_variables(self, context, data_dict):
Expand Down
3 changes: 2 additions & 1 deletion ckan/tests/functional/test_cors.py
Expand Up @@ -9,7 +9,8 @@ def test_options(self):
self.ourapp = webtest.TestApp(self.wsgiapp)
out = self.ourapp.request('/', method='OPTIONS')
assert out.status_int == 200, out
print out
#print out
print out.body.decode('utf-8', 'ignore')
assert len(str(out.body)) == 0, 'OPTIONS must return no content'

def test_headers(self):
Expand Down

0 comments on commit b886462

Please sign in to comment.