tractr / directus-sync

A CLI tool for synchronizing the schema and configuration of Directus across various environments.
GNU General Public License v3.0
254 stars 10 forks source link

You don't have permission to access field \"role\" in collection \"directus_permissions\" #102

Closed NilsBaumgartner1994 closed 2 months ago

NilsBaumgartner1994 commented 2 months ago
Use `node --trace-warnings ...` to show where the warning was created)
[18:35:11.977] INFO (47846): ---- Push schema ----
[18:35:12.926] INFO (47846): [snapshot] No changes to apply
[18:35:12.932] INFO (47846): ---- Clean up collections ----
[18:35:13.025] INFO (47846): [dashboards] Deleted 0 dangling items
[18:35:13.701] INFO (47846): [flows] Deleted 0 dangling items
[18:35:14.156] INFO (47846): [folders] Deleted 0 dangling items
[18:35:14.550] INFO (47846): [operations] Deleted 0 dangling items
[18:35:14.588] INFO (47846): [panels] Deleted 0 dangling items
[18:35:16.258] INFO (47846): [permissions] Deleted 0 dangling items
[18:35:16.299] INFO (47846): [presets] Deleted 0 dangling items
[18:35:16.359] INFO (47846): [roles] Deleted 0 dangling items
[18:35:16.416] INFO (47846): [settings] Deleted 0 dangling items
[18:35:16.455] INFO (47846): [translations] Deleted 0 dangling items
[18:35:16.455] INFO (47846): ---- Push: iteration 1 ----
[18:35:16.488] INFO (47846): [dashboards] Created 0 items
[18:35:16.489] INFO (47846): [dashboards] Updated 0 items
[18:35:16.489] INFO (47846): [dashboards] Deleted 0 items
[18:35:16.808] INFO (47846): [flows] Created 0 items
[18:35:16.808] INFO (47846): [flows] Updated 0 items
[18:35:16.808] INFO (47846): [flows] Deleted 0 items
[18:35:17.092] INFO (47846): [folders] Created 0 items
[18:35:17.092] INFO (47846): [folders] Updated 0 items
[18:35:17.092] INFO (47846): [folders] Deleted 0 items
[18:35:17.214] INFO (47846): [operations] Created 0 items
[18:35:17.214] INFO (47846): [operations] Updated 0 items
[18:35:17.214] INFO (47846): [operations] Deleted 0 items
[18:35:17.254] INFO (47846): [panels] Created 0 items
[18:35:17.254] INFO (47846): [panels] Updated 0 items
[18:35:17.254] INFO (47846): [panels] Deleted 0 items
[18:35:19.069] ERROR (47846):
    errors: [
      {
        "message": "You don't have permission to access field \"role\" in collection \"directus_permissions\" or it does not exist. Queried in root.",
        "extensions": {
          "reason": "You don't have permission to access field \"role\" in collection \"directus_permissions\" or it does not exist. Queried in root.",
          "code": "FORBIDDEN"
        }
      }
    ]
    response: {}
EdouardDem commented 2 months ago

It seems that your JSON files are not up to date with the Directus 11. Did you follow these steps ?

NilsBaumgartner1994 commented 2 months ago

Yup. Delete Database Start my server on directus 10 Push schema Dop server upgrade to 11 and rebuild docker, then start let migration finish pull schema push schema --> error

NilsBaumgartner1994 commented 2 months ago

Wait, maybe i forgot to reinstall directus sync from 3 back to 2

NilsBaumgartner1994 commented 2 months ago

No, i made sure that i used

cleared database directus sync 2 for directus 10 setup and push scheme switch to directus 11 and extension v3 and confirm in backend api install directus sync 3 and pull then directly push

NilsBaumgartner1994 commented 2 months ago

So i tried with a clean database with a new table and that works. So the problem must rely somewhere in my schema?

NilsBaumgartner1994 commented 2 months ago

When i create the field "role" in permissions the push works. Lets see if i can then make a pull, and push. And then if I can delete the field and make a pull and push

NilsBaumgartner1994 commented 2 months ago

Okay so by creating a custom field role the push works. Lets check if we can then remove it.

NilsBaumgartner1994 commented 2 months ago

Removing the field, then pulling and pushing does not work. Resulting in the same error

NilsBaumgartner1994 commented 2 months ago

Disabled all extensions (2), still no change

NilsBaumgartner1994 commented 2 months ago

Also deleting all tables and removing all permissions result in the same error.

NilsBaumgartner1994 commented 2 months ago

Ahhhh i found a first problem.

When preserving permissions for public policies in the collection file:

   "policy": "abf8a154-5b1c-4a46-ac9c-7300570f4f17",
    "role": null,

is saves the role as null, for well the public role. Removing this, manually, fixed that error.

So basically when pulling with preserve ids, we have to delete the field "role" in the collection permissions

NilsBaumgartner1994 commented 2 months ago

We deleted the presered ids for permissions and roles. Now trying to recreate them and to pull them

NilsBaumgartner1994 commented 2 months ago

it seems there is also a problem when saving the policies for the role:

[16:07:05.374] INFO (8809): [roles] Created 0 items
[16:07:05.436] ERROR (8809):
    errors: [
      {
        "message": "You don't have permission to access this.",
        "extensions": {
          "code": "FORBIDDEN"
        }
      }
    ]
    response: {}
In my directus logs:
```rocket-meals-directus-4         | [16:07:05] PATCH /roles/abe3a726-f85c-4d70-a86c-15e7092e5da2 403 21ms```

It tries to update the relation of the role to the policies:
    [
  {
    "name": "User",
    "icon": "supervised_user_circle",
    "description": null,
    "parent": null,
    "children": [],
    "policies": [
      "dcdd19da-d0eb-4adf-8a3b-b40c1f67e5a4",
      "a780fc0d-de6d-4ebf-aaa1-5b4421e29b7d"
    ],
    "_syncId": "abe3a726-f85c-4d70-a86c-15e7092e5da2"
  }
]

and exactly here seems to be the problem, that he does not find the access_ids which are here preserved

Because our policies have different ids:

  {
    "collection": "devices",
....
    "policy": "abe3a726-f85c-4d70-a86c-15e7092e5da2",
    "role": null,
    "_syncId": "dd9ccdca-0be6-435a-ba1e-9c8f3cbc9d45"
  },
NilsBaumgartner1994 commented 2 months ago

In the roles collection it seems that not the policy id is saved but the "directus_access" relation

NilsBaumgartner1994 commented 2 months ago

Was my bad.Was my bad. I installed in package.json the correct version but then used the wrong version with npx for my script.