Repository: ckan/ckan

Issue:
Member_delete causes not found errors even though everything should be present
**CKAN version**
2.9, master

**Describe the bug**
Clicking delete member from organization results in not found.

**Steps to reproduce**
Create an organization.
Add an user to it.
Delete the user from it.

**Expected behavior**
Member is deleted and the UI returns to member view 

**Additional details**
Most likely bug resides in this line https://github.com/ckan/ckan/blob/91c9366cf8df0dc4e12a9a043756eda5e40534b0/ckan/views/group.py#L548 as it calls `group_show` with user id. 



Discussion:
Add a test that prevents this failure
I can not reproduce the error...

CKAN master
<img width="1314" alt="image" src="https://user-images.githubusercontent.com/72216462/171497285-78db82e7-037b-4038-b281-555d56133690.png">

CKAN 2.9.5
<img width="1624" alt="image" src="https://user-images.githubusercontent.com/72216462/171498236-ff92b63c-c48d-4f16-a123-382ce651cbc6.png">

This actually requires that javascript is disabled for whatever reason, which is why it wasn't caught before. The modal works, but the url from the delete button does not. Can be reproduced by copying the url from the button and pasting it to the browser url bar.

Resolving patch:
diff --git a/ckan/views/group.py b/ckan/views/group.py
--- a/ckan/views/group.py
+++ b/ckan/views/group.py
@@ -545,7 +545,7 @@ def member_delete(id: str, group_type: str,
             })
             h.flash_notice(_(u'Group member has been deleted.'))
             return h.redirect_to(u'{}.members'.format(group_type), id=id)
-        user_dict = _action(u'group_show')(context, {u'id': user_id})
+        user_dict = _action(u'user_show')(context, {u'id': user_id})
 
         # TODO: Remove
         # ckan 2.9: Adding variables that were removed from c object for
@@ -561,7 +561,8 @@ def member_delete(id: str, group_type: str,
     extra_vars: dict[str, Any] = {
         u"user_id": user_id,
         u"user_dict": user_dict,
-        u"group_id": id
+        u"group_id": id,
+        u"group_type": group_type
     }
     return base.render(_replace_group_org(u'group/confirm_delete_member.html'),
                        extra_vars)


Test patch:
diff --git a/ckan/tests/controllers/test_organization.py b/ckan/tests/controllers/test_organization.py
--- a/ckan/tests/controllers/test_organization.py
+++ b/ckan/tests/controllers/test_organization.py
@@ -575,3 +575,23 @@ def test_anonymous_users_cannot_add_members(self, app):
                 },
                 status=403,
             )
+
+    def test_member_delete(self, app):
+        sysadmin = factories.Sysadmin()
+        user = factories.User()
+        org = factories.Organization(
+            users=[{"name": user["name"], "capacity": "member"}]
+        )
+        env = {"REMOTE_USER": six.ensure_str(sysadmin["name"])}
+        # our user + test.ckan.net
+        assert len(org["users"]) == 2
+        with app.flask_app.test_request_context():
+            app.post(
+                url_for("organization.member_delete", id=org["id"], user=user["id"]),
+                extra_environ=env,
+            )
+            org = helpers.call_action('organization_show', id=org['id'])
+
+            # only test.ckan.net
+            assert len(org['users']) == 1
+            assert user["id"] not in org["users"][0]["id"]