linagora / james-project

Mirror of Apache James Project
Apache License 2.0
70 stars 63 forks source link

Identity : mayDelete=true but deletion fails #5112

Closed chibenwa closed 6 months ago

chibenwa commented 6 months ago

GIVEN I modified my default identity in the webmain WHEN I try to delete it THEN it fails


{
    "sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
    "methodResponses": [
        [
            "Identity/get",
            {
                "accountId": "51e6371779b54390bf5970559c64c2725da1d3b8a3c548a97ddf98522822ca75",
                "state": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
                "list": [
                    {
                        "name": "w",
                        "htmlSignature": "",
                        "id": "3422dcb7-f5f0-33da-844f-6328a488c828",
                        "sortOrder": 0,
                        "bcc": [],
                        "textSignature": "",
                        "mayDelete": true,
                        "email": "comptetest15.linagora@avocat.fr",
                        "replyTo": []
                    }
                ]
            },
            "c0"
        ]
    ]
}
{
    "using": [
        "urn:ietf:params:jmap:core",
        "urn:ietf:params:jmap:submission",
        "urn:apache:james:params:jmap:mail:identity:sortorder"
    ],
    "methodCalls": [
        [
            "Identity/set",
            {
                "accountId": "51e6371779b54390bf5970559c64c2725da1d3b8a3c548a97ddf98522822ca75",
                "destroy": [
                    "3422dcb7-f5f0-33da-844f-6328a488c828"
                ]
            },
            "c0"
        ]
    ]
}

results in

{
    "sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
    "methodResponses": [
        [
            "Identity/set",
            {
                "accountId": "51e6371779b54390bf5970559c64c2725da1d3b8a3c548a97ddf98522822ca75",
                "newState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
                "notDestroyed": {
                    "3422dcb7-f5f0-33da-844f-6328a488c828": {
                        "type": "forbidden",
                        "description": "User do not have permission to delete IdentityId(3422dcb7-f5f0-33da-844f-6328a488c828)"
                    }
                }
            },
            "c0"
        ]
    ]
}

Either mayDelete=false or have the deletion succeeds.

CC @quantranhong1999

chibenwa commented 6 months ago

image

Arsnael commented 6 months ago

I thought yes it was designed that way? You can't delete a server-set identity? What's wrong with that?

EDIT: Got it reading the PR

Missing link to it btw: https://github.com/apache/james-project/pull/2083

quantranhong1999 commented 6 months ago

CC @quantranhong1999

It is likely not related to the JMAP default identity work but the merging and updating server set identity logic. cc @vttranlina may give better insight on this?

vttranlina commented 6 months ago

Bug came from when We tried to update the serverSet identity the first time, The current logic will create the new Identity, and set mayDelete = true https://github.com/apache/james-project/blob/ea088b79869afee4666f13f26f96670833d7cb2f/server/data/data-jmap/src/main/scala/org/apache/james/jmap/api/identity/CustomIdentityDAO.scala#L245

How to fix it?

pr fix it: https://github.com/apache/james-project/pull/2087

chibenwa commented 6 months ago

Or you fix it by remembering this is server set when merging the custom identity and the server set ones.

Which would also fix instantly existing instances...

quantranhong1999 commented 6 months ago

Can combine two fixes I guess?

chibenwa commented 6 months ago

Why not