Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Blocks fields internal fields don't respect access modifiers.

default discord avatar
kaspartr2 years 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_not_jared
    2 years ago

    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
    kaspartr2 years 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_not_jared
    2 years 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
    kaspartr2 years ago

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

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.