예제 #1
0
파일: create.py 프로젝트: gabelula/ckan
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
예제 #2
0
파일: create.py 프로젝트: gabelula/ckan
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}
예제 #3
0
파일: create.py 프로젝트: gabelula/ckan
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}
예제 #4
0
파일: create.py 프로젝트: slmnhq/ckan
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}
예제 #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}
예제 #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}
예제 #7
0
파일: update.py 프로젝트: arkka/ckan
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}
예제 #8
0
파일: delete.py 프로젝트: emphanos/ckan
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}
예제 #9
0
파일: update.py 프로젝트: arkka/ckan
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}
예제 #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}
예제 #11
0
파일: update.py 프로젝트: arkka/ckan
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}
예제 #12
0
파일: update.py 프로젝트: arkka/ckan
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}
예제 #13
0
파일: get.py 프로젝트: AltisCorp/ckan
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}
예제 #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}
예제 #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}
예제 #16
0
파일: get.py 프로젝트: AltisCorp/ckan
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}
예제 #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}
예제 #18
0
파일: update.py 프로젝트: Big-Data/ckan
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}
예제 #19
0
파일: delete.py 프로젝트: emphanos/ckan
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}
예제 #20
0
파일: update.py 프로젝트: kindly/ckan
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}
예제 #21
0
파일: get.py 프로젝트: pingali/ckan
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}
예제 #22
0
파일: update.py 프로젝트: kindly/ckan
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}
예제 #23
0
파일: update.py 프로젝트: kindly/ckan
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}
예제 #24
0
파일: update.py 프로젝트: kindly/ckan
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}
예제 #25
0
파일: create.py 프로젝트: pingali/ckan
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}
예제 #26
0
파일: update.py 프로젝트: petrushev/ckan
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}
예제 #27
0
파일: create.py 프로젝트: slmnhq/ckan
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}
예제 #28
0
파일: delete.py 프로젝트: emphanos/ckan
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}
예제 #29
0
파일: create.py 프로젝트: fusionx1/ckan
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}
예제 #30
0
파일: update.py 프로젝트: kindly/ckan
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}
예제 #31
0
파일: update.py 프로젝트: kindly/ckan
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}
예제 #32
0
파일: delete.py 프로젝트: pingali/ckan
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}
예제 #33
0
파일: create.py 프로젝트: Big-Data/ckan
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}
예제 #34
0
파일: create.py 프로젝트: pingali/ckan
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}
예제 #35
0
파일: delete.py 프로젝트: pingali/ckan
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}
예제 #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}
예제 #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}
예제 #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}
예제 #39
0
파일: create.py 프로젝트: slmnhq/ckan
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
예제 #40
0
파일: create.py 프로젝트: pingali/ckan
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
예제 #41
0
파일: create.py 프로젝트: petrushev/ckan
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}