Can we restrict an user to a specific locale ?

default discord avatar
Britiklast year
3

Hello !



Scenario :


I have 2 users and 2 locales (EN, FR).


I have a Post collection with localized fields, but can I achieve to restrict user to edit only their attributed locale ?


-> The FR user could not edit the EN posts.



I thought about duplicate a post for each locale, add a locale field in users collection and in the post collection, and filter posts by the current user's locale field.



Any ideas about this ? Thanks in advance

  • default discord avatar
    damnstaychilllast year

    Not 100% but in the roles and access function you might be able to read locale and grant / deny access based on it



    So they can only read/write etc if the locale matches the collection

  • discord user avatar
    jesschow
    last year

    Hey @Britik yes you can access

    locale

    and

    language

    from the

    req

    property when you set your access control.



    I would do something like this:



      access: {
        update: ({ req: { locale, language } }) => {
          if (locale === language) return true;
          return false;
        },
      },


    This compares the language you set in account options against the current locale, if they match you can update, otherwise you can read but not update.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.