This project is a User and Organisation Management System built using Django and Django REST Framework. The application allows users to register, log in, and manage organisations. Each user can belong to multiple organisations, and each organisation can have multiple users.
- User Registration and Login
- JWT-based Authentication
- Organisation Management
- User and Organisation Relationship Management
- Validation and Error Handling
- Django
- Django REST Framework
- PostgreSQL
- Simple JWT
- Pytest
- Python 3.x
- PostgreSQL
-
Clone the repository
git clone https://github.com/Goodnessmbakara/django-user-org-management.git cd django-user-org-management
-
Create and activate a virtual environment
python3 -m venv env source env/bin/activate # On Windows use `env\Scripts\activate`
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
Create a
.env
file in the root directory and add the following variables:SECRET_KEY=your_secret_key DEBUG=True ALLOWED_HOSTS=localhost,127.0.0.1 DATABASE_URL=postgres://your_db_user:your_db_password@localhost:5432/your_db_name
-
Apply migrations
python manage.py makemigrations python manage.py migrate
-
Run the development server
python manage.py runserver
-
Register:
POST /auth/register
- Request Body:
{ "firstName": "string", "lastName": "string", "email": "string", "password": "string", "phone": "string" }
- Successful Response:
{ "status": "success", "message": "Registration successful", "data": { "accessToken": "eyJh...", "user": { "userId": "string", "firstName": "string", "lastName": "string", "email": "string", "phone": "string" } } }
- Request Body:
-
Login:
POST /auth/login
- Request Body:
{ "email": "string", "password": "string" }
- Successful Response:
{ "status": "success", "message": "Login successful", "data": { "accessToken": "eyJh...", "user": { "userId": "string", "firstName": "string", "lastName": "string", "email": "string", "phone": "string" } } }
- Request Body:
- Get User:
GET /api/users/:id
- Successful Response:
{ "status": "success", "message": "<message>", "data": { "userId": "string", "firstName": "string", "lastName": "string", "email": "string", "phone": "string" } }
- Successful Response:
-
Get All Organisations:
GET /api/organisations
- Successful Response:
{ "status": "success", "message": "<message>", "data": { "organisations": [ { "orgId": "string", "name": "string", "description": "string" } ] } }
- Successful Response:
-
Get Organisation:
GET /api/organisations/:orgId
- Successful Response:
{ "status": "success", "message": "<message>", "data": { "orgId": "string", "name": "string", "description": "string" } }
- Successful Response:
-
Create Organisation:
POST /api/organisations
- Request Body:
{ "name": "string", "description": "string" }
- Successful Response:
{ "status": "success", "message": "Organisation created successfully", "data": { "orgId": "string", "name": "string", "description": "string" } }
- Request Body:
-
Add User to Organisation:
POST /api/organisations/:orgId/users
- Request Body:
{ "userId": "string" }
- Successful Response:
{ "status": "success", "message": "User added to organisation successfully" }
- Request Body:
To run the tests, use the following command:
pytest
- Token Generation: Ensure token expires at the correct time and correct user details are found in the token.
- Organisation Access: Ensure users can’t see data from organisations they don’t have access to.
- User Registration: Verify default organisation name generation and response details.
- User Login: Verify response details and token generation.
- Validation: Ensure appropriate error messages and status codes for missing or duplicate fields.
We welcome contributions! Please see the CONTRIBUTING.md file for guidelines on how to contribute to this project.
This project is licensed under the MIT License. See the LICENSE file for more details.
This README.md
file provides a comprehensive overview of the project, including setup instructions, API endpoint details, testing, and contributing guidelines.