Пример #1
0
def protect_portal_release_date(key, data, errors, context):
    """
    Ensure the portal_release_date is not changed by an unauthorized user.
    """
    if is_sysadmin(context['user']):
        return
    original = ''
    package = context.get('package')
    if package:
        original = package.extras.get('portal_release_date', '')
    value = data.get(key, '')
    if original == value:
        return

    user = context['user']
    user = model.User.get(user)
    if may_publish_datasets(user):
        return

    if value == '':
        # silently replace with the old value when none is sent
        data[key] = original
        return

    raise Invalid('Cannot change value of key from %s to %s. '
                  'This key is read-only' % (original, value))
Пример #2
0
def owner_org_validator_publisher(key, data, errors, context):
    """
    owner_org_validator modified to allow publisher to update
    datasets for any org
    """

    value = data.get(key)

    if value is missing or not value:
        if not ckan.new_authz.check_config_permission(
                'create_unowned_dataset'):
            raise Invalid(_('A organization must be supplied'))
        data.pop(key, None)
        raise StopOnError

    model = context['model']
    group = model.Group.get(value)
    if not group:
        raise Invalid(_('Organization does not exist'))
    group_id = group.id
    user = context['user']
    user = model.User.get(user)
    if not (may_publish_datasets(user) or user.is_in_group(group_id)):
        raise Invalid(_('You cannot add a dataset to this organization'))
    data[key] = group_id
Пример #3
0
def protect_portal_release_date(key, data, errors, context):
    """
    Ensure the portal_release_date is not changed by an unauthorized user.
    """
    if is_sysadmin(context['user']):
        return
    original = ''
    package = context.get('package')
    if package:
        original = package.extras.get('portal_release_date', '')
    value = data.get(key, '')
    if original == value:
        return

    user = context['user']
    user = model.User.get(user)
    if may_publish_datasets(user):
        return

    if not value:
        # silently replace with the old value when none is sent
        data[key] = original
        return

    errors[key].append("Cannot change value of key from '%s' to '%s'. "
                       'This key is read-only' % (original, value))

    raise StopOnError
Пример #4
0
def protect_portal_release_date(key, data, errors, context):
    """
    Ensure the portal_release_date is not changed by an unauthorized user.
    """
    if is_sysadmin(context['user']):
        return
    original = ''
    package = context.get('package')
    if package:
        original = package.extras.get('portal_release_date', '')
    value = data.get(key, '')
    if original == value:
        return

    user = context['user']
    user = model.User.get(user)
    if may_publish_datasets(user):
        return

    raise Invalid('Cannot change value of key from %s to %s. '
                  'This key is read-only' % (original, value))
Пример #5
0
def owner_org_validator_publisher(key, data, errors, context):
    """
    owner_org_validator modified to allow publisher to update
    datasets for any org
    """

    value = data.get(key)

    if value is missing or not value:
        if not ckan.new_authz.check_config_permission('create_unowned_dataset'):
            raise Invalid(_('A organization must be supplied'))
        data.pop(key, None)
        raise StopOnError

    model = context['model']
    group = model.Group.get(value)
    if not group:
        raise Invalid(_('Organization does not exist'))
    group_id = group.id
    user = context['user']
    user = model.User.get(user)
    if not(may_publish_datasets(user) or user.is_in_group(group_id)):
        raise Invalid(_('You cannot add a dataset to this organization'))
    data[key] = group_id