当前位置: 首页>>代码示例>>Python>>正文


Python logic.NotAuthorized方法代码示例

本文整理汇总了Python中ckan.logic.NotAuthorized方法的典型用法代码示例。如果您正苦于以下问题:Python logic.NotAuthorized方法的具体用法?Python logic.NotAuthorized怎么用?Python logic.NotAuthorized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ckan.logic的用法示例。


在下文中一共展示了logic.NotAuthorized方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_resource_delete_editor

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [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'])) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:20,代码来源:test_example_iauthfunctions.py

示例2: ignore_not_group_admin

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [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) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:24,代码来源:validators.py

示例3: _am_following

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def _am_following(context, data_dict, default_schema, FollowerClass):
    schema = context.get('schema', default_schema)
    data_dict, errors = _validate(data_dict, schema, context)
    if errors:
        raise ValidationError(errors)

    if 'user' not in context:
        raise logic.NotAuthorized

    model = context['model']

    userobj = model.User.get(context['user'])
    if not userobj:
        raise logic.NotAuthorized

    object_id = data_dict.get('id')

    return FollowerClass.is_following(userobj.id, object_id) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:20,代码来源:get.py

示例4: test_user_update_with_no_user_in_context

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def test_user_update_with_no_user_in_context(self):

        # Make a mock ckan.model.User object.
        mock_user = factories.MockUser(name='fred')

        # Make a mock ckan.model object.
        mock_model = mock.MagicMock()
        # model.User.get(user_id) should return our mock user.
        mock_model.User.get.return_value = mock_user

        # Put the mock model in the context.
        # This is easier than patching import ckan.model.
        context = {'model': mock_model}

        # For this test we're going to have no 'user' in the context.
        context['user'] = None

        params = {
            'id': mock_user.id,
            'name': 'updated_user_name',
        }

        nose.tools.assert_raises(logic.NotAuthorized, helpers.call_auth,
                                 'user_update', context=context, **params) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:26,代码来源:test_update.py

示例5: test_user_generate_apikey_for_another_user

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def test_user_generate_apikey_for_another_user(self):
        fred = factories.MockUser(name='fred')
        bob = factories.MockUser(name='bob')
        mock_model = mock.MagicMock()
        mock_model.User.get.return_value = fred
        # auth_user_obj shows user as logged in for non-anonymous auth
        # functions
        context = {'model': mock_model, 'auth_user_obj': bob}
        context['user'] = bob.name
        params = {
            'id': fred.id,
        }

        nose.tools.assert_raises(logic.NotAuthorized, helpers.call_auth,
                                 'user_generate_apikey', context=context,
                                 **params) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:18,代码来源:test_update.py

示例6: test_27_get_site_user_not_authorized

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
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

        site_id = config.get('ckan.site_id')
        user = get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
        assert user['name'] == site_id

        user = model.User.get(site_id)
        assert user

        user=get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
        assert user['name'] == site_id

        user = model.Session.query(model.User).filter_by(name=site_id).one()
        assert user 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:test_action.py

示例7: read

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def read(self, id, limit=20):
        group_type = self._ensure_controller_matches_group_type(
            id.split('@')[0])

        context = {'model': model, 'session': model.Session,
                   'user': c.user,
                   'schema': self._db_to_form_schema(group_type=group_type),
                   'for_view': True}
        data_dict = {'id': id, 'type': group_type}

        # unicode format (decoded from utf8)
        c.q = request.params.get('q', '')

        try:
            # Do not query for the group datasets when dictizing, as they will
            # be ignored and get requested on the controller anyway
            data_dict['include_datasets'] = False
            c.group_dict = self._action('group_show')(context, data_dict)
            c.group = context['group']
        except (NotFound, NotAuthorized):
            abort(404, _('Group not found'))

        self._read(id, limit, group_type)
        return render(self._read_template(c.group_dict['type']),
                      extra_vars={'group_type': group_type}) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:27,代码来源:group.py

示例8: _save_new

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def _save_new(self, context, group_type=None):
        try:
            data_dict = clean_dict(dict_fns.unflatten(
                tuplize_dict(parse_params(request.params))))
            data_dict['type'] = group_type or 'group'
            context['message'] = data_dict.get('log_message', '')
            data_dict['users'] = [{'name': c.user, 'capacity': 'admin'}]
            group = self._action('group_create')(context, data_dict)

            # Redirect to the appropriate _read route for the type of group
            h.redirect_to(group['type'] + '_read', id=group['name'])
        except (NotFound, NotAuthorized), e:
            abort(404, _('Group not found'))
        except dict_fns.DataError:
            abort(400, _(u'Integrity Error'))
        except ValidationError, e:
            errors = e.error_dict
            error_summary = e.error_summary
            return self.new(data_dict, errors, error_summary) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:group.py

示例9: members

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def members(self, id):
        group_type = self._ensure_controller_matches_group_type(id)

        context = {'model': model, 'session': model.Session,
                   'user': c.user}

        try:
            c.members = self._action('member_list')(
                context, {'id': id, 'object_type': 'user'}
            )
            data_dict = {'id': id}
            data_dict['include_datasets'] = False
            c.group_dict = self._action('group_show')(context, data_dict)
        except (NotFound, NotAuthorized):
            abort(404, _('Group not found'))
        return self._render_template('group/members.html', group_type) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:18,代码来源:group.py

示例10: follow

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def follow(self, id):
        '''Start following this group.'''
        self._ensure_controller_matches_group_type(id)
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user}
        data_dict = {'id': id}
        try:
            get_action('follow_group')(context, data_dict)
            group_dict = get_action('group_show')(context, data_dict)
            h.flash_success(_("You are now following {0}").format(
                group_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except NotAuthorized as e:
            h.flash_error(e.message)
        h.redirect_to(controller='group', action='read', id=id) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:group.py

示例11: unfollow

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def unfollow(self, id):
        '''Stop following this group.'''
        self._ensure_controller_matches_group_type(id)
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user}
        data_dict = {'id': id}
        try:
            get_action('unfollow_group')(context, data_dict)
            group_dict = get_action('group_show')(context, data_dict)
            h.flash_success(_("You are no longer following {0}").format(
                group_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except (NotFound, NotAuthorized) as e:
            error_message = e.message
            h.flash_error(error_message)
        h.redirect_to(controller='group', action='read', id=id) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:22,代码来源:group.py

示例12: __before__

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [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 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:22,代码来源:home.py

示例13: resources

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def resources(self, id):
        context = {'model': model, 'session': model.Session,
                   'user': c.user, 'for_view': True,
                   'auth_user_obj': c.userobj}
        data_dict = {'id': id, 'include_tracking': True}

        try:
            check_access('package_update', context, data_dict)
        except NotFound:
            abort(404, _('Dataset not found'))
        except NotAuthorized:
            abort(403, _('User %r not authorized to edit %s') % (c.user, id))
        # check if package exists
        try:
            c.pkg_dict = get_action('package_show')(context, data_dict)
            c.pkg = context['package']
        except (NotFound, NotAuthorized):
            abort(404, _('Dataset not found'))

        package_type = c.pkg_dict['type'] or 'dataset'
        self._setup_template_variables(context, {'id': id},
                                       package_type=package_type)

        return render('package/resources.html',
                      extra_vars={'dataset_type': package_type}) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:27,代码来源:package.py

示例14: follow

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def follow(self, id):
        '''Start following this dataset.'''
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user, 'auth_user_obj': c.userobj}
        data_dict = {'id': id}
        try:
            get_action('follow_dataset')(context, data_dict)
            package_dict = get_action('package_show')(context, data_dict)
            h.flash_success(_("You are now following {0}").format(
                package_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except NotAuthorized as e:
            h.flash_error(e.message)
        h.redirect_to(controller='package', action='read', id=id) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:20,代码来源:package.py

示例15: unfollow

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotAuthorized [as 别名]
def unfollow(self, id):
        '''Stop following this dataset.'''
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user, 'auth_user_obj': c.userobj}
        data_dict = {'id': id}
        try:
            get_action('unfollow_dataset')(context, data_dict)
            package_dict = get_action('package_show')(context, data_dict)
            h.flash_success(_("You are no longer following {0}").format(
                package_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except (NotFound, NotAuthorized) as e:
            error_message = e.message
            h.flash_error(error_message)
        h.redirect_to(controller='package', action='read', id=id) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:package.py


注:本文中的ckan.logic.NotAuthorized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。