immich-app / immich

High performance self-hosted photo and video management solution.
https://immich.app
GNU Affero General Public License v3.0
51.08k stars 2.7k forks source link

[Bug]: Recover the account before the delete script starts #1022

Closed NeleB54Gold closed 1 year ago

NeleB54Gold commented 1 year ago

Feature detail

i'm so stupid i requested deletion of the only admin account on immich, how can i cancel it? I stopped the docker before it can start delete everything, please HELP

Platform

Server

jrasm91 commented 1 year ago

If you have access to the database you can null out the deleted at column for the user to undo it.

Or, I wonder if you can create a second admin account and then use that to undo the first one.

NeleB54Gold commented 1 year ago

If you have access to the database you can null out the deleted at column for the user to undo it.

Or, I wonder if you can create a second admin account and then use that to undo the first one.

How can I read the postgre database in order to change it/add a new account?

alextran1502 commented 1 year ago

Assuming your database name is immich and your database user is postgres (default value from Immich)

  1. Attach to the Postgres container
  2. execute psql -U postgres -d immich
  3. Then execute
    UPDATE users
    SET "deletedAt" = null
    WHERE email = 'your-admin-email';

Should be good to go.

jrasm91 commented 1 year ago

Maybe it would be good to add some checks that prevent deleting the admin account 😛.

It also might be worthwhile to add some cli commands to help with resolving some of these database related fixes, like make a user an admin, etc.

alextran1502 commented 1 year ago

Maybe it would be good to add some checks that prevent deleting the admin account 😛.

It also might be worthwhile to add some cli commands to help with resolving some of these database related fixes, like make a user an admin, etc.

From the PR deleting user I remember I saw that check 🤔

alextran1502 commented 1 year ago

Maybe it would be good to add some checks that prevent deleting the admin account 😛. It also might be worthwhile to add some cli commands to help with resolving some of these database related fixes, like make a user an admin, etc.

From the PR deleting user I remember I saw that check 🤔

damnit I missed it

NeleB54Gold commented 1 year ago

Assuming your database name is immich and your database user is postgres (default value from Immich)

  1. Attach to the Postgres container
  2. execute psql -U postgres -d immich
  3. Then execute
UPDATE users
SET "deletedAt" = null
WHERE email = 'your-admin-email';

Should be good to go.

I'm sorry, I'm not an expert with docker, how can I find the immich name to attach? I tried with immich, immich-app, immich_app, but maybe is an ID from the conteiner idk

jrasm91 commented 1 year ago

You can run docker ps to get a list of running containers, or docker ps -a to include ones that are stopped.

Also, it'd probably be easier to assist/chat/help if you posted on discord, instead of using this GitHub issue.

alextran1502 commented 1 year ago

With docker ps you will see a list below

Screenshot 2022-11-26 at 15 10 26

Then using the command below to get into the container

docker exec -it immich_postgres bash
NeleB54Gold commented 1 year ago

Cattura

Ok, I recovered my account, but why the other account is still there? I deleted the "salvatore"'s account, and when I clicked on it too many time (yes, I know, sometimes I'm really stupid), probably some ID changed in order to delete my account, because, how can I delete myself from my profile?

alextran1502 commented 1 year ago

Cattura

Ok, I recovered my account, but why the other account is still there? I deleted the "salvatore"'s account, and when I clicked on it too many time (yes, I know, sometimes I'm really stupid), probably some ID changed in order to delete my account, because, how can I delete myself from my profile?

So the salvator account is a non-admin account, correct?

NeleB54Gold commented 1 year ago

Cattura Ok, I recovered my account, but why the other account is still there? I deleted the "salvatore"'s account, and when I clicked on it too many time (yes, I know, sometimes I'm really stupid), probably some ID changed in order to delete my account, because, how can I delete myself from my profile?

So the salvator account is a non-admin account, correct?

Correct, now the schedule delete go to 3 December, it's 7 days later, maybe I need to update immich to be sure that it can be deleted that day, but it's ok, the salvatore have no media files on it, it was only an account management test for me

alextran1502 commented 1 year ago

The delete action will trigger 7 days grace period where you can recover the account.

I wonder how did you delete the admin account in the first place. Or do you mean you were deleting the non-admin account salvatore? Note that the admin account doesn't show up in the user management.

NeleB54Gold commented 1 year ago

The delete action will trigger 7 days grace period where you can recover the account.

I wonder how did you delete the admin account in the first place. Or do you mean you were deleting the non-admin account salvatore? Note that the admin account doesn't show up in the user management.

As I said before, I was constantly clicking on the button to delete Salvatore's account, and I don't know how, and I scheduled the deletion to mine, because it wouldn't let me login anymore and when i updated with the request on the database i was able to login again. Oof, really, I want to help, but this time was totally random

alextran1502 commented 1 year ago

Hmm strange, but good report, though. I will take a look at the continuation clicking on the button. I guess we can close this issue.

NeleB54Gold commented 1 year ago

Hmm strange, but good report, though. I will take a look at the continuation clicking on the button. I guess we can close this issue.

Yes, thank you all for the instant help!

jrasm91 commented 1 year ago

I think there is a bug where email is not uniquely enforced at the database level so two request (submit button clicked twice quickly) can cause two accounts with the same email to be successfully created. I know we patched the UI for this, but maybe there are two accounts with the same email and that has led to this weird situation/behavior.

Can you use SQL to list all the users? I bet there are two with the same email, one or both are admins.

NeleB54Gold commented 1 year ago

I think there is a bug where email is not uniquely enforced at the database level so two request (submit button clicked twice quickly) can cause two accounts with the same email to be successfully created. I know we patched the UI for this, but maybe there are two accounts with the same email and that has led to this weird situation/behavior.

Can you use SQL to list all the users? I bet there are two with the same email, one or both are admins.

Oh, ok, I'm on my phone now, sorry for Termius quality lol 20221126_230935.jpg

jrasm91 commented 1 year ago

Looks normal/good, so there goes that theory!