Skip to content

Commit

Permalink
Merge pull request #798 from bcgov/ckanext-bcgov775-hidden-groups
Browse files Browse the repository at this point in the history
Ckanext bcgov775 hidden groups
  • Loading branch information
BrandonSharratt authored Sep 30, 2019
2 parents f174f19 + 8238682 commit 2c762aa
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 22 deletions.
13 changes: 12 additions & 1 deletion ckanext/bcgov/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -45,14 +47,14 @@
_or_ = sqlalchemy.or_



@toolkit.side_effect_free
def organization_list(context, data_dict):
'''
Overriding the `organization_list` action,
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')
Expand All @@ -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.
Expand Down
26 changes: 13 additions & 13 deletions ckanext/bcgov/logic/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
51 changes: 43 additions & 8 deletions ckanext/bcgov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
47 changes: 47 additions & 0 deletions ckanext/bcgov/templates/group/snippets/info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% block info %}
<div class="module context-info">
<section class="module-content">
{% block inner %}
{% block image %}
<div class="image">
<a href="{{ group.url }}">
<img src="{{ group.image_display_url or h.url_for_static('/base/images/placeholder-group.png') }}" width="190" height="118" alt="{{ group.name }}" />
</a>
</div>
{% endblock %}
{% block heading %}
<h1 class="heading">
{{ h.get_translated(group, 'title') or group.display_name }}
{% if group.state == 'deleted' %}
[{{ _('Deleted') }}]
{% endif %}
</h1>
{% endblock %}
{% block description %}
{% if h.get_translated(group, 'description') %}
<p>
{{ h.markdown_extract(h.get_translated(group, 'description'), 180) }}
{% link_for _('read more'), controller='group', action='about', id=group.name %}
</p>
{% endif %}
{% endblock %}
{% if show_nums %}
{% block nums %}
<div class="nums">

<dl>
<dt>{{ _('Datasets') }}</dt>
<dd>{{ h.SI_number_span(group.package_count) }}</dd>
</dl>
</div>
{% endblock %}
{% block follow %}
<div class="follow_button">
{{ h.follow_button('group', group.id) }}
</div>
{% endblock %}
{% endif %}
{% endblock %}
</section>
</div>
{% endblock %}

0 comments on commit 2c762aa

Please sign in to comment.