From 0a52a6de9935b03e7aefb4988eaa70d9022e3753 Mon Sep 17 00:00:00 2001 From: John Churchill Date: Tue, 20 Aug 2019 10:13:04 -0700 Subject: [PATCH 1/2] Updated to allow private groups, filtering is only done on group_list, groups are made private by setting the attribute private on the group, only works via API --- ckanext/bcgov/logic/action.py | 13 ++++++++- ckanext/bcgov/logic/get.py | 26 +++++++++--------- ckanext/bcgov/plugin.py | 51 +++++++++++++++++++++++++++++------ 3 files changed, 68 insertions(+), 22 deletions(-) diff --git a/ckanext/bcgov/logic/action.py b/ckanext/bcgov/logic/action.py index 2fb9b81f..f1de0a7f 100644 --- a/ckanext/bcgov/logic/action.py +++ b/ckanext/bcgov/logic/action.py @@ -29,6 +29,8 @@ from ckan.lib.mailer import MailerException import ckan.model as model +from ckanext.bcgov.logic.get import (_group_or_org_list) + import pprint @@ -45,6 +47,7 @@ _or_ = sqlalchemy.or_ + @toolkit.side_effect_free def organization_list(context, data_dict): ''' @@ -52,7 +55,6 @@ def organization_list(context, data_dict): See github issue #353 To replace the bcgov ckan fork modification from https://github.com/bcgov/ckan/pull/16 ''' - from ckanext.bcgov.logic.get import (_group_or_org_list) toolkit.check_access('organization_list', context, data_dict) groups = data_dict.get('organizations', 'None') @@ -67,6 +69,15 @@ def organization_list(context, data_dict): data_dict.setdefault('type', 'organization') return _group_or_org_list(context, data_dict, is_org=True) +@toolkit.side_effect_free +def group_list(context, data_dict): + ''' + This is being overridden from core so we can use our own _group_or_org_list, probs a better way to do this but + this needed to be done timely and this is minimally impactful + ''' + _check_access('group_list', context, data_dict) + return _group_or_org_list(context, data_dict, is_org=False) + ''' Checking package status and sending a notification if the state is changed. diff --git a/ckanext/bcgov/logic/get.py b/ckanext/bcgov/logic/get.py index a0bd86d4..390bf3bc 100644 --- a/ckanext/bcgov/logic/get.py +++ b/ckanext/bcgov/logic/get.py @@ -126,18 +126,18 @@ def _group_or_org_list(context, data_dict, is_org=False): groups = query.all() - if all_fields: - action = 'organization_show' if is_org else 'group_show' - group_list = [] - for group in groups: - data_dict['id'] = group.id - for key in ('include_extras', 'include_tags', 'include_users', - 'include_groups', 'include_followers'): - if key not in data_dict: - data_dict[key] = False - - group_list.append(logic.get_action(action)(context, data_dict)) - else: - group_list = [getattr(group, ref_group_by) for group in groups] + action = 'organization_show' if is_org else 'group_show' + group_list = [] + for group in groups: + data_dict['id'] = group.id + data_dict['include_extras'] = True + for key in ('include_tags', 'include_users', + 'include_groups', 'include_followers'): + if key not in data_dict: + data_dict[key] = False + group_detail = logic.get_action(action)(context, data_dict) + if 'private' in group_detail and not context['user']: + continue + group_list.append(group_detail if all_fields else getattr(group, ref_group_by)) return group_list diff --git a/ckanext/bcgov/plugin.py b/ckanext/bcgov/plugin.py index e1c5d813..b5dcbdf7 100644 --- a/ckanext/bcgov/plugin.py +++ b/ckanext/bcgov/plugin.py @@ -9,6 +9,12 @@ import ckan.lib.base as base import ckan.plugins as plugins import ckan.plugins.toolkit as toolkit +from ckan.lib.plugins import DefaultGroupForm + +import ckanext.bcgov.forms.converters as converters +cnvrt_to_ext = converters.convert_to_extras; +cnvrt_from_ext = converters.convert_from_extras; +from ckan.lib.navl.validators import (ignore_missing) from paste.deploy.converters import asbool from routes.mapper import SubMapper @@ -71,23 +77,17 @@ filter_query_regex = re.compile(r'([^:]+:"[^"]+"\s?)') -class SchemaPlugin(plugins.SingletonPlugin): +class SchemaPlugin(plugins.SingletonPlugin, DefaultGroupForm): plugins.implements(plugins.IConfigurer) - plugins.implements(plugins.IRoutes, inherit=True) - plugins.implements(plugins.ITemplateHelpers, inherit=False) - plugins.implements(plugins.IPackageController, inherit=True) - plugins.implements(plugins.IFacets, inherit=True) - plugins.implements(plugins.IActions, inherit=True) - plugins.implements(plugins.IAuthFunctions) - plugins.implements(plugins.IResourceController, inherit=True) + plugins.implements(plugins.IGroupForm, inherit=True) def get_helpers(self): return { @@ -401,6 +401,7 @@ def get_actions(self): from ckanext.bcgov.logic.ofi import call_action as ofi return { 'organization_list': edc_action.organization_list, + 'group_list': edc_action.group_list, 'edc_package_update': edc_action.edc_package_update, 'edc_package_update_bcgw': edc_action.edc_package_update_bcgw, 'package_update': edc_action.package_update, @@ -436,3 +437,37 @@ def get_auth_functions(self): def before_create(self, context, resource): # preventative fix for #386 - make sure facet format types are always lowercase; resource['format'] = resource.get('format', '').lower() + + # IGroupForm + def group_types(self): + return ('group',) + + def form_to_db_schema_options(self, options): + + # Get the default organization schema + schema = super(SchemaPlugin, self).form_to_db_schema_options(options) + + if not schema: + from ckan.logic.schema import group_form_schema + schema = group_form_schema() + + # Add custom fields to organization schema + schema.update({ + 'private': [ignore_missing, unicode, cnvrt_to_ext] + }) + + return schema + + def db_to_form_schema_options(self, options): + # Get the default organization schema + schema = super(SchemaPlugin, self).db_to_form_schema_options(options) + + if not schema: + from ckan.logic.schema import default_group_schema + schema = default_group_schema() + + # Add custom fileds to organization schema + schema.update({ + 'private': [cnvrt_from_ext, ignore_missing, unicode] + }) + return schema \ No newline at end of file From 82386822e33bbdf96c06422f782e985d6428ef56 Mon Sep 17 00:00:00 2001 From: John Churchill Date: Tue, 20 Aug 2019 16:49:59 -0700 Subject: [PATCH 2/2] Overrode template for group info and removed follower count due to weird error --- .../bcgov/templates/group/snippets/info.html | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ckanext/bcgov/templates/group/snippets/info.html diff --git a/ckanext/bcgov/templates/group/snippets/info.html b/ckanext/bcgov/templates/group/snippets/info.html new file mode 100644 index 00000000..7f374c75 --- /dev/null +++ b/ckanext/bcgov/templates/group/snippets/info.html @@ -0,0 +1,47 @@ +{% block info %} +
+
+ {% block inner %} + {% block image %} +
+ + {{ group.name }} + +
+ {% endblock %} + {% block heading %} +

+ {{ h.get_translated(group, 'title') or group.display_name }} + {% if group.state == 'deleted' %} + [{{ _('Deleted') }}] + {% endif %} +

+ {% endblock %} + {% block description %} + {% if h.get_translated(group, 'description') %} +

+ {{ h.markdown_extract(h.get_translated(group, 'description'), 180) }} + {% link_for _('read more'), controller='group', action='about', id=group.name %} +

+ {% endif %} + {% endblock %} + {% if show_nums %} + {% block nums %} +
+ +
+
{{ _('Datasets') }}
+
{{ h.SI_number_span(group.package_count) }}
+
+
+ {% endblock %} + {% block follow %} + + {% endblock %} + {% endif %} + {% endblock %} +
+
+{% endblock %}