Ejemplo n.º 1
0
def package_create(context, data_dict=None):
    user = context['user']

    if new_authz.auth_is_anon_user(context):
        check1 = all(new_authz.check_config_permission(p) for p in (
            'anon_create_dataset',
            'create_dataset_if_not_in_organization',
            'create_unowned_dataset',
            ))
    else:
        check1 = all(new_authz.check_config_permission(p) for p in (
            'create_dataset_if_not_in_organization',
            'create_unowned_dataset',
            )) or new_authz.has_user_permission_for_some_org(
            user, 'create_dataset')

    if not check1:
        return {'success': False, 'msg': _('User %s not authorized to create packages') % user}

    check2 = _check_group_auth(context,data_dict)
    if not check2:
        return {'success': False, 'msg': _('User %s not authorized to edit these groups') % user}

    # If an organization is given are we able to add a dataset to it?
    data_dict = data_dict or {}
    org_id = data_dict.get('owner_org')
    if org_id and not new_authz.has_user_permission_for_group_or_org(
            org_id, user, 'create_dataset'):
        return {'success': False, 'msg': _('User %s not authorized to add dataset to this organization') % user}
    return {'success': True}
Ejemplo n.º 2
0
def package_update(context, data_dict):
    user = context.get('user')
    package = logic_auth.get_package_object(context, data_dict)

    if package.owner_org:
        # if there is an owner org then we must have update_dataset
        # premission for that organization
        check1 = new_authz.has_user_permission_for_group_or_org(
            package.owner_org, user, 'update_dataset'
        )
    else:
        # If dataset is not owned then we can edit if config permissions allow
        if not new_authz.auth_is_anon_user(context):
            check1 = new_authz.check_config_permission(
                'create_dataset_if_not_in_organization')
        else:
            check1 = new_authz.check_config_permission('anon_create_dataset')
    if not check1:
        return {'success': False,
                'msg': _('User %s not authorized to edit package %s') %
                        (str(user), package.id)}
    else:
        check2 = _check_group_auth(context, data_dict)
        if not check2:
            return {'success': False,
                    'msg': _('User %s not authorized to edit these groups') %
                            (str(user))}

    return {'success': True}
Ejemplo n.º 3
0
def package_create(context, data_dict=None):
    user = context['user']
    user_roles = user_custom_roles(context, data_dict)
    if 'datovy-kurator' in user_roles:
        return {'success': True}
    
    if new_authz.auth_is_anon_user(context):
        check1 = all(new_authz.check_config_permission(p) for p in (
            'anon_create_dataset',
            'create_dataset_if_not_in_organization',
            'create_unowned_dataset',
            ))
    else:
        check1 = all(new_authz.check_config_permission(p) for p in (
            'create_dataset_if_not_in_organization',
            'create_unowned_dataset',
            )) or new_authz.has_user_permission_for_some_org(
            user, 'create_dataset')

    if not check1:
        return {'success': False, 'msg': _('User %s not authorized to create packages') % user}

    check2 = _check_group_auth(context,data_dict)
    if not check2:
        return {'success': False, 'msg': _('User %s not authorized to edit these groups') % user}

    # If an organization is given are we able to add a dataset to it?
    data_dict = data_dict or {}
    org_id = data_dict.get('owner_org')
    if org_id and not new_authz.has_user_permission_for_group_or_org(
            org_id, user, 'create_dataset'):
        return {'success': False, 'msg': _('User %s not authorized to add dataset to this organization') % user}
    return {'success': True}
        def package_create(context, data_dict=None):

            import ckan.new_authz as new_authz
            from ckan.logic.auth.create import _check_group_auth

            user = context['user']

            if new_authz.auth_is_anon_user(context):
                check1 = new_authz.check_config_permission('anon_create_dataset')
            else:
                # CKAN default options that grant any user rights to create datasets removed here.
                check1 = new_authz.has_user_permission_for_some_org(user, 'create_dataset')

            if not check1:
                return {'success': False, 'msg': _('User %s not authorized to create packages') % user}

            check2 = _check_group_auth(context,data_dict)
            if not check2:
                return {'success': False, 'msg': _('User %s not authorized to edit these groups') % user}

            # If an organization is given are we able to add a dataset to it?
            data_dict = data_dict or {}
            org_id = data_dict.get('organization_id')
            if org_id and not new_authz.has_user_permission_for_group_or_org(org_id, user, 'create_dataset'):
                return {'success': False, 'msg': _('User %s not authorized to add dataset to this organization') % user}
            # Note the default value True except when we're actually trying to create a new dataset...
            if data_dict:
                org_id = data_dict.get('owner_org')
                if org_id and not new_authz.has_user_permission_for_group_or_org(org_id, user, 'create_dataset'):
                    return {'success': False, 'msg': _('User %s not authorized to add dataset to this organization') % user}
                elif not org_id:
                    return {'success': False}
            return {'success': True}
Ejemplo n.º 5
0
def file_upload(context, data_dict=None):
    user = context['user']
    if new_authz.auth_is_anon_user(context):
        return {
            'success': False,
            'msg': _('User %s not authorized to create packages') % user
        }
    return {'success': True}
Ejemplo n.º 6
0
        def package_create(context, data_dict=None):

            import ckan.new_authz as new_authz
            from ckan.logic.auth.create import _check_group_auth

            user = context['user']

            if new_authz.auth_is_anon_user(context):
                check1 = new_authz.check_config_permission(
                    'anon_create_dataset')
            else:
                # CKAN default options that grant any user rights to create datasets removed here.
                check1 = new_authz.has_user_permission_for_some_org(
                    user, 'create_dataset')

            if not check1:
                return {
                    'success': False,
                    'msg':
                    _('User %s not authorized to create packages') % user
                }

            check2 = _check_group_auth(context, data_dict)
            if not check2:
                return {
                    'success': False,
                    'msg':
                    _('User %s not authorized to edit these groups') % user
                }

            # If an organization is given are we able to add a dataset to it?
            data_dict = data_dict or {}
            org_id = data_dict.get('organization_id')
            if org_id and not new_authz.has_user_permission_for_group_or_org(
                    org_id, user, 'create_dataset'):
                return {
                    'success':
                    False,
                    'msg':
                    _('User %s not authorized to add dataset to this organization'
                      ) % user
                }
            # Note the default value True except when we're actually trying to create a new dataset...
            if data_dict:
                org_id = data_dict.get('owner_org')
                if org_id and not new_authz.has_user_permission_for_group_or_org(
                        org_id, user, 'create_dataset'):
                    return {
                        'success':
                        False,
                        'msg':
                        _('User %s not authorized to add dataset to this organization'
                          ) % user
                    }
                elif not org_id:
                    return {'success': False}
            return {'success': True}
Ejemplo n.º 7
0
def file_upload(context, data_dict=None):
    user = context['user']
    if new_authz.auth_is_anon_user(context):
        return {'success': False, 'msg': _('User %s not authorized to create packages') % user}
    return {'success': True}