Skip to content

User Management

This guide explains how to manage users in the Tracker System. There are two ways to manage users:

  1. Admin Panel: The primary way to manage users through the user-friendly web interface
  2. 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

  1. Log in to the admin panel with an admin account
  2. Navigate to the "Users" section in the sidebar

Creating a User

  1. Click the "Create User" button
  2. Fill in the required fields:
  3. Name: User's full name
  4. Email: User's email address (used for login)
  5. Password: Initial password for the user
  6. Roles: Select one or more roles (admin, user)
  7. Client List: Select which clients the user can access
  8. Click "Save" to create the user

Viewing Users

The users page displays a list of all users with key information:

  • Name
  • Email
  • Roles
  • Client access list

You can click on a user's name to view their detailed profile.

Editing a User

  1. Navigate to the user's detail page
  2. Click the "Edit" button
  3. Update the user's information
  4. Click "Save" to apply the changes

Deleting a User

  1. Navigate to the user's detail page
  2. Click the "Delete" button
  3. 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:

  1. When creating or editing a user, select the clients they should have access to
  2. The user will only be able to view and manage data related to those clients
  3. 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 .env file

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:

  1. The database is running
  2. The connection details in .env are correct
  3. 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:

  1. Use a different email address
  2. Update the existing user instead of creating a new one
  3. 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:

  1. The user ID is incorrect
  2. The user has been deleted
  3. 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