Example #1
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 new_authz.auth_is_registered_user():
            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}
Example #2
0
def datahub_package_create(context, data_dict):
    from ckan.logic.auth.create import _check_group_auth

    if authz.is_sysadmin(context.get('user')):
        return {'success': True}

    user = context['user']
    if not authz.auth_is_registered_user():
        if '/new' in c.environ['PATH_INFO']:
            h.redirect_to(CREATE_DATASET_HELP_PAGE)
        else:
            return {'success': False, 'msg': _('You must login to create a dataset')}

    check1 = authz.check_config_permission('create_dataset_if_not_in_organization') \
        or authz.check_config_permission('create_unowned_dataset')

    #if not authorized and not a part of any org, redirect to help page on how to join one
    if not check1 and not authz.has_user_permission_for_some_org(user, 'create_dataset'):
        if '/new' in c.environ['PATH_INFO']:
            h.redirect_to(CREATE_DATASET_HELP_PAGE)
        else:
            return {'success': False, 'msg': _('User %s not authorized to create packages') % user}

    check2 = _check_group_auth(context,data_dict)
    if not check2 and not check1:
        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 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}
Example #3
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 new_authz.auth_is_registered_user():
            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}
Example #4
0
def datahub_package_create(context, data_dict):
    from ckan.logic.auth.create import _check_group_auth

    if new_authz.is_sysadmin(context.get('user')):
        return {'success': True}

    user = context['user']
    if not new_authz.auth_is_registered_user():
        return {'success': False, 'msg': _('You must login to create a dataset')}
    else:
        check1 = new_authz.check_config_permission('create_dataset_if_not_in_organization') \
            or new_authz.check_config_permission('create_unowned_dataset')

        if not check1 and not new_authz.has_user_permission_for_some_org(user, 'create_dataset'):
            h.redirect_to('/pages/requesting-an-organization')

    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}
    return {'success': True}
Example #5
0
def file_upload(context, data_dict=None):
    user = context['user']
    if not new_authz.auth_is_registered_user():
        return {
            'success': False,
            'msg': _('User %s not authorized to create packages') % user
        }
    return {'success': True}
Example #6
0
def datahub_package_create(context, data_dict):
    from ckan.logic.auth.create import _check_group_auth

    if new_authz.is_sysadmin(context.get('user')):
        return {'success': True}

    user = context['user']
    if not new_authz.auth_is_registered_user():
        if '/new' in c.environ['PATH_INFO']:
            h.redirect_to(CREATE_DATASET_HELP_PAGE)
        else:
            return {
                'success': False,
                'msg': _('You must login to create a dataset')
            }

    check1 = new_authz.check_config_permission('create_dataset_if_not_in_organization') \
        or new_authz.check_config_permission('create_unowned_dataset')

    #if not authorized and not a part of any org, redirect to help page on how to join one
    if not check1 and not new_authz.has_user_permission_for_some_org(
            user, 'create_dataset'):
        if '/new' in c.environ['PATH_INFO']:
            h.redirect_to(CREATE_DATASET_HELP_PAGE)
        else:
            return {
                'success': False,
                'msg': _('User %s not authorized to create packages') % user
            }

    check2 = _check_group_auth(context, data_dict)
    if not check2 and not check1:
        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
        }
    return {'success': True}
Example #7
0
File: auth.py Project: haphut/ytp
def member_request_create(context, data_dict):
    """ Create request access check """

    if not new_authz.auth_is_registered_user():
        return {'success': False, 'msg': _('User is not logged in')}

    organization_id = None if not data_dict else data_dict.get('organization_id', None)

    if organization_id:
        member = get_user_member(organization_id)
        if member:
            return {'success': False, 'msg': _('The user has already a pending request or an active membership')}

    return {'success': True}
Example #8
0
def package_create(context, data_dict=None):
    user = context['user']
    if not new_authz.auth_is_registered_user():
        check1 = new_authz.check_config_permission('anon_create_dataset')
    else:
        check1 = new_authz.check_config_permission('create_dataset_if_not_in_organization') \
            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}
    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}
Example #9
0
def package_create(context, data_dict=None):
    user = context['user']
    if not new_authz.auth_is_registered_user():
        check1 = new_authz.check_config_permission('anon_create_dataset')
    else:
        check1 = new_authz.check_config_permission('create_dataset_if_not_in_organization') \
            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}
    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}
Example #10
0
def package_update(context, data_dict):
    user = context.get("user")
    package = 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 new_authz.auth_is_registered_user():
            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}
Example #11
0
def package_create(context, data_dict=None):
    user = context['user']
    if not new_authz.auth_is_registered_user():
        check1 = new_authz.check_config_permission('anon_create_dataset')
    else:
        check1 = new_authz.check_config_permission('create_dataset_if_not_in_organization') \
            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('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}
    return {'success': True}
Example #12
0
def package_create(context, data_dict=None):
    user = context['user']
    if not new_authz.auth_is_registered_user():
        check1 = new_authz.check_config_permission('anon_create_dataset')
    else:
        check1 = new_authz.check_config_permission('create_dataset_if_not_in_organization') \
            or new_authz.check_config_permission('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('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}
    return {'success': True}
Example #13
0
def file_upload(context, data_dict=None):
    user = context['user']
    if not new_authz.auth_is_registered_user():
        return {'success': False, 'msg': _('User %s not authorized to create packages') % user}
    return {'success': True}
Example #14
0
File: auth.py Project: haphut/ytp
def _only_registered_user():
    if not new_authz.auth_is_registered_user():
        return {'success': False, 'msg': _('User is not logged in')}
    return {'success': True}