Skip to content

Conversation

@Kosztyk
Copy link

@Kosztyk Kosztyk commented Jan 12, 2026

  • add user;

  • delete

  • update user

    First user created after application installation will be administrator by default, the rest of the users can be admin users or normal users.

Screenshot 2026-01-12 at 12 07 33 Screenshot 2026-01-12 at 12 07 24

Summary by cubic

Adds role-based user management. First user becomes admin; admins can add, edit, and delete users from the Account page.

  • New Features

    • Roles: admin or user, stored in DB and included in JWT (fallback to user for old tokens).
    • Registration: first user is admin; others default to user; ACCOUNT_REGISTRATION respected after first run.
    • Admin-only UI and routes to add users, change role/reset password, and delete users.
    • Safeguards: cannot delete yourself or the last admin, and cannot demote the last admin; deletions remove the user’s jobs/files in a transaction.
    • Account page lists other users for admins.
  • Migration

    • Adds users.role with default 'user' on startup and promotes the oldest existing user to admin; no manual steps.

Written for commit ca61491. Summary will update on new commits.

added user management
updated db to work with the new user management functionality
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/pages/user.tsx">

<violation number="1" location="src/pages/user.tsx:188">
P1: First-user/admin gating relies on a stale in-memory flag (FIRST_RUN) so multiple instances can all allow registration and create admins even when registration is disabled.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

src/db/db.ts Outdated

/**
* Ensure `role` column exists on users table.
* This works for both fresh installs and existing DBs, without touching user_version.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not touch user_version I think it was made for things like this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't addressed

try {
db.exec("ROLLBACK");
} catch {
// ignore rollback errors
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe log them at least?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please at least comment on the reason why you are closing this without addressing it

@C4illin
Copy link
Owner

C4illin commented Jan 12, 2026

Thanks for separating this! Looks good! There is some weird comments that sounds very AI, maybe look over them.

I am also thinking about if you already have a first user, maybe it should be promoted to admin as part of the db migration? Though this is a little bit scary but deleting the db and starting from scratch is also some work. What do you think?

@Kosztyk
Copy link
Author

Kosztyk commented Jan 12, 2026

Thanks for separating this! Looks good! There is some weird comments that sounds very AI, maybe look over them.

I am also thinking about if you already have a first user, maybe it should be promoted to admin as part of the db migration? Though this is a little bit scary but deleting the db and starting from scratch is also some work. What do you think?

HI, exactly like this is working, an existing first user will be promoted to admin during the migration.

@Kosztyk Kosztyk requested a review from C4illin January 12, 2026 19:18
@C4illin
Copy link
Owner

C4illin commented Jan 12, 2026

Thanks for separating this! Looks good! There is some weird comments that sounds very AI, maybe look over them.
I am also thinking about if you already have a first user, maybe it should be promoted to admin as part of the db migration? Though this is a little bit scary but deleting the db and starting from scratch is also some work. What do you think?

HI, exactly like this is working, an existing first user will be promoted to admin during the migration.

Could you send a link to the code lines I can't find it

@Kosztyk
Copy link
Author

Kosztyk commented Jan 12, 2026

Thanks for separating this! Looks good! There is some weird comments that sounds very AI, maybe look over them.
I am also thinking about if you already have a first user, maybe it should be promoted to admin as part of the db migration? Though this is a little bit scary but deleting the db and starting from scratch is also some work. What do you think?

HI, exactly like this is working, an existing first user will be promoted to admin during the migration.

Could you send a link to the code lines I can't find it

you can find the files here https://github.com/Kosztyk/ConvertX/tree/adduser

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/pages/user.tsx">

<violation number="1" location="src/pages/user.tsx:965">
P1: Last-admin protection is not atomic; concurrent demotions can leave zero admins.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/pages/user.tsx">

<violation number="1" location="src/pages/user.tsx:967">
P1: Transaction left open across await: BEGIN IMMEDIATE holds the shared SQLite connection while awaiting password hash, risking lock contention and cross-request interleaving.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@Kosztyk
Copy link
Author

Kosztyk commented Jan 12, 2026

@C4illin I tried to fix all reported issues, hopefully now all the checks will pass and is safe to marge them.

@C4illin
Copy link
Owner

C4illin commented Jan 13, 2026

Thanks for separating this! Looks good! There is some weird comments that sounds very AI, maybe look over them.
I am also thinking about if you already have a first user, maybe it should be promoted to admin as part of the db migration? Though this is a little bit scary but deleting the db and starting from scratch is also some work. What do you think?

HI, exactly like this is working, an existing first user will be promoted to admin during the migration.

Could you send a link to the code lines I can't find it

you can find the files here Kosztyk/ConvertX@adduser

Could you link me the specific file and linenumber like this: https://github.com/C4illin/ConvertX/pull/503/changes#diff-edc834adbf0274511449786b6f3cf185c31f47eeccbe158e8377f772d7614c61R44-R47

@Kosztyk
Copy link
Author

Kosztyk commented Jan 13, 2026 via email

@Kosztyk
Copy link
Author

Kosztyk commented Jan 13, 2026 via email

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/db/db.ts">

<violation number="1" location="src/db/db.ts:47">
P1: Migration for v0 DBs no longer adds `file_names.status`, leaving existing v0 databases without the required column and causing SQL errors when status is inserted/queried.</violation>
</file>

<file name="src/pages/user.tsx">

<violation number="1">
P1: FIRST_RUN is now a stale module-level flag and is set false before successful user creation, so failures leave setup/login bricked when no user exists.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/pages/user.tsx">

<violation number="1" location="src/pages/user.tsx:931">
P1: Last-admin demotion check is no longer atomic; concurrent demotions can remove all admins</violation>
</file>

<file name="src/db/db.ts">

<violation number="1">
P2: Schema/migration drift: file_names.status defaults differ between fresh create ('not started', nullable) and migration ('queued', NOT NULL), yielding inconsistent data across installs.</violation>

<violation number="2">
P1: `users.email` uniqueness dropped for new DBs; duplicates now allowed at DB layer</violation>

<violation number="3">
P1: Foreign key enforcement and cascade deletes removed: constraints are no longer enabled and ON DELETE CASCADE is missing, allowing orphaned rows.</violation>

<violation number="4" location="src/db/db.ts:50">
P1: Role migration no longer seeds an admin; upgraded deployments will have zero admins and no way to manage users.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Removed comments related to initial schema bootstrap and version marker for clarity. Simplified the database initialization logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants