Cannot use ignore_not_sysadmin validator
- Dominant language
- Python
- Stars
- 102
- Forks
- 182
- PR merge metrics
- No merged PRs in 30d
Description
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!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in ckanext-scheming/ckanext/scheming/plugins.py and follow the validation path shown through ckan/ckan/lib/navl/dictization_functions.py and ckan/ckan/logic/converters.py. Reproduce the organization edit with ignore_not_sysadmin, compare it with ignore_missing, and verify that an org admin cannot change or clear the existing field without triggering the KeyError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- authorization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100