diff --git a/ckanext/datasetapproval/plugin.py b/ckanext/datasetapproval/plugin.py index 5fe517b..ac605d0 100644 --- a/ckanext/datasetapproval/plugin.py +++ b/ckanext/datasetapproval/plugin.py @@ -88,7 +88,12 @@ def get_validators(self): # IPackageController def before_search(self, search_params): - include_approval_pending= search_params.get('include_approval_pending', False) + if toolkit.c.userobj: + user_is_syadmin = toolkit.c.userobj.sysadmin + else: + user_is_syadmin = False + + include_approval_pending = search_params.get('include_approval_pending', False) include_drafts = search_params.get('include_drafts', False) if include_drafts: @@ -96,8 +101,14 @@ def before_search(self, search_params): search_params.update({ 'fq': "+creator_user_id:{0} ".format(c.userobj.id) + search_params.get('fq', '') }) - elif include_approval_pending: - search_params.pop('include_approval_pending') + elif include_approval_pending or user_is_syadmin: + search_params.pop('include_approval_pending', None) + + # Order dataset by approval state for sysadmin user. + if search_params.get('sort', '').startswith('approval_state'): + search_params.update({ + 'fq': '!(approval_state:(active OR approved))' + search_params.get('fq', '') + }) return search_params else: search_params.update({ diff --git a/ckanext/datasetapproval/validation.py b/ckanext/datasetapproval/validation.py index 633ca19..b6f9b5f 100644 --- a/ckanext/datasetapproval/validation.py +++ b/ckanext/datasetapproval/validation.py @@ -18,13 +18,13 @@ def state_validator(key, data, errors, context): for org in user_orgs: if org.get('id') == office_id: if org.get('capacity') == 'admin': - # If no state provided and user is an admin, default to active - state = state or 'active' + # If no state provided and user is an admin, default to approved + state = state or 'approved' elif is_ready_to_publish: # If not admin and not draft, dataset has to go through approval process. state = 'pending' else: state = False - data[key] = state or 'active' - return 'hello' + data[key] = state + return