Beispiel #1
0
def check_group_auth(context, data_dict):
    if not data_dict:
        return True

    model = context['model']
    pkg = context.get("package")

    api_version = context.get('api_version') or '1'

    group_blobs = data_dict.get("groups", []) 
    groups = set()
    for group_blob in group_blobs:
        # group_blob might be a dict or a group_ref
        if isinstance(group_blob, dict):
            if api_version == '1':
                id = group_blob.get('name')
            else:
                id = group_blob.get('id')
            if not id:
                continue
        else:
            id = group_blob
        grp = model.Group.get(id)
        if grp is None:
            raise NotFound(_('Group was not found.'))
        groups.add(grp)

    if pkg:
        groups = groups - set(pkg.groups)

    for group in groups:
        if not check_access_old(group, model.Action.EDIT, context):
            return False

    return True
Beispiel #2
0
def authorization_group_create(context, data_dict=None):
    model = context['model']
    user = context['user']
   
    authorized = check_access_old(model.System(), model.Action.AUTHZ_GROUP_CREATE, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to create authorization groups') % str(user)}
    else:
        return {'success': True}
Beispiel #3
0
def user_create(context, data_dict=None):
    model = context['model']
    user = context['user']
   
    authorized = check_access_old(model.System(), model.Action.USER_CREATE, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to create users') % str(user)}
    else:
        return {'success': True}
Beispiel #4
0
def user_create(context, data_dict=None):
    model = context["model"]
    user = context["user"]

    authorized = logic.check_access_old(model.System(), model.Action.USER_CREATE, context)
    if not authorized:
        return {"success": False, "msg": _("User %s not authorized to create users") % str(user)}
    else:
        return {"success": True}
Beispiel #5
0
def group_change_state(context, data_dict):
    model = context['model']
    user = context['user']
    group = get_group_object(context, data_dict)

    authorized = check_access_old(group, model.Action.CHANGE_STATE, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to change state of group %s') % (str(user),group.id)}
    else:
        return {'success': True}
Beispiel #6
0
def package_change_state(context, data_dict):
    model = context['model']
    user = context['user']
    package = get_package_object(context, data_dict)

    authorized = check_access_old(package, model.Action.CHANGE_STATE, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to change state of package %s') % (str(user),package.id)}
    else:
        return {'success': True}
Beispiel #7
0
def group_change_state(context, data_dict):
    model = context['model']
    user = context['user']
    group = get_group_object(context, data_dict)

    authorized = logic.check_access_old(group, model.Action.CHANGE_STATE, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to change state of group %s') % (str(user),group.id)}
    else:
        return {'success': True}
Beispiel #8
0
def package_delete(context, data_dict):
    model = context['model']
    user = context['user']
    package = get_package_object(context, data_dict)

    authorized = logic.check_access_old(package, model.Action.PURGE, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to delete package %s') % (str(user),package.id)}
    else:
        return {'success': True}
Beispiel #9
0
def package_edit_permissions(context, data_dict):
    model = context['model']
    user = context['user']
    package = get_package_object(context, data_dict)

    authorized = logic.check_access_old(package, model.Action.EDIT_PERMISSIONS, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to edit permissions of package %s') % (str(user),package.id)}
    else:
        return {'success': True}
Beispiel #10
0
def group_update(context, data_dict):
    model = context['model']
    user = context['user']
    group = get_group_object(context, data_dict)
    
    authorized = check_access_old(group, model.Action.EDIT, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to edit group %s') % (str(user),group.id)}
    else:
        return {'success': True}
Beispiel #11
0
def authorization_group_edit_permissions(context, data_dict):
    model = context['model']
    user = context['user']
    authorization_group = get_authorization_group_object(context, data_dict)

    authorized = logic.check_access_old(authorization_group, model.Action.EDIT_PERMISSIONS, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to edit permissions of authorization group %s') % (str(user),authorization_group.id)}
    else:
        return {'success': True}
Beispiel #12
0
def package_change_state(context, data_dict):
    model = context['model']
    user = context['user']
    package = get_package_object(context, data_dict)

    authorized = logic.check_access_old(package, model.Action.CHANGE_STATE, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to change state of package %s') % (str(user),package.id)}
    else:
        return {'success': True}
Beispiel #13
0
def group_show(context, data_dict):
    model = context['model']
    user = context.get('user')
    group = get_group_object(context, data_dict)

    authorized =  logic.check_access_old(group, model.Action.READ, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to read group %s') % (str(user),group.id)}
    else:
        return {'success': True}
Beispiel #14
0
def group_show(context, data_dict):
    model = context['model']
    user = context.get('user')
    group = get_group_object(context, data_dict)

    authorized =  logic.check_access_old(group, model.Action.READ, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to read group %s') % (str(user),group.id)}
    else:
        return {'success': True}
Beispiel #15
0
def authorization_group_edit_permissions(context, data_dict):
    model = context['model']
    user = context['user']
    authorization_group = get_authorization_group_object(context, data_dict)

    authorized = logic.check_access_old(authorization_group, model.Action.EDIT_PERMISSIONS, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to edit permissions of authorization group %s') % (str(user),authorization_group.id)}
    else:
        return {'success': True}
Beispiel #16
0
def package_show(context, data_dict):
    model = context['model']
    user = context.get('user')
    package = get_package_object(context, data_dict)

    authorized = logic.check_access_old(package, model.Action.READ, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to read package %s') % (str(user),package.id)}
    else:
        return {'success': True}
Beispiel #17
0
def relationship_delete(context, data_dict):
    model = context['model']
    user = context['user']
    relationship = context['relationship']

    authorized = check_access_old(relationship, model.Action.PURGE, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to delete relationship %s') % (str(user),relationship.id)}
    else:
        return {'success': True}
Beispiel #18
0
def package_edit_permissions(context, data_dict):
    model = context['model']
    user = context['user']
    package = get_package_object(context, data_dict)

    authorized = logic.check_access_old(package, model.Action.EDIT_PERMISSIONS, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to edit permissions of package %s') % (str(user),package.id)}
    else:
        return {'success': True}
Beispiel #19
0
def group_delete(context, data_dict):
    model = context['model']
    user = context['user']
    group = get_group_object(context, data_dict)

    authorized = logic.check_access_old(group, model.Action.PURGE, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to delete group %s') % (str(user),group.id)}
    else:
        return {'success': True}
Beispiel #20
0
def group_update(context, data_dict):
    model = context["model"]
    user = context["user"]
    group = get_group_object(context, data_dict)

    authorized = check_access_old(group, model.Action.EDIT, context)
    if not authorized:
        return {"success": False, "msg": _("User %s not authorized to edit group %s") % (str(user), group.id)}
    else:
        return {"success": True}
Beispiel #21
0
def package_show(context, data_dict):
    model = context['model']
    user = context.get('user')
    package = get_package_object(context, data_dict)

    authorized = check_access_old(package, model.Action.READ, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to read package %s') % (str(user),package.id)}
    else:
        return {'success': True}
Beispiel #22
0
def group_change_state(context, data_dict):
    model = context["model"]
    user = context["user"]
    group = get_group_object(context, data_dict)

    authorized = check_access_old(group, model.Action.CHANGE_STATE, context)
    if not authorized:
        return {
            "success": False,
            "msg": _("User %s not authorized to change state of group %s") % (str(user), group.id),
        }
    else:
        return {"success": True}
Beispiel #23
0
def package_change_state(context, data_dict):
    model = context["model"]
    user = context["user"]
    package = get_package_object(context, data_dict)

    authorized = check_access_old(package, model.Action.CHANGE_STATE, context)
    if not authorized:
        return {
            "success": False,
            "msg": _("User %s not authorized to change state of package %s") % (str(user), package.id),
        }
    else:
        return {"success": True}
Beispiel #24
0
def package_edit_permissions(context, data_dict):
    model = context["model"]
    user = context["user"]
    package = get_package_object(context, data_dict)

    authorized = check_access_old(package, model.Action.EDIT_PERMISSIONS, context)
    if not authorized:
        return {
            "success": False,
            "msg": _("User %s not authorized to edit permissions of package %s") % (str(user), package.id),
        }
    else:
        return {"success": True}
Beispiel #25
0
def user_create(context, data_dict=None):
    model = context['model']
    user = context['user']

    authorized = check_access_old(model.System(), model.Action.USER_CREATE,
                                  context)
    if not authorized:
        return {
            'success': False,
            'msg': _('User %s not authorized to create users') % str(user)
        }
    else:
        return {'success': True}
Beispiel #26
0
def package_update(context, data_dict):
    model = context['model']
    user = context.get('user')
    package = get_package_object(context, data_dict)

    check1 = logic.check_access_old(package, model.Action.EDIT, context)
    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}
Beispiel #27
0
def package_create(context, data_dict=None):
    model = context["model"]
    user = context["user"]
    check1 = logic.check_access_old(model.System(), model.Action.PACKAGE_CREATE, context)

    if not check1:
        return {"success": False, "msg": _("User %s not authorized to create packages") % str(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}
Beispiel #28
0
def package_relationship_delete(context, data_dict):
    can_edit_this_relationship = package_relationship_create(context, data_dict)
    if not can_edit_this_relationship['success']:
        return can_edit_this_relationship

    model = context['model']
    user = context['user']
    relationship = context['relationship']

    authorized = logic.check_access_old(relationship, model.Action.PURGE, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to delete relationship %s') % (str(user),relationship.id)}
    else:
        return {'success': True}
Beispiel #29
0
def package_create(context, data_dict=None):
    model = context['model']
    user = context['user']
    check1 = logic.check_access_old(model.System(), model.Action.PACKAGE_CREATE, context)

    if not check1:
        return {'success': False, 'msg': _('User %s not authorized to create packages') % str(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}
Beispiel #30
0
def authorization_group_edit_permissions(context, data_dict):
    model = context["model"]
    user = context["user"]
    authorization_group = get_authorization_group_object(context, data_dict)

    authorized = check_access_old(authorization_group, model.Action.EDIT_PERMISSIONS, context)
    if not authorized:
        return {
            "success": False,
            "msg": _("User %s not authorized to edit permissions of authorization group %s")
            % (str(user), authorization_group.id),
        }
    else:
        return {"success": True}
Beispiel #31
0
def package_update(context, data_dict):
    model = context["model"]
    user = context.get("user")
    package = get_package_object(context, data_dict)

    check1 = check_access_old(package, model.Action.EDIT, context)
    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}
Beispiel #32
0
def package_delete(context, data_dict):
    model = context['model']
    user = context['user']
    package = get_package_object(context, data_dict)

    authorized = check_access_old(package, model.Action.PURGE, context)
    if not authorized:
        return {
            'success':
            False,
            'msg':
            _('User %s not authorized to delete package %s') %
            (str(user), package.id)
        }
    else:
        return {'success': True}
Beispiel #33
0
def resource_create(context, data_dict):
    # resource_create runs through package_update, no need to
    # check users eligibility to add resource to package here.
    model = context['model']
    user = context['user']
    check1 = logic.check_access_old(model.System(), model.Action.PACKAGE_CREATE, context)

    if not check1:
        return {'success': False, 'msg': _('User %s not authorized to create packages') % str(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}
Beispiel #34
0
def authorization_group_create(context, data_dict=None):
    model = context['model']
    user = context['user']

    authorized = check_access_old(model.System(),
                                  model.Action.AUTHZ_GROUP_CREATE, context)
    if not authorized:
        return {
            'success':
            False,
            'msg':
            _('User %s not authorized to create authorization groups') %
            str(user)
        }
    else:
        return {'success': True}
Beispiel #35
0
def relationship_delete(context, data_dict):
    model = context['model']
    user = context['user']
    relationship = context['relationship']

    authorized = check_access_old(relationship, model.Action.PURGE, context)
    if not authorized:
        return {
            'success':
            False,
            'msg':
            _('User %s not authorized to delete relationship %s') %
            (str(user), relationship.id)
        }
    else:
        return {'success': True}
Beispiel #36
0
def package_show(context, data_dict):
    model = context['model']
    user = context.get('user')
    package = get_package_object(context, data_dict)

    authorized = logic.check_access_old(package, model.Action.READ, context)
    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to read package %s') % (str(user),package.id)}
    else:
        # draft state indicates package is still in the creation process
        # so we need to check we have creation rights.
        if package.state.startswith('draft'):
            auth = ckan.new_authz.is_authorized('package_update',
                                                context, data_dict)
            if not auth.get('success'):
                msg = _('User %s not authorized to read package %s') \
                        % (str(user),package.id)
                return {'success': False, 'msg': msg}

        return {'success': True}
Beispiel #37
0
def package_relationship_delete(context, data_dict):
    can_edit_this_relationship = package_relationship_create(
        context, data_dict)
    if not can_edit_this_relationship['success']:
        return can_edit_this_relationship

    model = context['model']
    user = context['user']
    relationship = context['relationship']

    authorized = check_access_old(relationship, model.Action.PURGE, context)
    if not authorized:
        return {
            'success':
            False,
            'msg':
            _('User %s not authorized to delete relationship %s') %
            (str(user), relationship.id)
        }
    else:
        return {'success': True}
Beispiel #38
0
def package_create(context, data_dict=None):
    model = context['model']
    user = context['user']
    check1 = logic.check_access_old(model.System(),
                                    model.Action.PACKAGE_CREATE, context)

    if not check1:
        return {
            'success': False,
            'msg': _('User %s not authorized to create packages') % str(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}
Beispiel #39
0
def _check_group_auth(context, data_dict):
    if not data_dict:
        return True

    model = context["model"]
    pkg = context.get("package")

    api_version = context.get("api_version") or "1"

    group_blobs = data_dict.get("groups", [])
    groups = set()
    for group_blob in group_blobs:
        # group_blob might be a dict or a group_ref
        if isinstance(group_blob, dict):
            if api_version == "1":
                id = group_blob.get("name")
            else:
                id = group_blob.get("id")
            if not id:
                continue
        else:
            id = group_blob
        grp = model.Group.get(id)
        if grp is None:
            raise logic.NotFound(_("Group was not found."))
        groups.add(grp)

    if pkg:
        pkg_groups = pkg.get_groups()

        groups = groups - set(pkg_groups)

    for group in groups:
        if not logic.check_access_old(group, model.Action.EDIT, context):
            return False

    return True
Beispiel #40
0
def check_group_auth(context, data_dict):
    if not data_dict:
        return True

    model = context['model']
    pkg = context.get("package")

    api_version = context.get('api_version') or '1'

    group_blobs = data_dict.get("groups", [])
    groups = set()
    for group_blob in group_blobs:
        # group_blob might be a dict or a group_ref
        if isinstance(group_blob, dict):
            if api_version == '1':
                id = group_blob.get('name')
            else:
                id = group_blob.get('id')
            if not id:
                continue
        else:
            id = group_blob
        grp = model.Group.get(id)
        if grp is None:
            raise NotFound(_('Group was not found.'))
        groups.add(grp)

    if pkg:
        pkg_groups = pkg.get_groups()

        groups = groups - set(pkg_groups)

    for group in groups:
        if not check_access_old(group, model.Action.EDIT, context):
            return False

    return True
Beispiel #41
0
def resource_create(context, data_dict):
    # resource_create runs through package_update, no need to
    # check users eligibility to add resource to package here.
    model = context['model']
    user = context['user']
    check1 = logic.check_access_old(model.System(),
                                    model.Action.PACKAGE_CREATE, context)

    if not check1:
        return {
            'success': False,
            'msg': _('User %s not authorized to create packages') % str(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}