Repository: ckan/ckan

Issue:
/Organization package count incorrect, Collaborator private packages aren't included. 
**CKAN 2.9**

Packages that you are a collaborator of are not included in the dataset count on the /organization view page but then are included on the organizations/<organistion_name> page.

I'm not sure whether this is the intended functionality? But it seems like packages you are a collaborator of should be included.

Thanks in advance.


Discussion:
Hey, @n00dl3nate I've just tested this out, works fine for me, the only dataset that didn't count in the `/organization` page are those set to private...

If the core team agree to count the private datasets for collaborators on the `/organization` page I will make a PR
Hello, Thanks for your response, Apologies I left out that piece of information that it is private datasets that you are a collaborator of isn't being included in the dataset count on but private datasets that are owned by an organisation that you are a member of are included in the count. is there a reason why they shouldn't be included in the count?
@TomeCirun @n00dl3nate Yes, these two counts should have the same value. Also compare it to the Organization facet on the dataset search page to make sure they match

Resolving patch:
diff --git a/ckan/lib/dictization/model_dictize.py b/ckan/lib/dictization/model_dictize.py
--- a/ckan/lib/dictization/model_dictize.py
+++ b/ckan/lib/dictization/model_dictize.py
@@ -35,6 +35,7 @@
 import ckan.lib.munge as munge
 import ckan.model as model
 from ckan.types import Context, Query
+from ckan.common import config
 
 ## package save
 
@@ -360,13 +361,15 @@ def get_packages_for_this_group(group_: model.Group,
             else:
                 q['fq'] = '+groups:"{0}"'.format(group_.name)
 
-            # Allow members of organizations to see private datasets.
             if group_.is_organization:
                 is_group_member = (context.get('user') and
                     authz.has_user_permission_for_group_or_org(
                         group_.id, context.get('user'), 'read'))
                 if is_group_member:
                     q['include_private'] = True
+                else:
+                    if config.get('ckan.auth.allow_dataset_collaborators'):
+                        q['include_private'] = True
 
             if not just_the_count:
                 # package_search limits 'rows' anyway, so this is only if you


Test patch:
diff --git a/ckan/tests/lib/dictization/test_model_dictize.py b/ckan/tests/lib/dictization/test_model_dictize.py
--- a/ckan/tests/lib/dictization/test_model_dictize.py
+++ b/ckan/tests/lib/dictization/test_model_dictize.py
@@ -317,6 +317,33 @@ def test_group_dictize_for_org_with_package_count(self):
 
         assert org["package_count"] == 1
 
+    @pytest.mark.ckan_config("ckan.auth.allow_dataset_collaborators", True)
+    def test_group_dictize_for_org_with_private_package_count_collaborator(
+        self,
+    ):
+        import ckan.tests.helpers as helpers
+
+        org_obj = factories.Organization.model()
+        user_obj = factories.User.model()
+        private_dataset = factories.Dataset(owner_org=org_obj.id, private=True)
+        factories.Dataset(owner_org=org_obj.id)
+        context = {
+            "model": model,
+            "session": model.Session,
+            "auth_user_obj": user_obj,
+        }
+        org = model_dictize.group_dictize(org_obj, context)
+        assert org["package_count"] == 1
+
+        helpers.call_action(
+            "package_collaborator_create",
+            id=private_dataset["id"],
+            user_id=user_obj.id,
+            capacity="member",
+        )
+        org = model_dictize.group_dictize(org_obj, context)
+        assert org["package_count"] == 2
+
 
 @pytest.mark.usefixtures("non_clean_db")
 class TestPackageDictize: