本文整理汇总了Python中ckan.logic.check_access方法的典型用法代码示例。如果您正苦于以下问题:Python logic.check_access方法的具体用法?Python logic.check_access怎么用?Python logic.check_access使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckan.logic
的用法示例。
在下文中一共展示了logic.check_access方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_resource_delete_editor
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def test_resource_delete_editor(self):
'''Normally organization admins can delete resources
Our plugin prevents this by blocking delete organization.
Ensure the delete button is not displayed (as only resource delete
is checked for showing this)
'''
user = factories.User()
owner_org = factories.Organization(
users=[{'name': user['id'], 'capacity': 'admin'}]
)
dataset = factories.Dataset(owner_org=owner_org['id'])
resource = factories.Resource(package_id=dataset['id'])
with assert_raises(logic.NotAuthorized) as e:
logic.check_access('resource_delete', {'user': user['name']}, {'id': resource['id']})
assert_equal(e.exception.message, 'User %s not authorized to delete resource %s' % (user['name'], resource['id']))
示例2: ignore_not_group_admin
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def ignore_not_group_admin(key, data, errors, context):
'''Ignore if the user is not allowed to administer for the group specified.'''
model = context['model']
user = context.get('user')
if user and authz.is_sysadmin(user):
return
authorized = False
group = context.get('group')
if group:
try:
logic.check_access('group_change_state',context)
authorized = True
except logic.NotAuthorized:
authorized = False
if (user and group and authorized):
return
data.pop(key)
示例3: __before__
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def __before__(self, action, **env):
try:
base.BaseController.__before__(self, action, **env)
context = {'model': model, 'user': c.user,
'auth_user_obj': c.userobj}
logic.check_access('site_read', context)
except logic.NotAuthorized:
base.abort(403, _('Not authorized to see this page'))
except (sqlalchemy.exc.ProgrammingError,
sqlalchemy.exc.OperationalError), e:
# postgres and sqlite errors for missing tables
msg = str(e)
if ('relation' in msg and 'does not exist' in msg) or \
('no such table' in msg):
# table missing, major database problem
base.abort(503, _('This site is currently off-line. Database '
'is not initialised.'))
# TODO: send an email to the admin person (#1285)
else:
raise
示例4: activity
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def activity(self, id, offset=0):
'''Render this user's public activity stream page.'''
context = {'model': model, 'session': model.Session,
'user': c.user, 'auth_user_obj': c.userobj,
'for_view': True}
data_dict = {'id': id, 'user_obj': c.userobj,
'include_num_followers': True}
try:
check_access('user_show', context, data_dict)
except NotAuthorized:
abort(403, _('Not authorized to see this page'))
self._setup_template_variables(context, data_dict)
try:
c.user_activity_stream = get_action('user_activity_list_html')(
context, {'id': c.user_dict['id'], 'offset': offset})
except ValidationError:
base.abort(400)
return render('user/activity_stream.html')
示例5: __before__
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def __before__(self, action, **env):
base.BaseController.__before__(self, action, **env)
context = {'model': model, 'user': c.user,
'auth_user_obj': c.userobj}
if c.user:
try:
logic.check_access('revision_change_state', context)
c.revision_change_state_allowed = True
except logic.NotAuthorized:
c.revision_change_state_allowed = False
else:
c.revision_change_state_allowed = False
try:
logic.check_access('site_read', context)
except logic.NotAuthorized:
base.abort(403, _('Not authorized to see this page'))
示例6: test_resource_delete_sysadmin
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def test_resource_delete_sysadmin(self):
'''Normally organization admins can delete resources
Our plugin prevents this by blocking delete organization.
Ensure the delete button is not displayed (as only resource delete
is checked for showing this)
'''
user = factories.Sysadmin()
owner_org = factories.Organization(
users=[{'name': user['id'], 'capacity': 'admin'}]
)
dataset = factories.Dataset(owner_org=owner_org['id'])
resource = factories.Resource(package_id=dataset['id'])
assert_equal(logic.check_access('resource_delete', {'user': user['name']}, {'id': resource['id']}), True)
示例7: build_nav_main
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def build_nav_main(*args):
''' build a set of menu items.
args: tuples of (menu type, title) eg ('login', _('Login'))
outputs <li><a href="...">title</a></li>
'''
output = ''
for item in args:
menu_item, title = item[:2]
if len(item) == 3 and not check_access(item[2]):
continue
output += _make_menu_item(menu_item, title)
return output
示例8: check_access
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def check_access(action, data_dict=None):
context = {'model': model,
'user': c.user}
if not data_dict:
data_dict = {}
try:
logic.check_access(action, context, data_dict)
authorized = True
except logic.NotAuthorized:
authorized = False
return authorized
示例9: setup_template_variables
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def setup_template_variables(self, context, data_dict):
authz_fn = logic.get_action('group_list_authz')
c.groups_authz = authz_fn(context, data_dict)
data_dict.update({'available_only': True})
c.groups_available = authz_fn(context, data_dict)
c.licenses = [('', '')] + base.model.Package.get_license_options()
# CS: bad_spelling ignore 2 lines
c.licences = c.licenses
maintain.deprecate_context_item('licences', 'Use `c.licenses` instead')
c.is_sysadmin = ckan.authz.is_sysadmin(c.user)
if context.get('revision_id') or context.get('revision_date'):
if context.get('revision_id'):
rev = base.model.Session.query(base.model.Revision) \
.filter_by(id=context['revision_id']) \
.first()
c.revision_date = rev.timestamp if rev else '?'
else:
c.revision_date = context.get('revision_date')
## This is messy as auths take domain object not data_dict
context_pkg = context.get('package', None)
pkg = context_pkg or c.pkg
if pkg:
try:
if not context_pkg:
context['package'] = pkg
logic.check_access('package_change_state', context)
c.auth_for_change_state = True
except logic.NotAuthorized:
c.auth_for_change_state = False
示例10: ignore_not_package_admin
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def ignore_not_package_admin(key, data, errors, context):
'''Ignore if the user is not allowed to administer the package specified.'''
model = context['model']
user = context.get('user')
if 'ignore_auth' in context:
return
if user and authz.is_sysadmin(user):
return
authorized = False
pkg = context.get('package')
if pkg:
try:
logic.check_access('package_change_state',context)
authorized = True
except logic.NotAuthorized:
authorized = False
if (user and pkg and authorized):
return
# allow_state_change in the context will allow the state to be changed
# FIXME is this the best way to cjeck for state only?
if key == ('state',) and context.get('allow_state_change'):
return
data.pop(key)
示例11: call_auth
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def call_auth(auth_name, context, **kwargs):
'''Call the named ``ckan.logic.auth`` function and return the result.
This is just a convenience function for tests in
:py:mod:`ckan.tests.logic.auth` to use.
Usage::
result = helpers.call_auth('user_update', context=context,
id='some_user_id',
name='updated_user_name')
:param auth_name: the name of the auth function to call, e.g.
``'user_update'``
:type auth_name: string
:param context: the context dict to pass to the auth function, must
contain ``'user'`` and ``'model'`` keys,
e.g. ``{'user': 'fred', 'model': my_mock_model_object}``
:type context: dict
:returns: the dict that the auth function returns, e.g.
``{'success': True}`` or ``{'success': False, msg: '...'}``
or just ``{'success': False}``
:rtype: dict
'''
assert 'user' in context, ('Test methods must put a user name in the '
'context dict')
assert 'model' in context, ('Test methods must put a model in the '
'context dict')
return logic.check_access(auth_name, context, data_dict=kwargs)
示例12: test_check_access_auth_user_obj_is_set
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def test_check_access_auth_user_obj_is_set(self):
create_test_data.CreateTestData.create_test_user()
user_name = 'tester'
context = {'user': user_name}
result = logic.check_access('package_create', context)
assert result
assert context['__auth_user_obj_checked']
assert context['auth_user_obj'].name == user_name
示例13: test_check_access_auth_user_obj_is_not_set
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def test_check_access_auth_user_obj_is_not_set(self):
user_names = ('unknown_user', '', None,)
for user_name in user_names:
context = {'user': user_name}
result = logic.check_access('package_search', context)
assert result
assert context['__auth_user_obj_checked']
assert context['auth_user_obj'] is None
示例14: __before__
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def __before__(self, action, **env):
base.BaseController.__before__(self, action, **env)
try:
context = {'model': model, 'user': c.user,
'auth_user_obj': c.userobj}
logic.check_access('site_read', context)
except logic.NotAuthorized:
base.abort(403, _('Not authorized to see this page'))
示例15: _check_access
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import check_access [as 别名]
def _check_access(self, action_name, *args, **kw):
''' select the correct group/org check_access '''
return check_access(self._replace_group_org(action_name), *args, **kw)