strapi-community / strapi-plugin-protected-populate

MIT License
20 stars 5 forks source link

How to get the locale field? #18

Closed panosru closed 8 months ago

panosru commented 8 months ago

Hi, I believe my issue is related to issue #14, I will try to be as detailed as possible.

Here is my setup: image

When I access /api/books/1 I get:

{
    "data": {
        "id": 1,
        "Title": "My Book",
        "ISBN": "1234354",
        "localizations": [
            {
                "id": 3,
                "Title": "Моя книга",
                "ISBN": "1234354"
            },
            {
                "id": 2,
                "Title": "Το βιβλίο μου",
                "ISBN": "1234354"
            }
        ]
    },
    "meta": {}
}

When I access /api/books/1?locale=ru I get the same result as above.

If I remove the setting from protected-populate* and access either /api/books/1 or /api/books/1?locale=ru I get:

{
    "data": {
        "id": 1,
        "Title": "My Book",
        "ISBN": "1234354",
        "createdAt": "2024-03-04T00:32:22.257Z",
        "updatedAt": "2024-03-04T01:09:16.632Z",
        "publishedAt": "2024-03-04T00:32:24.682Z",
        "locale": "en"
    },
    "meta": {}
}

If I access /api/books/1?populate=* I get:

{
    "data": {
        "id": 1,
        "Title": "My Book",
        "ISBN": "1234354",
        "createdAt": "2024-03-04T00:32:22.257Z",
        "updatedAt": "2024-03-04T01:09:16.632Z",
        "publishedAt": "2024-03-04T00:32:24.682Z",
        "locale": "en",
        "localizations": [
            {
                "id": 3,
                "Title": "Моя книга",
                "ISBN": "1234354",
                "createdAt": "2024-03-04T00:32:22.257Z",
                "updatedAt": "2024-03-04T01:09:40.874Z",
                "publishedAt": "2024-03-04T01:09:40.873Z",
                "locale": "ru"
            },
            {
                "id": 2,
                "Title": "Το βιβλίο μου",
                "ISBN": "1234354",
                "createdAt": "2024-03-04T00:35:00.604Z",
                "updatedAt": "2024-03-04T01:09:16.632Z",
                "publishedAt": null,
                "locale": "el"
            }
        ]
    },
    "meta": {}
}

What I want to get is:

{
    "data": {
        "id": 1,
        "Title": "My Book",
        "ISBN": "1234354",
        "localizations": [
            {
                "id": 3,
                "Title": "Моя книга",
                "ISBN": "1234354",
                "locale": "ru"
            },
            {
                "id": 2,
                "Title": "Το βιβλίο μου",
                "ISBN": "1234354",
                "locale": "el"
            }
        ]
    },
    "meta": {}
}

But, I don't see any option in the configuration to include the locale attribute in the result.

Hey, really appreciate your work on this, it is very good and indeed, like you, I too got sick of those query strings to get to the needed result and avoid unnecessary data in responses.

Boegie19 commented 8 months ago

Will do a test tomorow to see what is causing this and fix it if I can replicate it thanks for the report.

panosru commented 8 months ago

wow mate, your response time! You live here? haha

Thanks a ton! If you need anything else from me to provide as additional data let me know

Boegie19 commented 8 months ago

Just figured out the issue I forgot to add the local key to the UI. update will be out in a hour or so to fix this.

Boegie19 commented 8 months ago

@panosru Just publised a new version this should fix your issue if it does not fix it please feel free to reopen the issue. this adds locale to the options in the plugin interface after updating the plugin and rebuilding the admin image

panosru commented 8 months ago

Thanks a lot mate!

Boegie19 commented 8 months ago

One final note locale needs to be enabled for everyting where you want to use ?locale