[ckan-changes] commit/ckan: kindly: [action] #1408 get site user on request if not make one
Bitbucket
commits-noreply at bitbucket.org
Wed Oct 19 10:17:13 UTC 2011
1 new changeset in ckan:
http://bitbucket.org/okfn/ckan/changeset/51c7d51f3c17/
changeset: 51c7d51f3c17
branch: feature-1371-task-status-logic-layer
user: kindly
date: 2011-10-19 12:16:27
summary: [action] #1408 get site user on request if not make one
affected #: 3 files (-1 bytes)
--- a/ckan/logic/action/get.py Tue Oct 18 14:56:03 2011 +0100
+++ b/ckan/logic/action/get.py Wed Oct 19 11:16:27 2011 +0100
@@ -1,11 +1,13 @@
from sqlalchemy.sql import select
from sqlalchemy import or_, and_, func, desc, case
+import uuid
from ckan.logic import NotFound
from ckan.logic import check_access
from ckan.plugins import (PluginImplementations,
IGroupController,
IPackageController)
+from pylons import config
from ckan.authz import Authorizer
from ckan.lib.dictization import table_dictize
from ckan.lib.dictization.model_dictize import (package_dictize,
@@ -772,3 +774,19 @@
task_status_dict = task_status_dictize(task_status, context)
return task_status_dict
+
+def get_site_user(context, data_dict):
+ check_access('get_site_user', context, data_dict)
+ model = context['model']
+ site_id = config.get('ckan.site_id', 'ckan_site_user')
+ user = model.User.get(site_id)
+ if not user:
+ apikey = str(uuid.uuid4())
+ user = model.User(name=site_id,
+ password=apikey,
+ apikey=apikey)
+ model.add_user_to_role(user, model.Role.ADMIN, model.System())
+ model.Session.add(user)
+ model.Session.commit()
+ return {'name': user.name,
+ 'api': user.apikey}
--- a/ckan/logic/auth/get.py Tue Oct 18 14:56:03 2011 +0100
+++ b/ckan/logic/auth/get.py Wed Oct 19 11:16:27 2011 +0100
@@ -164,3 +164,9 @@
def tag_show_rest(context, data_dict):
return tag_show(context, data_dict)
+
+def get_site_user(context, data_dict):
+ if not context.get('ignore_auth'):
+ return {'success': False, 'msg': 'Only internal services allowed to use this action'}
+ else:
+ return {'success': True}
--- a/ckan/tests/functional/api/test_action.py Tue Oct 18 14:56:03 2011 +0100
+++ b/ckan/tests/functional/api/test_action.py Wed Oct 19 11:16:27 2011 +0100
@@ -1,12 +1,13 @@
import json
from pprint import pprint
-from nose.tools import assert_equal
+from nose.tools import assert_equal, assert_raises
from ckan.lib.create_test_data import CreateTestData
from ckan.lib.dictization.model_dictize import resource_dictize
import ckan.model as model
from ckan.tests import WsgiAppCase
from ckan.tests.functional.api import assert_dicts_equal_ignoring_ordering
+from ckan.logic import get_action, NotAuthorized
class TestAction(WsgiAppCase):
@@ -704,3 +705,30 @@
result.pop('revision_timestamp')
assert result == resource_dict, (result, resource_dict)
+
+ def test_27_get_site_user_not_authorized(self):
+ assert_raises(NotAuthorized,
+ get_action('get_site_user'),
+ {'model': model}, {})
+ user = model.User.get('test.ckan.net')
+ assert not user
+
+ user=get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
+ assert user['name'] == 'test.ckan.net'
+
+ user = model.User.get('test.ckan.net')
+ assert user
+
+ user=get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
+ assert user['name'] == 'test.ckan.net'
+
+ user = model.Session.query(model.User).filter_by(name='test.ckan.net').one()
+ assert user
+
+
+
+
+
+
+
+
Repository URL: https://bitbucket.org/okfn/ckan/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list