當前位置: 首頁>>代碼示例>>Python>>正文


Python logic.check_access方法代碼示例

本文整理匯總了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'])) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:20,代碼來源:test_example_iauthfunctions.py

示例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) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:24,代碼來源:validators.py

示例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 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:22,代碼來源:home.py

示例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') 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:24,代碼來源:user.py

示例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')) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:19,代碼來源:revision.py

示例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) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:17,代碼來源:test_example_iauthfunctions.py

示例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 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:15,代碼來源:helpers.py

示例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 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:14,代碼來源:helpers.py

示例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 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:35,代碼來源:plugins.py

示例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) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:31,代碼來源:validators.py

示例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) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:35,代碼來源:helpers.py

示例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 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:14,代碼來源:test_init.py

示例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 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:13,代碼來源:test_init.py

示例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')) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:10,代碼來源:tag.py

示例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) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:5,代碼來源:group.py


注:本文中的ckan.logic.check_access方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。