Repository: ckan/ckan

Issue:
group_followee_count returns incorrect amount
The function `logic.action.get.group_followee_count` returns the amount of groups **and** organization the user follows. This is incorrect because according to the documentation (and function name) it should **only** return organisations.

This is because organisations are also groups and the function `logic.action.get._followee_count` doesn't filter the groups like `logic.action.get.group_followee_list` and `logic.action.get.organization_followee_list` do.



Discussion:
Do you want to submit a quick PR @trickvi ? Seems pretty easy to fix

I'll fix
Made [PR](https://github.com/ckan/ckan/pull/3458)
The associated PR looks okay, but needs tests.  

Resolving patch:
diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -2723,14 +2723,20 @@ def am_following_group(context: Context,
 
 def _followee_count(
         context: Context, data_dict: DataDict,
-        FollowerClass: Type['ModelFollowingModel[Any ,Any]']) -> int:
+        FollowerClass: Type['ModelFollowingModel[Any ,Any]'],
+        is_org: bool = False
+        ) -> int:
     if not context.get('skip_validation'):
         schema = context.get('schema',
                              ckan.logic.schema.default_follow_user_schema())
         data_dict, errors = _validate(data_dict, schema, context)
         if errors:
             raise ValidationError(errors)
-    return FollowerClass.followee_count(data_dict['id'])
+    
+    followees = _group_or_org_followee_list(context, data_dict, is_org)
+
+    return len(followees)
+
 
 
 def followee_count(context: Context,
@@ -2807,8 +2813,24 @@ def group_followee_count(
     '''
     return _followee_count(
         context, data_dict,
-        context['model'].UserFollowingGroup)
+        context['model'].UserFollowingGroup,
+        is_org = False)
 
+def organization_followee_count(
+        context: Context,
+        data_dict: DataDict) -> ActionResult.OrganizationFolloweeCount:
+    '''Return the number of organizations that are followed by the given user.
+
+    :param id: the id of the user
+    :type id: string
+
+    :rtype: int
+
+    '''
+    return _followee_count(
+        context, data_dict,
+        context['model'].UserFollowingGroup,
+        is_org = True)
 
 @logic.validate(ckan.logic.schema.default_follow_user_schema)
 def followee_list(
diff --git a/ckan/model/follower.py b/ckan/model/follower.py
--- a/ckan/model/follower.py
+++ b/ckan/model/follower.py
@@ -106,7 +106,8 @@ def _get_followers(
 
     @classmethod
     def _get(
-            cls, follower_id: Optional[str] = None,
+            cls, 
+            follower_id: Optional[str] = None,
             object_id: Optional[str] = None
     ) -> Query[tuple[Self, Follower, Followed]]:
         follower_alias = sqlalchemy.orm.aliased(cls._follower_class())
diff --git a/ckan/types/logic/action_result.py b/ckan/types/logic/action_result.py
--- a/ckan/types/logic/action_result.py
+++ b/ckan/types/logic/action_result.py
@@ -64,6 +64,7 @@
 UserFolloweeCount = int
 DatasetFolloweeCount = int
 GroupFolloweeCount = int
+OrganizationFolloweeCount = int
 FolloweeList = List[AnyDict]
 UserFolloweeList = List[AnyDict]
 DatasetFolloweeList = List[AnyDict]


Test patch:
diff --git a/ckan/tests/logic/action/test_get.py b/ckan/tests/logic/action/test_get.py
--- a/ckan/tests/logic/action/test_get.py
+++ b/ckan/tests/logic/action/test_get.py
@@ -2877,6 +2877,30 @@ def test_followee_list_with_q(self):
         assert len(followee_list) == 1
         assert followee_list[0]["display_name"] == "Environment"
 
+    def test_followee_count_for_org_or_group(self):
+        group = factories.Group(title="Finance")
+        group2 = factories.Group(title="Environment")
+        org = factories.Organization(title="Acme")
+
+        user = factories.User()
+
+        context = {"user": user["name"]}
+
+        helpers.call_action("follow_group", context, id=group["id"])
+        helpers.call_action("follow_group", context, id=group2["id"])
+        helpers.call_action("follow_group", context, id=org["id"])
+
+        group_followee_count = helpers.call_action(
+            "group_followee_count", context, id=user["name"]
+        )
+
+        organization_followee_count = helpers.call_action(
+            "organization_followee_count", context, id=user["name"]
+        )
+
+        assert group_followee_count == 2
+        assert organization_followee_count == 1
+
 
 class TestStatusShow(object):
     @pytest.mark.ckan_config("ckan.plugins", "stats")
diff --git a/ckan/tests/test_coding_standards.py b/ckan/tests/test_coding_standards.py
--- a/ckan/tests/test_coding_standards.py
+++ b/ckan/tests/test_coding_standards.py
@@ -319,6 +319,7 @@ class TestActionAuth(object):
         "get: dataset_follower_count",
         "get: followee_count",
         "get: group_followee_count",
+        "get: organization_followee_count",
         "get: group_follower_count",
         "get: group_package_show",
         "get: member_list",