Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use ignore_not_sysadmin validator #362

Open
mmeisel opened this issue Mar 22, 2023 · 0 comments
Open

Cannot use ignore_not_sysadmin validator #362

mmeisel opened this issue Mar 22, 2023 · 0 comments

Comments

@mmeisel
Copy link

mmeisel commented Mar 22, 2023

I'm trying to create an organization field that is only editable by sysadmins. I don't care if org admins can see it, but I don't want them to be able to change it (or clear it). Here's my attempt at such a field:

    {
      "field_name": "request_limit",
      "label": "Request Limit",
      "form_placeholder": "0",
      "validators": "ignore_not_sysadmin"
    }

But when I try to edit the organization as a non-sysadmin, I get this exception (I guess because the ignore_not_sysadmin validator deletes the key):

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/lib/python3.8/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/flask/views.py", line 163, in dispatch_request
    return meth(*args, **kwargs)
  File "/srv/app/src/ckan/ckan/config/middleware/../../views/group.py", line 955, in post
    group = _action(u'group_update')(context, data_dict)
  File "/srv/app/src/ckan/ckan/logic/__init__.py", line 504, in wrapped
    result = _action(context, data_dict, **kw)
  File "/srv/app/src/ckan/ckan/logic/action/update.py", line 812, in organization_update
    return _group_or_org_update(context, data_dict, is_org=True)
  File "/srv/app/src/ckan/ckan/logic/action/update.py", line 684, in _group_or_org_update
    data, errors = lib_plugins.plugin_validate(
  File "/srv/app/src/ckan/ckan/lib/plugins.py", line 312, in plugin_validate
    result = plugin.validate(context, data_dict, schema, action)
  File "/srv/app/src/ckanext-scheming/ckanext/scheming/plugins.py", line 191, in validate
    return navl_validate(data_dict, schema, context)
  File "/srv/app/src/ckan/ckan/lib/navl/dictization_functions.py", line 285, in validate
    converted_data, errors = _validate(flattened, schema, validators_context)
  File "/srv/app/src/ckan/ckan/lib/navl/dictization_functions.py", line 335, in _validate
    convert(converter, key, converted_data, errors, context)
  File "/srv/app/src/ckan/ckan/lib/navl/dictization_functions.py", line 237, in convert
    converter(key, converted_data, errors, context)
  File "/srv/app/src/ckan/ckan/logic/converters.py", line 24, in convert_to_extras
    data[('extras', new_index, 'value')] = data[key]
KeyError: ('forecast_daily_locations_limit',)

If I add ignore_missing to the validators, no exception is raised, but editing the org as an org admin clears the field.

Any way to accomplish this?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant