User Management
This guide explains how to manage users in the Tracker System. There are two ways to manage users:
- Admin Panel: The primary way to manage users through the user-friendly web interface
- CLI Tool: For initial setup or automation when the admin panel is not available
User Management via Admin Panel
The admin panel provides a comprehensive interface for managing users, with features for creating, viewing, updating, and deleting user accounts.
Accessing User Management
- Log in to the admin panel with an admin account
- Navigate to the "Users" section in the sidebar
Creating a User
- Click the "Create User" button
- Fill in the required fields:
- Name: User's full name
- Email: User's email address (used for login)
- Password: Initial password for the user
- Roles: Select one or more roles (admin, user)
- Client List: Select which clients the user can access
- Click "Save" to create the user
Viewing Users
The users page displays a list of all users with key information:
- Name
- Roles
- Client access list
You can click on a user's name to view their detailed profile.
Editing a User
- Navigate to the user's detail page
- Click the "Edit" button
- Update the user's information
- Click "Save" to apply the changes
Deleting a User
- Navigate to the user's detail page
- Click the "Delete" button
- Confirm the deletion
User Roles
The system supports the following roles:
- Admin: Full access to all features and data
- User: Access to data based on their client list
Client Access Control
Users can be restricted to only access data related to specific clients:
- When creating or editing a user, select the clients they should have access to
- The user will only be able to view and manage data related to those clients
- Admin users bypass client filtering and can access all data
User Management CLI Tool
The User Management CLI tool allows you to create, update, and delete users from the command line. This is particularly useful for initial setup when no users exist in the system yet, or for automation purposes.
Prerequisites
- Access to the server where the Tracker API is deployed
- Database connection configured in
.envfile
Usage
The User Management CLI tool provides several commands to manage users:
Create a User
./scripts/user create --name "Admin User" --email "admin@example.com" --password "securepassword" --roles admin,user
Parameters:
--name: User's full name (required)--email: User's email address (required)--password: User's password (required)--roles: Comma-separated list of roles (default: "user")--client-list: Comma-separated list of client IDs (optional)--notification-preferences: JSON string of notification preferences (optional)
Example with all parameters:
./scripts/user create \
--name "Admin User" \
--email "admin@example.com" \
--password "securepassword" \
--roles admin,user \
--client-list 1,2,3 \
--notification-preferences '{"email":true,"ui":true}'
Update a User
./scripts/user update 1 --name "Updated Name" --password "newpassword"
Parameters:
user_id: ID of the user to update (required, positional argument)--name: User's updated full name (optional)--email: User's updated email address (optional)--password: User's updated password (optional)--roles: Comma-separated list of updated roles (optional)--client-list: Comma-separated list of updated client IDs (optional)--notification-preferences: JSON string of updated notification preferences (optional)
Example with multiple parameters:
./scripts/user update 1 \
--name "Updated Name" \
--email "updated@example.com" \
--roles admin,user,manager
Delete a User
./scripts/user delete 1
Parameters:
user_id: ID of the user to delete (required, positional argument)
List All Users
./scripts/user list
Parameters:
--skip: Number of users to skip (default: 0)--limit: Maximum number of users to return (default: 100)
Get a Specific User
./scripts/user get 1
Parameters:
user_id: ID of the user to get (required, positional argument)
Creating an Admin User
To create an initial admin user for the system:
./scripts/user create \
--name "Admin User" \
--email "admin@example.com" \
--password "securepassword" \
--roles admin
This will create a user with admin privileges who can then use the API to manage other users.
Common Scenarios
Initial System Setup
When setting up the system for the first time, you'll need to create an admin user:
./scripts/user create \
--name "Admin User" \
--email "admin@example.com" \
--password "securepassword" \
--roles admin
Resetting a User's Password
If a user forgets their password, you can reset it:
./scripts/user update 1 --password "newpassword"
Granting Admin Privileges
To grant admin privileges to an existing user:
./scripts/user update 1 --roles admin,user
Troubleshooting
Database Connection Issues
If you encounter database connection issues, check that:
- The database is running
- The connection details in
.envare correct - The user has permission to access the database
User Already Exists
If you get an error that a user already exists when trying to create a new user, you can either:
- Use a different email address
- Update the existing user instead of creating a new one
- Delete the existing user first (if appropriate)
User Not Found
When trying to get, update, or delete a user that doesn't exist, the API will return a 404 error with the message "The user with this id does not exist in the system". This can happen if:
- The user ID is incorrect
- The user has been deleted
- The database has been reset
In these cases, verify that the user ID is correct and that the user exists in the database.
Permission Issues
If you can't run the script due to permission issues, make sure the script is executable:
chmod +x scripts/user
chmod +x scripts/manage_users.py