Repository: ckan/ckan

Issue:
Group facets cannot be customized in the same way as dataset facets
When implementing IFacets interface, we want to override the default facet titles. For example, we may only want a part of the default facets for our dataset/group/organization page.
There are two ways to achieve this. Take `dataset_facets(self, facets_dict, package_type)` for example.

Method 1 is to change the facets_dict variable passed into the function, i.e

```
def dataset_facets(self, facets_dict, package_type):
        facets_dict.pop('organization')
        facets_dict.pop('license_id')
        return facets_dict
```

Method 2 is to return a new facet dictionary that contains all the facets titles that I want:

```
def dataset_facets(self, facets_dict, package_type):
        my_facet_titles = {
                    'groups': tk._('Categories'),
                    'tags': tk._('Tags'),
                    'res_format': tk._('Formats'),
                    }
        return my_facet_titles
```

Both methods work for dataset_facets, but the 2nd method will fail on group_facets. 
The issue is [here](https://github.com/ckan/ckan/blob/91e41b2e68faa3df5296a632f4862f5a55e69e62/ckan/controllers/group.py#L381). You can only make changes directly on the variable facets. Creating and returning any new dictionary in the `group_facets` method will not work.

Why is it necessary to define this [function](https://github.com/ckan/ckan/blob/91e41b2e68faa3df5296a632f4862f5a55e69e62/ckan/controllers/group.py#L379)? Why not make it consistent with the dataset counterpart?
Well, my current quick fix for my project is to always use method 1, or move the code outside `_update_facet_titles()`



Discussion:
:+1: I'd say the IFacets implementation for groups and organizations is currently broken (well kind-of).

@perceptron-XYZ please submit a fix for this to align the IGroupForm behaviour to IDatasetForm's

@wardi , is this issue actual?
@gleb-rudenko the issue described is still present, in case you want to submit a patch
We decided to close old issues that are not actively worked on so that we can focus our effort and attention on issues affecting the current versions of CKAN.

If this issue is still affecting the version of CKAN you're working with now, please feel free to comment or reopen the issue.

If you do reopen this issue, please update it with new details. One reason it might not have been resolved in the past is that it wasn't clear how a contributor could address the issue.

Resolving patch:
diff --git a/ckan/controllers/group.py b/ckan/controllers/group.py
--- a/ckan/controllers/group.py
+++ b/ckan/controllers/group.py
@@ -326,7 +326,7 @@ def pager_url(q=None, page=None):
                     facets[facet] = facet
 
             # Facet titles
-            self._update_facet_titles(facets, group_type)
+            facets = self._update_facet_titles(facets, group_type)
 
             c.facet_titles = facets
 
@@ -377,6 +377,7 @@ def _update_facet_titles(self, facets, group_type):
         for plugin in plugins.PluginImplementations(plugins.IFacets):
             facets = plugin.group_facets(
                 facets, group_type, None)
+        return facets
 
     def bulk_process(self, id):
         ''' Allow bulk processing of datasets for an organization.  Make
diff --git a/ckan/controllers/organization.py b/ckan/controllers/organization.py
--- a/ckan/controllers/organization.py
+++ b/ckan/controllers/organization.py
@@ -28,3 +28,4 @@ def _update_facet_titles(self, facets, group_type):
         for plugin in plugins.PluginImplementations(plugins.IFacets):
             facets = plugin.organization_facets(
                 facets, group_type, None)
+        return facets
diff --git a/ckan/views/group.py b/ckan/views/group.py
--- a/ckan/views/group.py
+++ b/ckan/views/group.py
@@ -353,7 +353,7 @@ def pager_url(q=None, page=None):
                 facets[facet] = facet
 
         # Facet titles
-        _update_facet_titles(facets, group_type)
+        facets = _update_facet_titles(facets, group_type)
 
         extra_vars["facet_titles"] = facets
 
@@ -413,6 +413,7 @@ def pager_url(q=None, page=None):
 def _update_facet_titles(facets, group_type):
     for plugin in plugins.PluginImplementations(plugins.IFacets):
         facets = plugin.group_facets(facets, group_type, None)
+    return facets
 
 
 def _get_group_dict(id, group_type):


Test patch: