access control to particular page

default discord avatar
bhavikak
4 weeks ago
4

is it possible to possible to give only edit access on particular page

  • default discord avatar
    dr_mint
    4 weeks ago

    Hi! Yes, with access functions, you can either return a boolean or an query constraint

    https://payloadcms.com/docs/access-control/collections#update

    The query constraint can be used to limit which document(s) a user can read/edit

  • default discord avatar
    bhavikak
    4 weeks ago

    @dr_mint but it's for collection ri8?



    i want to apply at page level

  • default discord avatar
    dr_mint
    4 weeks ago

    The query constraint allows you to filter which pages you want to give access. If you want to give access to a single page based on its ID, you may use the following query

    { id: { equals: "idToGiveAccessTo" } }
  • default discord avatar
    bhavikak
    3 weeks ago

    thanks @dr_mint i'll try



    hello @dr_mint i tried but i got id as undefined



    i have to use hook or accessControl?



    i'm getting confuse



    i want to allow only career page access to the user those have a 'hr' role



    import type { Access } from 'payload/config';



    import { checkRole } from './checkRole';



    const adminAndHrAndUser: Access = ({ req: { user }, id }) => {


    if (user) {


    if (checkRole(['admin'], user)) {


    return true;


    }



    if (checkRole(['hr'], user)) {


    if (id === '64df354b4574c2098e2c196a') {


    return true;


    }


    return {


    id: user.id,


    };


    }


    return {


    id: user.id,


    };


    }



    return false;


    };



    export default adminAndHrAndUser;



    this is my code

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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