Repository: ckan/ckan

Issue:
group_update is not updating 'image_url' field
**CKAN version**
master
2.8.5

**Describe the bug**
Executing `group_update` or `group_patch` with a new `image_url` doesn't have any effect. In the following command I'm trying to change the value to `new_image.jpg` but it is not working.

```
curl -X POST -H "Authorization: blablabla" -H "Content-Type: application/json" --data '{"id":"testing", "image_url":"new_image.jpg"}' "http://ckan:5000/api/action/group_patch"

{
  "help": "http://ckan:5000/api/3/action/help_show?name=group_patch",
  "success": true,
  "result": {
    "id": "e040fea8-4ba0-46d1-92ee-26dd5cbe5a7b",
    "name": "testing",
    "title": "Testing",
    "type": "group",
    "description": "Prueba",
    "image_url": "2020-10-30-124145.785791PDB0980.jpg",
    "created": "2020-10-30T09:41:45.798167",
    "is_organization": false,
    "approval_status": "approved",
    "state": "active",
    "display_name": "Testing",
    "extras": [],
    "packages": [],
    "package_count": 0,
    "tags": [],
    "groups": [],
    "users": [
      {
        "id": "9a5ffa4d-26e5-457f-8dca-570e1c3c9fb6",
        "name": "ckan_admin",
        "fullname": null,
        "created": "2020-10-30T09:40:56.162463",
        "about": null,
        "activity_streams_email_notifications": false,
        "sysadmin": true,
        "state": "active",
        "image_url": null,
        "capacity": "admin",
        "display_name": "ckan_admin",
        "email_hash": "b1443134b36be9f6993b6d4ea4b3f1f1",
        "number_created_packages": 0,
        "image_display_url": null
      }
    ],
    "image_display_url": "http://ckan:5000/uploads/group/2020-10-30-124145.785791PDB0980.jpg"
  }
}

```

**Steps to reproduce**
* Create a new group
* Add an image to it
* Try to update the field value with `group_patch` or `group_update`

**Expected behavior**
The field us updated correctly to the new value.

**Additional details**
This is working correctly for users. The problem seems to be in how the `user_update` and `group_update` instantiate the `upload` object:

https://github.com/ckan/ckan/blob/c44096e64e4ff0c98c79c9ad445b48c0750c331e/ckan/logic/action/update.py#L658-L660

https://github.com/ckan/ckan/blob/c44096e64e4ff0c98c79c9ad445b48c0750c331e/ckan/logic/action/update.py#L826-L828



Discussion:

Resolving patch:
diff --git a/ckan/logic/action/update.py b/ckan/logic/action/update.py
--- a/ckan/logic/action/update.py
+++ b/ckan/logic/action/update.py
@@ -655,7 +655,7 @@ def _group_or_org_update(context, data_dict, is_org=False):
     except AttributeError:
         schema = group_plugin.form_to_db_schema()
 
-    upload = uploader.get_uploader('group', group.image_url)
+    upload = uploader.get_uploader('group')
     upload.update_data_dict(data_dict, 'image_url',
                             'image_upload', 'clear_upload')
 


Test patch:
diff --git a/ckan/tests/logic/action/test_update.py b/ckan/tests/logic/action/test_update.py
--- a/ckan/tests/logic/action/test_update.py
+++ b/ckan/tests/logic/action/test_update.py
@@ -467,25 +467,6 @@ def test_update_organization_cant_change_type(self):
             == "organization"
         )
 
-    def test_update_group_cant_change_type(self):
-        user = factories.User()
-        context = {"user": user["name"]}
-        group = factories.Group(type="group", name="unchanging", user=user)
-
-        group = helpers.call_action(
-            "group_update",
-            context=context,
-            id=group["id"],
-            name="unchanging",
-            type="favouritecolour",
-        )
-
-        assert group["type"] == "group"
-        assert (
-            helpers.call_action("group_show", id="unchanging")["type"]
-            == "group"
-        )
-
 
 @pytest.mark.usefixtures("clean_db", "with_request_context")
 class TestDatasetUpdate(object):
@@ -1481,6 +1462,62 @@ def test_user_create_password_hash_not_for_normal_users(self):
         user_obj = model.User.get(user["id"])
         assert user_obj.password != "pretend-this-is-a-valid-hash"
 
+    def test_user_update_image_url(self):
+        user = factories.User(image_url='user_image.jpg')
+        context = {"user": user["name"]}
+
+        user = helpers.call_action(
+            "user_update",
+            context=context,
+            id=user["name"],
+            email="test@example.com",
+            image_url="new_image_url.jpg",
+        )
+
+        assert user["image_url"] == "new_image_url.jpg"
+
+
+@pytest.mark.usefixtures("clean_db", "with_request_context")
+class TestGroupUpdate(object):
+    def test_group_update_image_url_field(self):
+        user = factories.User()
+        context = {"user": user["name"]}
+        group = factories.Group(
+            type="group",
+            name="testing",
+            user=user,
+            image_url='group_image.jpg')
+
+        group = helpers.call_action(
+            "group_update",
+            context=context,
+            id=group["id"],
+            name=group["name"],
+            type=group["type"],
+            image_url="new_image_url.jpg"
+        )
+
+        assert group["image_url"] == "new_image_url.jpg"
+
+    def test_group_update_cant_change_type(self):
+        user = factories.User()
+        context = {"user": user["name"]}
+        group = factories.Group(type="group", name="unchanging", user=user)
+
+        group = helpers.call_action(
+            "group_update",
+            context=context,
+            id=group["id"],
+            name="unchanging",
+            type="favouritecolour",
+        )
+
+        assert group["type"] == "group"
+        assert (
+            helpers.call_action("group_show", id="unchanging")["type"]
+            == "group"
+        )
+
 
 @pytest.mark.usefixtures("clean_db", "with_request_context")
 class TestPackageOwnerOrgUpdate(object):