-
Notifications
You must be signed in to change notification settings - Fork 1
Implement multi-user annotation support with JWT authentication #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
d201abb
d0aa89a
b637aff
35e0416
c67af3e
afda911
fb2aaba
628aacc
70dc8e3
818c1d8
68acd06
54142e6
19174fe
051f2e8
3a8e585
f192dae
cb2edcd
6cb20a7
c4e8007
d1bc044
470cf58
83438bb
eaeafd0
172085c
d285b1b
e28c9c0
83dbfb9
6486dc0
dc8ea15
780dd8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ It currently supports the following features: | |
| - **Annotation Tools**: Apply consistent labels to signals and images using a customizable tagging system. | ||
| - **ML Models**: Train and infer from ML models within the UI. | ||
| - **Dataset Management**: Organize and manage annotations in a central repository. | ||
| - **Multi-User Support**: Role-based access control with per-project membership, suitable for team annotation workflows. | ||
| - **Extensible API**: A Python API for integrating with existing workflows and tools. | ||
|
|
||
|
|
||
|
|
@@ -49,13 +50,42 @@ uv tool install --python 3.12.6 toktagger[models] | |
| ``` | ||
|
|
||
| ## Quick Start | ||
| To get started, run: | ||
|
|
||
| To start a local single-user instance: | ||
|
|
||
| ```sh | ||
| toktagger | ||
| ``` | ||
|
|
||
| This will start a local instance of the application running at `http://localhost:8002`. | ||
| This starts the application at `http://localhost:8002`. On first launch an `admin` account is created automatically and the credentials are printed to the terminal. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should warn here that they will not see this password again after this point Should we have a way to either regenerate this password, or set it to a more memorable one (eg, |
||
|
|
||
| !!! warning | ||
| **Save the generated password immediately** — it is only printed once and cannot be recovered. | ||
|
|
||
| ### Multi-User / Team Deployment | ||
|
|
||
| For concurrent multi-user access, run with multiple Gunicorn workers: | ||
|
|
||
| ```sh | ||
| toktagger --workers 4 --host 0.0.0.0 --port 8002 --no-browser | ||
| ``` | ||
|
|
||
| Or directly via Gunicorn: | ||
|
|
||
| ```sh | ||
| gunicorn toktagger.api.asgi:app \ | ||
| --worker-class uvicorn.workers.UvicornWorker \ | ||
| --workers 4 \ | ||
| --bind 0.0.0.0:8002 | ||
| ``` | ||
|
|
||
| With Docker Compose, the production stack defaults to 4 workers. Override with the `WORKERS` environment variable: | ||
|
|
||
| ```sh | ||
| WORKERS=8 docker compose up | ||
| ``` | ||
|
|
||
| See [User Management](user_management.md) for creating accounts, assigning roles, and managing project membership. | ||
|
|
||
| ## Configuration | ||
| There are a series of additional options which you can configure to customise the functionality of TokTagger - [find details about these here.](./configuration.md) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| # User Management | ||
|
|
||
| TokTagger supports multiple concurrent users with role-based access control. An **admin** user manages accounts and project membership; regular **users** annotate within the projects they are assigned to. | ||
|
|
||
| --- | ||
|
|
||
| ## User Roles | ||
|
|
||
| TokTagger has two layers of roles: | ||
|
|
||
| ### Global roles (account-level) | ||
|
|
||
| | Global Role | Permissions | | ||
| |---|---| | ||
| | `admin` | Full access: create/edit/delete any project, manage all user accounts, view all annotations | | ||
| | `user` | Access only to projects they are a member of | | ||
|
|
||
| ### Project roles (per-project membership) | ||
|
|
||
| | Project Role | Permissions | | ||
| |---|---| | ||
| | `admin` | Manage project membership, delete samples and annotations | | ||
| | `annotator` | Submit and update annotations for samples | | ||
| | `viewer` | Read-only access to the project's samples and annotations | | ||
|
|
||
| A global `admin` automatically has unrestricted access to all projects regardless of project role. | ||
|
|
||
| --- | ||
|
|
||
| ## First-Run Setup | ||
|
|
||
| On first launch TokTagger automatically creates an `admin` account with a random password and prints the credentials to the terminal: | ||
|
|
||
| ``` | ||
| Admin user created — username: admin password: <generated> | ||
| ``` | ||
|
|
||
| !!! warning | ||
| Save this password immediately. You can change it afterwards from the **Profile** page, but it is only printed once. | ||
|
|
||
| --- | ||
|
|
||
| ## Signing In | ||
|
|
||
| Navigate to `http://<host>:<port>/ui/login` (or the root URL, which redirects there automatically). Enter your username and password to sign in. | ||
|
|
||
| --- | ||
|
|
||
| ## Admin Panel | ||
|
|
||
| The admin panel is accessible from the **Admin Panel** button on the Projects page (visible to admin users only). | ||
|
|
||
| ### Viewing Users | ||
|
|
||
| The panel lists all registered accounts with their username, email, role, and active status. | ||
|
|
||
| ### Creating a User | ||
|
|
||
| 1. Click **Add User**. | ||
| 2. Fill in **Username**, **Password**, and optionally **Email**. | ||
| 3. Select a **Role** (`user` or `admin`). | ||
| 4. Click **Create**. | ||
|
|
||
| ### Changing a User's Role | ||
|
|
||
| 1. Find the user in the table and click **Edit**. | ||
| 2. Select the new **Global Role**. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, you could reduce all admins down to regular users - maybe it should be enforced that at least one admin must be active, and if you try to change the final admin down to a regular user it doesnt allow it? |
||
| 3. Click **Save**. | ||
|
|
||
| !!! note | ||
| TokTagger prevents demoting or deactivating the last remaining active admin account to avoid an unrecoverable lockout. | ||
|
|
||
| ### Deactivating / Reactivating a User | ||
|
|
||
| Click **Deactivate** (or **Activate**) next to the user. Deactivated accounts cannot sign in but their annotations are preserved. You cannot deactivate your own account. | ||
|
|
||
| ### Deleting a User | ||
|
|
||
| Click **Delete** next to the user and confirm. This is permanent. You cannot delete your own account. | ||
|
|
||
| --- | ||
|
|
||
| ## Profile Page | ||
|
|
||
| Any signed-in user can update their own profile. Click **Profile** from the Projects page. | ||
|
|
||
| ### Updating Email | ||
|
|
||
| Enter a new address in the **Email** field and click **Save Email**. | ||
|
|
||
| ### Changing Password | ||
|
|
||
| 1. Enter a new password in **New password** (minimum 8 characters). | ||
| 2. Confirm it in **Confirm new password**. | ||
| 3. Click **Change Password**. | ||
|
|
||
| --- | ||
|
|
||
| ## Project Membership | ||
|
|
||
| Access to a project is controlled per-project. From the project's Samples page, an admin can click **Members** to add or remove users. | ||
|
|
||
| Only members (and admins) can view samples and submit annotations for a given project. | ||
|
|
||
| --- | ||
|
|
||
| ## Scripted User & Project Setup | ||
|
|
||
| For automated deployments, the helper script `scripts/setup.py` can create projects and samples via the API using token-based auth: | ||
|
|
||
| ```sh | ||
| python scripts/setup.py \ | ||
| --url http://localhost:8002 \ | ||
| --username admin \ | ||
| --password <password> | ||
| ``` | ||
|
|
||
| The script authenticates, obtains a JWT token, and creates projects and sample sets using the REST API. You can adapt it to pre-create user accounts with the `POST /users` endpoint: | ||
|
|
||
| ```python | ||
| import requests | ||
|
|
||
| token = get_token(base_url, "admin", admin_password) | ||
| requests.post( | ||
| f"{base_url}/users", | ||
| json={"username": "alice", "password": "s3cr3t", "global_role": "user"}, | ||
| headers={"Authorization": f"Bearer {token}"}, | ||
| ) | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Multi-User Deployment | ||
|
|
||
| For team use, run the API under **Gunicorn** so multiple requests can be served concurrently: | ||
|
|
||
| ```sh | ||
| # Command-line (installed package) | ||
| toktagger --workers 4 --host 0.0.0.0 --port 8002 | ||
|
|
||
| # Direct Gunicorn invocation | ||
| gunicorn toktagger.api.asgi:app \ | ||
| --worker-class uvicorn.workers.UvicornWorker \ | ||
| --workers 4 \ | ||
| --bind 0.0.0.0:8002 | ||
| ``` | ||
|
|
||
| With Docker Compose the `WORKERS` variable controls the worker count (default 4 in production, 1 in dev): | ||
|
|
||
| ```sh | ||
| WORKERS=8 docker compose up | ||
| ``` | ||
|
|
||
| A single Uvicorn worker (the default for `toktagger` without `--workers`) is sufficient for personal/local use but will serialise all requests, so concurrent annotators will experience latency under load. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assume this should be increased in both the models_disabled and models_enabled CI jobs?