Forbidden Error: enumValues

Feature(s) impacted

Use smart action forms with a field of type “EnumList” and a dynamic enumValues.

collection.addAction('Create a new group', {
    scope: 'Global',
    form: [
      {
        type: 'EnumList',
        label: 'selectedTemplate',
        enumValues: async context => {
          return ['foo', 'bar'];
        },
      },
    ],
    execute: async (context, resultBuilder) => {
      resultBuilder.success();
    },
  });

Observed behavior

The form never loads because of a back-end error.

Expected behavior

List all possible values in a dropdown menu in my form.

Failure Logs

ForbiddenError
    at ActionAuthorizationService.assertCanRequestCustomActionParameters (/***/forest-admin-backend/node_modules/@forestadmin/agent/dist/routes/modification/action/action-authorization.js:43:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ActionRoute.handleHook (/***/forest-admin-backend/node_modules/@forestadmin/agent/dist/routes/modification/action/action.js:93:9)
    at async ErrorHandling.errorHandler (/***forest-admin-backend/node_modules/@forestadmin/agent/dist/routes/system/error-handling.js:20:13)
    at async Logger.logger (/***/forest-admin-backend/node_modules/@forestadmin/agent/dist/routes/system/logger.js:19:13)
    at async bodyParser (/***/forest-admin-backend/node_modules/koa-bodyparser/index.js:95:5)
    at async cors (/***/forest-admin-backend/node_modules/@koa/cors/index.js:108:16)

Context

  • Project name: Inarix
  • Environment name: Development
  • Agent type & version: NodeJS agent, version 1.6.4

Hi @Guillaume_Robin ,

I copied and pasted your code and it works well on my end.
To find the issue your encounter I will need more details about your setup.

  • Is it your only action ?
  • Have you used : .customizeCollection("collectionName", (collection) => { ?

If you have more insight that could help me to solve this do not hesitate to add them.

Best regards,

Shohan

Hi @shohanr,

  • It’s my only action on this collection. But I have two others on another collection.
  • Yes I used .customizeCollection("collectionName", (collection) => {

Here you have more info about the setup:

  • Liana Version: 1.6.4
  • forestadmin/agent": “^1.6.4”,
  • forestadmin/datasource-sequelize": “^1.2.9”,
  • forestadmin/datasource-sql": “^1.1.9”,
  • sequelize/core": “^7.0.0-alpha.10”

When I transform the code as below, it works:

collection.addAction('Create a new group', {
    scope: 'Global',
    form: [
      {
        type: 'EnumList',
        label: 'selectedTemplate',
        enumValues: ['foo', 'bar']
      },
    ],
    execute: async (context, resultBuilder) => {
      resultBuilder.success();
    },
  });

Unfortunately, that’s not what I need. I spent quite some time to figure out my issue, but I couldn’t understand what I’m missing here.

Best regards,

Guillaume

Hi @Guillaume_Robin ,

Could you please check your roles for this smart action and send me the configuration for this action ?
It could be linked to your error.

Best,

Shohan

I have the role “Admin” and I enabled all smart actions like below:

Best,

Guillaume

Hello @Guillaume_Robin,

I can see that the environment named “Development” is wrongly declared as a remote environment in Forest Admin. In this case, verifications on roles are executed when trying to execute custom actions, and also when trying to read enum values like this.

I can change the declaration of your environment in order to fix your issue (and I will if it’s ok for you), but I’d like to be sure that we don’t miss any real error.

Can you please paste here a part of the email address (just enough for me to identify it on your project) of the user that you are using when you receive this 403 error?

The action that shows this error is currently configured to authorize the Role Admin to execute it, but not other roles. If the user with which you are doing tests does not have the Admin role, then the error is expected. But if it’s the case we need to deep further.

1 Like

Hi @GuillaumeGautreau,

Yes, go head to change the environment’s declaration. My e-mail address is guill[REDACTED]@[REDACTED].com. From what I see on our panel, I should have the Admin role.

Best,

Ok, I changed your environment’s type. Let me know if it fixed your issue.

In the meantime, I’ll try to reproduce your issue with a remote environment to see if there is something to fix on our side.

1 Like

Hi @GuillaumeGautreau,

Yes it fixed the issue! I had to forest init my local repository but now it’s working. However, I’m still seeing the “Development” remote environment, but I don’t see it in my environments in the project settings.

Screenshot 2023-01-31 at 17.58.11

I’ll continue my new feature and I’ll tell you if it works when I’ll deploy in staging environment.

Best,

Guillaume

Ok, it created a new environment. I think you can delete the environment named Development in your project’s settings and everything will be back to normal.

I’ll let you know about the reproduction of your issue.

Hello @Guillaume_Robin,

I could reproduce your issue with a remote environment and the code you provided. Thanks a lot for having described your issue with so much detail. It helped a lot.

A fix has been released (from this PR): you can upgrade to @forestadmin/agent@1.7.1 and everything will work also fine on your staging environment.

1 Like

Hello @GuillaumeGautreau ,

Thanks a lot! I’m glad to help.

Best regards,

Guillaume