Blocks fields internal fields don't respect access modifiers.

default discord avatar
KasparTr
2 months ago
4

I am using a Blocks field but it's own field access modifier are not respected


i.e. Block internal fields access modifier update is set to false, but all fields of the block can still be updated after the document has been created.


update: () => false


Code below:


Main collection


{
  name: 'shares',
  label: 'Transactions',
  type: 'blocks',
  minRows: 1,
  blocks: [
    ShareBlock
  ],
  admin: {
    description: "Buy (pos) and sell (neg) transactions with shares",
    condition: (data, siblingData) => {
      if (data.assetType && data.assetType.includes(AssetType.SHARE)) return true;
      else {
        return false
      };
    }
  }
}


Block component


import { Block } from "payload/types";
export const ShareBlock: Block = {
    slug: 'Share',
    fields: [
        {
            name: 'nrOfParts',
            type: 'number',
            required: true,
            admin: {
                description: "Shares bought (pos) or sold (neg)."
            },
            access: {
                create: () => true,
                update: () => false // <-- not respected
            }
        },
        {
            name: 'pricePerPart',
            type: 'number',
            required: true,
            admin: {
                description: "Share price at transaction"

            },
            access: {
                create: () => true,
                update: () => false // <-- not respected
            }
        },
    ]
};
  • discord user avatar
    Jarrod
    Payload Team
    last month

    Oh, sounds like it might be a bug. Do you think you could take a bit of time to write up an issue with a small repro? Would be super helpful!

    https://github.com/payloadcms/payload/issues/new?assignees=&labels=possible-bug&template=1.bug_report.yml
  • default discord avatar
    KasparTr
    4 weeks ago

    Would love to raise a ticket but really no time to fork and launch a reproduction server. Any workaround until this bug gets solved?

  • discord user avatar
    Jarrod
    Payload Team
    4 weeks ago

    How long do you think it would take you? I am guessing it would take less than 10 mins to create a fork or clone payload and push to a branch with a simplified version to reproduce your issue.



    If you were to clone/fork, you would already have the basics stubbed out for you in the _community test folder (

    https://github.com/payloadcms/payload/tree/master/test/_community

    ) and then you would just have to add 1

    blocks

    field (to the already stubbed out posts collection) that has 1 block that shows that this is an issue. You can spin it up to verify by running

    yarn dev _community

    and then all you have to do is push (to a branch if cloned, or upstream if forked)

  • default discord avatar
    KasparTr
    3 weeks ago

    I thought it requires to run a server with the bug. Just fork I will check it out.

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.