parcelvoy / platform

Parcelvoy: Open source multi-channel marketing automation platform. Send data-driven emails, sms, push notifications and more!
https://parcelvoy.com
Other
210 stars 31 forks source link

Onboarding error: Minimum organization role admin is required #415

Closed mattes3 closed 5 months ago

mattes3 commented 5 months ago

Hi, I have re-installed Parcelvoy 1.4.7, and when I try to create my first project, I get this error in the log and an error on the screen as well: "Minimum organization role admin is required"

This is blocking me. What to do?

api_1           | [1711887298044] ERROR (8 on b5768d61e42d): error
api_1           |     ctx: {
api_1           |       "request": {
api_1           |         "method": "POST",
api_1           |         "url": "/api/admin/projects",
api_1           |         "header": {
api_1           |           "host": "api:3001",
api_1           |           "connection": "close",
api_1           |           "content-length": "94",
api_1           |           "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0",
api_1           |           "accept": "application/json, text/plain, */*",
api_1           |           "accept-encoding": "gzip, deflate, br",
api_1           |           "accept-language": "en",
api_1           |           "content-type": "application/json",
api_1           |           "cookie": "oauth={\"access_token\":\"eyJhb...\",\"expires_at\":\"2024-04-01T12:14:43.842Z\"}; oauth.sig=Pp...",
api_1           |           "origin": "https://email-automation.bohlenlabs.com",
api_1           |           "referer": "https://email-automation.bohlenlabs.com/onboarding/project",
api_1           |           "sec-fetch-dest": "empty",
api_1           |           "sec-fetch-mode": "cors",
api_1           |           "sec-fetch-site": "same-origin",
api_1           |           "sec-gpc": "1",
api_1           |           "x-forwarded-for": "91.5.111.191",
api_1           |           "x-forwarded-host": "email-automation.bohlenlabs.com",
api_1           |           "x-forwarded-proto": "https"
api_1           |         }
api_1           |       },
api_1           |       "response": {
api_1           |         "status": 404,
api_1           |         "message": "Not Found",
api_1           |         "header": {
api_1           |           "vary": "Origin",
api_1           |           "access-control-allow-origin": "*"
api_1           |         }
api_1           |       },
api_1           |       "app": {
api_1           |         "subdomainOffset": 2,
api_1           |         "proxy": true,
api_1           |         "env": "production"
api_1           |       },
api_1           |       "originalUrl": "/api/admin/projects",
api_1           |       "req": "<original node req>",
api_1           |       "res": "<original node res>",
api_1           |       "socket": "<original node socket>"
api_1           |     }
api_1           |     error: {
api_1           |       "status": "error",
api_1           |       "error": "Minimum organization role admin is required"
api_1           |     }
parcelvoy-ui_1  | 172.30.0.2 - - [31/Mar/2024:12:14:58 +0000] "POST /api/admin/projects HTTP/1.1" 403 72 "https://email-automation.bohlenlabs.com/onboarding/project" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0" "91.5.111.191"
mattes3 commented 5 months ago

Ah, I just saw that this is a duplicate of #399

I updated the admin and it suddenly works:

update admins set organization_id=1, role=admin

pushchris commented 5 months ago

Was your original install pre-1.4.7 or is this a fresh install? Want to make sure it is not still happening

mattes3 commented 5 months ago

No, it was a totally fresh install. I tried it again with 1.4.6 but it happened again.

At the beginning, there is a lot of flashing going on in my browser. Firefox is slower than Chrome, maybe it is a matter of timing and therefore the ordering of API calls? Just thinking.

pushchris commented 5 months ago

The very first user ever created should automatically have the role level owner but perhaps there is still a bug, I will try and investigate further

mattes3 commented 5 months ago

The role name is 'member' and the organization_id is NULL, all in the admins table.

pushchris commented 5 months ago

This should be fixed in the 1.5.0 release, looks like it was unique to the basic auth type during onboarding. If you haven't gotten too far in, I would potentially suggest restarting fresh. Otherwise, create a blank organization and add it to the user you've created (organization_id). This should resolve any future issues.

mattes3 commented 5 months ago

Thanks for taking care of this, Chris! Fortunately, Parcelvoy had already created an org so that I could simply set organization_id=1 for the admin. I also set the role to 'admin', and all was well.

mattes3 commented 5 months ago

Hi Chris, I tried this again, today. This time with version 1.5.1. The error message still appears when I try to create the first project in an empty database:

CleanShot 2024-04-04 at 09 08 08@2x
pushchris commented 5 months ago

Ok, I think I found the combination of items to make this reliable happen on my end. There were at least so far three different situations that could cause it, the one I'm assuming you are in is: single org mode, basic auth, fresh install. There is a migration that previously was added to add an organization (back when we added that model) to existing installs since it's a required object now. The issue is that migration is still running for new installs meaning an org is created before login so that at login the user creation doesn't create an org, the org isn't marked as new so the user isn't set as owner. My test install was running in multi org mode which doesn't have this problem. The historical migration needs to be updated to only run if there are existing admins in the database (to only account for prior installs not new ones).