owncloud / ocis

:atom_symbol: ownCloud Infinite Scale Stack
https://doc.owncloud.com/ocis/next/
Apache License 2.0
1.38k stars 181 forks source link

Activities. Resource id is missing in the old activities #9712

Open Salipa-Gurung opened 2 months ago

Salipa-Gurung commented 2 months ago

Describe the bug

For activities api: GET /v1beta1/extensions/org.libregraph/activities, resource id is missing for file creation event when activity is checked after deleting the file.

Steps to reproduce

  1. Upload a file and check activity
    {
    "value": [
        {
            "id": "28a2a0e4-d17d-437b-933f-51046f273a84",
            "template": {
                "message": "{user} added {resource} to {space}",
                "variables": {
                    "resource": {
                        "id": "27f71740-c352-4a78-aac2-abe581a673a7$3793776a-a355-45c1-9b29-a1d2fc722ca4!160ae583-9e97-4b39-8158-e5df30325af1",
                        "name": "testavatar.png"
                    },
                    "space": {
                        "id": "3793776a-a355-45c1-9b29-a1d2fc722ca4!3793776a-a355-45c1-9b29-a1d2fc722ca4",
                        "name": "Admin"
                    },
                    "user": {
                        "id": "3793776a-a355-45c1-9b29-a1d2fc722ca4",
                        "displayName": "admin"
                    }
                }
            },
            "times": {
                "recordedTime": "2024-07-30T10:30:56.310361965Z"
            }
        }
    ]
    }
  2. Delete the file and check the activity
    {
    "value": [
        {
            "id": "1307c6db-9243-482f-943d-8999a85fb1ec",
            "template": {
                "message": "{user} deleted {resource} from {space}",
                "variables": {
                    "resource": {
                        "id": "27f71740-c352-4a78-aac2-abe581a673a7$3793776a-a355-45c1-9b29-a1d2fc722ca4!160ae583-9e97-4b39-8158-e5df30325af1",
                        "name": "testavatar.png"
                    },
                    "space": {
                        "id": "27f71740-c352-4a78-aac2-abe581a673a7$3793776a-a355-45c1-9b29-a1d2fc722ca4!3793776a-a355-45c1-9b29-a1d2fc722ca4",
                        "name": "Admin"
                    },
                    "user": {
                        "id": "3793776a-a355-45c1-9b29-a1d2fc722ca4",
                        "displayName": "admin"
                    }
                }
            },
            "times": {
                "recordedTime": "2024-07-30T10:32:44.990043512Z"
            }
        },
        {
            "id": "28a2a0e4-d17d-437b-933f-51046f273a84",
            "template": {
                "message": "{user} added {resource} to {space}",
                "variables": {
                    "resource": {
                        "id": "",
                        "name": "testavatar.png"
                    },
                    "space": {
                        "id": "27f71740-c352-4a78-aac2-abe581a673a7$3793776a-a355-45c1-9b29-a1d2fc722ca4!3793776a-a355-45c1-9b29-a1d2fc722ca4",
                        "name": "Admin"
                    },
                    "user": {
                        "id": "3793776a-a355-45c1-9b29-a1d2fc722ca4",
                        "displayName": "admin"
                    }
                }
            },
            "times": {
                "recordedTime": "2024-07-30T10:30:56.310361965Z"
            }
        }
    ]
    }

    For the file upload event, we receive an empty string in the resource id that previously contained the id when checking activity after file deletion.

Expected behavior

There should be resource id.

Actual behavior

Resource id is missing.

kobergj commented 2 months ago

This is somewhat expected behaviour. If an item is deleted, the resourceID cannot be retrieved any more (because the item is gone). Hence this field is omitted in the activity.

Note that the Delete activity is a special case because the event already holds the correct ID. But that information is obsolete as the client cannot do anything with the resourceID (as the item was deleted)

Salipa-Gurung commented 2 months ago

When a file is created, renamed and followed by moving it inside a folder then only the last activity (ie. moving the file inside a folder) will have a resource id and all other previous activities will have empty resource id. How about this behaviour? Is this behaviour expected or not? cc: @kobergj

json response ```json { "value": [ { "id": "d9c43535-14a2-40eb-a394-0911928a477c", "template": { "message": "{user} moved {resource} to {space}", "variables": { "resource": { "id": "2b925c95-bc36-4843-8f97-239aa208632b$c04b4b5a-ca00-48e2-bfb0-f1990461cedb!74257106-28d8-4311-9397-05bed6590955", "name": "error.txt" }, "space": { "id": "c04b4b5a-ca00-48e2-bfb0-f1990461cedb!c04b4b5a-ca00-48e2-bfb0-f1990461cedb", "name": "Admin" }, "user": { "id": "c04b4b5a-ca00-48e2-bfb0-f1990461cedb", "displayName": "admin" } } }, "times": { "recordedTime": "2024-08-06T10:10:08.04644023Z" } }, { "id": "c1661be2-b847-4af4-8c81-125159491fec", "template": { "message": "{user} renamed {oldResource} to {resource}", "variables": { "oldResource": { "id": "", "name": "renamedFile.txt" }, "resource": { "id": "", "name": "error.txt" }, "user": { "id": "c04b4b5a-ca00-48e2-bfb0-f1990461cedb", "displayName": "admin" } } }, "times": { "recordedTime": "2024-08-06T10:05:49.625296602Z" } }, { "id": "d83c1e03-e1f2-4d3f-bf58-b29dda0b79a2", "template": { "message": "{user} added {resource} to {space}", "variables": { "resource": { "id": "", "name": "renamedFile.txt" }, "space": { "id": "2b925c95-bc36-4843-8f97-239aa208632b$c04b4b5a-ca00-48e2-bfb0-f1990461cedb!c04b4b5a-ca00-48e2-bfb0-f1990461cedb", "name": "Admin" }, "user": { "id": "c04b4b5a-ca00-48e2-bfb0-f1990461cedb", "displayName": "admin" } } }, "times": { "recordedTime": "2024-08-06T10:05:08.139268732Z" } } ] } ```
kobergj commented 2 months ago

How about this behaviour? Is this behaviour expected or not?

No. The itemid doesn't change when a file is moved. This is a bug imo.

saw-jan commented 2 months ago

only the latest action activity has the value in the resource id:

"resource": {
   "id": "{resource-id}"
kobergj commented 2 months ago

I double checked. This is because the events do not contain the itemid but only a reference (containing a path).

The fix to this is rather expensive. There are two options:

A) We pass the itemID through the opaque until the events middleware. This brings some challenges. See for example discussion on this PR: https://github.com/cs3org/reva/pull/4767

B) We get rid of the events middleware and emit events at the place they are created in. This will bring code duplication (e.g. posixfs and decomposedfs both need to emit some events).

Both options are rather costly. I wouldn't want to tackle it without a proper plan.

Fix depends on priority.