Spaces:
Runtime error
Runtime error
Commit ·
97f32ec
0
Parent(s):
init
Browse files- .gitattributes +35 -0
- .github/workflows/hf-push.yml +27 -0
- .gitignore +59 -0
- API_DOCUMENTATION.md +0 -0
- Dockerfile +24 -0
- PMS_API_DOCUMENTATION.md +535 -0
- README.md +10 -0
- admin_app/__init__.py +0 -0
- admin_app/admin.py +3 -0
- admin_app/apps.py +6 -0
- admin_app/migrations/__init__.py +0 -0
- admin_app/models.py +23 -0
- admin_app/serializers.py +25 -0
- admin_app/urls.py +15 -0
- admin_app/views.py +362 -0
- api/__init__.py +0 -0
- api/admin.py +3 -0
- api/apps.py +6 -0
- api/migrations/__init__.py +0 -0
- api/models.py +58 -0
- api/serializers.py +79 -0
- api/urls.py +17 -0
- api/views.py +406 -0
- api_admin_test.py +639 -0
- api_test.py +620 -0
- app.py +16 -0
- auth_app/__init__.py +1 -0
- auth_app/admin.py +3 -0
- auth_app/apps.py +20 -0
- auth_app/firebase_app.py +20 -0
- auth_app/management/__init__.py +0 -0
- auth_app/management/commands/__init__.py +0 -0
- auth_app/management/commands/createsuperadmin.py +48 -0
- auth_app/migrations/__init__.py +0 -0
- auth_app/models.py +38 -0
- auth_app/serializers.py +51 -0
- auth_app/urls.py +9 -0
- auth_app/utils.py +15 -0
- auth_app/views.py +132 -0
- manage.py +22 -0
- package-lock.json +6 -0
- pms_server/__init__.py +0 -0
- pms_server/asgi.py +16 -0
- pms_server/settings.py +250 -0
- pms_server/urls.py +32 -0
- pms_server/wsgi.py +16 -0
- postman.json +778 -0
- postman_new.json +221 -0
- requirements.txt +8 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.github/workflows/hf-push.yml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Sync to Hugging Face Space
|
| 2 |
+
on:
|
| 3 |
+
push:
|
| 4 |
+
branches: [main]
|
| 5 |
+
workflow_dispatch:
|
| 6 |
+
|
| 7 |
+
jobs:
|
| 8 |
+
sync:
|
| 9 |
+
runs-on: ubuntu-latest
|
| 10 |
+
steps:
|
| 11 |
+
- uses: actions/checkout@v4
|
| 12 |
+
with:
|
| 13 |
+
fetch-depth: 0
|
| 14 |
+
lfs: true
|
| 15 |
+
- name: Configure git user
|
| 16 |
+
run: |
|
| 17 |
+
git config user.name "${GITHUB_ACTOR}"
|
| 18 |
+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
|
| 19 |
+
- name: Push to Space (main)
|
| 20 |
+
env:
|
| 21 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 22 |
+
HF_USERNAME: Noel-14
|
| 23 |
+
SPACE_NAME: pms_server
|
| 24 |
+
run: |
|
| 25 |
+
git push --force \
|
| 26 |
+
https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME \
|
| 27 |
+
HEAD:main
|
.gitignore
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ======================
|
| 2 |
+
# Python / Django
|
| 3 |
+
# ======================
|
| 4 |
+
__pycache__/
|
| 5 |
+
*.py[cod]
|
| 6 |
+
*$py.class
|
| 7 |
+
*.log
|
| 8 |
+
*.pot
|
| 9 |
+
*.pyc
|
| 10 |
+
*.pyo
|
| 11 |
+
|
| 12 |
+
# Local database (don’t commit dev DB)
|
| 13 |
+
db.sqlite3
|
| 14 |
+
*.sqlite3
|
| 15 |
+
|
| 16 |
+
# Media & static (collected/served at runtime)
|
| 17 |
+
media/
|
| 18 |
+
paperworks/
|
| 19 |
+
staticfiles/
|
| 20 |
+
static/
|
| 21 |
+
|
| 22 |
+
# Migrations (only keep __init__.py so Django can detect the package)
|
| 23 |
+
*/migrations/*.py
|
| 24 |
+
!*/migrations/__init__.py
|
| 25 |
+
|
| 26 |
+
# Secrets / environment configs
|
| 27 |
+
.env
|
| 28 |
+
*.env
|
| 29 |
+
.env.*
|
| 30 |
+
secrets.json
|
| 31 |
+
|
| 32 |
+
# ======================
|
| 33 |
+
# Docker / Hugging Face
|
| 34 |
+
# ======================
|
| 35 |
+
*.pid
|
| 36 |
+
*.seed
|
| 37 |
+
*.bak
|
| 38 |
+
*.backup
|
| 39 |
+
*.tar
|
| 40 |
+
*.gz
|
| 41 |
+
*.tmp
|
| 42 |
+
|
| 43 |
+
# Keep Dockerfile & docker-compose.yml for Hugging Face build
|
| 44 |
+
!Dockerfile
|
| 45 |
+
!docker-compose.yml
|
| 46 |
+
|
| 47 |
+
# ======================
|
| 48 |
+
# Editor / IDE / System
|
| 49 |
+
# ======================
|
| 50 |
+
.vscode/
|
| 51 |
+
.idea/
|
| 52 |
+
*.swp
|
| 53 |
+
*~
|
| 54 |
+
.DS_Store
|
| 55 |
+
|
| 56 |
+
# ======================
|
| 57 |
+
# Firebase Services
|
| 58 |
+
# ======================
|
| 59 |
+
paper-ms-firebase-adminsdk-fbsvc-5bcb4de51e.json
|
API_DOCUMENTATION.md
ADDED
|
File without changes
|
Dockerfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Base Python image
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
|
| 8 |
+
# Set work directory
|
| 9 |
+
WORKDIR /app
|
| 10 |
+
|
| 11 |
+
# Copy project files
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
# Install Python dependencies
|
| 15 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 16 |
+
|
| 17 |
+
RUN chmod -R 777 /app
|
| 18 |
+
|
| 19 |
+
# Expose port
|
| 20 |
+
EXPOSE 7860
|
| 21 |
+
|
| 22 |
+
# Run the Django app using Uvicorn
|
| 23 |
+
CMD ["python", "app.py"]
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Paper Management System API Documentation
|
| 2 |
+
|
| 3 |
+
This document provides comprehensive documentation for the Paper Management System API endpoints.
|
| 4 |
+
|
| 5 |
+
## Table of Contents
|
| 6 |
+
|
| 7 |
+
1. [Authentication](#authentication)
|
| 8 |
+
2. [API Endpoints](#api-endpoints)
|
| 9 |
+
- [Auth API](#auth-api)
|
| 10 |
+
- [Admin API](#admin-api)
|
| 11 |
+
- [Paper Management API](#paper-management-api)
|
| 12 |
+
3. [Models](#models)
|
| 13 |
+
4. [Error Handling](#error-handling)
|
| 14 |
+
|
| 15 |
+
## Authentication
|
| 16 |
+
|
| 17 |
+
The API uses JWT (JSON Web Token) authentication. Most endpoints require authentication.
|
| 18 |
+
|
| 19 |
+
### Token Acquisition
|
| 20 |
+
|
| 21 |
+
**Endpoint**: `POST /auth/login/`
|
| 22 |
+
|
| 23 |
+
**Request Body**:
|
| 24 |
+
```json
|
| 25 |
+
{
|
| 26 |
+
"username": "string",
|
| 27 |
+
"password": "string"
|
| 28 |
+
}
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
**Response**:
|
| 32 |
+
```json
|
| 33 |
+
{
|
| 34 |
+
"refresh": "string",
|
| 35 |
+
"access": "string",
|
| 36 |
+
"user": {
|
| 37 |
+
"id": "uuid",
|
| 38 |
+
"username": "string",
|
| 39 |
+
"email": "string",
|
| 40 |
+
"role": "string",
|
| 41 |
+
"status": "string"
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
### Google Authentication
|
| 47 |
+
|
| 48 |
+
**Endpoint**: `POST /auth/google/`
|
| 49 |
+
|
| 50 |
+
**Request Body**:
|
| 51 |
+
```json
|
| 52 |
+
{
|
| 53 |
+
"id_token": "string"
|
| 54 |
+
}
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
**Response**: Same as regular login
|
| 58 |
+
|
| 59 |
+
## API Endpoints
|
| 60 |
+
|
| 61 |
+
### Auth API
|
| 62 |
+
|
| 63 |
+
#### Register User
|
| 64 |
+
|
| 65 |
+
**Endpoint**: `POST /auth/register/`
|
| 66 |
+
|
| 67 |
+
**Permission**: AllowAny
|
| 68 |
+
|
| 69 |
+
**Request Body**:
|
| 70 |
+
```json
|
| 71 |
+
{
|
| 72 |
+
"username": "string",
|
| 73 |
+
"email": "string",
|
| 74 |
+
"password": "string",
|
| 75 |
+
"role": "string" // Optional, defaults to "RESEARCHER"
|
| 76 |
+
}
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
**Response**:
|
| 80 |
+
```json
|
| 81 |
+
{
|
| 82 |
+
"message": "User registered successfully",
|
| 83 |
+
"user": {
|
| 84 |
+
"id": "uuid",
|
| 85 |
+
"email": "string",
|
| 86 |
+
"first_name": "string",
|
| 87 |
+
"last_name": "string",
|
| 88 |
+
"role": "string"
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
#### Get Current User
|
| 94 |
+
|
| 95 |
+
**Endpoint**: `GET /auth/me/`
|
| 96 |
+
|
| 97 |
+
**Permission**: IsAuthenticated
|
| 98 |
+
|
| 99 |
+
**Response**:
|
| 100 |
+
```json
|
| 101 |
+
{
|
| 102 |
+
"id": "uuid",
|
| 103 |
+
"username": "string",
|
| 104 |
+
"email": "string",
|
| 105 |
+
"role": "string",
|
| 106 |
+
"status": "string"
|
| 107 |
+
}
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
### Admin API
|
| 111 |
+
|
| 112 |
+
#### Create User
|
| 113 |
+
|
| 114 |
+
**Endpoint**: `POST /admin_app/createusers/`
|
| 115 |
+
|
| 116 |
+
**Permission**: IsAuthenticated, IsAdmin
|
| 117 |
+
|
| 118 |
+
**Request Body**:
|
| 119 |
+
```json
|
| 120 |
+
{
|
| 121 |
+
"username": "string",
|
| 122 |
+
"email": "string",
|
| 123 |
+
"role": "string",
|
| 124 |
+
"status": "string"
|
| 125 |
+
}
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
**Response**: User object
|
| 129 |
+
|
| 130 |
+
#### Update User Status
|
| 131 |
+
|
| 132 |
+
**Endpoint**: `PATCH /admin_app/updateusers/<username>/status/`
|
| 133 |
+
|
| 134 |
+
**Permission**: IsAuthenticated, IsAdmin
|
| 135 |
+
|
| 136 |
+
**Request Body**:
|
| 137 |
+
```json
|
| 138 |
+
{
|
| 139 |
+
"status": "string" // One of: "ACTIVE", "FROZEN", "INACTIVE"
|
| 140 |
+
}
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
**Response**: User object
|
| 144 |
+
|
| 145 |
+
#### List Users
|
| 146 |
+
|
| 147 |
+
**Endpoint**: `GET /admin_app/users/`
|
| 148 |
+
|
| 149 |
+
**Permission**: IsAuthenticated, IsAdmin
|
| 150 |
+
|
| 151 |
+
**Response**: Array of User objects (excluding admins)
|
| 152 |
+
|
| 153 |
+
#### Get User Detail
|
| 154 |
+
|
| 155 |
+
**Endpoint**: `GET /admin_app/users/<user_id>/`
|
| 156 |
+
|
| 157 |
+
**Permission**: IsAuthenticated, IsAdmin
|
| 158 |
+
|
| 159 |
+
**Response**: User object
|
| 160 |
+
|
| 161 |
+
#### View Paperwork File
|
| 162 |
+
|
| 163 |
+
**Endpoint**: `GET /admin_app/paperworks/<paperwork_id>/versions/<version_no>/<file_type>/view/`
|
| 164 |
+
|
| 165 |
+
**Permission**: IsAuthenticated, IsAdmin
|
| 166 |
+
|
| 167 |
+
**Parameters**:
|
| 168 |
+
- `paperwork_id`: UUID of the paperwork
|
| 169 |
+
- `version_no`: Integer version number
|
| 170 |
+
- `file_type`: String, one of: "pdf", "latex", "python", "docx"
|
| 171 |
+
|
| 172 |
+
**Response**: File content with appropriate content type
|
| 173 |
+
|
| 174 |
+
**Notes**:
|
| 175 |
+
- Allows administrators to view files directly in the browser without downloading
|
| 176 |
+
- Returns 404 if the version or file doesn't exist
|
| 177 |
+
- Returns 400 for invalid file types
|
| 178 |
+
|
| 179 |
+
#### Assign Paper Work
|
| 180 |
+
|
| 181 |
+
**Endpoint**: `POST /admin_app/paperworks/`
|
| 182 |
+
|
| 183 |
+
**Permission**: IsAuthenticated, IsAdmin
|
| 184 |
+
|
| 185 |
+
**Request Body**:
|
| 186 |
+
```json
|
| 187 |
+
{
|
| 188 |
+
"title": "string",
|
| 189 |
+
"researcher_id": "uuid",
|
| 190 |
+
"deadline": "datetime" // Optional
|
| 191 |
+
}
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
**Response**: PaperWork object
|
| 195 |
+
|
| 196 |
+
#### Update Paper Work Deadline
|
| 197 |
+
|
| 198 |
+
**Endpoint**: `PATCH /admin_app/paperworks/<id>/deadline/`
|
| 199 |
+
|
| 200 |
+
**Permission**: IsAuthenticated, IsAdmin
|
| 201 |
+
|
| 202 |
+
**Request Body**:
|
| 203 |
+
```json
|
| 204 |
+
{
|
| 205 |
+
"deadline": "datetime"
|
| 206 |
+
}
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
+
**Response**: PaperWork object
|
| 210 |
+
|
| 211 |
+
### Paper Management API
|
| 212 |
+
|
| 213 |
+
#### List Paper Works
|
| 214 |
+
|
| 215 |
+
**Endpoint**: `GET /api/paperworks/`
|
| 216 |
+
|
| 217 |
+
**Permission**: IsAuthenticated
|
| 218 |
+
|
| 219 |
+
**Notes**:
|
| 220 |
+
- Researchers can only see their own paperworks
|
| 221 |
+
- Admins can see all paperworks
|
| 222 |
+
|
| 223 |
+
**Response**: Array of PaperWork objects
|
| 224 |
+
|
| 225 |
+
#### Get Paper Work Detail
|
| 226 |
+
|
| 227 |
+
**Endpoint**: `GET /api/paperworks/<id>/`
|
| 228 |
+
|
| 229 |
+
**Permission**: IsAuthenticated
|
| 230 |
+
|
| 231 |
+
**Notes**:
|
| 232 |
+
- Researchers can only access their own paperworks
|
| 233 |
+
- Admins can access all paperworks
|
| 234 |
+
|
| 235 |
+
**Response**: PaperWork object
|
| 236 |
+
|
| 237 |
+
#### List Versions
|
| 238 |
+
|
| 239 |
+
**Endpoint**: `GET /api/paperworks/<id>/versions/`
|
| 240 |
+
|
| 241 |
+
**Permission**: IsAuthenticated
|
| 242 |
+
|
| 243 |
+
**Notes**:
|
| 244 |
+
- Researchers can only access their own paperworks
|
| 245 |
+
- Admins can access all paperworks
|
| 246 |
+
|
| 247 |
+
**Response**: Array of Version objects
|
| 248 |
+
|
| 249 |
+
#### Submit Version
|
| 250 |
+
|
| 251 |
+
**Endpoint**: `POST /api/paperworks/<id>/versions/`
|
| 252 |
+
|
| 253 |
+
**Permission**: IsAuthenticated
|
| 254 |
+
|
| 255 |
+
**Notes**:
|
| 256 |
+
- Only researchers can submit versions for their own paperworks
|
| 257 |
+
|
| 258 |
+
**Request Body**: Multipart form data
|
| 259 |
+
```
|
| 260 |
+
paper_pdf: file (required)
|
| 261 |
+
latex_tex: file (required)
|
| 262 |
+
python_zip: file (required)
|
| 263 |
+
docx_file: file (optional)
|
| 264 |
+
ai_percent_self: float (optional)
|
| 265 |
+
```
|
| 266 |
+
|
| 267 |
+
**Response**: Version object
|
| 268 |
+
|
| 269 |
+
#### Get Version Detail
|
| 270 |
+
|
| 271 |
+
**Endpoint**: `GET /api/paperworks/<id>/versions/<ver>/`
|
| 272 |
+
|
| 273 |
+
**Permission**: IsAuthenticated
|
| 274 |
+
|
| 275 |
+
**Notes**:
|
| 276 |
+
- Researchers can only access their own paperworks
|
| 277 |
+
- Admins can access all paperworks
|
| 278 |
+
|
| 279 |
+
**Response**:
|
| 280 |
+
```json
|
| 281 |
+
{
|
| 282 |
+
"id": "uuid",
|
| 283 |
+
"paperwork": { /* PaperWork object */ },
|
| 284 |
+
"version_no": "integer",
|
| 285 |
+
"submitted_at": "datetime",
|
| 286 |
+
"pdf_path": "string",
|
| 287 |
+
"latex_path": "string",
|
| 288 |
+
"python_path": "string",
|
| 289 |
+
"docx_path": "string",
|
| 290 |
+
"ai_percent_self": "float",
|
| 291 |
+
"ai_percent_verified": "float",
|
| 292 |
+
"pdf_url": "string",
|
| 293 |
+
"latex_url": "string",
|
| 294 |
+
"python_url": "string"
|
| 295 |
+
}
|
| 296 |
+
```
|
| 297 |
+
|
| 298 |
+
#### Review Paper Work
|
| 299 |
+
|
| 300 |
+
**Endpoint**: `POST /api/paperworks/<id>/review/`
|
| 301 |
+
|
| 302 |
+
**Permission**: IsAuthenticated, IsAdmin
|
| 303 |
+
|
| 304 |
+
**Request Body**:
|
| 305 |
+
```json
|
| 306 |
+
{
|
| 307 |
+
"status": "string", // One of: "ASSIGNED", "SUBMITTED", "CHANGES_REQUESTED", "APPROVED"
|
| 308 |
+
"comments": "string" // Optional
|
| 309 |
+
}
|
| 310 |
+
```
|
| 311 |
+
|
| 312 |
+
**Response**: PaperWork object
|
| 313 |
+
|
| 314 |
+
#### Get All Paperwork Reviews
|
| 315 |
+
|
| 316 |
+
**Endpoint**: `GET /api/paperworks/<id>/reviews/`
|
| 317 |
+
|
| 318 |
+
**Permission**: IsAuthenticated
|
| 319 |
+
|
| 320 |
+
**Notes**:
|
| 321 |
+
- Researchers can only access reviews for their own paperworks
|
| 322 |
+
- Admins can access all paperwork reviews
|
| 323 |
+
|
| 324 |
+
**Response**: Array of Review objects
|
| 325 |
+
|
| 326 |
+
#### Get Specific Paperwork Review
|
| 327 |
+
|
| 328 |
+
**Endpoint**: `GET /api/paperworks/<id>/reviews/<review_id>/`
|
| 329 |
+
|
| 330 |
+
**Permission**: IsAuthenticated
|
| 331 |
+
|
| 332 |
+
**Notes**:
|
| 333 |
+
- Researchers can only access reviews for their own paperworks
|
| 334 |
+
- Admins can access all paperwork reviews
|
| 335 |
+
|
| 336 |
+
**Response**: Review object
|
| 337 |
+
|
| 338 |
+
#### Get Reports Summary
|
| 339 |
+
|
| 340 |
+
**Endpoint**: `GET /api/reports/summary/`
|
| 341 |
+
|
| 342 |
+
**Permission**: IsAuthenticated, IsAdmin
|
| 343 |
+
|
| 344 |
+
**Response**:
|
| 345 |
+
```json
|
| 346 |
+
{
|
| 347 |
+
"total_papers": "integer",
|
| 348 |
+
"papers_by_status": {
|
| 349 |
+
"status1": "count",
|
| 350 |
+
"status2": "count"
|
| 351 |
+
},
|
| 352 |
+
"papers_by_researcher": {
|
| 353 |
+
"username1": "count",
|
| 354 |
+
"username2": "count"
|
| 355 |
+
},
|
| 356 |
+
"average_ai_percentage": "float"
|
| 357 |
+
}
|
| 358 |
+
```
|
| 359 |
+
|
| 360 |
+
#### Export Reports
|
| 361 |
+
|
| 362 |
+
**Endpoint**: `GET /api/reports/export.csv/`
|
| 363 |
+
|
| 364 |
+
**Permission**: IsAuthenticated, IsAdmin
|
| 365 |
+
|
| 366 |
+
**Response**: CSV file with paper work data
|
| 367 |
+
|
| 368 |
+
#### Delete Paper Work
|
| 369 |
+
|
| 370 |
+
**Endpoint**: `DELETE /api/paperworks/<id>/delete/`
|
| 371 |
+
|
| 372 |
+
**Permission**: IsAuthenticated, IsNotFrozen, IsAdmin or PaperWork Owner
|
| 373 |
+
|
| 374 |
+
**Notes**:
|
| 375 |
+
- Admins can delete any paperwork.
|
| 376 |
+
- Deletes associated files (PDF, LaTeX, Python, DOCX) from the file system.
|
| 377 |
+
|
| 378 |
+
**Response**: `204 No Content` on successful deletion.
|
| 379 |
+
|
| 380 |
+
#### Get Researcher Statistics
|
| 381 |
+
|
| 382 |
+
**Endpoint**: `GET /api/stats/researcher/`
|
| 383 |
+
|
| 384 |
+
**Permission**: IsAuthenticated, IsNotFrozen
|
| 385 |
+
|
| 386 |
+
**Notes**:
|
| 387 |
+
- Researchers can only see their own statistics.
|
| 388 |
+
|
| 389 |
+
**Response**:
|
| 390 |
+
```json
|
| 391 |
+
{
|
| 392 |
+
"total_paperworks": "integer",
|
| 393 |
+
"pending_review": "integer",
|
| 394 |
+
"approved": "integer",
|
| 395 |
+
"changes_requested": "integer"
|
| 396 |
+
}
|
| 397 |
+
```
|
| 398 |
+
|
| 399 |
+
#### Get Admin Statistics
|
| 400 |
+
|
| 401 |
+
**Endpoint**: `GET /admin_app/stats/admin/`
|
| 402 |
+
|
| 403 |
+
**Permission**: IsAuthenticated, IsNotFrozen, IsAdmin
|
| 404 |
+
|
| 405 |
+
**Notes**:
|
| 406 |
+
- Admins can see overall statistics.
|
| 407 |
+
|
| 408 |
+
**Response**:
|
| 409 |
+
```json
|
| 410 |
+
{
|
| 411 |
+
"total_paperworks": "integer",
|
| 412 |
+
"submitted": "integer",
|
| 413 |
+
"approved": "integer",
|
| 414 |
+
"changes_requested": "integer"
|
| 415 |
+
}
|
| 416 |
+
```
|
| 417 |
+
|
| 418 |
+
#### List Notifications
|
| 419 |
+
|
| 420 |
+
**Endpoint**: `GET /api/notifications/`
|
| 421 |
+
|
| 422 |
+
**Permission**: IsAuthenticated
|
| 423 |
+
|
| 424 |
+
**Notes**:
|
| 425 |
+
- Researchers only see notifications for their papers
|
| 426 |
+
- Admins see all notifications
|
| 427 |
+
|
| 428 |
+
**Response**: Array of Notification objects
|
| 429 |
+
|
| 430 |
+
#### Mark Notification as Read
|
| 431 |
+
|
| 432 |
+
**Endpoint**: `POST /api/notifications/:id/`
|
| 433 |
+
|
| 434 |
+
**Permission**: IsAuthenticated
|
| 435 |
+
|
| 436 |
+
**Notes**:
|
| 437 |
+
- Users can only mark their own notifications as read
|
| 438 |
+
|
| 439 |
+
**Request Body**:
|
| 440 |
+
```json
|
| 441 |
+
{
|
| 442 |
+
"is_read": true
|
| 443 |
+
}
|
| 444 |
+
```
|
| 445 |
+
|
| 446 |
+
**Response**: Notification object
|
| 447 |
+
|
| 448 |
+
## Models
|
| 449 |
+
|
| 450 |
+
### User
|
| 451 |
+
|
| 452 |
+
```
|
| 453 |
+
id: UUID (primary key)
|
| 454 |
+
username: string
|
| 455 |
+
email: string
|
| 456 |
+
role: string (ADMIN, RESEARCHER)
|
| 457 |
+
status: string (ACTIVE, FROZEN, INACTIVE)
|
| 458 |
+
```
|
| 459 |
+
|
| 460 |
+
### PaperWork
|
| 461 |
+
|
| 462 |
+
```
|
| 463 |
+
id: UUID (primary key)
|
| 464 |
+
title: string
|
| 465 |
+
researcher: User (foreign key)
|
| 466 |
+
status: string (ASSIGNED, SUBMITTED, CHANGES_REQUESTED, APPROVED)
|
| 467 |
+
assigned_at: datetime
|
| 468 |
+
deadline: datetime (optional)
|
| 469 |
+
updated_at: datetime
|
| 470 |
+
```
|
| 471 |
+
|
| 472 |
+
### Version
|
| 473 |
+
|
| 474 |
+
```
|
| 475 |
+
id: UUID (primary key)
|
| 476 |
+
paperwork: PaperWork (foreign key)
|
| 477 |
+
version_no: integer
|
| 478 |
+
submitted_at: datetime
|
| 479 |
+
pdf_path: string
|
| 480 |
+
latex_path: string
|
| 481 |
+
python_path: string
|
| 482 |
+
docx_path: string (optional)
|
| 483 |
+
ai_percent_self: float
|
| 484 |
+
ai_percent_verified: float (optional)
|
| 485 |
+
```
|
| 486 |
+
|
| 487 |
+
### Notification
|
| 488 |
+
|
| 489 |
+
```
|
| 490 |
+
id: UUID (primary key)
|
| 491 |
+
event: string (WORK_ASSIGNED, SUBMITTED, CHANGES_REQUESTED, APPROVED)
|
| 492 |
+
paper: PaperWork (foreign key)
|
| 493 |
+
at: datetime
|
| 494 |
+
```
|
| 495 |
+
|
| 496 |
+
### Review
|
| 497 |
+
|
| 498 |
+
```
|
| 499 |
+
id: UUID (primary key)
|
| 500 |
+
paperwork: PaperWork (foreign key)
|
| 501 |
+
status: string (ASSIGNED, SUBMITTED, CHANGES_REQUESTED, APPROVED)
|
| 502 |
+
comments: string (optional)
|
| 503 |
+
created_at: datetime
|
| 504 |
+
updated_at: datetime
|
| 505 |
+
```
|
| 506 |
+
|
| 507 |
+
## Error Handling
|
| 508 |
+
|
| 509 |
+
The API returns standard HTTP status codes:
|
| 510 |
+
|
| 511 |
+
- 200: OK - Request succeeded
|
| 512 |
+
- 201: Created - Resource created successfully
|
| 513 |
+
- 400: Bad Request - Invalid input
|
| 514 |
+
- 401: Unauthorized - Authentication required
|
| 515 |
+
- 403: Forbidden - Permission denied
|
| 516 |
+
- 404: Not Found - Resource not found
|
| 517 |
+
- 500: Internal Server Error - Server error
|
| 518 |
+
|
| 519 |
+
Error responses include a JSON object with an error message:
|
| 520 |
+
|
| 521 |
+
```json
|
| 522 |
+
{
|
| 523 |
+
"error": "Error message"
|
| 524 |
+
}
|
| 525 |
+
```
|
| 526 |
+
|
| 527 |
+
For validation errors, the response includes field-specific errors:
|
| 528 |
+
|
| 529 |
+
```json
|
| 530 |
+
{
|
| 531 |
+
"field_name": [
|
| 532 |
+
"Error message"
|
| 533 |
+
]
|
| 534 |
+
}
|
| 535 |
+
```
|
README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Pms Backend Server
|
| 3 |
+
emoji: 🐠
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
admin_app/__init__.py
ADDED
|
File without changes
|
admin_app/admin.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib import admin
|
| 2 |
+
|
| 3 |
+
# Register your models here.
|
admin_app/apps.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.apps import AppConfig
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class AdminAppConfig(AppConfig):
|
| 5 |
+
default_auto_field = "django.db.models.BigAutoField"
|
| 6 |
+
name = "admin_app"
|
admin_app/migrations/__init__.py
ADDED
|
File without changes
|
admin_app/models.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import models
|
| 2 |
+
import uuid
|
| 3 |
+
from auth_app.models import User
|
| 4 |
+
|
| 5 |
+
class PaperWork(models.Model):
|
| 6 |
+
STATUS_CHOICES = (
|
| 7 |
+
('ASSIGNED', 'Assigned'),
|
| 8 |
+
('SUBMITTED', 'Submitted'),
|
| 9 |
+
('CHANGES_REQUESTED', 'Changes Requested'),
|
| 10 |
+
('APPROVED', 'Approved'),
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
| 14 |
+
title = models.CharField(max_length=255)
|
| 15 |
+
researcher = models.ForeignKey(User, on_delete=models.CASCADE, related_name='paperworks')
|
| 16 |
+
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='ASSIGNED')
|
| 17 |
+
assigned_at = models.DateTimeField(auto_now_add=True)
|
| 18 |
+
deadline = models.DateTimeField(null=True, blank=True)
|
| 19 |
+
updated_at = models.DateTimeField(auto_now=True)
|
| 20 |
+
|
| 21 |
+
class Meta:
|
| 22 |
+
verbose_name = 'Paper Work'
|
| 23 |
+
verbose_name_plural = 'Paper Works'
|
admin_app/serializers.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rest_framework import serializers
|
| 2 |
+
from .models import PaperWork
|
| 3 |
+
from auth_app.serializers import UserSerializer
|
| 4 |
+
|
| 5 |
+
class PaperWorkSerializer(serializers.ModelSerializer):
|
| 6 |
+
researcher = UserSerializer(read_only=True)
|
| 7 |
+
researcher_id = serializers.UUIDField(write_only=True)
|
| 8 |
+
|
| 9 |
+
class Meta:
|
| 10 |
+
model = PaperWork
|
| 11 |
+
fields = ['id', 'title', 'researcher', 'researcher_id', 'status', 'assigned_at', 'deadline', 'updated_at']
|
| 12 |
+
read_only_fields = ['id', 'assigned_at', 'updated_at']
|
| 13 |
+
|
| 14 |
+
def create(self, validated_data):
|
| 15 |
+
return PaperWork.objects.create(**validated_data)
|
| 16 |
+
|
| 17 |
+
class PaperWorkStatusUpdateSerializer(serializers.ModelSerializer):
|
| 18 |
+
class Meta:
|
| 19 |
+
model = PaperWork
|
| 20 |
+
fields = ['status']
|
| 21 |
+
|
| 22 |
+
class PaperWorkDeadlineUpdateSerializer(serializers.ModelSerializer):
|
| 23 |
+
class Meta:
|
| 24 |
+
model = PaperWork
|
| 25 |
+
fields = ['deadline']
|
admin_app/urls.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.urls import path
|
| 2 |
+
from . import views
|
| 3 |
+
|
| 4 |
+
urlpatterns = [
|
| 5 |
+
path('createusers/', views.create_user, name='create_user'),
|
| 6 |
+
path('updateusers/<str:username>/status/', views.update_user_status, name='update_user_status'),
|
| 7 |
+
path('users/', views.users_list, name='users_list'),
|
| 8 |
+
path('users/<uuid:user_id>/', views.user_detail, name='user_detail'),
|
| 9 |
+
path('paperworks/', views.assign_paperwork, name='assign_paperwork'),
|
| 10 |
+
path('paperworks/<uuid:id>/deadline/', views.update_paperwork_deadline, name='update_paperwork_deadline'),
|
| 11 |
+
path('paperworks/<uuid:paperwork_id>/versions/<int:version_no>/<str:file_type>/view/', views.view_paperwork_file, name='view_paperwork_file'),
|
| 12 |
+
path('paperworks/<uuid:paperwork_id>/versions/<int:version_no>/zip-contents/', views.view_zip_contents, name='view_zip_contents'),
|
| 13 |
+
path('paperworks/<uuid:paperwork_id>/versions/<int:version_no>/zip-file/<path:file_path>/', views.view_zip_file_content, name='view_zip_file_content'),
|
| 14 |
+
path("paperworks/<uuid:pk>/versions/<int:version_no>/<str:file_type>/download/", views.download_paperwork_file, name="download_paperwork_file")
|
| 15 |
+
]
|
admin_app/views.py
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.shortcuts import get_object_or_404
|
| 2 |
+
from rest_framework import status
|
| 3 |
+
from rest_framework.decorators import api_view, permission_classes
|
| 4 |
+
from django.views.decorators.csrf import csrf_exempt
|
| 5 |
+
from rest_framework.response import Response
|
| 6 |
+
from rest_framework.permissions import IsAuthenticated, AllowAny
|
| 7 |
+
from django.views.decorators.clickjacking import xframe_options_exempt
|
| 8 |
+
from rest_framework_simplejwt.tokens import AccessToken
|
| 9 |
+
from rest_framework_simplejwt.exceptions import TokenError
|
| 10 |
+
from rest_framework_simplejwt.authentication import JWTAuthentication
|
| 11 |
+
from rest_framework.exceptions import AuthenticationFailed
|
| 12 |
+
from django.contrib.auth import get_user_model
|
| 13 |
+
from auth_app.utils import IsAdmin
|
| 14 |
+
from auth_app.models import User
|
| 15 |
+
from .models import PaperWork
|
| 16 |
+
from .serializers import PaperWorkSerializer, PaperWorkDeadlineUpdateSerializer
|
| 17 |
+
from auth_app.serializers import UserRegistrationSerializer, UserSerializer
|
| 18 |
+
from api.models import Version
|
| 19 |
+
from django.conf import settings
|
| 20 |
+
import os
|
| 21 |
+
import zipfile
|
| 22 |
+
import base64
|
| 23 |
+
from django.http import FileResponse, Http404, JsonResponse, HttpResponseNotFound
|
| 24 |
+
|
| 25 |
+
def _auth_from_query_token(request):
|
| 26 |
+
token = getattr(request, "query_params", {}).get("token") or request.GET.get("token")
|
| 27 |
+
if not token:
|
| 28 |
+
return None
|
| 29 |
+
try:
|
| 30 |
+
decoded = AccessToken(token)
|
| 31 |
+
user_id = decoded.get("user_id")
|
| 32 |
+
if not user_id:
|
| 33 |
+
return None
|
| 34 |
+
User = get_user_model()
|
| 35 |
+
user = User.objects.get(id=user_id)
|
| 36 |
+
request.user = user
|
| 37 |
+
return user
|
| 38 |
+
except TokenError as e:
|
| 39 |
+
print(f"Token authentication error: {e}")
|
| 40 |
+
return None
|
| 41 |
+
except get_user_model().DoesNotExist:
|
| 42 |
+
return None
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"Unexpected token parse error: {e}")
|
| 45 |
+
return None
|
| 46 |
+
|
| 47 |
+
@api_view(['POST'])
|
| 48 |
+
@permission_classes([IsAuthenticated, IsAdmin])
|
| 49 |
+
@csrf_exempt
|
| 50 |
+
def create_user(request):
|
| 51 |
+
|
| 52 |
+
serializer = UserRegistrationSerializer(data=request.data)
|
| 53 |
+
if serializer.is_valid():
|
| 54 |
+
user = serializer.save()
|
| 55 |
+
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
| 56 |
+
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
| 57 |
+
|
| 58 |
+
@api_view(['PATCH'])
|
| 59 |
+
@permission_classes([IsAuthenticated, IsAdmin])
|
| 60 |
+
@csrf_exempt
|
| 61 |
+
def update_paperwork_deadline(request, id):
|
| 62 |
+
|
| 63 |
+
paperwork = get_object_or_404(PaperWork, id=id)
|
| 64 |
+
|
| 65 |
+
serializer = PaperWorkDeadlineUpdateSerializer(paperwork, data=request.data, partial=True)
|
| 66 |
+
if serializer.is_valid():
|
| 67 |
+
serializer.save()
|
| 68 |
+
return Response(PaperWorkSerializer(paperwork).data)
|
| 69 |
+
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
| 70 |
+
|
| 71 |
+
@api_view(['PATCH'])
|
| 72 |
+
@permission_classes([IsAuthenticated, IsAdmin])
|
| 73 |
+
@csrf_exempt
|
| 74 |
+
def update_user_status(request, username):
|
| 75 |
+
|
| 76 |
+
user = get_object_or_404(User, username=username)
|
| 77 |
+
|
| 78 |
+
if 'status' not in request.data:
|
| 79 |
+
return Response({'error': 'Status field is required'}, status=status.HTTP_400_BAD_REQUEST)
|
| 80 |
+
|
| 81 |
+
status_value = request.data['status']
|
| 82 |
+
if status_value not in dict(User.STATUS_CHOICES):
|
| 83 |
+
return Response({'error': 'Invalid status value'}, status=status.HTTP_400_BAD_REQUEST)
|
| 84 |
+
|
| 85 |
+
user.status = status_value
|
| 86 |
+
user.save()
|
| 87 |
+
|
| 88 |
+
return Response(UserSerializer(user).data)
|
| 89 |
+
|
| 90 |
+
@api_view(['POST'])
|
| 91 |
+
@permission_classes([IsAuthenticated, IsAdmin])
|
| 92 |
+
@csrf_exempt
|
| 93 |
+
def assign_paperwork(request):
|
| 94 |
+
|
| 95 |
+
serializer = PaperWorkSerializer(data=request.data)
|
| 96 |
+
if serializer.is_valid():
|
| 97 |
+
# Get the researcher
|
| 98 |
+
researcher_id = serializer.validated_data.pop('researcher_id')
|
| 99 |
+
researcher = get_object_or_404(User, id=researcher_id, role='RESEARCHER')
|
| 100 |
+
|
| 101 |
+
# Create the paperwork
|
| 102 |
+
paperwork = serializer.save(researcher=researcher)
|
| 103 |
+
|
| 104 |
+
return Response(PaperWorkSerializer(paperwork).data, status=status.HTTP_201_CREATED)
|
| 105 |
+
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
| 106 |
+
|
| 107 |
+
@api_view(['GET'])
|
| 108 |
+
@permission_classes([IsAuthenticated, IsAdmin])
|
| 109 |
+
def users_list(request):
|
| 110 |
+
"""Endpoint to list all users except admins in the system. Only accessible to admins."""
|
| 111 |
+
users = User.objects.exclude(role='ADMIN')
|
| 112 |
+
serializer = UserSerializer(users, many=True)
|
| 113 |
+
return Response(serializer.data)
|
| 114 |
+
|
| 115 |
+
@api_view(['GET'])
|
| 116 |
+
@permission_classes([AllowAny]) # was IsAuthenticated
|
| 117 |
+
@xframe_options_exempt # allow rendering in <iframe>
|
| 118 |
+
def view_paperwork_file(request, paperwork_id, version_no, file_type):
|
| 119 |
+
# 1) Try auth from ?token=...
|
| 120 |
+
_auth_from_query_token(request)
|
| 121 |
+
|
| 122 |
+
# 2) If still unauthenticated, reject (works for either header or query-token)
|
| 123 |
+
if not request.user or not request.user.is_authenticated:
|
| 124 |
+
return Response({'detail': 'Authentication credentials were not provided.'},
|
| 125 |
+
status=status.HTTP_401_UNAUTHORIZED)
|
| 126 |
+
|
| 127 |
+
# Existing lookup
|
| 128 |
+
try:
|
| 129 |
+
version = Version.objects.get(
|
| 130 |
+
paperwork__id=paperwork_id, version_no=version_no
|
| 131 |
+
)
|
| 132 |
+
except Version.DoesNotExist:
|
| 133 |
+
raise Http404("Version not found")
|
| 134 |
+
|
| 135 |
+
# 3) Object-level authorization: admin OR the assigned researcher
|
| 136 |
+
is_admin = getattr(request.user, 'role', '').upper() == 'ADMIN'
|
| 137 |
+
is_owner = getattr(version.paperwork, 'researcher_id', None) == getattr(request.user, 'id', None)
|
| 138 |
+
if not (is_admin or is_owner):
|
| 139 |
+
return Response({'detail': 'Forbidden'}, status=status.HTTP_403_FORBIDDEN)
|
| 140 |
+
|
| 141 |
+
# ... keep your existing file path logic below unchanged ...
|
| 142 |
+
file_path = None
|
| 143 |
+
storage_path = None
|
| 144 |
+
if file_type == 'pdf':
|
| 145 |
+
file_path = version.pdf_path
|
| 146 |
+
storage_path = settings.PDF_STORAGE_PATH
|
| 147 |
+
elif file_type == 'tex':
|
| 148 |
+
file_path = version.latex_path
|
| 149 |
+
storage_path = settings.LATEX_STORAGE_PATH
|
| 150 |
+
elif file_type == 'zip':
|
| 151 |
+
file_path = version.python_path
|
| 152 |
+
storage_path = settings.PYTHON_STORAGE_PATH
|
| 153 |
+
elif file_type == 'docx':
|
| 154 |
+
file_path = version.docx_path
|
| 155 |
+
storage_path = settings.DOCX_STORAGE_PATH
|
| 156 |
+
else:
|
| 157 |
+
return Response({'error': 'Invalid file type'}, status=status.HTTP_400_BAD_REQUEST)
|
| 158 |
+
|
| 159 |
+
if not file_path:
|
| 160 |
+
raise Http404(f"{file_type.capitalize()} file not found for this version")
|
| 161 |
+
|
| 162 |
+
filename = os.path.basename(file_path) if file_path else f"paper.{file_type}"
|
| 163 |
+
version_str = f"v{version_no}"
|
| 164 |
+
|
| 165 |
+
storage_full_path = os.path.join(
|
| 166 |
+
settings.MEDIA_ROOT, storage_path, str(paperwork_id), version_str, filename
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
if os.path.exists(storage_full_path):
|
| 170 |
+
response = FileResponse(open(storage_full_path, 'rb'))
|
| 171 |
+
disposition = 'attachment' if request.GET.get('download') else 'inline'
|
| 172 |
+
response['Content-Disposition'] = f'{disposition}; filename="{filename}"'
|
| 173 |
+
return response
|
| 174 |
+
|
| 175 |
+
direct_path = os.path.join(settings.MEDIA_ROOT, file_path)
|
| 176 |
+
if os.path.exists(direct_path):
|
| 177 |
+
response = FileResponse(open(direct_path, 'rb'))
|
| 178 |
+
disposition = 'attachment' if request.GET.get('download') else 'inline'
|
| 179 |
+
response['Content-Disposition'] = f'{disposition}; filename="{filename}"'
|
| 180 |
+
return response
|
| 181 |
+
|
| 182 |
+
print(f"Attempted paths:\n1. {storage_full_path}\n2. {direct_path}")
|
| 183 |
+
raise Http404("File not found on server")
|
| 184 |
+
|
| 185 |
+
@api_view(['GET'])
|
| 186 |
+
@permission_classes([IsAuthenticated, IsAdmin])
|
| 187 |
+
def user_detail(request, user_id):
|
| 188 |
+
"""Endpoint to get a specific user by ID. Only accessible to admins."""
|
| 189 |
+
from django.shortcuts import get_object_or_404
|
| 190 |
+
user = get_object_or_404(User, id=user_id)
|
| 191 |
+
serializer = UserSerializer(user)
|
| 192 |
+
return Response(serializer.data)
|
| 193 |
+
|
| 194 |
+
@api_view(['GET'])
|
| 195 |
+
@permission_classes([AllowAny]) # was [IsAuthenticated, IsAdmin]
|
| 196 |
+
@xframe_options_exempt # allow rendering in <iframe>
|
| 197 |
+
def view_zip_contents(request, paperwork_id, version_no):
|
| 198 |
+
# 1) Try auth from ?token=
|
| 199 |
+
_auth_from_query_token(request)
|
| 200 |
+
|
| 201 |
+
# 2) Require auth
|
| 202 |
+
if not request.user or not request.user.is_authenticated:
|
| 203 |
+
return Response({'detail': 'Authentication credentials were not provided.'},
|
| 204 |
+
status=status.HTTP_401_UNAUTHORIZED)
|
| 205 |
+
|
| 206 |
+
# 3) If you want admin-only, keep this:
|
| 207 |
+
# is_admin = getattr(request.user, 'role', '').upper() == 'ADMIN'
|
| 208 |
+
# if not is_admin:
|
| 209 |
+
# return Response({'detail': 'Forbidden'}, status=status.HTTP_403_FORBIDDEN)
|
| 210 |
+
|
| 211 |
+
# OR: allow the researcher who owns this paperwork to view too
|
| 212 |
+
try:
|
| 213 |
+
version = Version.objects.get(
|
| 214 |
+
paperwork__id=paperwork_id, version_no=version_no
|
| 215 |
+
)
|
| 216 |
+
except Version.DoesNotExist:
|
| 217 |
+
raise Http404("Version not found")
|
| 218 |
+
|
| 219 |
+
is_admin = getattr(request.user, 'role', '').upper() == 'ADMIN'
|
| 220 |
+
is_owner = getattr(version.paperwork, 'researcher_id', None) == getattr(request.user, 'id', None)
|
| 221 |
+
if not (is_admin or is_owner):
|
| 222 |
+
return Response({'detail': 'Forbidden'}, status=status.HTTP_403_FORBIDDEN)
|
| 223 |
+
|
| 224 |
+
version_str = f"v{version_no}"
|
| 225 |
+
zip_path = os.path.join(
|
| 226 |
+
settings.MEDIA_ROOT,
|
| 227 |
+
settings.PYTHON_STORAGE_PATH,
|
| 228 |
+
str(paperwork_id),
|
| 229 |
+
version_str,
|
| 230 |
+
"code.zip"
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
if not os.path.exists(zip_path):
|
| 234 |
+
raise Http404("ZIP file not found")
|
| 235 |
+
|
| 236 |
+
contents = []
|
| 237 |
+
with zipfile.ZipFile(zip_path, 'r') as z:
|
| 238 |
+
for name in z.namelist():
|
| 239 |
+
contents.append(name)
|
| 240 |
+
|
| 241 |
+
return JsonResponse({"files": contents})
|
| 242 |
+
|
| 243 |
+
@api_view(['GET'])
|
| 244 |
+
@permission_classes([AllowAny])
|
| 245 |
+
@xframe_options_exempt
|
| 246 |
+
def view_zip_file_content(request, paperwork_id, version_no, file_path):
|
| 247 |
+
# 1) Try auth from ?token=...
|
| 248 |
+
_auth_from_query_token(request)
|
| 249 |
+
|
| 250 |
+
# 2) If still unauthenticated, reject
|
| 251 |
+
if not request.user or not request.user.is_authenticated:
|
| 252 |
+
return Response({'detail': 'Authentication credentials were not provided.'},
|
| 253 |
+
status=status.HTTP_401_UNAUTHORIZED)
|
| 254 |
+
|
| 255 |
+
# Existing lookup
|
| 256 |
+
try:
|
| 257 |
+
version = Version.objects.get(
|
| 258 |
+
paperwork__id=paperwork_id, version_no=version_no
|
| 259 |
+
)
|
| 260 |
+
except Version.DoesNotExist:
|
| 261 |
+
raise Http404("Version not found")
|
| 262 |
+
|
| 263 |
+
# 3) Object-level authorization: admin OR the assigned researcher
|
| 264 |
+
is_admin = getattr(request.user, 'role', '').upper() == 'ADMIN'
|
| 265 |
+
is_owner = getattr(version.paperwork, 'researcher_id', None) == getattr(request.user, 'id', None)
|
| 266 |
+
if not (is_admin or is_owner):
|
| 267 |
+
return Response({'detail': 'Forbidden'}, status=status.HTTP_403_FORBIDDEN)
|
| 268 |
+
|
| 269 |
+
version_str = f"v{version_no}"
|
| 270 |
+
zip_path = os.path.join(
|
| 271 |
+
settings.MEDIA_ROOT,
|
| 272 |
+
settings.PYTHON_STORAGE_PATH,
|
| 273 |
+
str(paperwork_id),
|
| 274 |
+
version_str,
|
| 275 |
+
"code.zip"
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
if not os.path.exists(zip_path):
|
| 279 |
+
raise Http404("ZIP file not found")
|
| 280 |
+
|
| 281 |
+
try:
|
| 282 |
+
with zipfile.ZipFile(zip_path, 'r') as z:
|
| 283 |
+
# Check if the file exists in the ZIP
|
| 284 |
+
if file_path not in z.namelist():
|
| 285 |
+
return Response({'error': 'File not found in ZIP archive'}, status=status.HTTP_404_NOT_FOUND)
|
| 286 |
+
|
| 287 |
+
# Determine content type based on file extension
|
| 288 |
+
file_extension = file_path.split('.')[-1].lower() if '.' in file_path else ''
|
| 289 |
+
content_type = 'text/plain'
|
| 290 |
+
is_binary = False
|
| 291 |
+
|
| 292 |
+
# Text-based files
|
| 293 |
+
if file_extension in ['py']:
|
| 294 |
+
content_type = 'text/x-python'
|
| 295 |
+
elif file_extension in ['ipynb']:
|
| 296 |
+
content_type = 'application/json'
|
| 297 |
+
# Image files
|
| 298 |
+
elif file_extension in ['png']:
|
| 299 |
+
content_type = 'image/png'
|
| 300 |
+
is_binary = True
|
| 301 |
+
elif file_extension in ['jpg', 'jpeg']:
|
| 302 |
+
content_type = 'image/jpeg'
|
| 303 |
+
is_binary = True
|
| 304 |
+
|
| 305 |
+
# Handle binary files (images)
|
| 306 |
+
if is_binary:
|
| 307 |
+
file_content = base64.b64encode(z.read(file_path)).decode('utf-8')
|
| 308 |
+
return Response({
|
| 309 |
+
'content': file_content,
|
| 310 |
+
'content_type': content_type,
|
| 311 |
+
'is_binary': True
|
| 312 |
+
})
|
| 313 |
+
else:
|
| 314 |
+
# Handle text files
|
| 315 |
+
file_content = z.read(file_path).decode('utf-8', errors='replace')
|
| 316 |
+
return Response({
|
| 317 |
+
'content': file_content,
|
| 318 |
+
'content_type': content_type,
|
| 319 |
+
'is_binary': False
|
| 320 |
+
})
|
| 321 |
+
except Exception as e:
|
| 322 |
+
return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
| 323 |
+
|
| 324 |
+
def download_paperwork_file(request, pk, version_no, file_type):
|
| 325 |
+
# Try token auth first
|
| 326 |
+
token = request.GET.get("token")
|
| 327 |
+
if token:
|
| 328 |
+
jwt_auth = JWTAuthentication()
|
| 329 |
+
try:
|
| 330 |
+
validated_token = jwt_auth.get_validated_token(token)
|
| 331 |
+
user = jwt_auth.get_user(validated_token)
|
| 332 |
+
request.user = user
|
| 333 |
+
except Exception:
|
| 334 |
+
raise AuthenticationFailed("Invalid token")
|
| 335 |
+
|
| 336 |
+
if not request.user or not request.user.is_authenticated:
|
| 337 |
+
return Response({"detail": "Authentication credentials were not provided."}, status=401)
|
| 338 |
+
|
| 339 |
+
paperwork = get_object_or_404(PaperWork, pk=pk)
|
| 340 |
+
version = get_object_or_404(paperwork.versions, version_no=version_no)
|
| 341 |
+
# Map file_type string to the correct model field
|
| 342 |
+
path_map = {
|
| 343 |
+
"pdf": getattr(version, "pdf_path", None),
|
| 344 |
+
"docx": getattr(version, "docx_path", None),
|
| 345 |
+
"tex": getattr(version, "latex_path", None),
|
| 346 |
+
"python": getattr(version, "python_path", None),
|
| 347 |
+
"zip": getattr(version, "zip_path", None),
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
rel_path = path_map.get(file_type)
|
| 351 |
+
if not rel_path:
|
| 352 |
+
return HttpResponseNotFound(f"Unsupported file type: {file_type}")
|
| 353 |
+
|
| 354 |
+
# Build absolute path
|
| 355 |
+
file_path = os.path.join(settings.MEDIA_ROOT, rel_path)
|
| 356 |
+
|
| 357 |
+
if not os.path.exists(file_path):
|
| 358 |
+
return HttpResponseNotFound("File not found on disk")
|
| 359 |
+
|
| 360 |
+
response = FileResponse(open(file_path, "rb"), content_type="application/octet-stream")
|
| 361 |
+
response["Content-Disposition"] = f"attachment; filename={os.path.basename(file_path)}"
|
| 362 |
+
return response
|
api/__init__.py
ADDED
|
File without changes
|
api/admin.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib import admin
|
| 2 |
+
|
| 3 |
+
# Register your models here.
|
api/apps.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.apps import AppConfig
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class ApiConfig(AppConfig):
|
| 5 |
+
default_auto_field = "django.db.models.BigAutoField"
|
| 6 |
+
name = "api"
|
api/migrations/__init__.py
ADDED
|
File without changes
|
api/models.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import models
|
| 2 |
+
import uuid
|
| 3 |
+
from admin_app.models import PaperWork
|
| 4 |
+
|
| 5 |
+
class Review(models.Model):
|
| 6 |
+
STATUS_CHOICES = (
|
| 7 |
+
('ASSIGNED', 'Assigned'),
|
| 8 |
+
('SUBMITTED', 'Submitted'),
|
| 9 |
+
('CHANGES_REQUESTED', 'Changes Requested'),
|
| 10 |
+
('APPROVED', 'Approved'),
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
| 14 |
+
paperwork = models.ForeignKey(PaperWork, on_delete=models.CASCADE, related_name='reviews')
|
| 15 |
+
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='ASSIGNED')
|
| 16 |
+
comments = models.TextField(blank=True, null=True)
|
| 17 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
| 18 |
+
updated_at = models.DateTimeField(auto_now=True)
|
| 19 |
+
|
| 20 |
+
class Meta:
|
| 21 |
+
verbose_name = 'Review'
|
| 22 |
+
verbose_name_plural = 'Reviews'
|
| 23 |
+
ordering = ['-created_at']
|
| 24 |
+
|
| 25 |
+
class Version(models.Model):
|
| 26 |
+
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
| 27 |
+
paperwork = models.ForeignKey(PaperWork, on_delete=models.CASCADE, related_name='versions')
|
| 28 |
+
version_no = models.PositiveIntegerField()
|
| 29 |
+
submitted_at = models.DateTimeField(auto_now_add=True)
|
| 30 |
+
pdf_path = models.CharField(max_length=255, blank=True, null=True)
|
| 31 |
+
latex_path = models.CharField(max_length=255, blank=True, null=True)
|
| 32 |
+
python_path = models.CharField(max_length=255, blank=True, null=True)
|
| 33 |
+
docx_path = models.CharField(max_length=255, blank=True, null=True)
|
| 34 |
+
ai_percent_self = models.FloatField(default=0.0)
|
| 35 |
+
ai_percent_verified = models.FloatField(default=0.0, null=True, blank=True)
|
| 36 |
+
|
| 37 |
+
class Meta:
|
| 38 |
+
verbose_name = 'Version'
|
| 39 |
+
verbose_name_plural = 'Versions'
|
| 40 |
+
ordering = ['-version_no']
|
| 41 |
+
|
| 42 |
+
class Notification(models.Model):
|
| 43 |
+
EVENT_CHOICES = (
|
| 44 |
+
('WORK_ASSIGNED', 'Work Assigned'),
|
| 45 |
+
('SUBMITTED', 'Submitted'),
|
| 46 |
+
('CHANGES_REQUESTED', 'Changes Requested'),
|
| 47 |
+
('APPROVED', 'Approved'),
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
| 51 |
+
event = models.CharField(max_length=20, choices=EVENT_CHOICES)
|
| 52 |
+
paper = models.ForeignKey(PaperWork, on_delete=models.CASCADE, related_name='notifications')
|
| 53 |
+
at = models.DateTimeField(auto_now_add=True)
|
| 54 |
+
|
| 55 |
+
class Meta:
|
| 56 |
+
verbose_name = 'Notification'
|
| 57 |
+
verbose_name_plural = 'Notifications'
|
| 58 |
+
ordering = ['-at']
|
api/serializers.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rest_framework import serializers
|
| 2 |
+
from .models import Version, Notification, Review
|
| 3 |
+
from admin_app.models import PaperWork
|
| 4 |
+
from admin_app.serializers import PaperWorkSerializer
|
| 5 |
+
|
| 6 |
+
class VersionSerializer(serializers.ModelSerializer):
|
| 7 |
+
paperwork = PaperWorkSerializer(read_only=True)
|
| 8 |
+
|
| 9 |
+
class Meta:
|
| 10 |
+
model = Version
|
| 11 |
+
fields = ['id', 'paperwork', 'version_no', 'submitted_at', 'pdf_path',
|
| 12 |
+
'latex_path', 'python_path', 'docx_path', 'ai_percent_self', 'ai_percent_verified']
|
| 13 |
+
read_only_fields = ['id', 'submitted_at']
|
| 14 |
+
|
| 15 |
+
class VersionCreateSerializer(serializers.ModelSerializer):
|
| 16 |
+
paperwork_id = serializers.UUIDField(write_only=True, required=False)
|
| 17 |
+
paper_pdf = serializers.FileField(required=True)
|
| 18 |
+
latex_tex = serializers.FileField(required=True)
|
| 19 |
+
python_zip = serializers.FileField(required=True)
|
| 20 |
+
docx_file = serializers.FileField(required=False)
|
| 21 |
+
|
| 22 |
+
class Meta:
|
| 23 |
+
model = Version
|
| 24 |
+
fields = ['paperwork_id', 'version_no', 'paper_pdf', 'latex_tex', 'python_zip', 'docx_file',
|
| 25 |
+
'ai_percent_self', 'ai_percent_verified']
|
| 26 |
+
read_only_fields = ['pdf_path', 'latex_path', 'python_path', 'docx_path']
|
| 27 |
+
|
| 28 |
+
def create(self, validated_data):
|
| 29 |
+
# File fields will be handled in the view
|
| 30 |
+
paper_pdf = validated_data.pop('paper_pdf', None)
|
| 31 |
+
latex_tex = validated_data.pop('latex_tex', None)
|
| 32 |
+
python_zip = validated_data.pop('python_zip', None)
|
| 33 |
+
docx_file = validated_data.pop('docx_file', None)
|
| 34 |
+
|
| 35 |
+
# Create version instance without file paths
|
| 36 |
+
version = Version.objects.create(**validated_data)
|
| 37 |
+
|
| 38 |
+
return version
|
| 39 |
+
|
| 40 |
+
class NotificationSerializer(serializers.ModelSerializer):
|
| 41 |
+
paper = PaperWorkSerializer(read_only=True)
|
| 42 |
+
|
| 43 |
+
class Meta:
|
| 44 |
+
model = Notification
|
| 45 |
+
fields = ['id', 'event', 'paper', 'at']
|
| 46 |
+
read_only_fields = ['id', 'at']
|
| 47 |
+
|
| 48 |
+
class ReviewModelSerializer(serializers.ModelSerializer):
|
| 49 |
+
class Meta:
|
| 50 |
+
model = Review
|
| 51 |
+
fields = ['id', 'paperwork', 'status', 'comments', 'created_at', 'updated_at']
|
| 52 |
+
read_only_fields = ['id', 'created_at', 'updated_at']
|
| 53 |
+
|
| 54 |
+
class ReviewSerializer(serializers.Serializer):
|
| 55 |
+
status = serializers.ChoiceField(choices=[
|
| 56 |
+
('ASSIGNED', 'Assigned'),
|
| 57 |
+
('SUBMITTED', 'Submitted'),
|
| 58 |
+
('CHANGES_REQUESTED', 'Changes Requested'),
|
| 59 |
+
('APPROVED', 'Approved'),
|
| 60 |
+
])
|
| 61 |
+
comments = serializers.CharField(required=False, allow_blank=True)
|
| 62 |
+
|
| 63 |
+
class ReportSummarySerializer(serializers.Serializer):
|
| 64 |
+
total_papers = serializers.IntegerField()
|
| 65 |
+
papers_by_status = serializers.DictField(child=serializers.IntegerField())
|
| 66 |
+
papers_by_researcher = serializers.DictField(child=serializers.IntegerField())
|
| 67 |
+
average_ai_percentage = serializers.FloatField()
|
| 68 |
+
|
| 69 |
+
class ResearcherStatsSerializer(serializers.Serializer):
|
| 70 |
+
total_paperwork = serializers.IntegerField()
|
| 71 |
+
pending_review = serializers.IntegerField()
|
| 72 |
+
approved = serializers.IntegerField()
|
| 73 |
+
changes_requested = serializers.IntegerField()
|
| 74 |
+
|
| 75 |
+
class AdminStatsSerializer(serializers.Serializer):
|
| 76 |
+
total_paperwork = serializers.IntegerField()
|
| 77 |
+
submitted = serializers.IntegerField()
|
| 78 |
+
approved = serializers.IntegerField()
|
| 79 |
+
changes_requested = serializers.IntegerField()
|
api/urls.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.urls import path
|
| 2 |
+
from . import views
|
| 3 |
+
|
| 4 |
+
urlpatterns = [
|
| 5 |
+
path('paperworks/', views.paperworks_list, name='paperworks_list'),
|
| 6 |
+
path('paperworks/<uuid:id>/', views.paperwork_detail, name='paperwork_detail'),
|
| 7 |
+
path('paperworks/<uuid:id>/versions/', views.versions_list, name='versions_list'),
|
| 8 |
+
path('paperworks/<uuid:id>/versions/<int:ver>/', views.version_detail, name='version_detail'),
|
| 9 |
+
path('paperworks/<uuid:id>/review/', views.review_paperwork, name='review_paperwork'),
|
| 10 |
+
path('paperworks/<uuid:id>/reviews/', views.paperwork_reviews, name='paperwork_reviews'),
|
| 11 |
+
path('paperworks/<uuid:id>/delete/', views.delete_paperwork, name='delete_paperwork'),
|
| 12 |
+
path('reports/summary/', views.reports_summary, name='reports_summary'),
|
| 13 |
+
path('reports/export.csv/', views.reports_export, name='reports_export'),
|
| 14 |
+
path('notifications/', views.notifications_list, name='notifications_list'),
|
| 15 |
+
path('stats/researcher/', views.researcher_stats, name='researcher_stats'),
|
| 16 |
+
path('stats/admin/', views.admin_stats, name='admin_stats'),
|
| 17 |
+
]
|
api/views.py
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.shortcuts import render, get_object_or_404
|
| 2 |
+
from rest_framework import status
|
| 3 |
+
from rest_framework.decorators import api_view, permission_classes
|
| 4 |
+
from django.views.decorators.csrf import csrf_exempt
|
| 5 |
+
from rest_framework.response import Response
|
| 6 |
+
from rest_framework.permissions import IsAuthenticated
|
| 7 |
+
from auth_app.utils import IsAdmin, IsNotFrozen
|
| 8 |
+
from django.db.models import Count, Avg
|
| 9 |
+
from django.http import HttpResponse
|
| 10 |
+
from django.conf import settings
|
| 11 |
+
import csv
|
| 12 |
+
import os
|
| 13 |
+
|
| 14 |
+
from auth_app.models import User
|
| 15 |
+
from admin_app.models import PaperWork
|
| 16 |
+
from .models import Version, Notification, Review
|
| 17 |
+
from .serializers import (
|
| 18 |
+
VersionSerializer, VersionCreateSerializer, NotificationSerializer,
|
| 19 |
+
ReviewSerializer, ReportSummarySerializer, ResearcherStatsSerializer,
|
| 20 |
+
AdminStatsSerializer, ReviewModelSerializer
|
| 21 |
+
)
|
| 22 |
+
from admin_app.serializers import PaperWorkSerializer
|
| 23 |
+
|
| 24 |
+
@api_view(['GET'])
|
| 25 |
+
@permission_classes([IsAuthenticated, IsNotFrozen])
|
| 26 |
+
def paperworks_list(request):
|
| 27 |
+
# Researchers can only see their own paperworks
|
| 28 |
+
if request.user.role == 'RESEARCHER':
|
| 29 |
+
paperworks = PaperWork.objects.filter(researcher=request.user)
|
| 30 |
+
else:
|
| 31 |
+
paperworks = PaperWork.objects.all()
|
| 32 |
+
|
| 33 |
+
serializer = PaperWorkSerializer(paperworks, many=True)
|
| 34 |
+
return Response(serializer.data)
|
| 35 |
+
|
| 36 |
+
@api_view(['GET'])
|
| 37 |
+
@permission_classes([IsAuthenticated, IsNotFrozen])
|
| 38 |
+
def paperwork_detail(request, id):
|
| 39 |
+
paperwork = get_object_or_404(PaperWork, id=id)
|
| 40 |
+
|
| 41 |
+
# Researchers can only see their own paperworks
|
| 42 |
+
if request.user.role == 'RESEARCHER' and paperwork.researcher != request.user:
|
| 43 |
+
return Response({'error': 'Permission denied'}, status=status.HTTP_403_FORBIDDEN)
|
| 44 |
+
|
| 45 |
+
serializer = PaperWorkSerializer(paperwork)
|
| 46 |
+
return Response(serializer.data)
|
| 47 |
+
|
| 48 |
+
@api_view(['GET', 'POST'])
|
| 49 |
+
@permission_classes([IsAuthenticated, IsNotFrozen])
|
| 50 |
+
@csrf_exempt
|
| 51 |
+
def versions_list(request, id):
|
| 52 |
+
paperwork = get_object_or_404(PaperWork, id=id)
|
| 53 |
+
|
| 54 |
+
# Researchers can only access their own paperworks
|
| 55 |
+
if request.user.role == 'RESEARCHER' and paperwork.researcher != request.user:
|
| 56 |
+
return Response({'error': 'Permission denied'}, status=status.HTTP_403_FORBIDDEN)
|
| 57 |
+
|
| 58 |
+
if request.method == 'GET':
|
| 59 |
+
versions = Version.objects.filter(paperwork=paperwork)
|
| 60 |
+
serializer = VersionSerializer(versions, many=True)
|
| 61 |
+
return Response(serializer.data)
|
| 62 |
+
|
| 63 |
+
elif request.method == 'POST':
|
| 64 |
+
# Only researchers can submit versions
|
| 65 |
+
if request.user.role != 'RESEARCHER' or paperwork.researcher != request.user:
|
| 66 |
+
return Response({'error': 'Permission denied'}, status=status.HTTP_403_FORBIDDEN)
|
| 67 |
+
|
| 68 |
+
# Get the latest version number for this paperwork
|
| 69 |
+
latest_version = Version.objects.filter(paperwork=paperwork).order_by('-version_no').first()
|
| 70 |
+
next_version_no = 1 if not latest_version else latest_version.version_no + 1
|
| 71 |
+
|
| 72 |
+
# Process the uploaded files
|
| 73 |
+
serializer = VersionCreateSerializer(data=request.data)
|
| 74 |
+
if serializer.is_valid():
|
| 75 |
+
# Handle file uploads
|
| 76 |
+
paper_pdf = request.FILES.get('paper_pdf')
|
| 77 |
+
latex_tex = request.FILES.get('latex_tex')
|
| 78 |
+
python_zip = request.FILES.get('python_zip')
|
| 79 |
+
docx_file = request.FILES.get('docx_file')
|
| 80 |
+
|
| 81 |
+
# Create file paths
|
| 82 |
+
paper_id = str(paperwork.id)
|
| 83 |
+
version_str = f"v{next_version_no}"
|
| 84 |
+
|
| 85 |
+
# Check if required files are provided
|
| 86 |
+
if not paper_pdf or not latex_tex or not python_zip:
|
| 87 |
+
return Response({'error': 'PDF, LaTeX, and Python ZIP files are required'}, status=status.HTTP_400_BAD_REQUEST)
|
| 88 |
+
|
| 89 |
+
# Save files to media storage
|
| 90 |
+
pdf_path = None
|
| 91 |
+
latex_path = None
|
| 92 |
+
python_path = None
|
| 93 |
+
docx_path = None
|
| 94 |
+
|
| 95 |
+
# Create directory structures if they don't exist
|
| 96 |
+
pdf_folder = os.path.join(settings.PDF_STORAGE_PATH, paper_id, version_str)
|
| 97 |
+
latex_folder = os.path.join(settings.LATEX_STORAGE_PATH, paper_id, version_str)
|
| 98 |
+
python_folder = os.path.join(settings.PYTHON_STORAGE_PATH, paper_id, version_str)
|
| 99 |
+
docx_folder = os.path.join(settings.DOCX_STORAGE_PATH, paper_id, version_str)
|
| 100 |
+
|
| 101 |
+
# Ensure all directories exist
|
| 102 |
+
for folder in [pdf_folder, latex_folder, python_folder, docx_folder]:
|
| 103 |
+
full_path = os.path.join(settings.MEDIA_ROOT, folder)
|
| 104 |
+
os.makedirs(full_path, exist_ok=True)
|
| 105 |
+
|
| 106 |
+
if paper_pdf:
|
| 107 |
+
pdf_path = f"{pdf_folder}/paper.pdf"
|
| 108 |
+
full_pdf_path = os.path.join(settings.MEDIA_ROOT, pdf_path)
|
| 109 |
+
with open(full_pdf_path, 'wb+') as destination:
|
| 110 |
+
for chunk in paper_pdf.chunks():
|
| 111 |
+
destination.write(chunk)
|
| 112 |
+
|
| 113 |
+
if latex_tex:
|
| 114 |
+
latex_path = f"{latex_folder}/latex.tex"
|
| 115 |
+
full_latex_path = os.path.join(settings.MEDIA_ROOT, latex_path)
|
| 116 |
+
with open(full_latex_path, 'wb+') as destination:
|
| 117 |
+
for chunk in latex_tex.chunks():
|
| 118 |
+
destination.write(chunk)
|
| 119 |
+
|
| 120 |
+
if python_zip:
|
| 121 |
+
python_path = f"{python_folder}/code.zip"
|
| 122 |
+
full_python_path = os.path.join(settings.MEDIA_ROOT, python_path)
|
| 123 |
+
with open(full_python_path, 'wb+') as destination:
|
| 124 |
+
for chunk in python_zip.chunks():
|
| 125 |
+
destination.write(chunk)
|
| 126 |
+
|
| 127 |
+
if docx_file:
|
| 128 |
+
docx_path = f"{docx_folder}/paper.docx"
|
| 129 |
+
full_docx_path = os.path.join(settings.MEDIA_ROOT, docx_path)
|
| 130 |
+
with open(full_docx_path, 'wb+') as destination:
|
| 131 |
+
for chunk in docx_file.chunks():
|
| 132 |
+
destination.write(chunk)
|
| 133 |
+
|
| 134 |
+
# Create version with file paths
|
| 135 |
+
version = Version.objects.create(
|
| 136 |
+
paperwork=paperwork,
|
| 137 |
+
version_no=next_version_no,
|
| 138 |
+
pdf_path=pdf_path,
|
| 139 |
+
latex_path=latex_path,
|
| 140 |
+
python_path=python_path,
|
| 141 |
+
docx_path=docx_path,
|
| 142 |
+
ai_percent_self=serializer.validated_data.get('ai_percent_self', 0.0)
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
# Update paperwork status
|
| 146 |
+
paperwork.status = 'SUBMITTED'
|
| 147 |
+
paperwork.save()
|
| 148 |
+
|
| 149 |
+
# Check if there are more than 5 versions and delete the oldest ones
|
| 150 |
+
versions = Version.objects.filter(paperwork=paperwork).order_by('-version_no')
|
| 151 |
+
if versions.count() > 5:
|
| 152 |
+
# Get versions to delete (all except the 5 most recent)
|
| 153 |
+
versions_to_delete = versions[5:]
|
| 154 |
+
|
| 155 |
+
for old_version in versions_to_delete:
|
| 156 |
+
# Delete files associated with this version
|
| 157 |
+
if old_version.pdf_path and os.path.exists(os.path.join(settings.MEDIA_ROOT, old_version.pdf_path)):
|
| 158 |
+
os.remove(os.path.join(settings.MEDIA_ROOT, old_version.pdf_path))
|
| 159 |
+
|
| 160 |
+
if old_version.latex_path and os.path.exists(os.path.join(settings.MEDIA_ROOT, old_version.latex_path)):
|
| 161 |
+
os.remove(os.path.join(settings.MEDIA_ROOT, old_version.latex_path))
|
| 162 |
+
|
| 163 |
+
if old_version.python_path and os.path.exists(os.path.join(settings.MEDIA_ROOT, old_version.python_path)):
|
| 164 |
+
os.remove(os.path.join(settings.MEDIA_ROOT, old_version.python_path))
|
| 165 |
+
|
| 166 |
+
if old_version.docx_path and os.path.exists(os.path.join(settings.MEDIA_ROOT, old_version.docx_path)):
|
| 167 |
+
os.remove(os.path.join(settings.MEDIA_ROOT, old_version.docx_path))
|
| 168 |
+
|
| 169 |
+
# Delete the version record
|
| 170 |
+
old_version.delete()
|
| 171 |
+
|
| 172 |
+
# Create notification for new version
|
| 173 |
+
Notification.objects.create(
|
| 174 |
+
event='SUBMITTED',
|
| 175 |
+
paper=paperwork
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
return Response(VersionSerializer(version).data, status=status.HTTP_201_CREATED)
|
| 179 |
+
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
| 180 |
+
|
| 181 |
+
@api_view(['GET'])
|
| 182 |
+
@permission_classes([IsAuthenticated, IsNotFrozen])
|
| 183 |
+
def version_detail(request, id, ver):
|
| 184 |
+
paperwork = get_object_or_404(PaperWork, id=id)
|
| 185 |
+
|
| 186 |
+
# Researchers can only access their own paperworks
|
| 187 |
+
if request.user.role == 'RESEARCHER' and paperwork.researcher != request.user:
|
| 188 |
+
return Response({'error': 'Permission denied'}, status=status.HTTP_403_FORBIDDEN)
|
| 189 |
+
|
| 190 |
+
version = get_object_or_404(Version, paperwork=paperwork, version_no=ver)
|
| 191 |
+
serializer = VersionSerializer(version)
|
| 192 |
+
|
| 193 |
+
# Add full URLs for file downloads
|
| 194 |
+
data = serializer.data
|
| 195 |
+
if version.pdf_path:
|
| 196 |
+
data['pdf_url'] = request.build_absolute_uri(settings.MEDIA_URL + version.pdf_path)
|
| 197 |
+
if version.latex_path:
|
| 198 |
+
data['latex_url'] = request.build_absolute_uri(settings.MEDIA_URL + version.latex_path)
|
| 199 |
+
if version.python_path:
|
| 200 |
+
data['python_url'] = request.build_absolute_uri(settings.MEDIA_URL + version.python_path)
|
| 201 |
+
|
| 202 |
+
return Response(data)
|
| 203 |
+
|
| 204 |
+
@api_view(['POST'])
|
| 205 |
+
@permission_classes([IsAuthenticated, IsAdmin, IsNotFrozen])
|
| 206 |
+
@csrf_exempt
|
| 207 |
+
def review_paperwork(request, id):
|
| 208 |
+
|
| 209 |
+
paperwork = get_object_or_404(PaperWork, id=id)
|
| 210 |
+
serializer = ReviewSerializer(data=request.data)
|
| 211 |
+
|
| 212 |
+
if serializer.is_valid():
|
| 213 |
+
# Update paperwork status
|
| 214 |
+
paperwork.status = serializer.validated_data['status']
|
| 215 |
+
paperwork.save()
|
| 216 |
+
|
| 217 |
+
# Create or update review
|
| 218 |
+
comments = serializer.validated_data.get('comments')
|
| 219 |
+
if comments:
|
| 220 |
+
Review.objects.create(
|
| 221 |
+
status=paperwork.status,
|
| 222 |
+
paperwork=paperwork,
|
| 223 |
+
comments=comments
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
# Create notification for review
|
| 227 |
+
Notification.objects.create(
|
| 228 |
+
event='CHANGES_REQUESTED' if paperwork.status == 'CHANGES_REQUESTED' else 'APPROVED',
|
| 229 |
+
paper=paperwork
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
return Response(PaperWorkSerializer(paperwork).data)
|
| 233 |
+
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
| 234 |
+
|
| 235 |
+
@api_view(['GET'])
|
| 236 |
+
@permission_classes([IsAuthenticated])
|
| 237 |
+
def paperwork_reviews(request, id):
|
| 238 |
+
paperwork = get_object_or_404(PaperWork, id=id)
|
| 239 |
+
|
| 240 |
+
# Check if user is admin or the researcher who owns the paperwork
|
| 241 |
+
if not (request.user.is_superuser or request.user == paperwork.researcher):
|
| 242 |
+
return Response({"detail": "You do not have permission to view these reviews."},
|
| 243 |
+
status=status.HTTP_403_FORBIDDEN)
|
| 244 |
+
|
| 245 |
+
reviews = Review.objects.filter(paperwork=paperwork).order_by('-created_at')
|
| 246 |
+
serializer = ReviewModelSerializer(reviews, many=True)
|
| 247 |
+
|
| 248 |
+
return Response(serializer.data)
|
| 249 |
+
|
| 250 |
+
@api_view(['GET'])
|
| 251 |
+
@permission_classes([IsAuthenticated, IsAdmin, IsNotFrozen])
|
| 252 |
+
def reports_summary(request):
|
| 253 |
+
|
| 254 |
+
# Get total papers count
|
| 255 |
+
total_papers = PaperWork.objects.count()
|
| 256 |
+
|
| 257 |
+
# Get papers by status
|
| 258 |
+
papers_by_status = PaperWork.objects.values('status').annotate(count=Count('id'))
|
| 259 |
+
status_dict = {item['status']: item['count'] for item in papers_by_status}
|
| 260 |
+
|
| 261 |
+
# Get papers by researcher
|
| 262 |
+
papers_by_researcher = PaperWork.objects.values('researcher__username').annotate(count=Count('id'))
|
| 263 |
+
researcher_dict = {item['researcher__username']: item['count'] for item in papers_by_researcher}
|
| 264 |
+
|
| 265 |
+
# Get average AI percentage
|
| 266 |
+
avg_ai_percent = Version.objects.aggregate(avg=Avg('ai_percent_verified'))['avg'] or 0
|
| 267 |
+
|
| 268 |
+
data = {
|
| 269 |
+
'total_papers': total_papers,
|
| 270 |
+
'papers_by_status': status_dict,
|
| 271 |
+
'papers_by_researcher': researcher_dict,
|
| 272 |
+
'average_ai_percentage': avg_ai_percent
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
serializer = ReportSummarySerializer(data)
|
| 276 |
+
return Response(serializer.data)
|
| 277 |
+
|
| 278 |
+
@api_view(['GET'])
|
| 279 |
+
@permission_classes([IsAuthenticated, IsAdmin, IsNotFrozen])
|
| 280 |
+
def reports_export(request):
|
| 281 |
+
|
| 282 |
+
# Create CSV response
|
| 283 |
+
response = HttpResponse(content_type='text/csv')
|
| 284 |
+
response['Content-Disposition'] = 'attachment; filename="papers_report.csv"'
|
| 285 |
+
|
| 286 |
+
writer = csv.writer(response)
|
| 287 |
+
writer.writerow(['ID', 'Title', 'Researcher', 'Status', 'Assigned At', 'Latest Version', 'AI Percentage'])
|
| 288 |
+
|
| 289 |
+
paperworks = PaperWork.objects.all()
|
| 290 |
+
for paper in paperworks:
|
| 291 |
+
# Get latest version if exists
|
| 292 |
+
latest_version = Version.objects.filter(paperwork=paper).order_by('-version_no').first()
|
| 293 |
+
version_no = latest_version.version_no if latest_version else 'N/A'
|
| 294 |
+
ai_percent = latest_version.ai_percent_verified if latest_version else 'N/A'
|
| 295 |
+
|
| 296 |
+
writer.writerow([
|
| 297 |
+
paper.id,
|
| 298 |
+
paper.title,
|
| 299 |
+
paper.researcher.username,
|
| 300 |
+
paper.status,
|
| 301 |
+
paper.assigned_at.strftime('%Y-%m-%d'),
|
| 302 |
+
version_no,
|
| 303 |
+
ai_percent
|
| 304 |
+
])
|
| 305 |
+
|
| 306 |
+
return response
|
| 307 |
+
|
| 308 |
+
@api_view(['GET'])
|
| 309 |
+
@permission_classes([IsAuthenticated, IsNotFrozen])
|
| 310 |
+
def notifications_list(request):
|
| 311 |
+
# Get notifications relevant to the user
|
| 312 |
+
if request.user.role == 'RESEARCHER':
|
| 313 |
+
# Researchers only see notifications for their papers
|
| 314 |
+
notifications = Notification.objects.filter(paper__researcher=request.user).order_by('-at')
|
| 315 |
+
else:
|
| 316 |
+
# Admins see all notifications
|
| 317 |
+
notifications = Notification.objects.all().order_by('-at')
|
| 318 |
+
|
| 319 |
+
serializer = NotificationSerializer(notifications, many=True)
|
| 320 |
+
return Response(serializer.data)
|
| 321 |
+
|
| 322 |
+
@api_view(['GET'])
|
| 323 |
+
@permission_classes([IsAuthenticated, IsNotFrozen])
|
| 324 |
+
def researcher_stats(request):
|
| 325 |
+
# Only researchers can access their own stats
|
| 326 |
+
if request.user.role != 'RESEARCHER':
|
| 327 |
+
return Response({'error': 'Permission denied'}, status=status.HTTP_403_FORBIDDEN)
|
| 328 |
+
|
| 329 |
+
# Get all paperworks for this researcher
|
| 330 |
+
paperworks = PaperWork.objects.filter(researcher=request.user)
|
| 331 |
+
|
| 332 |
+
# Calculate statistics
|
| 333 |
+
total_paperwork = paperworks.count()
|
| 334 |
+
pending_review = paperworks.filter(status='SUBMITTED').count()
|
| 335 |
+
approved = paperworks.filter(status='APPROVED').count()
|
| 336 |
+
changes_requested = paperworks.filter(status='CHANGES_REQUESTED').count()
|
| 337 |
+
|
| 338 |
+
data = {
|
| 339 |
+
'total_paperwork': total_paperwork,
|
| 340 |
+
'pending_review': pending_review,
|
| 341 |
+
'approved': approved,
|
| 342 |
+
'changes_requested': changes_requested
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
serializer = ResearcherStatsSerializer(data)
|
| 346 |
+
return Response(serializer.data)
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
@api_view(['DELETE'])
|
| 350 |
+
@permission_classes([IsAuthenticated, IsNotFrozen])
|
| 351 |
+
def delete_paperwork(request, id):
|
| 352 |
+
paperwork = get_object_or_404(PaperWork, id=id)
|
| 353 |
+
|
| 354 |
+
# Check permissions: Only admins or the researcher who owns the paperwork can delete it
|
| 355 |
+
if request.user.role != 'ADMIN' and (request.user.role == 'RESEARCHER' and paperwork.researcher != request.user):
|
| 356 |
+
return Response({'error': 'Permission denied'}, status=status.HTTP_403_FORBIDDEN)
|
| 357 |
+
|
| 358 |
+
# Get all versions to delete associated files
|
| 359 |
+
versions = Version.objects.filter(paperwork=paperwork)
|
| 360 |
+
|
| 361 |
+
# Delete all files associated with this paperwork
|
| 362 |
+
for version in versions:
|
| 363 |
+
# Delete PDF file if exists
|
| 364 |
+
if version.pdf_path and os.path.exists(os.path.join(settings.MEDIA_ROOT, version.pdf_path)):
|
| 365 |
+
os.remove(os.path.join(settings.MEDIA_ROOT, version.pdf_path))
|
| 366 |
+
|
| 367 |
+
# Delete LaTeX file if exists
|
| 368 |
+
if version.latex_path and os.path.exists(os.path.join(settings.MEDIA_ROOT, version.latex_path)):
|
| 369 |
+
os.remove(os.path.join(settings.MEDIA_ROOT, version.latex_path))
|
| 370 |
+
|
| 371 |
+
# Delete Python ZIP file if exists
|
| 372 |
+
if version.python_path and os.path.exists(os.path.join(settings.MEDIA_ROOT, version.python_path)):
|
| 373 |
+
os.remove(os.path.join(settings.MEDIA_ROOT, version.python_path))
|
| 374 |
+
|
| 375 |
+
# Delete DOCX file if exists
|
| 376 |
+
if version.docx_path and os.path.exists(os.path.join(settings.MEDIA_ROOT, version.docx_path)):
|
| 377 |
+
os.remove(os.path.join(settings.MEDIA_ROOT, version.docx_path))
|
| 378 |
+
|
| 379 |
+
# Delete the paperwork (this will cascade delete versions and notifications)
|
| 380 |
+
paperwork.delete()
|
| 381 |
+
|
| 382 |
+
return Response({'message': 'Research task deleted successfully'}, status=status.HTTP_204_NO_CONTENT)
|
| 383 |
+
|
| 384 |
+
@api_view(['GET'])
|
| 385 |
+
@permission_classes([IsAuthenticated, IsAdmin, IsNotFrozen])
|
| 386 |
+
def admin_stats(request):
|
| 387 |
+
# Only admins can access these stats
|
| 388 |
+
|
| 389 |
+
# Get all paperworks
|
| 390 |
+
paperworks = PaperWork.objects.all()
|
| 391 |
+
|
| 392 |
+
# Calculate statistics
|
| 393 |
+
total_paperwork = paperworks.count()
|
| 394 |
+
submitted = paperworks.filter(status='SUBMITTED').count()
|
| 395 |
+
approved = paperworks.filter(status='APPROVED').count()
|
| 396 |
+
changes_requested = paperworks.filter(status='CHANGES_REQUESTED').count()
|
| 397 |
+
|
| 398 |
+
data = {
|
| 399 |
+
'total_paperwork': total_paperwork,
|
| 400 |
+
'submitted': submitted,
|
| 401 |
+
'approved': approved,
|
| 402 |
+
'changes_requested': changes_requested
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
serializer = AdminStatsSerializer(data)
|
| 406 |
+
return Response(serializer.data)
|
api_admin_test.py
ADDED
|
@@ -0,0 +1,639 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import uuid
|
| 4 |
+
import sys
|
| 5 |
+
import os
|
| 6 |
+
import time
|
| 7 |
+
from getpass import getpass
|
| 8 |
+
from tabulate import tabulate
|
| 9 |
+
from colorama import init, Fore, Style
|
| 10 |
+
|
| 11 |
+
# Initialize colorama
|
| 12 |
+
init()
|
| 13 |
+
|
| 14 |
+
BASE_URL = 'http://localhost:8000/'
|
| 15 |
+
API_URL = f"{BASE_URL}api/"
|
| 16 |
+
ADMIN_URL = f"{BASE_URL}admin_app/"
|
| 17 |
+
AUTH_URL = f"{BASE_URL}auth/"
|
| 18 |
+
|
| 19 |
+
class AdminAPITester:
|
| 20 |
+
def __init__(self):
|
| 21 |
+
self.session = requests.Session()
|
| 22 |
+
self.token = None
|
| 23 |
+
self.headers = {}
|
| 24 |
+
self.user_role = None
|
| 25 |
+
self.username = None
|
| 26 |
+
self.last_response = None
|
| 27 |
+
self.researchers = []
|
| 28 |
+
self.paperworks = []
|
| 29 |
+
|
| 30 |
+
def login(self, username, password):
|
| 31 |
+
"""Login to get authentication token"""
|
| 32 |
+
try:
|
| 33 |
+
print(f"{Fore.CYAN}Attempting to login...{Style.RESET_ALL}")
|
| 34 |
+
response = self.session.post(
|
| 35 |
+
f"{AUTH_URL}login/",
|
| 36 |
+
data={'username': username, 'password': password},
|
| 37 |
+
timeout=10
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
self.last_response = response
|
| 41 |
+
|
| 42 |
+
if response.status_code == 200:
|
| 43 |
+
data = response.json()
|
| 44 |
+
self.token = data.get('token')
|
| 45 |
+
self.headers = {'Authorization': f'Token {self.token}'}
|
| 46 |
+
self.username = username
|
| 47 |
+
|
| 48 |
+
# Assume admin role for this tool after successful login
|
| 49 |
+
self.user_role = 'ADMIN'
|
| 50 |
+
role_display = f"{Fore.GREEN}{self.user_role}{Style.RESET_ALL}"
|
| 51 |
+
print(f"{Fore.GREEN}✅ Logged in as {Fore.YELLOW}{username}{Fore.GREEN} (Role: {role_display}){Style.RESET_ALL}")
|
| 52 |
+
return True
|
| 53 |
+
else:
|
| 54 |
+
print(f"{Fore.RED}❌ Login failed: {response.text}{Style.RESET_ALL}")
|
| 55 |
+
return False
|
| 56 |
+
except requests.exceptions.ConnectionError:
|
| 57 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server. Is the server running?{Style.RESET_ALL}")
|
| 58 |
+
return False
|
| 59 |
+
except requests.exceptions.Timeout:
|
| 60 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 61 |
+
return False
|
| 62 |
+
except Exception as e:
|
| 63 |
+
print(f"{Fore.RED}❌ Error during login: {str(e)}{Style.RESET_ALL}")
|
| 64 |
+
return False
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def create_user(self, username, email, password, role="RESEARCHER", status="ACTIVE"):
|
| 69 |
+
"""Create a new user (Admin only)"""
|
| 70 |
+
try:
|
| 71 |
+
print(f"{Fore.CYAN}Creating new user: {username}...{Style.RESET_ALL}")
|
| 72 |
+
|
| 73 |
+
data = {
|
| 74 |
+
"username": username,
|
| 75 |
+
"email": email,
|
| 76 |
+
"password": password,
|
| 77 |
+
"role": role,
|
| 78 |
+
"status": status
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
response = requests.post(
|
| 82 |
+
f"{AUTH_URL}register/",
|
| 83 |
+
json=data,
|
| 84 |
+
headers=self.headers,
|
| 85 |
+
timeout=10
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
self.last_response = response
|
| 89 |
+
|
| 90 |
+
if response.status_code in [200, 201]:
|
| 91 |
+
user_data = response.json()
|
| 92 |
+
print(f"{Fore.GREEN}✅ User created successfully: {Fore.YELLOW}{username}{Style.RESET_ALL}")
|
| 93 |
+
|
| 94 |
+
# If it's a researcher, add to our list
|
| 95 |
+
if role == "RESEARCHER":
|
| 96 |
+
self.researchers.append(user_data)
|
| 97 |
+
|
| 98 |
+
return user_data
|
| 99 |
+
else:
|
| 100 |
+
print(f"{Fore.RED}❌ Failed to create user: {response.text}{Style.RESET_ALL}")
|
| 101 |
+
return None
|
| 102 |
+
except requests.exceptions.ConnectionError:
|
| 103 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 104 |
+
return None
|
| 105 |
+
except requests.exceptions.Timeout:
|
| 106 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 107 |
+
return None
|
| 108 |
+
except Exception as e:
|
| 109 |
+
print(f"{Fore.RED}❌ Error creating user: {str(e)}{Style.RESET_ALL}")
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
def update_user_status(self, username, new_status):
|
| 113 |
+
"""Update a user's status (Admin only)"""
|
| 114 |
+
try:
|
| 115 |
+
print(f"{Fore.CYAN}Updating status for user {username} to {new_status}...{Style.RESET_ALL}")
|
| 116 |
+
|
| 117 |
+
data = {"status": new_status}
|
| 118 |
+
|
| 119 |
+
response = requests.patch(
|
| 120 |
+
f"{ADMIN_URL}users/{username}/status/",
|
| 121 |
+
json=data,
|
| 122 |
+
headers=self.headers,
|
| 123 |
+
timeout=10
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
self.last_response = response
|
| 127 |
+
|
| 128 |
+
if response.status_code == 200:
|
| 129 |
+
user_data = response.json()
|
| 130 |
+
print(f"{Fore.GREEN}✅ User status updated successfully: {Fore.YELLOW}{username}{Fore.GREEN} → {Fore.YELLOW}{new_status}{Style.RESET_ALL}")
|
| 131 |
+
return user_data
|
| 132 |
+
else:
|
| 133 |
+
print(f"{Fore.RED}❌ Failed to update user status: {response.text}{Style.RESET_ALL}")
|
| 134 |
+
return None
|
| 135 |
+
except requests.exceptions.ConnectionError:
|
| 136 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 137 |
+
return None
|
| 138 |
+
except requests.exceptions.Timeout:
|
| 139 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 140 |
+
return None
|
| 141 |
+
except Exception as e:
|
| 142 |
+
print(f"{Fore.RED}❌ Error updating user status: {str(e)}{Style.RESET_ALL}")
|
| 143 |
+
return None
|
| 144 |
+
|
| 145 |
+
def list_users(self):
|
| 146 |
+
"""List all users (Admin only)"""
|
| 147 |
+
try:
|
| 148 |
+
print(f"{Fore.CYAN}Fetching users...{Style.RESET_ALL}")
|
| 149 |
+
|
| 150 |
+
response = requests.get(
|
| 151 |
+
f"{AUTH_URL}users/",
|
| 152 |
+
headers=self.headers,
|
| 153 |
+
timeout=10
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
self.last_response = response
|
| 157 |
+
|
| 158 |
+
if response.status_code == 200:
|
| 159 |
+
users = response.json()
|
| 160 |
+
print(f"{Fore.GREEN}✅ Retrieved {len(users)} users{Style.RESET_ALL}")
|
| 161 |
+
|
| 162 |
+
# Store researchers for later use
|
| 163 |
+
self.researchers = [u for u in users if u.get('role') == 'RESEARCHER']
|
| 164 |
+
|
| 165 |
+
# Display users in a table
|
| 166 |
+
table_data = []
|
| 167 |
+
for user in users:
|
| 168 |
+
table_data.append([
|
| 169 |
+
user.get('id', 'N/A'),
|
| 170 |
+
user.get('username', 'N/A'),
|
| 171 |
+
user.get('email', 'N/A'),
|
| 172 |
+
user.get('role', 'N/A'),
|
| 173 |
+
user.get('status', 'N/A')
|
| 174 |
+
])
|
| 175 |
+
|
| 176 |
+
headers = ["ID", "Username", "Email", "Role", "Status"]
|
| 177 |
+
print(tabulate(table_data, headers=headers, tablefmt="grid"))
|
| 178 |
+
|
| 179 |
+
return users
|
| 180 |
+
else:
|
| 181 |
+
print(f"{Fore.RED}❌ Failed to get users: {response.text}{Style.RESET_ALL}")
|
| 182 |
+
return None
|
| 183 |
+
except requests.exceptions.ConnectionError:
|
| 184 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 185 |
+
return None
|
| 186 |
+
except requests.exceptions.Timeout:
|
| 187 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 188 |
+
return None
|
| 189 |
+
except Exception as e:
|
| 190 |
+
print(f"{Fore.RED}❌ Error retrieving users: {str(e)}{Style.RESET_ALL}")
|
| 191 |
+
return None
|
| 192 |
+
|
| 193 |
+
def assign_paperwork(self, title, researcher_id, deadline=None):
|
| 194 |
+
"""Assign a new paperwork to a researcher (Admin only)"""
|
| 195 |
+
try:
|
| 196 |
+
print(f"{Fore.CYAN}Assigning new paperwork: {title}...{Style.RESET_ALL}")
|
| 197 |
+
|
| 198 |
+
data = {
|
| 199 |
+
"title": title,
|
| 200 |
+
"researcher_id": researcher_id
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
if deadline:
|
| 204 |
+
data["deadline"] = deadline
|
| 205 |
+
|
| 206 |
+
response = self.session.post(
|
| 207 |
+
f"{ADMIN_URL}paperworks/",
|
| 208 |
+
json=data,
|
| 209 |
+
headers=self.headers,
|
| 210 |
+
timeout=10
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
self.last_response = response
|
| 214 |
+
|
| 215 |
+
if response.status_code in [200, 201]:
|
| 216 |
+
paperwork = response.json()
|
| 217 |
+
print(f"{Fore.GREEN}✅ Paperwork assigned successfully: {Fore.YELLOW}{title}{Style.RESET_ALL}")
|
| 218 |
+
|
| 219 |
+
# Add to our list of paperworks
|
| 220 |
+
self.paperworks.append(paperwork)
|
| 221 |
+
|
| 222 |
+
# Display paperwork details
|
| 223 |
+
print(f"\n{Fore.CYAN}Paperwork Details:{Style.RESET_ALL}")
|
| 224 |
+
print(f"ID: {Fore.YELLOW}{paperwork.get('id')}{Style.RESET_ALL}")
|
| 225 |
+
print(f"Title: {Fore.YELLOW}{paperwork.get('title')}{Style.RESET_ALL}")
|
| 226 |
+
print(f"Status: {Fore.YELLOW}{paperwork.get('status')}{Style.RESET_ALL}")
|
| 227 |
+
print(f"Assigned At: {Fore.YELLOW}{paperwork.get('assigned_at')}{Style.RESET_ALL}")
|
| 228 |
+
if paperwork.get('deadline'):
|
| 229 |
+
print(f"Deadline: {Fore.YELLOW}{paperwork.get('deadline')}{Style.RESET_ALL}")
|
| 230 |
+
if paperwork.get('deadline'):
|
| 231 |
+
print(f"Deadline: {Fore.YELLOW}{paperwork.get('deadline')}{Style.RESET_ALL}")
|
| 232 |
+
|
| 233 |
+
return paperwork
|
| 234 |
+
else:
|
| 235 |
+
print(f"{Fore.RED}❌ Failed to assign paperwork: {response.text}{Style.RESET_ALL}")
|
| 236 |
+
return None
|
| 237 |
+
except requests.exceptions.ConnectionError:
|
| 238 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 239 |
+
return None
|
| 240 |
+
except requests.exceptions.Timeout:
|
| 241 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 242 |
+
return None
|
| 243 |
+
except Exception as e:
|
| 244 |
+
print(f"{Fore.RED}❌ Error assigning paperwork: {str(e)}{Style.RESET_ALL}")
|
| 245 |
+
return None
|
| 246 |
+
|
| 247 |
+
def list_paperworks(self):
|
| 248 |
+
"""List all paperworks (Admin sees all)"""
|
| 249 |
+
try:
|
| 250 |
+
print(f"{Fore.CYAN}Fetching paperworks...{Style.RESET_ALL}")
|
| 251 |
+
|
| 252 |
+
response = requests.get(
|
| 253 |
+
f"{API_URL}paperworks/",
|
| 254 |
+
headers=self.headers,
|
| 255 |
+
timeout=10
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
self.last_response = response
|
| 259 |
+
|
| 260 |
+
if response.status_code == 200:
|
| 261 |
+
paperworks = response.json()
|
| 262 |
+
print(f"{Fore.GREEN}✅ Retrieved {len(paperworks)} paperworks{Style.RESET_ALL}")
|
| 263 |
+
|
| 264 |
+
# Store for later use
|
| 265 |
+
self.paperworks = paperworks
|
| 266 |
+
|
| 267 |
+
# Display paperworks in a table
|
| 268 |
+
table_data = []
|
| 269 |
+
for pw in paperworks:
|
| 270 |
+
table_data.append([
|
| 271 |
+
pw.get('id'),
|
| 272 |
+
pw.get('title'),
|
| 273 |
+
pw.get('researcher', {}).get('username', 'N/A'),
|
| 274 |
+
pw.get('status')
|
| 275 |
+
])
|
| 276 |
+
|
| 277 |
+
headers = ["ID", "Title", "Researcher", "Status"]
|
| 278 |
+
print(tabulate(table_data, headers=headers, tablefmt="grid"))
|
| 279 |
+
|
| 280 |
+
return paperworks
|
| 281 |
+
else:
|
| 282 |
+
print(f"{Fore.RED}❌ Failed to get paperworks: {response.text}{Style.RESET_ALL}")
|
| 283 |
+
return None
|
| 284 |
+
except requests.exceptions.ConnectionError:
|
| 285 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 286 |
+
return None
|
| 287 |
+
except requests.exceptions.Timeout:
|
| 288 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 289 |
+
return None
|
| 290 |
+
except Exception as e:
|
| 291 |
+
print(f"{Fore.RED}❌ Error retrieving paperworks: {str(e)}{Style.RESET_ALL}")
|
| 292 |
+
return None
|
| 293 |
+
|
| 294 |
+
def review_paperwork(self, paperwork_id, action, reviewer_notes, ai_percent_verified=None, reassign_to=None):
|
| 295 |
+
"""Review a paperwork (Admin only)"""
|
| 296 |
+
try:
|
| 297 |
+
print(f"{Fore.CYAN}Reviewing paperwork {paperwork_id}...{Style.RESET_ALL}")
|
| 298 |
+
|
| 299 |
+
data = {
|
| 300 |
+
"action": action,
|
| 301 |
+
"reviewer_notes": reviewer_notes
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
if action == "APPROVE" and ai_percent_verified is not None:
|
| 305 |
+
data["ai_percent_verified"] = ai_percent_verified
|
| 306 |
+
|
| 307 |
+
if action == "REQUEST_CHANGES" and reassign_to is not None:
|
| 308 |
+
data["reassign_to"] = reassign_to
|
| 309 |
+
|
| 310 |
+
response = requests.post(
|
| 311 |
+
f"{API_URL}paperworks/{paperwork_id}/review/",
|
| 312 |
+
json=data,
|
| 313 |
+
headers=self.headers,
|
| 314 |
+
timeout=10
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
self.last_response = response
|
| 318 |
+
|
| 319 |
+
if response.status_code == 200:
|
| 320 |
+
result = response.json()
|
| 321 |
+
status = result.get('status')
|
| 322 |
+
status_color = Fore.GREEN if status == "APPROVED" else Fore.YELLOW
|
| 323 |
+
print(f"{Fore.GREEN}✅ Paperwork reviewed successfully. New status: {status_color}{status}{Style.RESET_ALL}")
|
| 324 |
+
|
| 325 |
+
# Display review details
|
| 326 |
+
print(f"\n{Fore.CYAN}Review Details:{Style.RESET_ALL}")
|
| 327 |
+
print(f"Action: {Fore.YELLOW}{action}{Style.RESET_ALL}")
|
| 328 |
+
print(f"Notes: {Fore.YELLOW}{reviewer_notes}{Style.RESET_ALL}")
|
| 329 |
+
if ai_percent_verified:
|
| 330 |
+
print(f"AI Percentage: {Fore.YELLOW}{ai_percent_verified}%{Style.RESET_ALL}")
|
| 331 |
+
|
| 332 |
+
return result
|
| 333 |
+
else:
|
| 334 |
+
print(f"{Fore.RED}❌ Failed to review paperwork: {response.text}{Style.RESET_ALL}")
|
| 335 |
+
return None
|
| 336 |
+
except requests.exceptions.ConnectionError:
|
| 337 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 338 |
+
return None
|
| 339 |
+
except requests.exceptions.Timeout:
|
| 340 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 341 |
+
return None
|
| 342 |
+
except Exception as e:
|
| 343 |
+
print(f"{Fore.RED}❌ Error reviewing paperwork: {str(e)}{Style.RESET_ALL}")
|
| 344 |
+
return None
|
| 345 |
+
|
| 346 |
+
def get_reports_summary(self):
|
| 347 |
+
"""Get reports summary (Admin only)"""
|
| 348 |
+
try:
|
| 349 |
+
print(f"{Fore.CYAN}Fetching reports summary...{Style.RESET_ALL}")
|
| 350 |
+
|
| 351 |
+
response = requests.get(
|
| 352 |
+
f"{API_URL}reports/summary/",
|
| 353 |
+
headers=self.headers,
|
| 354 |
+
timeout=10
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
self.last_response = response
|
| 358 |
+
|
| 359 |
+
if response.status_code == 200:
|
| 360 |
+
summary = response.json()
|
| 361 |
+
print(f"{Fore.GREEN}✅ Retrieved reports summary{Style.RESET_ALL}")
|
| 362 |
+
|
| 363 |
+
# Display summary in a table
|
| 364 |
+
table_data = []
|
| 365 |
+
for status, count in summary.items():
|
| 366 |
+
table_data.append([status, count])
|
| 367 |
+
|
| 368 |
+
headers = ["Status", "Count"]
|
| 369 |
+
print(tabulate(table_data, headers=headers, tablefmt="grid"))
|
| 370 |
+
|
| 371 |
+
return summary
|
| 372 |
+
else:
|
| 373 |
+
print(f"{Fore.RED}❌ Failed to get reports summary: {response.text}{Style.RESET_ALL}")
|
| 374 |
+
return None
|
| 375 |
+
except requests.exceptions.ConnectionError:
|
| 376 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 377 |
+
return None
|
| 378 |
+
except requests.exceptions.Timeout:
|
| 379 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 380 |
+
return None
|
| 381 |
+
except Exception as e:
|
| 382 |
+
print(f"{Fore.RED}❌ Error retrieving reports summary: {str(e)}{Style.RESET_ALL}")
|
| 383 |
+
return None
|
| 384 |
+
|
| 385 |
+
def clear_screen():
|
| 386 |
+
"""Clear the terminal screen"""
|
| 387 |
+
os.system('cls' if os.name == 'nt' else 'clear')
|
| 388 |
+
|
| 389 |
+
def print_header():
|
| 390 |
+
"""Print application header"""
|
| 391 |
+
clear_screen()
|
| 392 |
+
print(f"{Fore.CYAN}{'=' * 80}{Style.RESET_ALL}")
|
| 393 |
+
print(f"{Fore.YELLOW}{'PMS ADMIN API TESTING TOOL':^80}{Style.RESET_ALL}")
|
| 394 |
+
print(f"{Fore.CYAN}{'=' * 80}{Style.RESET_ALL}")
|
| 395 |
+
|
| 396 |
+
def main():
|
| 397 |
+
print_header()
|
| 398 |
+
print(f"{Fore.GREEN}Welcome to the PMS Admin API Testing Tool!{Style.RESET_ALL}")
|
| 399 |
+
print(f"This tool allows you to test the admin-specific API endpoints of the PMS-Backend system.\n")
|
| 400 |
+
|
| 401 |
+
# Check if server is running
|
| 402 |
+
try:
|
| 403 |
+
requests.get(BASE_URL, timeout=2)
|
| 404 |
+
except requests.exceptions.ConnectionError:
|
| 405 |
+
print(f"{Fore.RED}ERROR: Cannot connect to the server at {BASE_URL}{Style.RESET_ALL}")
|
| 406 |
+
print(f"{Fore.YELLOW}Please make sure the server is running before using this tool.{Style.RESET_ALL}")
|
| 407 |
+
print(f"\nTo start the server, run: {Fore.CYAN}python manage.py runserver{Style.RESET_ALL}")
|
| 408 |
+
sys.exit(1)
|
| 409 |
+
except Exception:
|
| 410 |
+
pass
|
| 411 |
+
|
| 412 |
+
tester = AdminAPITester()
|
| 413 |
+
|
| 414 |
+
# Get login credentials
|
| 415 |
+
print(f"\n{Fore.YELLOW}Please login with ADMIN credentials:{Style.RESET_ALL}")
|
| 416 |
+
username = input(f"{Fore.CYAN}Username: {Style.RESET_ALL}")
|
| 417 |
+
password = getpass(f"{Fore.CYAN}Password: {Style.RESET_ALL}")
|
| 418 |
+
|
| 419 |
+
if not tester.login(username, password):
|
| 420 |
+
print(f"\n{Fore.RED}Login failed or user is not an admin. Exiting...{Style.RESET_ALL}")
|
| 421 |
+
time.sleep(2)
|
| 422 |
+
sys.exit(1)
|
| 423 |
+
|
| 424 |
+
# Store last used IDs for convenience
|
| 425 |
+
last_paperwork_id = None
|
| 426 |
+
last_researcher_id = None
|
| 427 |
+
last_username = None
|
| 428 |
+
|
| 429 |
+
# Test menu
|
| 430 |
+
while True:
|
| 431 |
+
print(f"\n{Fore.CYAN}{'=' * 80}{Style.RESET_ALL}")
|
| 432 |
+
print(f"{Fore.YELLOW}{'ADMIN API TESTING MENU':^80}{Style.RESET_ALL}")
|
| 433 |
+
print(f"{Fore.CYAN}{'=' * 80}{Style.RESET_ALL}")
|
| 434 |
+
|
| 435 |
+
# Show user info
|
| 436 |
+
if tester.username and tester.user_role:
|
| 437 |
+
print(f"Logged in as: {Fore.YELLOW}{tester.username}{Style.RESET_ALL} | Role: {Fore.GREEN}{tester.user_role}{Style.RESET_ALL}")
|
| 438 |
+
|
| 439 |
+
print(f"\n{Fore.CYAN}User Management:{Style.RESET_ALL}")
|
| 440 |
+
print(f"{Fore.WHITE}1. List all users{Style.RESET_ALL}")
|
| 441 |
+
print(f"{Fore.WHITE}2. Create new user{Style.RESET_ALL}")
|
| 442 |
+
print(f"{Fore.WHITE}3. Update user status{Style.RESET_ALL}")
|
| 443 |
+
|
| 444 |
+
print(f"\n{Fore.CYAN}Paperwork Management:{Style.RESET_ALL}")
|
| 445 |
+
print(f"{Fore.WHITE}4. List all paperworks{Style.RESET_ALL}")
|
| 446 |
+
print(f"{Fore.WHITE}5. Assign new paperwork{Style.RESET_ALL}")
|
| 447 |
+
print(f"\n{Fore.CYAN}Reports:{Style.RESET_ALL}")
|
| 448 |
+
print(f"{Fore.WHITE}6. Get reports summary{Style.RESET_ALL}")
|
| 449 |
+
|
| 450 |
+
print(f"\n{Fore.WHITE}7. Clear screen{Style.RESET_ALL}")
|
| 451 |
+
print(f"{Fore.RED}0. Exit{Style.RESET_ALL}")
|
| 452 |
+
|
| 453 |
+
choice = input(f"\n{Fore.YELLOW}Enter your choice: {Style.RESET_ALL}")
|
| 454 |
+
|
| 455 |
+
if choice == '1':
|
| 456 |
+
# List all users
|
| 457 |
+
users = tester.list_users()
|
| 458 |
+
if users and len(users) > 0:
|
| 459 |
+
# Store the first researcher ID for convenience
|
| 460 |
+
researchers = [u for u in users if u.get('role') == 'RESEARCHER']
|
| 461 |
+
if researchers:
|
| 462 |
+
last_researcher_id = researchers[0].get('id')
|
| 463 |
+
last_username = researchers[0].get('username')
|
| 464 |
+
|
| 465 |
+
elif choice == '2':
|
| 466 |
+
# Create new user
|
| 467 |
+
print(f"\n{Fore.CYAN}Create New User:{Style.RESET_ALL}")
|
| 468 |
+
username = input(f"Username: ")
|
| 469 |
+
email = input(f"Email: ")
|
| 470 |
+
password = getpass(f"Password: ")
|
| 471 |
+
|
| 472 |
+
print(f"\nSelect role:")
|
| 473 |
+
print(f"1. RESEARCHER")
|
| 474 |
+
print(f"2. ADMIN")
|
| 475 |
+
role_choice = input(f"Choice (default: 1): ") or "1"
|
| 476 |
+
role = "ADMIN" if role_choice == "2" else "RESEARCHER"
|
| 477 |
+
|
| 478 |
+
print(f"\nSelect status:")
|
| 479 |
+
print(f"1. ACTIVE")
|
| 480 |
+
print(f"2. FROZEN")
|
| 481 |
+
print(f"3. INACTIVE")
|
| 482 |
+
status_choice = input(f"Choice (default: 1): ") or "1"
|
| 483 |
+
status = "ACTIVE"
|
| 484 |
+
if status_choice == "2":
|
| 485 |
+
status = "FROZEN"
|
| 486 |
+
elif status_choice == "3":
|
| 487 |
+
status = "INACTIVE"
|
| 488 |
+
|
| 489 |
+
user = tester.create_user(username, email, password, role, status)
|
| 490 |
+
if user and role == "RESEARCHER":
|
| 491 |
+
last_researcher_id = user.get('id')
|
| 492 |
+
last_username = user.get('username')
|
| 493 |
+
|
| 494 |
+
elif choice == '3':
|
| 495 |
+
# Update user status
|
| 496 |
+
if last_username:
|
| 497 |
+
print(f"Last used username: {Fore.YELLOW}{last_username}{Style.RESET_ALL}")
|
| 498 |
+
use_last = input(f"Use this username? (y/n, default: y): ").lower() != 'n'
|
| 499 |
+
if use_last:
|
| 500 |
+
username = last_username
|
| 501 |
+
else:
|
| 502 |
+
username = input(f"Enter username to update: ")
|
| 503 |
+
else:
|
| 504 |
+
username = input(f"Enter username to update: ")
|
| 505 |
+
|
| 506 |
+
print(f"\nSelect new status:")
|
| 507 |
+
print(f"1. ACTIVE")
|
| 508 |
+
print(f"2. FROZEN")
|
| 509 |
+
print(f"3. INACTIVE")
|
| 510 |
+
status_choice = input(f"Choice: ")
|
| 511 |
+
status = "ACTIVE"
|
| 512 |
+
if status_choice == "2":
|
| 513 |
+
status = "FROZEN"
|
| 514 |
+
elif status_choice == "3":
|
| 515 |
+
status = "INACTIVE"
|
| 516 |
+
|
| 517 |
+
tester.update_user_status(username, status)
|
| 518 |
+
last_username = username
|
| 519 |
+
|
| 520 |
+
elif choice == '4':
|
| 521 |
+
# List all paperworks
|
| 522 |
+
paperworks = tester.list_paperworks()
|
| 523 |
+
if paperworks and len(paperworks) > 0:
|
| 524 |
+
# Store the first paperwork ID for convenience
|
| 525 |
+
last_paperwork_id = paperworks[0].get('id')
|
| 526 |
+
|
| 527 |
+
elif choice == '5':
|
| 528 |
+
# Assign new paperwork
|
| 529 |
+
if not last_researcher_id:
|
| 530 |
+
# Try to get researchers first
|
| 531 |
+
tester.list_users()
|
| 532 |
+
|
| 533 |
+
if tester.researchers:
|
| 534 |
+
print(f"\n{Fore.CYAN}Available Researchers:{Style.RESET_ALL}")
|
| 535 |
+
for i, r in enumerate(tester.researchers):
|
| 536 |
+
print(f"{i+1}. {r.get('username')} (ID: {r.get('id')})")
|
| 537 |
+
|
| 538 |
+
researcher_choice = input(f"\nSelect researcher (1-{len(tester.researchers)}): ")
|
| 539 |
+
try:
|
| 540 |
+
idx = int(researcher_choice) - 1
|
| 541 |
+
if 0 <= idx < len(tester.researchers):
|
| 542 |
+
researcher_id = tester.researchers[idx].get('id')
|
| 543 |
+
title = input(f"\nEnter paperwork title: ")
|
| 544 |
+
deadline_choice = input(f"Set deadline? (y/n, default: n): ").lower()
|
| 545 |
+
deadline = None
|
| 546 |
+
if deadline_choice == 'y':
|
| 547 |
+
deadline_date = input(f"Enter deadline date (YYYY-MM-DD): ")
|
| 548 |
+
deadline_time = input(f"Enter deadline time (HH:MM): ")
|
| 549 |
+
deadline = f"{deadline_date}T{deadline_time}:00Z"
|
| 550 |
+
paperwork = tester.assign_paperwork(title, researcher_id, deadline)
|
| 551 |
+
if paperwork:
|
| 552 |
+
last_paperwork_id = paperwork.get('id')
|
| 553 |
+
else:
|
| 554 |
+
print(f"{Fore.RED}Invalid selection.{Style.RESET_ALL}")
|
| 555 |
+
except ValueError:
|
| 556 |
+
print(f"{Fore.RED}Please enter a valid number.{Style.RESET_ALL}")
|
| 557 |
+
else:
|
| 558 |
+
print(f"{Fore.RED}No researchers available. Please create a researcher first.{Style.RESET_ALL}")
|
| 559 |
+
|
| 560 |
+
elif choice == '6':
|
| 561 |
+
# Review paperwork
|
| 562 |
+
if not last_paperwork_id:
|
| 563 |
+
# Try to get paperworks first
|
| 564 |
+
tester.list_paperworks()
|
| 565 |
+
|
| 566 |
+
if tester.paperworks:
|
| 567 |
+
if last_paperwork_id:
|
| 568 |
+
print(f"Last used paperwork ID: {Fore.YELLOW}{last_paperwork_id}{Style.RESET_ALL}")
|
| 569 |
+
use_last = input(f"Use this ID? (y/n, default: y): ").lower() != 'n'
|
| 570 |
+
if use_last:
|
| 571 |
+
paperwork_id = last_paperwork_id
|
| 572 |
+
else:
|
| 573 |
+
paperwork_id = input(f"Enter paperwork ID to review: ")
|
| 574 |
+
else:
|
| 575 |
+
paperwork_id = input(f"Enter paperwork ID to review: ")
|
| 576 |
+
|
| 577 |
+
print(f"\nSelect review action:")
|
| 578 |
+
print(f"1. APPROVE")
|
| 579 |
+
print(f"2. REQUEST_CHANGES")
|
| 580 |
+
action_choice = input(f"Choice: ")
|
| 581 |
+
|
| 582 |
+
if action_choice == "1":
|
| 583 |
+
action = "APPROVE"
|
| 584 |
+
ai_percent = input(f"Enter AI percentage verified (0-100): ")
|
| 585 |
+
try:
|
| 586 |
+
ai_percent = float(ai_percent)
|
| 587 |
+
notes = input(f"Enter reviewer notes: ")
|
| 588 |
+
tester.review_paperwork(paperwork_id, action, notes, ai_percent_verified=ai_percent)
|
| 589 |
+
except ValueError:
|
| 590 |
+
print(f"{Fore.RED}Please enter a valid number for AI percentage.{Style.RESET_ALL}")
|
| 591 |
+
elif action_choice == "2":
|
| 592 |
+
action = "REQUEST_CHANGES"
|
| 593 |
+
notes = input(f"Enter reviewer notes: ")
|
| 594 |
+
reassign = input(f"Reassign to another researcher? (y/n, default: n): ").lower() == 'y'
|
| 595 |
+
|
| 596 |
+
if reassign and tester.researchers:
|
| 597 |
+
print(f"\n{Fore.CYAN}Available Researchers:{Style.RESET_ALL}")
|
| 598 |
+
for i, r in enumerate(tester.researchers):
|
| 599 |
+
print(f"{i+1}. {r.get('username')} (ID: {r.get('id')})")
|
| 600 |
+
|
| 601 |
+
researcher_choice = input(f"\nSelect researcher (1-{len(tester.researchers)}): ")
|
| 602 |
+
try:
|
| 603 |
+
idx = int(researcher_choice) - 1
|
| 604 |
+
if 0 <= idx < len(tester.researchers):
|
| 605 |
+
reassign_to = tester.researchers[idx].get('id')
|
| 606 |
+
tester.review_paperwork(paperwork_id, action, notes, reassign_to=reassign_to)
|
| 607 |
+
else:
|
| 608 |
+
print(f"{Fore.RED}Invalid selection.{Style.RESET_ALL}")
|
| 609 |
+
except ValueError:
|
| 610 |
+
print(f"{Fore.RED}Please enter a valid number.{Style.RESET_ALL}")
|
| 611 |
+
else:
|
| 612 |
+
tester.review_paperwork(paperwork_id, action, notes)
|
| 613 |
+
else:
|
| 614 |
+
print(f"{Fore.RED}Invalid action choice.{Style.RESET_ALL}")
|
| 615 |
+
|
| 616 |
+
last_paperwork_id = paperwork_id
|
| 617 |
+
else:
|
| 618 |
+
print(f"{Fore.RED}No paperworks available. Please assign a paperwork first.{Style.RESET_ALL}")
|
| 619 |
+
|
| 620 |
+
elif choice == '7':
|
| 621 |
+
# Get reports summary
|
| 622 |
+
tester.get_reports_summary()
|
| 623 |
+
|
| 624 |
+
elif choice == '8':
|
| 625 |
+
# Clear screen
|
| 626 |
+
print_header()
|
| 627 |
+
|
| 628 |
+
elif choice == '0':
|
| 629 |
+
# Exit
|
| 630 |
+
print(f"\n{Fore.GREEN}Thank you for using the PMS Admin API Testing Tool. Goodbye!{Style.RESET_ALL}")
|
| 631 |
+
sys.exit(0)
|
| 632 |
+
|
| 633 |
+
else:
|
| 634 |
+
print(f"{Fore.RED}Invalid choice. Please try again.{Style.RESET_ALL}")
|
| 635 |
+
|
| 636 |
+
input(f"\n{Fore.CYAN}Press Enter to continue...{Style.RESET_ALL}")
|
| 637 |
+
|
| 638 |
+
if __name__ == "__main__":
|
| 639 |
+
main()
|
api_test.py
ADDED
|
@@ -0,0 +1,620 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import uuid
|
| 4 |
+
import sys
|
| 5 |
+
import os
|
| 6 |
+
import time
|
| 7 |
+
from getpass import getpass
|
| 8 |
+
from tabulate import tabulate
|
| 9 |
+
from colorama import init, Fore, Style
|
| 10 |
+
|
| 11 |
+
# Initialize colorama
|
| 12 |
+
init()
|
| 13 |
+
|
| 14 |
+
BASE_URL = 'http://localhost:8000/api/'
|
| 15 |
+
|
| 16 |
+
class APITester:
|
| 17 |
+
def __init__(self, base_url):
|
| 18 |
+
self.base_url = base_url
|
| 19 |
+
self.token = None
|
| 20 |
+
self.headers = {}
|
| 21 |
+
self.user_role = None
|
| 22 |
+
self.username = None
|
| 23 |
+
self.last_response = None
|
| 24 |
+
|
| 25 |
+
def login(self, username, password):
|
| 26 |
+
"""Login to get authentication token"""
|
| 27 |
+
try:
|
| 28 |
+
print(f"{Fore.CYAN}Attempting to login...{Style.RESET_ALL}")
|
| 29 |
+
response = requests.post(
|
| 30 |
+
f"{self.base_url.replace('/api/', '/auth/')}login/",
|
| 31 |
+
data={'username': username, 'password': password},
|
| 32 |
+
timeout=10
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
self.last_response = response
|
| 36 |
+
|
| 37 |
+
if response.status_code == 200:
|
| 38 |
+
data = response.json()
|
| 39 |
+
self.token = data.get('token')
|
| 40 |
+
self.headers = {'Authorization': f'Token {self.token}'}
|
| 41 |
+
self.username = username
|
| 42 |
+
|
| 43 |
+
# Get user info to determine role
|
| 44 |
+
user_info = self.get_user_info()
|
| 45 |
+
if user_info:
|
| 46 |
+
self.user_role = user_info.get('role')
|
| 47 |
+
role_display = f"{Fore.GREEN}{self.user_role}{Style.RESET_ALL}"
|
| 48 |
+
print(f"{Fore.GREEN}✅ Logged in as {Fore.YELLOW}{username}{Fore.GREEN} (Role: {role_display}){Style.RESET_ALL}")
|
| 49 |
+
return True
|
| 50 |
+
return False
|
| 51 |
+
else:
|
| 52 |
+
print(f"{Fore.RED}❌ Login failed: {response.text}{Style.RESET_ALL}")
|
| 53 |
+
return False
|
| 54 |
+
except requests.exceptions.ConnectionError:
|
| 55 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server. Is the server running?{Style.RESET_ALL}")
|
| 56 |
+
return False
|
| 57 |
+
except requests.exceptions.Timeout:
|
| 58 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 59 |
+
return False
|
| 60 |
+
except Exception as e:
|
| 61 |
+
print(f"{Fore.RED}❌ Error during login: {str(e)}{Style.RESET_ALL}")
|
| 62 |
+
return False
|
| 63 |
+
|
| 64 |
+
def get_user_info(self):
|
| 65 |
+
"""Get current user information"""
|
| 66 |
+
try:
|
| 67 |
+
response = requests.get(
|
| 68 |
+
f"{self.base_url.replace('/api/', '/auth/')}me/",
|
| 69 |
+
headers=self.headers,
|
| 70 |
+
timeout=10
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
if response.status_code == 200:
|
| 74 |
+
return response.json()
|
| 75 |
+
return None
|
| 76 |
+
except Exception:
|
| 77 |
+
return None
|
| 78 |
+
|
| 79 |
+
def test_paperworks_list(self):
|
| 80 |
+
"""Test getting list of paperworks"""
|
| 81 |
+
try:
|
| 82 |
+
print(f"{Fore.CYAN}Fetching paperworks...{Style.RESET_ALL}")
|
| 83 |
+
response = requests.get(
|
| 84 |
+
f"{self.base_url}paperworks/",
|
| 85 |
+
headers=self.headers,
|
| 86 |
+
timeout=10
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
self.last_response = response
|
| 90 |
+
|
| 91 |
+
if response.status_code == 200:
|
| 92 |
+
paperworks = response.json()
|
| 93 |
+
print(f"{Fore.GREEN}✅ Retrieved {len(paperworks)} paperworks{Style.RESET_ALL}")
|
| 94 |
+
|
| 95 |
+
if paperworks:
|
| 96 |
+
# Display paperworks in a table
|
| 97 |
+
table_data = []
|
| 98 |
+
for pw in paperworks:
|
| 99 |
+
table_data.append([
|
| 100 |
+
pw.get('id'),
|
| 101 |
+
pw.get('title'),
|
| 102 |
+
pw.get('researcher', {}).get('username'),
|
| 103 |
+
pw.get('status'),
|
| 104 |
+
pw.get('assigned_at')
|
| 105 |
+
])
|
| 106 |
+
|
| 107 |
+
headers = ["ID", "Title", "Researcher", "Status", "Assigned At"]
|
| 108 |
+
print(tabulate(table_data, headers=headers, tablefmt="grid"))
|
| 109 |
+
|
| 110 |
+
return paperworks
|
| 111 |
+
else:
|
| 112 |
+
print(f"{Fore.RED}❌ Failed to get paperworks: {response.text}{Style.RESET_ALL}")
|
| 113 |
+
return None
|
| 114 |
+
except requests.exceptions.ConnectionError:
|
| 115 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 116 |
+
return None
|
| 117 |
+
except requests.exceptions.Timeout:
|
| 118 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 119 |
+
return None
|
| 120 |
+
except Exception as e:
|
| 121 |
+
print(f"{Fore.RED}❌ Error retrieving paperworks: {str(e)}{Style.RESET_ALL}")
|
| 122 |
+
return None
|
| 123 |
+
|
| 124 |
+
def test_paperwork_detail(self, paperwork_id):
|
| 125 |
+
"""Test getting paperwork details"""
|
| 126 |
+
try:
|
| 127 |
+
print(f"{Fore.CYAN}Fetching paperwork details...{Style.RESET_ALL}")
|
| 128 |
+
response = requests.get(
|
| 129 |
+
f"{self.base_url}paperworks/{paperwork_id}/",
|
| 130 |
+
headers=self.headers,
|
| 131 |
+
timeout=10
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
self.last_response = response
|
| 135 |
+
|
| 136 |
+
if response.status_code == 200:
|
| 137 |
+
paperwork = response.json()
|
| 138 |
+
print(f"{Fore.GREEN}✅ Retrieved paperwork: {paperwork['title']}{Style.RESET_ALL}")
|
| 139 |
+
|
| 140 |
+
# Display paperwork details in a formatted way
|
| 141 |
+
print(f"\n{Fore.YELLOW}Paperwork Details:{Style.RESET_ALL}")
|
| 142 |
+
print(f" {Fore.CYAN}ID:{Style.RESET_ALL} {paperwork.get('id')}")
|
| 143 |
+
print(f" {Fore.CYAN}Title:{Style.RESET_ALL} {paperwork.get('title')}")
|
| 144 |
+
print(f" {Fore.CYAN}Researcher:{Style.RESET_ALL} {paperwork.get('researcher', {}).get('username')}")
|
| 145 |
+
print(f" {Fore.CYAN}Status:{Style.RESET_ALL} {paperwork.get('status')}")
|
| 146 |
+
print(f" {Fore.CYAN}Assigned At:{Style.RESET_ALL} {paperwork.get('assigned_at')}")
|
| 147 |
+
print(f" {Fore.CYAN}Updated At:{Style.RESET_ALL} {paperwork.get('updated_at')}")
|
| 148 |
+
|
| 149 |
+
return paperwork
|
| 150 |
+
else:
|
| 151 |
+
print(f"{Fore.RED}❌ Failed to get paperwork details: {response.text}{Style.RESET_ALL}")
|
| 152 |
+
return None
|
| 153 |
+
except requests.exceptions.ConnectionError:
|
| 154 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 155 |
+
return None
|
| 156 |
+
except requests.exceptions.Timeout:
|
| 157 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 158 |
+
return None
|
| 159 |
+
except Exception as e:
|
| 160 |
+
print(f"{Fore.RED}❌ Error retrieving paperwork details: {str(e)}{Style.RESET_ALL}")
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
def test_versions_list(self, paperwork_id):
|
| 164 |
+
"""Test getting versions for a paperwork"""
|
| 165 |
+
try:
|
| 166 |
+
print(f"{Fore.CYAN}Fetching versions for paperwork {paperwork_id}...{Style.RESET_ALL}")
|
| 167 |
+
response = requests.get(
|
| 168 |
+
f"{self.base_url}paperworks/{paperwork_id}/versions/",
|
| 169 |
+
headers=self.headers,
|
| 170 |
+
timeout=10
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
self.last_response = response
|
| 174 |
+
|
| 175 |
+
if response.status_code == 200:
|
| 176 |
+
versions = response.json()
|
| 177 |
+
print(f"{Fore.GREEN}✅ Retrieved {len(versions)} versions for paperwork{Style.RESET_ALL}")
|
| 178 |
+
|
| 179 |
+
if versions:
|
| 180 |
+
# Display versions in a table
|
| 181 |
+
table_data = []
|
| 182 |
+
for v in versions:
|
| 183 |
+
table_data.append([
|
| 184 |
+
v.get('version_no'),
|
| 185 |
+
v.get('submitted_at'),
|
| 186 |
+
f"{v.get('ai_percent_self', 'N/A')}%",
|
| 187 |
+
"✓" if v.get('pdf_path') else "✗",
|
| 188 |
+
"✓" if v.get('latex_path') else "✗",
|
| 189 |
+
"✓" if v.get('python_path') else "✗"
|
| 190 |
+
])
|
| 191 |
+
|
| 192 |
+
headers = ["Version", "Submitted At", "AI %", "PDF", "LaTeX", "Python"]
|
| 193 |
+
print(tabulate(table_data, headers=headers, tablefmt="grid"))
|
| 194 |
+
|
| 195 |
+
return versions
|
| 196 |
+
else:
|
| 197 |
+
print(f"{Fore.RED}❌ Failed to get versions: {response.text}{Style.RESET_ALL}")
|
| 198 |
+
return None
|
| 199 |
+
except requests.exceptions.ConnectionError:
|
| 200 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 201 |
+
return None
|
| 202 |
+
except requests.exceptions.Timeout:
|
| 203 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 204 |
+
return None
|
| 205 |
+
except Exception as e:
|
| 206 |
+
print(f"{Fore.RED}❌ Error retrieving versions: {str(e)}{Style.RESET_ALL}")
|
| 207 |
+
return None
|
| 208 |
+
|
| 209 |
+
def test_submit_version(self, paperwork_id, version_data):
|
| 210 |
+
"""Test submitting a new version"""
|
| 211 |
+
try:
|
| 212 |
+
print(f"{Fore.CYAN}Submitting new version for paperwork {paperwork_id}...{Style.RESET_ALL}")
|
| 213 |
+
response = requests.post(
|
| 214 |
+
f"{self.base_url}paperworks/{paperwork_id}/versions/",
|
| 215 |
+
headers=self.headers,
|
| 216 |
+
json=version_data,
|
| 217 |
+
timeout=10
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
self.last_response = response
|
| 221 |
+
|
| 222 |
+
if response.status_code == 201:
|
| 223 |
+
version = response.json()
|
| 224 |
+
print(f"{Fore.GREEN}✅ Submitted new version {version['version_no']}{Style.RESET_ALL}")
|
| 225 |
+
|
| 226 |
+
# Display version details
|
| 227 |
+
print(f"\n{Fore.YELLOW}Version Details:{Style.RESET_ALL}")
|
| 228 |
+
print(f" {Fore.CYAN}Version Number:{Style.RESET_ALL} {version.get('version_no')}")
|
| 229 |
+
print(f" {Fore.CYAN}Submitted At:{Style.RESET_ALL} {version.get('submitted_at')}")
|
| 230 |
+
print(f" {Fore.CYAN}AI Percentage:{Style.RESET_ALL} {version.get('ai_percent_self')}%")
|
| 231 |
+
print(f" {Fore.CYAN}PDF Path:{Style.RESET_ALL} {version.get('pdf_path')}")
|
| 232 |
+
print(f" {Fore.CYAN}LaTeX Path:{Style.RESET_ALL} {version.get('latex_path')}")
|
| 233 |
+
print(f" {Fore.CYAN}Python Path:{Style.RESET_ALL} {version.get('python_path')}")
|
| 234 |
+
|
| 235 |
+
return version
|
| 236 |
+
else:
|
| 237 |
+
print(f"{Fore.RED}❌ Failed to submit version: {response.text}{Style.RESET_ALL}")
|
| 238 |
+
return None
|
| 239 |
+
except requests.exceptions.ConnectionError:
|
| 240 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 241 |
+
return None
|
| 242 |
+
except requests.exceptions.Timeout:
|
| 243 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 244 |
+
return None
|
| 245 |
+
except Exception as e:
|
| 246 |
+
print(f"{Fore.RED}❌ Error submitting version: {str(e)}{Style.RESET_ALL}")
|
| 247 |
+
return None
|
| 248 |
+
|
| 249 |
+
def test_version_detail(self, paperwork_id, version_no):
|
| 250 |
+
"""Test getting version details"""
|
| 251 |
+
try:
|
| 252 |
+
print(f"{Fore.CYAN}Fetching version {version_no} details for paperwork {paperwork_id}...{Style.RESET_ALL}")
|
| 253 |
+
response = requests.get(
|
| 254 |
+
f"{self.base_url}paperworks/{paperwork_id}/versions/{version_no}/",
|
| 255 |
+
headers=self.headers,
|
| 256 |
+
timeout=10
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
self.last_response = response
|
| 260 |
+
|
| 261 |
+
if response.status_code == 200:
|
| 262 |
+
version = response.json()
|
| 263 |
+
print(f"{Fore.GREEN}✅ Retrieved version {version['version_no']} details{Style.RESET_ALL}")
|
| 264 |
+
|
| 265 |
+
# Display version details
|
| 266 |
+
print(f"\n{Fore.YELLOW}Version Details:{Style.RESET_ALL}")
|
| 267 |
+
print(f" {Fore.CYAN}Version Number:{Style.RESET_ALL} {version.get('version_no')}")
|
| 268 |
+
print(f" {Fore.CYAN}Submitted At:{Style.RESET_ALL} {version.get('submitted_at')}")
|
| 269 |
+
print(f" {Fore.CYAN}AI Percentage:{Style.RESET_ALL} {version.get('ai_percent_self')}%")
|
| 270 |
+
print(f" {Fore.CYAN}PDF Path:{Style.RESET_ALL} {version.get('pdf_path')}")
|
| 271 |
+
print(f" {Fore.CYAN}LaTeX Path:{Style.RESET_ALL} {version.get('latex_path')}")
|
| 272 |
+
print(f" {Fore.CYAN}Python Path:{Style.RESET_ALL} {version.get('python_path')}")
|
| 273 |
+
|
| 274 |
+
if 'paperwork' in version:
|
| 275 |
+
print(f"\n{Fore.YELLOW}Associated Paperwork:{Style.RESET_ALL}")
|
| 276 |
+
print(f" {Fore.CYAN}Title:{Style.RESET_ALL} {version['paperwork'].get('title')}")
|
| 277 |
+
print(f" {Fore.CYAN}Status:{Style.RESET_ALL} {version['paperwork'].get('status')}")
|
| 278 |
+
print(f" {Fore.CYAN}Researcher:{Style.RESET_ALL} {version['paperwork'].get('researcher_name')}")
|
| 279 |
+
|
| 280 |
+
return version
|
| 281 |
+
else:
|
| 282 |
+
print(f"{Fore.RED}❌ Failed to get version details: {response.text}{Style.RESET_ALL}")
|
| 283 |
+
return None
|
| 284 |
+
except requests.exceptions.ConnectionError:
|
| 285 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 286 |
+
return None
|
| 287 |
+
except requests.exceptions.Timeout:
|
| 288 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 289 |
+
return None
|
| 290 |
+
except Exception as e:
|
| 291 |
+
print(f"{Fore.RED}❌ Error retrieving version details: {str(e)}{Style.RESET_ALL}")
|
| 292 |
+
return None
|
| 293 |
+
|
| 294 |
+
def test_review_paperwork(self, paperwork_id, review_data):
|
| 295 |
+
"""Test reviewing a paperwork"""
|
| 296 |
+
try:
|
| 297 |
+
print(f"{Fore.CYAN}Reviewing paperwork {paperwork_id}...{Style.RESET_ALL}")
|
| 298 |
+
response = requests.post(
|
| 299 |
+
f"{self.base_url}paperworks/{paperwork_id}/review/",
|
| 300 |
+
headers=self.headers,
|
| 301 |
+
json=review_data,
|
| 302 |
+
timeout=10
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
self.last_response = response
|
| 306 |
+
|
| 307 |
+
if response.status_code == 200:
|
| 308 |
+
paperwork = response.json()
|
| 309 |
+
print(f"{Fore.GREEN}✅ Reviewed paperwork: {paperwork['title']} - Status: {paperwork['status']}{Style.RESET_ALL}")
|
| 310 |
+
|
| 311 |
+
# Display paperwork details
|
| 312 |
+
print(f"\n{Fore.YELLOW}Updated Paperwork Details:{Style.RESET_ALL}")
|
| 313 |
+
print(f" {Fore.CYAN}Title:{Style.RESET_ALL} {paperwork.get('title')}")
|
| 314 |
+
print(f" {Fore.CYAN}Status:{Style.RESET_ALL} {paperwork.get('status')}")
|
| 315 |
+
print(f" {Fore.CYAN}Researcher:{Style.RESET_ALL} {paperwork.get('researcher', {}).get('username')}")
|
| 316 |
+
print(f" {Fore.CYAN}Updated At:{Style.RESET_ALL} {paperwork.get('updated_at')}")
|
| 317 |
+
|
| 318 |
+
if 'comments' in review_data and review_data['comments']:
|
| 319 |
+
print(f" {Fore.CYAN}Comments:{Style.RESET_ALL} {review_data['comments']}")
|
| 320 |
+
|
| 321 |
+
return paperwork
|
| 322 |
+
else:
|
| 323 |
+
print(f"{Fore.RED}❌ Failed to review paperwork: {response.text}{Style.RESET_ALL}")
|
| 324 |
+
return None
|
| 325 |
+
except requests.exceptions.ConnectionError:
|
| 326 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 327 |
+
return None
|
| 328 |
+
except requests.exceptions.Timeout:
|
| 329 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 330 |
+
return None
|
| 331 |
+
except Exception as e:
|
| 332 |
+
print(f"{Fore.RED}❌ Error reviewing paperwork: {str(e)}{Style.RESET_ALL}")
|
| 333 |
+
return None
|
| 334 |
+
|
| 335 |
+
def test_reports_summary(self):
|
| 336 |
+
"""Test getting reports summary"""
|
| 337 |
+
try:
|
| 338 |
+
print(f"{Fore.CYAN}Fetching reports summary...{Style.RESET_ALL}")
|
| 339 |
+
response = requests.get(
|
| 340 |
+
f"{self.base_url}reports/summary/",
|
| 341 |
+
headers=self.headers,
|
| 342 |
+
timeout=10
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
self.last_response = response
|
| 346 |
+
|
| 347 |
+
if response.status_code == 200:
|
| 348 |
+
summary = response.json()
|
| 349 |
+
print(f"{Fore.GREEN}✅ Retrieved reports summary - Total papers: {summary['total_papers']}{Style.RESET_ALL}")
|
| 350 |
+
|
| 351 |
+
# Display summary details
|
| 352 |
+
print(f"\n{Fore.YELLOW}Summary Statistics:{Style.RESET_ALL}")
|
| 353 |
+
print(f" {Fore.CYAN}Total Papers:{Style.RESET_ALL} {summary.get('total_papers')}")
|
| 354 |
+
print(f" {Fore.CYAN}Average AI Percentage:{Style.RESET_ALL} {summary.get('average_ai_percentage', 'N/A')}%")
|
| 355 |
+
|
| 356 |
+
if 'papers_by_status' in summary:
|
| 357 |
+
print(f"\n{Fore.YELLOW}Papers by Status:{Style.RESET_ALL}")
|
| 358 |
+
status_data = []
|
| 359 |
+
for status, count in summary['papers_by_status'].items():
|
| 360 |
+
status_data.append([status, count])
|
| 361 |
+
print(tabulate(status_data, headers=["Status", "Count"], tablefmt="grid"))
|
| 362 |
+
|
| 363 |
+
return summary
|
| 364 |
+
else:
|
| 365 |
+
print(f"{Fore.RED}❌ Failed to get reports summary: {response.text}{Style.RESET_ALL}")
|
| 366 |
+
return None
|
| 367 |
+
except requests.exceptions.ConnectionError:
|
| 368 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 369 |
+
return None
|
| 370 |
+
except requests.exceptions.Timeout:
|
| 371 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 372 |
+
return None
|
| 373 |
+
except Exception as e:
|
| 374 |
+
print(f"{Fore.RED}❌ Error retrieving reports summary: {str(e)}{Style.RESET_ALL}")
|
| 375 |
+
return None
|
| 376 |
+
|
| 377 |
+
def test_notifications_list(self):
|
| 378 |
+
"""Test getting notifications"""
|
| 379 |
+
try:
|
| 380 |
+
print(f"{Fore.CYAN}Fetching notifications...{Style.RESET_ALL}")
|
| 381 |
+
response = requests.get(
|
| 382 |
+
f"{self.base_url}notifications/",
|
| 383 |
+
headers=self.headers,
|
| 384 |
+
timeout=10
|
| 385 |
+
)
|
| 386 |
+
|
| 387 |
+
self.last_response = response
|
| 388 |
+
|
| 389 |
+
if response.status_code == 200:
|
| 390 |
+
notifications = response.json()
|
| 391 |
+
print(f"{Fore.GREEN}✅ Retrieved {len(notifications)} notifications{Style.RESET_ALL}")
|
| 392 |
+
|
| 393 |
+
if notifications:
|
| 394 |
+
# Display notifications in a table
|
| 395 |
+
table_data = []
|
| 396 |
+
for notif in notifications:
|
| 397 |
+
table_data.append([
|
| 398 |
+
notif.get('id'),
|
| 399 |
+
notif.get('event'),
|
| 400 |
+
notif.get('paper', {}).get('title', 'N/A'),
|
| 401 |
+
notif.get('timestamp')
|
| 402 |
+
])
|
| 403 |
+
|
| 404 |
+
headers = ["ID", "Event", "Paper", "Timestamp"]
|
| 405 |
+
print(tabulate(table_data, headers=headers, tablefmt="grid"))
|
| 406 |
+
else:
|
| 407 |
+
print(f"{Fore.YELLOW}No notifications found.{Style.RESET_ALL}")
|
| 408 |
+
|
| 409 |
+
return notifications
|
| 410 |
+
else:
|
| 411 |
+
print(f"{Fore.RED}❌ Failed to get notifications: {response.text}{Style.RESET_ALL}")
|
| 412 |
+
return None
|
| 413 |
+
except requests.exceptions.ConnectionError:
|
| 414 |
+
print(f"{Fore.RED}❌ Connection error: Could not connect to the server.{Style.RESET_ALL}")
|
| 415 |
+
return None
|
| 416 |
+
except requests.exceptions.Timeout:
|
| 417 |
+
print(f"{Fore.RED}❌ Timeout: The server took too long to respond.{Style.RESET_ALL}")
|
| 418 |
+
return None
|
| 419 |
+
except Exception as e:
|
| 420 |
+
print(f"{Fore.RED}❌ Error retrieving notifications: {str(e)}{Style.RESET_ALL}")
|
| 421 |
+
return None
|
| 422 |
+
|
| 423 |
+
def clear_screen():
|
| 424 |
+
"""Clear the terminal screen"""
|
| 425 |
+
os.system('cls' if os.name == 'nt' else 'clear')
|
| 426 |
+
|
| 427 |
+
def print_header():
|
| 428 |
+
"""Print application header"""
|
| 429 |
+
clear_screen()
|
| 430 |
+
print(f"{Fore.CYAN}{'=' * 80}{Style.RESET_ALL}")
|
| 431 |
+
print(f"{Fore.YELLOW}{'PMS API TESTING TOOL':^80}{Style.RESET_ALL}")
|
| 432 |
+
print(f"{Fore.CYAN}{'=' * 80}{Style.RESET_ALL}")
|
| 433 |
+
|
| 434 |
+
def main():
|
| 435 |
+
print_header()
|
| 436 |
+
print(f"{Fore.GREEN}Welcome to the PMS API Testing Tool!{Style.RESET_ALL}")
|
| 437 |
+
print(f"This tool allows you to test the API endpoints of the PMS-Backend system.\n")
|
| 438 |
+
|
| 439 |
+
# Check if server is running
|
| 440 |
+
try:
|
| 441 |
+
requests.get(BASE_URL.rstrip('/'), timeout=2)
|
| 442 |
+
except requests.exceptions.ConnectionError:
|
| 443 |
+
print(f"{Fore.RED}ERROR: Cannot connect to the server at {BASE_URL}{Style.RESET_ALL}")
|
| 444 |
+
print(f"{Fore.YELLOW}Please make sure the server is running before using this tool.{Style.RESET_ALL}")
|
| 445 |
+
print(f"\nTo start the server, run: {Fore.CYAN}python manage.py runserver{Style.RESET_ALL}")
|
| 446 |
+
sys.exit(1)
|
| 447 |
+
except Exception:
|
| 448 |
+
pass
|
| 449 |
+
|
| 450 |
+
tester = APITester(BASE_URL)
|
| 451 |
+
|
| 452 |
+
# Get login credentials
|
| 453 |
+
print(f"\n{Fore.YELLOW}Please login to continue:{Style.RESET_ALL}")
|
| 454 |
+
username = input(f"{Fore.CYAN}Username: {Style.RESET_ALL}")
|
| 455 |
+
password = getpass(f"{Fore.CYAN}Password: {Style.RESET_ALL}")
|
| 456 |
+
|
| 457 |
+
if not tester.login(username, password):
|
| 458 |
+
print(f"\n{Fore.RED}Login failed. Exiting...{Style.RESET_ALL}")
|
| 459 |
+
time.sleep(2)
|
| 460 |
+
sys.exit(1)
|
| 461 |
+
|
| 462 |
+
# Store last used paperwork ID for convenience
|
| 463 |
+
last_paperwork_id = None
|
| 464 |
+
|
| 465 |
+
# Test menu
|
| 466 |
+
while True:
|
| 467 |
+
print(f"\n{Fore.CYAN}{'=' * 80}{Style.RESET_ALL}")
|
| 468 |
+
print(f"{Fore.YELLOW}{'API TESTING MENU':^80}{Style.RESET_ALL}")
|
| 469 |
+
print(f"{Fore.CYAN}{'=' * 80}{Style.RESET_ALL}")
|
| 470 |
+
|
| 471 |
+
# Show user info
|
| 472 |
+
if tester.username and tester.user_role:
|
| 473 |
+
print(f"Logged in as: {Fore.YELLOW}{tester.username}{Style.RESET_ALL} | Role: {Fore.GREEN}{tester.user_role}{Style.RESET_ALL}")
|
| 474 |
+
|
| 475 |
+
print(f"\n{Fore.CYAN}Available Actions:{Style.RESET_ALL}")
|
| 476 |
+
print(f"{Fore.WHITE}1. List all paperworks{Style.RESET_ALL}")
|
| 477 |
+
print(f"{Fore.WHITE}2. Get paperwork details{Style.RESET_ALL}")
|
| 478 |
+
print(f"{Fore.WHITE}3. List versions for a paperwork{Style.RESET_ALL}")
|
| 479 |
+
print(f"{Fore.WHITE}4. Submit a new version{Style.RESET_ALL}")
|
| 480 |
+
print(f"{Fore.WHITE}5. Get version details{Style.RESET_ALL}")
|
| 481 |
+
print(f"{Fore.WHITE}6. Review a paperwork{Style.RESET_ALL}")
|
| 482 |
+
print(f"{Fore.WHITE}7. Get reports summary{Style.RESET_ALL}")
|
| 483 |
+
print(f"{Fore.WHITE}8. List notifications{Style.RESET_ALL}")
|
| 484 |
+
print(f"{Fore.WHITE}9. Clear screen{Style.RESET_ALL}")
|
| 485 |
+
print(f"{Fore.RED}0. Exit{Style.RESET_ALL}")
|
| 486 |
+
|
| 487 |
+
choice = input(f"\n{Fore.YELLOW}Enter your choice: {Style.RESET_ALL}")
|
| 488 |
+
|
| 489 |
+
if choice == '1':
|
| 490 |
+
paperworks = tester.test_paperworks_list()
|
| 491 |
+
if paperworks and len(paperworks) > 0:
|
| 492 |
+
# Store the first paperwork ID for convenience
|
| 493 |
+
last_paperwork_id = paperworks[0].get('id')
|
| 494 |
+
|
| 495 |
+
elif choice == '2':
|
| 496 |
+
if last_paperwork_id:
|
| 497 |
+
print(f"Last used paperwork ID: {Fore.YELLOW}{last_paperwork_id}{Style.RESET_ALL}")
|
| 498 |
+
use_last = input(f"Use this ID? (y/n, default: y): ").lower() != 'n'
|
| 499 |
+
if use_last:
|
| 500 |
+
paperwork_id = last_paperwork_id
|
| 501 |
+
else:
|
| 502 |
+
paperwork_id = input(f"{Fore.CYAN}Enter paperwork ID: {Style.RESET_ALL}")
|
| 503 |
+
else:
|
| 504 |
+
paperwork_id = input(f"{Fore.CYAN}Enter paperwork ID: {Style.RESET_ALL}")
|
| 505 |
+
|
| 506 |
+
paperwork = tester.test_paperwork_detail(paperwork_id)
|
| 507 |
+
if paperwork:
|
| 508 |
+
last_paperwork_id = paperwork_id
|
| 509 |
+
|
| 510 |
+
elif choice == '3':
|
| 511 |
+
if last_paperwork_id:
|
| 512 |
+
print(f"Last used paperwork ID: {Fore.YELLOW}{last_paperwork_id}{Style.RESET_ALL}")
|
| 513 |
+
use_last = input(f"Use this ID? (y/n, default: y): ").lower() != 'n'
|
| 514 |
+
if use_last:
|
| 515 |
+
paperwork_id = last_paperwork_id
|
| 516 |
+
else:
|
| 517 |
+
paperwork_id = input(f"{Fore.CYAN}Enter paperwork ID: {Style.RESET_ALL}")
|
| 518 |
+
else:
|
| 519 |
+
paperwork_id = input(f"{Fore.CYAN}Enter paperwork ID: {Style.RESET_ALL}")
|
| 520 |
+
|
| 521 |
+
versions = tester.test_versions_list(paperwork_id)
|
| 522 |
+
if versions is not None:
|
| 523 |
+
last_paperwork_id = paperwork_id
|
| 524 |
+
|
| 525 |
+
elif choice == '4':
|
| 526 |
+
if last_paperwork_id:
|
| 527 |
+
print(f"Last used paperwork ID: {Fore.YELLOW}{last_paperwork_id}{Style.RESET_ALL}")
|
| 528 |
+
use_last = input(f"Use this ID? (y/n, default: y): ").lower() != 'n'
|
| 529 |
+
if use_last:
|
| 530 |
+
paperwork_id = last_paperwork_id
|
| 531 |
+
else:
|
| 532 |
+
paperwork_id = input(f"{Fore.CYAN}Enter paperwork ID: {Style.RESET_ALL}")
|
| 533 |
+
else:
|
| 534 |
+
paperwork_id = input(f"{Fore.CYAN}Enter paperwork ID: {Style.RESET_ALL}")
|
| 535 |
+
|
| 536 |
+
try:
|
| 537 |
+
version_no = int(input(f"{Fore.CYAN}Enter version number: {Style.RESET_ALL}"))
|
| 538 |
+
ai_percent = float(input(f"{Fore.CYAN}Enter AI percentage (0-100): {Style.RESET_ALL}"))
|
| 539 |
+
|
| 540 |
+
version_data = {
|
| 541 |
+
'paperwork_id': paperwork_id,
|
| 542 |
+
'version_no': version_no,
|
| 543 |
+
'pdf_path': f"uploads/papers/{paperwork_id}/v{version_no}.pdf",
|
| 544 |
+
'latex_path': f"uploads/papers/{paperwork_id}/v{version_no}.tex",
|
| 545 |
+
'python_path': f"uploads/papers/{paperwork_id}/v{version_no}.py",
|
| 546 |
+
'ai_percent_self': ai_percent
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
version = tester.test_submit_version(paperwork_id, version_data)
|
| 550 |
+
if version is not None:
|
| 551 |
+
last_paperwork_id = paperwork_id
|
| 552 |
+
except ValueError:
|
| 553 |
+
print(f"{Fore.RED}❌ Invalid input. Please enter numeric values.{Style.RESET_ALL}")
|
| 554 |
+
|
| 555 |
+
elif choice == '5':
|
| 556 |
+
if last_paperwork_id:
|
| 557 |
+
print(f"Last used paperwork ID: {Fore.YELLOW}{last_paperwork_id}{Style.RESET_ALL}")
|
| 558 |
+
use_last = input(f"Use this ID? (y/n, default: y): ").lower() != 'n'
|
| 559 |
+
if use_last:
|
| 560 |
+
paperwork_id = last_paperwork_id
|
| 561 |
+
else:
|
| 562 |
+
paperwork_id = input(f"{Fore.CYAN}Enter paperwork ID: {Style.RESET_ALL}")
|
| 563 |
+
else:
|
| 564 |
+
paperwork_id = input(f"{Fore.CYAN}Enter paperwork ID: {Style.RESET_ALL}")
|
| 565 |
+
|
| 566 |
+
version_no = input(f"{Fore.CYAN}Enter version number: {Style.RESET_ALL}")
|
| 567 |
+
version = tester.test_version_detail(paperwork_id, version_no)
|
| 568 |
+
if version is not None:
|
| 569 |
+
last_paperwork_id = paperwork_id
|
| 570 |
+
|
| 571 |
+
elif choice == '6':
|
| 572 |
+
if last_paperwork_id:
|
| 573 |
+
print(f"Last used paperwork ID: {Fore.YELLOW}{last_paperwork_id}{Style.RESET_ALL}")
|
| 574 |
+
use_last = input(f"Use this ID? (y/n, default: y): ").lower() != 'n'
|
| 575 |
+
if use_last:
|
| 576 |
+
paperwork_id = last_paperwork_id
|
| 577 |
+
else:
|
| 578 |
+
paperwork_id = input(f"{Fore.CYAN}Enter paperwork ID: {Style.RESET_ALL}")
|
| 579 |
+
else:
|
| 580 |
+
paperwork_id = input(f"{Fore.CYAN}Enter paperwork ID: {Style.RESET_ALL}")
|
| 581 |
+
|
| 582 |
+
print(f"\n{Fore.YELLOW}Available statuses:{Style.RESET_ALL}")
|
| 583 |
+
print(f" {Fore.CYAN}ASSIGNED{Style.RESET_ALL} - Paper is assigned to researcher")
|
| 584 |
+
print(f" {Fore.CYAN}SUBMITTED{Style.RESET_ALL} - Paper has been submitted")
|
| 585 |
+
print(f" {Fore.CYAN}CHANGES_REQUESTED{Style.RESET_ALL} - Changes have been requested")
|
| 586 |
+
print(f" {Fore.CYAN}APPROVED{Style.RESET_ALL} - Paper has been approved")
|
| 587 |
+
|
| 588 |
+
status = input(f"\n{Fore.CYAN}Enter new status: {Style.RESET_ALL}").upper()
|
| 589 |
+
comments = input(f"{Fore.CYAN}Enter comments (optional): {Style.RESET_ALL}")
|
| 590 |
+
|
| 591 |
+
review_data = {
|
| 592 |
+
'status': status,
|
| 593 |
+
'comments': comments
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
paperwork = tester.test_review_paperwork(paperwork_id, review_data)
|
| 597 |
+
if paperwork is not None:
|
| 598 |
+
last_paperwork_id = paperwork_id
|
| 599 |
+
|
| 600 |
+
elif choice == '7':
|
| 601 |
+
tester.test_reports_summary()
|
| 602 |
+
|
| 603 |
+
elif choice == '8':
|
| 604 |
+
tester.test_notifications_list()
|
| 605 |
+
|
| 606 |
+
elif choice == '9':
|
| 607 |
+
print_header()
|
| 608 |
+
|
| 609 |
+
elif choice == '0':
|
| 610 |
+
print(f"{Fore.YELLOW}Exiting...{Style.RESET_ALL}")
|
| 611 |
+
break
|
| 612 |
+
|
| 613 |
+
else:
|
| 614 |
+
print(f"{Fore.RED}Invalid choice. Please try again.{Style.RESET_ALL}")
|
| 615 |
+
|
| 616 |
+
# Pause before showing menu again
|
| 617 |
+
input(f"\n{Fore.CYAN}Press Enter to continue...{Style.RESET_ALL}")
|
| 618 |
+
|
| 619 |
+
if __name__ == "__main__":
|
| 620 |
+
main()
|
app.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
# ---- STEP 2: Create db.sqlite3 if missing (to avoid SQLite open errors)
|
| 4 |
+
db_path = os.path.join(os.getcwd(), "db.sqlite3")
|
| 5 |
+
if not os.path.exists(db_path):
|
| 6 |
+
with open(db_path, 'w') as f:
|
| 7 |
+
f.write("") # just create an empty file
|
| 8 |
+
|
| 9 |
+
# ---- STEP 3: Run migrations to initialize database
|
| 10 |
+
os.system("python manage.py makemigrations")
|
| 11 |
+
os.system("python manage.py migrate")
|
| 12 |
+
os.system("python manage.py createsuperadmin --username=Admin --email=admin@gmail.com --password=adminpassword")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# ---- STEP 4: Start Django dev server on required Hugging Face port
|
| 16 |
+
os.system("uvicorn pms_server.asgi:application --host 0.0.0.0 --port 7860")
|
auth_app/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
default_app_config = "auth_app.apps.AuthAppConfig"
|
auth_app/admin.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib import admin
|
| 2 |
+
|
| 3 |
+
# Register your models here.
|
auth_app/apps.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.apps import AppConfig
|
| 2 |
+
|
| 3 |
+
class AuthAppConfig(AppConfig):
|
| 4 |
+
default_auto_field = "django.db.models.BigAutoField"
|
| 5 |
+
name = "auth_app"
|
| 6 |
+
|
| 7 |
+
def ready(self):
|
| 8 |
+
# Import firebase initialization
|
| 9 |
+
from .firebase_app import initialize_firebase
|
| 10 |
+
initialize_firebase()
|
| 11 |
+
print("Firebase ready() called from AuthAppConfig")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class AccountsConfig(AppConfig):
|
| 15 |
+
default_auto_field = "django.db.models.BigAutoField"
|
| 16 |
+
name = "accounts"
|
| 17 |
+
|
| 18 |
+
def ready(self):
|
| 19 |
+
# Import firebase initialization
|
| 20 |
+
from . import firebase_app
|
auth_app/firebase_app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from django.conf import settings
|
| 3 |
+
import firebase_admin
|
| 4 |
+
from firebase_admin import credentials
|
| 5 |
+
|
| 6 |
+
def initialize_firebase():
|
| 7 |
+
if not firebase_admin._apps:
|
| 8 |
+
cred_data = getattr(settings, "FIREBASE_SERVICE_KEY", None)
|
| 9 |
+
if not cred_data:
|
| 10 |
+
raise RuntimeError("FIREBASE_SERVICE_KEY is not set in environment variables")
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
# Parse the JSON string from environment
|
| 14 |
+
cred_dict = json.loads(cred_data)
|
| 15 |
+
cred = credentials.Certificate(cred_dict)
|
| 16 |
+
firebase_admin.initialize_app(cred)
|
| 17 |
+
except json.JSONDecodeError:
|
| 18 |
+
raise RuntimeError("FIREBASE_SERVICE_KEY is not valid JSON")
|
| 19 |
+
except Exception as e:
|
| 20 |
+
raise RuntimeError(f"Failed to initialize Firebase: {e}")
|
auth_app/management/__init__.py
ADDED
|
File without changes
|
auth_app/management/commands/__init__.py
ADDED
|
File without changes
|
auth_app/management/commands/createsuperadmin.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.core.management.base import BaseCommand
|
| 2 |
+
from django.contrib.auth import get_user_model
|
| 3 |
+
from django.db import transaction
|
| 4 |
+
|
| 5 |
+
User = get_user_model()
|
| 6 |
+
|
| 7 |
+
class Command(BaseCommand):
|
| 8 |
+
help = 'Creates a superuser with admin role'
|
| 9 |
+
|
| 10 |
+
def add_arguments(self, parser):
|
| 11 |
+
parser.add_argument('--username', dest='username', default=None, help='Specifies the username for the superuser.')
|
| 12 |
+
parser.add_argument('--email', dest='email', default=None, help='Specifies the email for the superuser.')
|
| 13 |
+
parser.add_argument('--password', dest='password', default=None, help='Specifies the password for the superuser.')
|
| 14 |
+
parser.add_argument('--noinput', action='store_true', dest='noinput', help='Tells Django to NOT prompt the user for input of any kind.')
|
| 15 |
+
|
| 16 |
+
def handle(self, *args, **options):
|
| 17 |
+
username = options['username']
|
| 18 |
+
email = options['email']
|
| 19 |
+
password = options['password']
|
| 20 |
+
interactive = not options['noinput']
|
| 21 |
+
|
| 22 |
+
# If not provided, prompt for username/email/password
|
| 23 |
+
if interactive:
|
| 24 |
+
if username is None:
|
| 25 |
+
username = input('Username: ')
|
| 26 |
+
if email is None:
|
| 27 |
+
email = input('Email address: ')
|
| 28 |
+
if password is None:
|
| 29 |
+
password = input('Password: ')
|
| 30 |
+
|
| 31 |
+
if not username or not email or not password:
|
| 32 |
+
self.stdout.write(self.style.ERROR('Error: username, email, and password are required'))
|
| 33 |
+
return
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
with transaction.atomic():
|
| 37 |
+
user = User.objects.create_superuser(
|
| 38 |
+
username=username,
|
| 39 |
+
email=email,
|
| 40 |
+
password=password
|
| 41 |
+
)
|
| 42 |
+
# Set the role to ADMIN
|
| 43 |
+
user.role = 'ADMIN'
|
| 44 |
+
user.save()
|
| 45 |
+
|
| 46 |
+
self.stdout.write(self.style.SUCCESS(f'Superadmin user {username} created successfully'))
|
| 47 |
+
except Exception as e:
|
| 48 |
+
self.stdout.write(self.style.ERROR(f'Error creating superadmin user: {str(e)}'))
|
auth_app/migrations/__init__.py
ADDED
|
File without changes
|
auth_app/models.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import models
|
| 2 |
+
from django.contrib.auth.models import AbstractUser, UserManager
|
| 3 |
+
import uuid
|
| 4 |
+
|
| 5 |
+
class CustomUserManager(UserManager):
|
| 6 |
+
def create_superuser(self, username, email=None, password=None, **extra_fields):
|
| 7 |
+
extra_fields.setdefault('is_staff', True)
|
| 8 |
+
extra_fields.setdefault('is_superuser', True)
|
| 9 |
+
extra_fields.setdefault('role', 'ADMIN') # Set role to ADMIN for superusers
|
| 10 |
+
|
| 11 |
+
if extra_fields.get('is_staff') is not True:
|
| 12 |
+
raise ValueError('Superuser must have is_staff=True.')
|
| 13 |
+
if extra_fields.get('is_superuser') is not True:
|
| 14 |
+
raise ValueError('Superuser must have is_superuser=True.')
|
| 15 |
+
|
| 16 |
+
return self._create_user(username, email, password, **extra_fields)
|
| 17 |
+
|
| 18 |
+
class User(AbstractUser):
|
| 19 |
+
ROLE_CHOICES = (
|
| 20 |
+
('ADMIN', 'Admin'),
|
| 21 |
+
('RESEARCHER', 'Researcher'),
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
STATUS_CHOICES = (
|
| 25 |
+
('ACTIVE', 'Active'),
|
| 26 |
+
('FROZEN', 'Frozen'),
|
| 27 |
+
('INACTIVE', 'Inactive'),
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
| 31 |
+
role = models.CharField(max_length=20, choices=ROLE_CHOICES, default='RESEARCHER')
|
| 32 |
+
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='ACTIVE')
|
| 33 |
+
|
| 34 |
+
objects = CustomUserManager()
|
| 35 |
+
|
| 36 |
+
class Meta:
|
| 37 |
+
verbose_name = 'User'
|
| 38 |
+
verbose_name_plural = 'Users'
|
auth_app/serializers.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rest_framework import serializers
|
| 2 |
+
from .models import User
|
| 3 |
+
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
| 4 |
+
|
| 5 |
+
class UserSerializer(serializers.ModelSerializer):
|
| 6 |
+
class Meta:
|
| 7 |
+
model = User
|
| 8 |
+
fields = ['id', 'username', 'email', 'role', 'status']
|
| 9 |
+
read_only_fields = ['id']
|
| 10 |
+
|
| 11 |
+
class UserRegistrationSerializer(serializers.ModelSerializer):
|
| 12 |
+
password = serializers.CharField(write_only=True)
|
| 13 |
+
|
| 14 |
+
class Meta:
|
| 15 |
+
model = User
|
| 16 |
+
fields = ['username', 'email', 'password','role']
|
| 17 |
+
|
| 18 |
+
def create(self, validated_data):
|
| 19 |
+
user = User.objects.create_user(
|
| 20 |
+
username=validated_data['username'],
|
| 21 |
+
email=validated_data['email'],
|
| 22 |
+
password=validated_data['password'],
|
| 23 |
+
role=validated_data.get('role', 'RESEARCHER')
|
| 24 |
+
)
|
| 25 |
+
return user
|
| 26 |
+
|
| 27 |
+
class LoginSerializer(serializers.Serializer):
|
| 28 |
+
username = serializers.CharField()
|
| 29 |
+
password = serializers.CharField()
|
| 30 |
+
|
| 31 |
+
class CustomTokenObtainPairSerializer(TokenObtainPairSerializer):
|
| 32 |
+
def validate(self, attrs):
|
| 33 |
+
data = super().validate(attrs)
|
| 34 |
+
|
| 35 |
+
# Add refresh and access tokens
|
| 36 |
+
data['refresh'] = str(self.get_token(self.user))
|
| 37 |
+
data['access'] = str(self.get_token(self.user).access_token)
|
| 38 |
+
|
| 39 |
+
# Add user info
|
| 40 |
+
data['user'] = {
|
| 41 |
+
"id": self.user.id,
|
| 42 |
+
"username": self.user.username,
|
| 43 |
+
"email": self.user.email,
|
| 44 |
+
"role": self.user.role,
|
| 45 |
+
"status": self.user.status,
|
| 46 |
+
}
|
| 47 |
+
return data
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class FirebaseLoginSerializer(serializers.Serializer):
|
| 51 |
+
id_token = serializers.CharField(write_only=True)
|
auth_app/urls.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.urls import path
|
| 2 |
+
from . import views
|
| 3 |
+
|
| 4 |
+
urlpatterns = [
|
| 5 |
+
path('register/', views.register, name='register'),
|
| 6 |
+
path('login/', views.LoginView.as_view(), name='login'),
|
| 7 |
+
path('me/', views.me, name='me'),
|
| 8 |
+
path('google/', views.google_login, name='google_login'),
|
| 9 |
+
]
|
auth_app/utils.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rest_framework.permissions import BasePermission
|
| 2 |
+
|
| 3 |
+
class IsAdmin(BasePermission):
|
| 4 |
+
"""
|
| 5 |
+
Custom permission to only allow admin users to access the view.
|
| 6 |
+
"""
|
| 7 |
+
def has_permission(self, request, view):
|
| 8 |
+
return request.user and request.user.is_authenticated and request.user.role == 'ADMIN'
|
| 9 |
+
|
| 10 |
+
class IsNotFrozen(BasePermission):
|
| 11 |
+
"""
|
| 12 |
+
Custom permission to prevent frozen accounts from accessing views.
|
| 13 |
+
"""
|
| 14 |
+
def has_permission(self, request, view):
|
| 15 |
+
return request.user and request.user.is_authenticated and request.user.status != 'FROZEN'
|
auth_app/views.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rest_framework import status
|
| 2 |
+
from django.views.decorators.csrf import csrf_exempt
|
| 3 |
+
from rest_framework.decorators import api_view, permission_classes
|
| 4 |
+
from rest_framework.response import Response
|
| 5 |
+
from rest_framework.permissions import AllowAny, IsAuthenticated
|
| 6 |
+
from rest_framework_simplejwt.views import TokenObtainPairView
|
| 7 |
+
from .serializers import (
|
| 8 |
+
UserSerializer,
|
| 9 |
+
UserRegistrationSerializer,
|
| 10 |
+
CustomTokenObtainPairSerializer
|
| 11 |
+
)
|
| 12 |
+
from .models import User
|
| 13 |
+
from django.db import transaction
|
| 14 |
+
from .serializers import FirebaseLoginSerializer
|
| 15 |
+
from .utils import IsAdmin
|
| 16 |
+
from rest_framework_simplejwt.tokens import RefreshToken
|
| 17 |
+
from firebase_admin import auth as firebase_auth
|
| 18 |
+
import auth_app.firebase_app
|
| 19 |
+
from django.utils.text import slugify
|
| 20 |
+
|
| 21 |
+
@api_view(['POST'])
|
| 22 |
+
@permission_classes([AllowAny])
|
| 23 |
+
def register(request):
|
| 24 |
+
serializer = UserRegistrationSerializer(data=request.data)
|
| 25 |
+
if serializer.is_valid():
|
| 26 |
+
user = serializer.save()
|
| 27 |
+
return Response({
|
| 28 |
+
"message": "User registered successfully",
|
| 29 |
+
"user": {
|
| 30 |
+
"id": user.id,
|
| 31 |
+
"email": user.email,
|
| 32 |
+
"first_name": user.first_name,
|
| 33 |
+
"last_name": user.last_name,
|
| 34 |
+
"role": user.role,
|
| 35 |
+
}
|
| 36 |
+
}, status=status.HTTP_201_CREATED)
|
| 37 |
+
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
| 38 |
+
|
| 39 |
+
class LoginView(TokenObtainPairView):
|
| 40 |
+
permission_classes = [AllowAny]
|
| 41 |
+
serializer_class = CustomTokenObtainPairSerializer
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@api_view(['GET'])
|
| 45 |
+
@permission_classes([IsAuthenticated])
|
| 46 |
+
def me(request):
|
| 47 |
+
serializer = UserSerializer(request.user)
|
| 48 |
+
return Response(serializer.data)
|
| 49 |
+
|
| 50 |
+
def _issue_tokens_for_user(user: User) -> dict:
|
| 51 |
+
"""Create SimpleJWT tokens and return the same response shape as your normal login."""
|
| 52 |
+
refresh = RefreshToken.for_user(user)
|
| 53 |
+
return {
|
| 54 |
+
"refresh": str(refresh),
|
| 55 |
+
"access": str(refresh.access_token),
|
| 56 |
+
"user": {
|
| 57 |
+
"id": str(user.id),
|
| 58 |
+
"username": user.username,
|
| 59 |
+
"email": user.email,
|
| 60 |
+
"role": getattr(user, "role", None),
|
| 61 |
+
"status": getattr(user, "status", None),
|
| 62 |
+
},
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
@csrf_exempt
|
| 66 |
+
@api_view(["POST"])
|
| 67 |
+
@permission_classes([AllowAny])
|
| 68 |
+
@transaction.atomic
|
| 69 |
+
def google_login(request):
|
| 70 |
+
"""
|
| 71 |
+
Accepts a Firebase ID token from the client (Google sign-in),
|
| 72 |
+
verifies it with Firebase Admin, upserts a local User, and
|
| 73 |
+
returns SimpleJWT tokens.
|
| 74 |
+
"""
|
| 75 |
+
serializer = FirebaseLoginSerializer(data=request.data)
|
| 76 |
+
serializer.is_valid(raise_exception=True)
|
| 77 |
+
id_token = serializer.validated_data["id_token"]
|
| 78 |
+
|
| 79 |
+
# 1) Verify the Firebase ID token (raises if invalid/expired)
|
| 80 |
+
try:
|
| 81 |
+
decoded = firebase_auth.verify_id_token(id_token)
|
| 82 |
+
except Exception as e:
|
| 83 |
+
import traceback
|
| 84 |
+
traceback.print_exc()
|
| 85 |
+
return Response({"detail": f"Invalid Firebase token: {str(e)}"}, status=status.HTTP_401_UNAUTHORIZED)
|
| 86 |
+
|
| 87 |
+
# 2) Extract claims
|
| 88 |
+
email = decoded.get("email")
|
| 89 |
+
email_verified = decoded.get("email_verified", False)
|
| 90 |
+
name = decoded.get("name") or ""
|
| 91 |
+
uid = decoded.get("uid")
|
| 92 |
+
sign_in_provider = (decoded.get("firebase") or {}).get("sign_in_provider")
|
| 93 |
+
|
| 94 |
+
# Optional hard checks
|
| 95 |
+
if sign_in_provider != "google.com":
|
| 96 |
+
return Response({"detail": "Not a Google sign-in token."}, status=status.HTTP_400_BAD_REQUEST)
|
| 97 |
+
if not email or not email_verified:
|
| 98 |
+
return Response({"detail": "Email missing or not verified."}, status=status.HTTP_400_BAD_REQUEST)
|
| 99 |
+
|
| 100 |
+
# 3) Upsert user in your DB
|
| 101 |
+
try:
|
| 102 |
+
user = User.objects.get(email__iexact=email)
|
| 103 |
+
except User.DoesNotExist:
|
| 104 |
+
base_username = slugify(email.split("@")[0]) or (uid or "")[:8] or "user"
|
| 105 |
+
username = base_username
|
| 106 |
+
counter = 1
|
| 107 |
+
while User.objects.filter(username__iexact=username).exists():
|
| 108 |
+
counter += 1
|
| 109 |
+
username = f"{base_username}{counter}"
|
| 110 |
+
|
| 111 |
+
user = User.objects.create_user(
|
| 112 |
+
username=username,
|
| 113 |
+
email=email,
|
| 114 |
+
password=None, # no local password; Google-only sign-in
|
| 115 |
+
# set defaults if your User has extra fields:
|
| 116 |
+
role="RESEARCHER",
|
| 117 |
+
status="ACTIVE",
|
| 118 |
+
)
|
| 119 |
+
user.set_unusable_password()
|
| 120 |
+
if " " in name:
|
| 121 |
+
first, last = name.split(" ", 1)
|
| 122 |
+
user.first_name, user.last_name = first, last
|
| 123 |
+
else:
|
| 124 |
+
user.first_name = name
|
| 125 |
+
user.save()
|
| 126 |
+
|
| 127 |
+
# 4) Optional gate (e.g., only ACTIVE users)
|
| 128 |
+
if getattr(user, "status", "ACTIVE") != "ACTIVE":
|
| 129 |
+
return Response({"detail": f"Account {user.status}."}, status=status.HTTP_403_FORBIDDEN)
|
| 130 |
+
|
| 131 |
+
# 5) Mint SimpleJWT tokens and return
|
| 132 |
+
return Response(_issue_tokens_for_user(user), status=status.HTTP_200_OK)
|
manage.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Django's command-line utility for administrative tasks."""
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def main():
|
| 8 |
+
"""Run administrative tasks."""
|
| 9 |
+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pms_server.settings")
|
| 10 |
+
try:
|
| 11 |
+
from django.core.management import execute_from_command_line
|
| 12 |
+
except ImportError as exc:
|
| 13 |
+
raise ImportError(
|
| 14 |
+
"Couldn't import Django. Are you sure it's installed and "
|
| 15 |
+
"available on your PYTHONPATH environment variable? Did you "
|
| 16 |
+
"forget to activate a virtual environment?"
|
| 17 |
+
) from exc
|
| 18 |
+
execute_from_command_line(sys.argv)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
main()
|
package-lock.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "pms_backend",
|
| 3 |
+
"lockfileVersion": 3,
|
| 4 |
+
"requires": true,
|
| 5 |
+
"packages": {}
|
| 6 |
+
}
|
pms_server/__init__.py
ADDED
|
File without changes
|
pms_server/asgi.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ASGI config for pms_server project.
|
| 3 |
+
|
| 4 |
+
It exposes the ASGI callable as a module-level variable named ``application``.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
from django.core.asgi import get_asgi_application
|
| 13 |
+
|
| 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Django settings for pms_server project.
|
| 3 |
+
|
| 4 |
+
Generated by 'django-admin startproject' using Django 5.2.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/5.2/topics/settings/
|
| 8 |
+
|
| 9 |
+
For the full list of settings and their values, see
|
| 10 |
+
https://docs.djangoproject.com/en/5.2/ref/settings/
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
import os
|
| 15 |
+
from datetime import timedelta
|
| 16 |
+
from dotenv import load_dotenv
|
| 17 |
+
|
| 18 |
+
load_dotenv()
|
| 19 |
+
|
| 20 |
+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
| 21 |
+
BASE_DIR = Path(__file__).resolve().parent.parent
|
| 22 |
+
FIREBASE_SERVICE_KEY = os.getenv("FIREBASE_SERVICE_KEY")
|
| 23 |
+
|
| 24 |
+
STATIC_URL = "/static/"
|
| 25 |
+
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
|
| 26 |
+
|
| 27 |
+
# Quick-start development settings - unsuitable for production
|
| 28 |
+
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
| 29 |
+
|
| 30 |
+
# SECURITY WARNING: keep the secret key used in production secret!
|
| 31 |
+
SECRET_KEY = "django-insecure-%_zip)z12qf9n$%2mzz!fc$0u@zvd+i(3#v%-g=1#k*$v5080j"
|
| 32 |
+
|
| 33 |
+
# SECURITY WARNING: don't run with debug turned on in production!
|
| 34 |
+
DEBUG = True
|
| 35 |
+
|
| 36 |
+
ALLOWED_HOSTS = ["*"]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# Application definition
|
| 40 |
+
|
| 41 |
+
INSTALLED_APPS = [
|
| 42 |
+
"django.contrib.admin",
|
| 43 |
+
"django.contrib.auth",
|
| 44 |
+
"django.contrib.contenttypes",
|
| 45 |
+
"django.contrib.sessions",
|
| 46 |
+
"django.contrib.messages",
|
| 47 |
+
"django.contrib.staticfiles",
|
| 48 |
+
"rest_framework",
|
| 49 |
+
"rest_framework.authtoken",
|
| 50 |
+
"corsheaders",
|
| 51 |
+
"auth_app.apps.AuthAppConfig",
|
| 52 |
+
"admin_app",
|
| 53 |
+
"api",
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
MIDDLEWARE = [
|
| 57 |
+
"corsheaders.middleware.CorsMiddleware",
|
| 58 |
+
"django.middleware.security.SecurityMiddleware",
|
| 59 |
+
"django.contrib.sessions.middleware.SessionMiddleware",
|
| 60 |
+
"django.middleware.common.CommonMiddleware",
|
| 61 |
+
"django.middleware.csrf.CsrfViewMiddleware",
|
| 62 |
+
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
| 63 |
+
"django.contrib.messages.middleware.MessageMiddleware",
|
| 64 |
+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
| 65 |
+
]
|
| 66 |
+
|
| 67 |
+
# Allow iframes to display content from the same origin
|
| 68 |
+
X_FRAME_OPTIONS = 'SAMEORIGIN'
|
| 69 |
+
|
| 70 |
+
CORS_ALLOWED_ORIGINS = [
|
| 71 |
+
"http://localhost:3000", # React local dev server
|
| 72 |
+
"http://127.0.0.1:3000",
|
| 73 |
+
"http://localhost:5173",
|
| 74 |
+
"https://paper-management-system.netlify.app", # Deployed React app
|
| 75 |
+
]
|
| 76 |
+
|
| 77 |
+
# Allow all CORS headers and methods for API testing
|
| 78 |
+
CORS_ALLOW_ALL_ORIGINS = True
|
| 79 |
+
CORS_ALLOW_CREDENTIALS = True
|
| 80 |
+
CORS_ALLOW_METHODS = [
|
| 81 |
+
'DELETE',
|
| 82 |
+
'GET',
|
| 83 |
+
'OPTIONS',
|
| 84 |
+
'PATCH',
|
| 85 |
+
'POST',
|
| 86 |
+
'PUT',
|
| 87 |
+
]
|
| 88 |
+
CORS_ALLOW_HEADERS = [
|
| 89 |
+
'accept',
|
| 90 |
+
'accept-encoding',
|
| 91 |
+
'authorization',
|
| 92 |
+
'content-type',
|
| 93 |
+
'dnt',
|
| 94 |
+
'origin',
|
| 95 |
+
'user-agent',
|
| 96 |
+
'x-csrftoken',
|
| 97 |
+
'x-requested-with',
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
ROOT_URLCONF = "pms_server.urls"
|
| 101 |
+
|
| 102 |
+
TEMPLATES = [
|
| 103 |
+
{
|
| 104 |
+
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
| 105 |
+
"DIRS": [],
|
| 106 |
+
"APP_DIRS": True,
|
| 107 |
+
"OPTIONS": {
|
| 108 |
+
"context_processors": [
|
| 109 |
+
'django.template.context_processors.debug',
|
| 110 |
+
"django.template.context_processors.request",
|
| 111 |
+
"django.contrib.auth.context_processors.auth",
|
| 112 |
+
"django.contrib.messages.context_processors.messages",
|
| 113 |
+
],
|
| 114 |
+
},
|
| 115 |
+
},
|
| 116 |
+
]
|
| 117 |
+
|
| 118 |
+
WSGI_APPLICATION = "pms_server.wsgi.application"
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
# Database
|
| 122 |
+
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
| 123 |
+
|
| 124 |
+
# Default DB path (local)
|
| 125 |
+
db_path = BASE_DIR / "db.sqlite3"
|
| 126 |
+
|
| 127 |
+
# if os.getenv("SPACE_ID"):
|
| 128 |
+
# db_path = Path("/data/db.sqlite3")
|
| 129 |
+
|
| 130 |
+
DATABASES = {
|
| 131 |
+
"default": {
|
| 132 |
+
"ENGINE": "django.db.backends.sqlite3",
|
| 133 |
+
"NAME": db_path,
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
# Password validation
|
| 138 |
+
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
|
| 139 |
+
|
| 140 |
+
AUTH_PASSWORD_VALIDATORS = [
|
| 141 |
+
{
|
| 142 |
+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
| 152 |
+
},
|
| 153 |
+
]
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
# Internationalization
|
| 157 |
+
# https://docs.djangoproject.com/en/5.2/topics/i18n/
|
| 158 |
+
|
| 159 |
+
LANGUAGE_CODE = "en-us"
|
| 160 |
+
|
| 161 |
+
TIME_ZONE = "UTC"
|
| 162 |
+
|
| 163 |
+
USE_I18N = True
|
| 164 |
+
|
| 165 |
+
USE_TZ = True
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
# Static files (CSS, JavaScript, Images)
|
| 169 |
+
# https://docs.djangoproject.com/en/5.2/howto/static-files/
|
| 170 |
+
|
| 171 |
+
STATIC_URL = "static/"
|
| 172 |
+
|
| 173 |
+
# Media files (Uploads)
|
| 174 |
+
MEDIA_URL = '/media/'
|
| 175 |
+
MEDIA_ROOT = BASE_DIR / 'media'
|
| 176 |
+
|
| 177 |
+
# File type specific storage paths
|
| 178 |
+
PDF_STORAGE_PATH = 'pdf_files'
|
| 179 |
+
LATEX_STORAGE_PATH = 'latex_files'
|
| 180 |
+
PYTHON_STORAGE_PATH = 'python_files'
|
| 181 |
+
DOCX_STORAGE_PATH = 'docx_files'
|
| 182 |
+
|
| 183 |
+
# Default primary key field type
|
| 184 |
+
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
| 185 |
+
|
| 186 |
+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
| 187 |
+
|
| 188 |
+
# REST Framework settings
|
| 189 |
+
REST_FRAMEWORK = {
|
| 190 |
+
'DEFAULT_AUTHENTICATION_CLASSES': [
|
| 191 |
+
'rest_framework_simplejwt.authentication.JWTAuthentication'
|
| 192 |
+
],
|
| 193 |
+
'DEFAULT_PERMISSION_CLASSES': [
|
| 194 |
+
'rest_framework.permissions.IsAuthenticated',
|
| 195 |
+
],
|
| 196 |
+
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
| 197 |
+
'PAGE_SIZE': 20,
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
# Custom user model
|
| 201 |
+
AUTH_USER_MODEL = 'auth_app.User'
|
| 202 |
+
|
| 203 |
+
CORS_ALLOW_ALL_ORIGINS = True
|
| 204 |
+
|
| 205 |
+
SIMPLE_JWT = {
|
| 206 |
+
"ACCESS_TOKEN_LIFETIME": timedelta(hours=1),
|
| 207 |
+
"REFRESH_TOKEN_LIFETIME": timedelta(days=7),
|
| 208 |
+
"ROTATE_REFRESH_TOKENS": True,
|
| 209 |
+
"BLACKLIST_AFTER_ROTATION": True
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
# Allowed headers for CORS requests
|
| 213 |
+
CORS_ALLOW_HEADERS = [
|
| 214 |
+
"accept",
|
| 215 |
+
"accept-encoding",
|
| 216 |
+
"authorization",
|
| 217 |
+
"content-type",
|
| 218 |
+
"dnt",
|
| 219 |
+
"origin",
|
| 220 |
+
"user-agent",
|
| 221 |
+
"x-csrftoken",
|
| 222 |
+
"x-requested-with",
|
| 223 |
+
]
|
| 224 |
+
|
| 225 |
+
# Allowed methods for CORS requests
|
| 226 |
+
CORS_ALLOW_METHODS = [
|
| 227 |
+
"DELETE",
|
| 228 |
+
"GET",
|
| 229 |
+
"OPTIONS",
|
| 230 |
+
"PATCH",
|
| 231 |
+
"POST",
|
| 232 |
+
"PUT",
|
| 233 |
+
]
|
| 234 |
+
|
| 235 |
+
FIREBASE_CREDENTIALS_FILE = os.environ.get("FIREBASE_CREDENTIALS_FILE")
|
| 236 |
+
|
| 237 |
+
# Preflight request max age (in seconds)
|
| 238 |
+
CORS_PREFLIGHT_MAX_AGE = 86400
|
| 239 |
+
|
| 240 |
+
# Expose these headers to the frontend
|
| 241 |
+
CORS_EXPOSE_HEADERS = [
|
| 242 |
+
"content-type",
|
| 243 |
+
"x-csrftoken",
|
| 244 |
+
]
|
| 245 |
+
|
| 246 |
+
# Additional CORS settings for better React integration
|
| 247 |
+
CORS_ALLOW_PRIVATE_NETWORK = True
|
| 248 |
+
|
| 249 |
+
APPEND_SLASH=False
|
| 250 |
+
|
pms_server/urls.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
URL configuration for pms_server project.
|
| 3 |
+
|
| 4 |
+
The `urlpatterns` list routes URLs to views. For more information please see:
|
| 5 |
+
https://docs.djangoproject.com/en/5.2/topics/http/urls/
|
| 6 |
+
Examples:
|
| 7 |
+
Function views
|
| 8 |
+
1. Add an import: from my_app import views
|
| 9 |
+
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
| 10 |
+
Class-based views
|
| 11 |
+
1. Add an import: from other_app.views import Home
|
| 12 |
+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
| 13 |
+
Including another URLconf
|
| 14 |
+
1. Import the include() function: from django.urls import include, path
|
| 15 |
+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
from django.contrib import admin
|
| 19 |
+
from django.urls import path, include
|
| 20 |
+
from django.conf import settings
|
| 21 |
+
from django.conf.urls.static import static
|
| 22 |
+
|
| 23 |
+
urlpatterns = [
|
| 24 |
+
path("admin/", admin.site.urls),
|
| 25 |
+
path("auth/", include("auth_app.urls")),
|
| 26 |
+
path("admin_app/", include("admin_app.urls")),
|
| 27 |
+
path("api/", include("api.urls")),
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
# Serve media files during development
|
| 31 |
+
if settings.DEBUG:
|
| 32 |
+
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
pms_server/wsgi.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
WSGI config for pms_server project.
|
| 3 |
+
|
| 4 |
+
It exposes the WSGI callable as a module-level variable named ``application``.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
from django.core.wsgi import get_wsgi_application
|
| 13 |
+
|
| 14 |
+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pms_server.settings")
|
| 15 |
+
|
| 16 |
+
application = get_wsgi_application()
|
postman.json
ADDED
|
@@ -0,0 +1,778 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"info": {
|
| 3 |
+
"_postman_id": "a_unique_id_for_this_collection",
|
| 4 |
+
"name": "RPMS Backend API",
|
| 5 |
+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
| 6 |
+
},
|
| 7 |
+
"item": [
|
| 8 |
+
{
|
| 9 |
+
"name": "Authentication",
|
| 10 |
+
"item": [
|
| 11 |
+
{
|
| 12 |
+
"name": "User Registration",
|
| 13 |
+
"request": {
|
| 14 |
+
"method": "POST",
|
| 15 |
+
"header": [
|
| 16 |
+
{
|
| 17 |
+
"key": "Content-Type",
|
| 18 |
+
"value": "application/json"
|
| 19 |
+
}
|
| 20 |
+
],
|
| 21 |
+
"body": {
|
| 22 |
+
"mode": "raw",
|
| 23 |
+
"raw": "{\n \"username\": \"testuser\",\n \"email\": \"test@example.com\",\n \"password\": \"password123\",\n \"role\": \"RESEARCHER\"\n}",
|
| 24 |
+
"options": {
|
| 25 |
+
"raw": {
|
| 26 |
+
"language": "json"
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
},
|
| 30 |
+
"url": {
|
| 31 |
+
"raw": "{{base_url}}/auth/register/",
|
| 32 |
+
"host": [
|
| 33 |
+
"{{base_url}}"
|
| 34 |
+
],
|
| 35 |
+
"path": [
|
| 36 |
+
"auth",
|
| 37 |
+
"register",
|
| 38 |
+
""
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
"description": "Registers a new user."
|
| 42 |
+
},
|
| 43 |
+
"response": []
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"name": "User Login",
|
| 47 |
+
"request": {
|
| 48 |
+
"method": "POST",
|
| 49 |
+
"header": [
|
| 50 |
+
{
|
| 51 |
+
"key": "Content-Type",
|
| 52 |
+
"value": "application/json"
|
| 53 |
+
}
|
| 54 |
+
],
|
| 55 |
+
"body": {
|
| 56 |
+
"mode": "raw",
|
| 57 |
+
"raw": "{\n \"username\": \"testuser\",\n \"password\": \"password123\"\n}",
|
| 58 |
+
"options": {
|
| 59 |
+
"raw": {
|
| 60 |
+
"language": "json"
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
},
|
| 64 |
+
"url": {
|
| 65 |
+
"raw": "{{base_url}}/auth/login/",
|
| 66 |
+
"host": [
|
| 67 |
+
"{{base_url}}"
|
| 68 |
+
],
|
| 69 |
+
"path": [
|
| 70 |
+
"auth",
|
| 71 |
+
"login",
|
| 72 |
+
""
|
| 73 |
+
]
|
| 74 |
+
},
|
| 75 |
+
"description": "Logs in a user and returns access and refresh tokens."
|
| 76 |
+
},
|
| 77 |
+
"response": []
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"name": "Get Current User",
|
| 81 |
+
"request": {
|
| 82 |
+
"method": "GET",
|
| 83 |
+
"header": [
|
| 84 |
+
{
|
| 85 |
+
"key": "Authorization",
|
| 86 |
+
"value": "Bearer {{access_token}}"
|
| 87 |
+
}
|
| 88 |
+
],
|
| 89 |
+
"url": {
|
| 90 |
+
"raw": "{{base_url}}/auth/me/",
|
| 91 |
+
"host": [
|
| 92 |
+
"{{base_url}}"
|
| 93 |
+
],
|
| 94 |
+
"path": [
|
| 95 |
+
"auth",
|
| 96 |
+
"me",
|
| 97 |
+
""
|
| 98 |
+
]
|
| 99 |
+
},
|
| 100 |
+
"description": "Retrieves details of the currently authenticated user."
|
| 101 |
+
},
|
| 102 |
+
"response": []
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"name": "Google Login",
|
| 106 |
+
"request": {
|
| 107 |
+
"method": "POST",
|
| 108 |
+
"header": [
|
| 109 |
+
{
|
| 110 |
+
"key": "Content-Type",
|
| 111 |
+
"value": "application/json"
|
| 112 |
+
}
|
| 113 |
+
],
|
| 114 |
+
"body": {
|
| 115 |
+
"mode": "raw",
|
| 116 |
+
"raw": "{\n \"id_token\": \"your_firebase_id_token_here\"\n}",
|
| 117 |
+
"options": {
|
| 118 |
+
"raw": {
|
| 119 |
+
"language": "json"
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
},
|
| 123 |
+
"url": {
|
| 124 |
+
"raw": "{{base_url}}/auth/google-login/",
|
| 125 |
+
"host": [
|
| 126 |
+
"{{base_url}}"
|
| 127 |
+
],
|
| 128 |
+
"path": [
|
| 129 |
+
"auth",
|
| 130 |
+
"google-login",
|
| 131 |
+
""
|
| 132 |
+
]
|
| 133 |
+
},
|
| 134 |
+
"description": "Authenticates a user with Google Firebase ID token and returns access and refresh tokens."
|
| 135 |
+
},
|
| 136 |
+
"response": []
|
| 137 |
+
}
|
| 138 |
+
]
|
| 139 |
+
},
|
| 140 |
+
{
|
| 141 |
+
"name": "Admin Application",
|
| 142 |
+
"item": [
|
| 143 |
+
{
|
| 144 |
+
"name": "Get All Users",
|
| 145 |
+
"request": {
|
| 146 |
+
"method": "GET",
|
| 147 |
+
"header": [
|
| 148 |
+
{
|
| 149 |
+
"key": "Authorization",
|
| 150 |
+
"value": "Bearer {{admin_access_token}}"
|
| 151 |
+
}
|
| 152 |
+
],
|
| 153 |
+
"url": {
|
| 154 |
+
"raw": "{{base_url}}/admin_app/users/",
|
| 155 |
+
"host": [
|
| 156 |
+
"{{base_url}}"
|
| 157 |
+
],
|
| 158 |
+
"path": [
|
| 159 |
+
"admin_app",
|
| 160 |
+
"users",
|
| 161 |
+
""
|
| 162 |
+
]
|
| 163 |
+
},
|
| 164 |
+
"description": "Retrieves a list of all users."
|
| 165 |
+
},
|
| 166 |
+
"response": []
|
| 167 |
+
},
|
| 168 |
+
{
|
| 169 |
+
"name": "Update User Status",
|
| 170 |
+
"request": {
|
| 171 |
+
"method": "PATCH",
|
| 172 |
+
"header": [
|
| 173 |
+
{
|
| 174 |
+
"key": "Content-Type",
|
| 175 |
+
"value": "application/json"
|
| 176 |
+
},
|
| 177 |
+
{
|
| 178 |
+
"key": "Authorization",
|
| 179 |
+
"value": "Bearer {{admin_access_token}}"
|
| 180 |
+
}
|
| 181 |
+
],
|
| 182 |
+
"body": {
|
| 183 |
+
"mode": "raw",
|
| 184 |
+
"raw": "{\n \"status\": \"ACTIVE\"\n}",
|
| 185 |
+
"options": {
|
| 186 |
+
"raw": {
|
| 187 |
+
"language": "json"
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
},
|
| 191 |
+
"url": {
|
| 192 |
+
"raw": "{{base_url}}/admin_app/updateusers/:username/status/",
|
| 193 |
+
"host": [
|
| 194 |
+
"{{base_url}}"
|
| 195 |
+
],
|
| 196 |
+
"path": [
|
| 197 |
+
"admin_app",
|
| 198 |
+
"updateusers",
|
| 199 |
+
":username",
|
| 200 |
+
"status",
|
| 201 |
+
""
|
| 202 |
+
],
|
| 203 |
+
"variable": [
|
| 204 |
+
{
|
| 205 |
+
"key": "username",
|
| 206 |
+
"value": ""
|
| 207 |
+
}
|
| 208 |
+
]
|
| 209 |
+
},
|
| 210 |
+
"description": "Updates the status of a specific user. Status must be one of: 'ACTIVE', 'FROZEN', 'INACTIVE'."
|
| 211 |
+
},
|
| 212 |
+
"response": []
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"name": "Assign Research Paper",
|
| 216 |
+
"request": {
|
| 217 |
+
"method": "POST",
|
| 218 |
+
"header": [
|
| 219 |
+
{
|
| 220 |
+
"key": "Content-Type",
|
| 221 |
+
"value": "application/json"
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
"key": "Authorization",
|
| 225 |
+
"value": "Bearer {{admin_access_token}}"
|
| 226 |
+
}
|
| 227 |
+
],
|
| 228 |
+
"body": {
|
| 229 |
+
"mode": "raw",
|
| 230 |
+
"raw": "{\n \"title\": \"New Research Paper\",\n \"abstract\": \"This is an abstract of the new paper.\",\n \"assigned_to\": \"researcher_username\"\n}",
|
| 231 |
+
"options": {
|
| 232 |
+
"raw": {
|
| 233 |
+
"language": "json"
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
},
|
| 237 |
+
"url": {
|
| 238 |
+
"raw": "{{base_url}}/admin_app/paperworks/",
|
| 239 |
+
"host": [
|
| 240 |
+
"{{base_url}}"
|
| 241 |
+
],
|
| 242 |
+
"path": [
|
| 243 |
+
"admin_app",
|
| 244 |
+
"paperworks",
|
| 245 |
+
""
|
| 246 |
+
]
|
| 247 |
+
},
|
| 248 |
+
"description": "Assigns a new research paper."
|
| 249 |
+
},
|
| 250 |
+
"response": []
|
| 251 |
+
},
|
| 252 |
+
{
|
| 253 |
+
"name": "Review Submission",
|
| 254 |
+
"request": {
|
| 255 |
+
"method": "POST",
|
| 256 |
+
"header": [
|
| 257 |
+
{
|
| 258 |
+
"key": "Content-Type",
|
| 259 |
+
"value": "application/json"
|
| 260 |
+
},
|
| 261 |
+
{
|
| 262 |
+
"key": "Authorization",
|
| 263 |
+
"value": "Bearer {{admin_access_token}}"
|
| 264 |
+
}
|
| 265 |
+
],
|
| 266 |
+
"body": {
|
| 267 |
+
"mode": "raw",
|
| 268 |
+
"raw": "{\n \"status\": \"APPROVED\",\n \"comments\": \"Great work!\"\n}",
|
| 269 |
+
"options": {
|
| 270 |
+
"raw": {
|
| 271 |
+
"language": "json"
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
},
|
| 275 |
+
"url": {
|
| 276 |
+
"raw": "{{base_url}}/api/paperworks/:id/review/",
|
| 277 |
+
"host": [
|
| 278 |
+
"{{base_url}}"
|
| 279 |
+
],
|
| 280 |
+
"path": [
|
| 281 |
+
"api",
|
| 282 |
+
"paperworks",
|
| 283 |
+
":id",
|
| 284 |
+
"review",
|
| 285 |
+
""
|
| 286 |
+
],
|
| 287 |
+
"variable": [
|
| 288 |
+
{
|
| 289 |
+
"key": "id",
|
| 290 |
+
"value": ""
|
| 291 |
+
}
|
| 292 |
+
]
|
| 293 |
+
},
|
| 294 |
+
"description": "Creates a new review for a paper submission. Status must be one of: 'ASSIGNED', 'SUBMITTED', 'CHANGES_REQUESTED', 'APPROVED'."
|
| 295 |
+
},
|
| 296 |
+
"response": []
|
| 297 |
+
}
|
| 298 |
+
]
|
| 299 |
+
},
|
| 300 |
+
{
|
| 301 |
+
"name": "API Application",
|
| 302 |
+
"item": [
|
| 303 |
+
{
|
| 304 |
+
"name": "Get All Paperworks",
|
| 305 |
+
"request": {
|
| 306 |
+
"method": "GET",
|
| 307 |
+
"header": [
|
| 308 |
+
{
|
| 309 |
+
"key": "Authorization",
|
| 310 |
+
"value": "Bearer {{access_token}}"
|
| 311 |
+
}
|
| 312 |
+
],
|
| 313 |
+
"url": {
|
| 314 |
+
"raw": "{{base_url}}/api/paperworks/",
|
| 315 |
+
"host": [
|
| 316 |
+
"{{base_url}}"
|
| 317 |
+
],
|
| 318 |
+
"path": [
|
| 319 |
+
"api",
|
| 320 |
+
"paperworks",
|
| 321 |
+
""
|
| 322 |
+
]
|
| 323 |
+
},
|
| 324 |
+
"description": "Retrieves a list of all paperworks."
|
| 325 |
+
},
|
| 326 |
+
"response": []
|
| 327 |
+
},
|
| 328 |
+
{
|
| 329 |
+
"name": "Get Single Paperwork",
|
| 330 |
+
"request": {
|
| 331 |
+
"method": "GET",
|
| 332 |
+
"header": [
|
| 333 |
+
{
|
| 334 |
+
"key": "Authorization",
|
| 335 |
+
"value": "Bearer {{access_token}}"
|
| 336 |
+
}
|
| 337 |
+
],
|
| 338 |
+
"url": {
|
| 339 |
+
"raw": "{{base_url}}/api/paperworks/:id/",
|
| 340 |
+
"host": [
|
| 341 |
+
"{{base_url}}"
|
| 342 |
+
],
|
| 343 |
+
"path": [
|
| 344 |
+
"api",
|
| 345 |
+
"paperworks",
|
| 346 |
+
":id",
|
| 347 |
+
""
|
| 348 |
+
],
|
| 349 |
+
"variable": [
|
| 350 |
+
{
|
| 351 |
+
"key": "id",
|
| 352 |
+
"value": ""
|
| 353 |
+
}
|
| 354 |
+
]
|
| 355 |
+
},
|
| 356 |
+
"description": "Retrieves details of a specific paperwork."
|
| 357 |
+
},
|
| 358 |
+
"response": []
|
| 359 |
+
},
|
| 360 |
+
{
|
| 361 |
+
"name": "Submit New Version of Paperwork",
|
| 362 |
+
"request": {
|
| 363 |
+
"method": "POST",
|
| 364 |
+
"header": [
|
| 365 |
+
{
|
| 366 |
+
"key": "Authorization",
|
| 367 |
+
"value": "Bearer {{access_token}}"
|
| 368 |
+
}
|
| 369 |
+
],
|
| 370 |
+
"body": {
|
| 371 |
+
"mode": "formdata",
|
| 372 |
+
"formdata": [
|
| 373 |
+
{
|
| 374 |
+
"key": "paper_pdf",
|
| 375 |
+
"type": "file",
|
| 376 |
+
"src": "",
|
| 377 |
+
"description": "PDF file (required)"
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"key": "latex_tex",
|
| 381 |
+
"type": "file",
|
| 382 |
+
"src": "",
|
| 383 |
+
"description": "LaTeX file (required)"
|
| 384 |
+
},
|
| 385 |
+
{
|
| 386 |
+
"key": "python_zip",
|
| 387 |
+
"type": "file",
|
| 388 |
+
"src": "",
|
| 389 |
+
"description": "Python code as ZIP file (required)"
|
| 390 |
+
},
|
| 391 |
+
{
|
| 392 |
+
"key": "docx_file",
|
| 393 |
+
"type": "file",
|
| 394 |
+
"src": "",
|
| 395 |
+
"description": "DOCX file (optional)"
|
| 396 |
+
},
|
| 397 |
+
{
|
| 398 |
+
"key": "ai_percent_self",
|
| 399 |
+
"value": "0.0",
|
| 400 |
+
"type": "text",
|
| 401 |
+
"description": "Self-reported AI percentage (optional)"
|
| 402 |
+
}
|
| 403 |
+
]
|
| 404 |
+
},
|
| 405 |
+
"url": {
|
| 406 |
+
"raw": "{{base_url}}/api/paperworks/:id/versions/",
|
| 407 |
+
"host": [
|
| 408 |
+
"{{base_url}}"
|
| 409 |
+
],
|
| 410 |
+
"path": [
|
| 411 |
+
"api",
|
| 412 |
+
"paperworks",
|
| 413 |
+
":id",
|
| 414 |
+
"versions",
|
| 415 |
+
""
|
| 416 |
+
],
|
| 417 |
+
"variable": [
|
| 418 |
+
{
|
| 419 |
+
"key": "id",
|
| 420 |
+
"value": ""
|
| 421 |
+
}
|
| 422 |
+
]
|
| 423 |
+
},
|
| 424 |
+
"description": "Submits a new version for an existing paperwork. Requires multipart form data with file uploads."
|
| 425 |
+
},
|
| 426 |
+
"response": []
|
| 427 |
+
},
|
| 428 |
+
{
|
| 429 |
+
"name": "Get All Versions of Paperwork",
|
| 430 |
+
"request": {
|
| 431 |
+
"method": "GET",
|
| 432 |
+
"header": [
|
| 433 |
+
{
|
| 434 |
+
"key": "Authorization",
|
| 435 |
+
"value": "Bearer {{access_token}}"
|
| 436 |
+
}
|
| 437 |
+
],
|
| 438 |
+
"url": {
|
| 439 |
+
"raw": "{{base_url}}/api/paperworks/:id/versions/",
|
| 440 |
+
"host": [
|
| 441 |
+
"{{base_url}}"
|
| 442 |
+
],
|
| 443 |
+
"path": [
|
| 444 |
+
"api",
|
| 445 |
+
"paperworks",
|
| 446 |
+
":id",
|
| 447 |
+
"versions",
|
| 448 |
+
""
|
| 449 |
+
],
|
| 450 |
+
"variable": [
|
| 451 |
+
{
|
| 452 |
+
"key": "id",
|
| 453 |
+
"value": ""
|
| 454 |
+
}
|
| 455 |
+
]
|
| 456 |
+
},
|
| 457 |
+
"description": "Retrieves all versions of a specific paperwork."
|
| 458 |
+
},
|
| 459 |
+
"response": []
|
| 460 |
+
},
|
| 461 |
+
{
|
| 462 |
+
"name": "Delete Paper Work",
|
| 463 |
+
"request": {
|
| 464 |
+
"method": "DELETE",
|
| 465 |
+
"header": [
|
| 466 |
+
{
|
| 467 |
+
"key": "Authorization",
|
| 468 |
+
"value": "Bearer {{access_token}}"
|
| 469 |
+
}
|
| 470 |
+
],
|
| 471 |
+
"url": {
|
| 472 |
+
"raw": "{{base_url}}/api/paperworks/:id/",
|
| 473 |
+
"host": [
|
| 474 |
+
"{{base_url}}"
|
| 475 |
+
],
|
| 476 |
+
"path": [
|
| 477 |
+
"api",
|
| 478 |
+
"paperworks",
|
| 479 |
+
":id",
|
| 480 |
+
""
|
| 481 |
+
],
|
| 482 |
+
"variable": [
|
| 483 |
+
{
|
| 484 |
+
"key": "id",
|
| 485 |
+
"value": ""
|
| 486 |
+
}
|
| 487 |
+
]
|
| 488 |
+
},
|
| 489 |
+
"description": "Deletes a paperwork. Only available to researchers who own the paperwork."
|
| 490 |
+
},
|
| 491 |
+
"response": []
|
| 492 |
+
},
|
| 493 |
+
{
|
| 494 |
+
"name": "Get Specific Version of Paperwork",
|
| 495 |
+
"request": {
|
| 496 |
+
"method": "GET",
|
| 497 |
+
"header": [
|
| 498 |
+
{
|
| 499 |
+
"key": "Authorization",
|
| 500 |
+
"value": "Bearer {{access_token}}"
|
| 501 |
+
}
|
| 502 |
+
],
|
| 503 |
+
"url": {
|
| 504 |
+
"raw": "{{base_url}}/api/paperworks/:id/versions/:version_id/",
|
| 505 |
+
"host": [
|
| 506 |
+
"{{base_url}}"
|
| 507 |
+
],
|
| 508 |
+
"path": [
|
| 509 |
+
"api",
|
| 510 |
+
"paperworks",
|
| 511 |
+
":id",
|
| 512 |
+
"versions",
|
| 513 |
+
":version_id",
|
| 514 |
+
""
|
| 515 |
+
],
|
| 516 |
+
"variable": [
|
| 517 |
+
{
|
| 518 |
+
"key": "id",
|
| 519 |
+
"value": ""
|
| 520 |
+
},
|
| 521 |
+
{
|
| 522 |
+
"key": "version_id",
|
| 523 |
+
"value": ""
|
| 524 |
+
}
|
| 525 |
+
]
|
| 526 |
+
},
|
| 527 |
+
"description": "Retrieves a specific version of a paperwork."
|
| 528 |
+
},
|
| 529 |
+
"response": []
|
| 530 |
+
},
|
| 531 |
+
{
|
| 532 |
+
"name": "Get All Paperwork Reviews",
|
| 533 |
+
"request": {
|
| 534 |
+
"method": "GET",
|
| 535 |
+
"header": [
|
| 536 |
+
{
|
| 537 |
+
"key": "Authorization",
|
| 538 |
+
"value": "Bearer {{access_token}}"
|
| 539 |
+
}
|
| 540 |
+
],
|
| 541 |
+
"url": {
|
| 542 |
+
"raw": "{{base_url}}/api/paperworks/:id/reviews/",
|
| 543 |
+
"host": [
|
| 544 |
+
"{{base_url}}"
|
| 545 |
+
],
|
| 546 |
+
"path": [
|
| 547 |
+
"api",
|
| 548 |
+
"paperworks",
|
| 549 |
+
":id",
|
| 550 |
+
"reviews",
|
| 551 |
+
""
|
| 552 |
+
],
|
| 553 |
+
"variable": [
|
| 554 |
+
{
|
| 555 |
+
"key": "id",
|
| 556 |
+
"value": ""
|
| 557 |
+
}
|
| 558 |
+
]
|
| 559 |
+
},
|
| 560 |
+
"description": "Retrieves all reviews for a specific paperwork."
|
| 561 |
+
},
|
| 562 |
+
"response": []
|
| 563 |
+
},
|
| 564 |
+
{
|
| 565 |
+
"name": "Get Specific Paperwork Review",
|
| 566 |
+
"request": {
|
| 567 |
+
"method": "GET",
|
| 568 |
+
"header": [
|
| 569 |
+
{
|
| 570 |
+
"key": "Authorization",
|
| 571 |
+
"value": "Bearer {{access_token}}"
|
| 572 |
+
}
|
| 573 |
+
],
|
| 574 |
+
"url": {
|
| 575 |
+
"raw": "{{base_url}}/api/paperworks/:id/reviews/:review_id/",
|
| 576 |
+
"host": [
|
| 577 |
+
"{{base_url}}"
|
| 578 |
+
],
|
| 579 |
+
"path": [
|
| 580 |
+
"api",
|
| 581 |
+
"paperworks",
|
| 582 |
+
":id",
|
| 583 |
+
"reviews",
|
| 584 |
+
":review_id",
|
| 585 |
+
""
|
| 586 |
+
],
|
| 587 |
+
"variable": [
|
| 588 |
+
{
|
| 589 |
+
"key": "id",
|
| 590 |
+
"value": ""
|
| 591 |
+
},
|
| 592 |
+
{
|
| 593 |
+
"key": "review_id",
|
| 594 |
+
"value": ""
|
| 595 |
+
}
|
| 596 |
+
]
|
| 597 |
+
},
|
| 598 |
+
"description": "Retrieves a specific review for a paperwork."
|
| 599 |
+
},
|
| 600 |
+
"response": []
|
| 601 |
+
},
|
| 602 |
+
{
|
| 603 |
+
"name": "Get Summary Report",
|
| 604 |
+
"request": {
|
| 605 |
+
"method": "GET",
|
| 606 |
+
"header": [
|
| 607 |
+
{
|
| 608 |
+
"key": "Authorization",
|
| 609 |
+
"value": "Bearer {{access_token}}"
|
| 610 |
+
}
|
| 611 |
+
],
|
| 612 |
+
"url": {
|
| 613 |
+
"raw": "{{base_url}}/api/reports/summary/",
|
| 614 |
+
"host": [
|
| 615 |
+
"{{base_url}}"
|
| 616 |
+
],
|
| 617 |
+
"path": [
|
| 618 |
+
"api",
|
| 619 |
+
"reports",
|
| 620 |
+
"summary",
|
| 621 |
+
""
|
| 622 |
+
]
|
| 623 |
+
},
|
| 624 |
+
"description": "Retrieves a summary report of paperworks by status."
|
| 625 |
+
},
|
| 626 |
+
"response": []
|
| 627 |
+
},
|
| 628 |
+
{
|
| 629 |
+
"name": "Export Report to CSV",
|
| 630 |
+
"request": {
|
| 631 |
+
"method": "GET",
|
| 632 |
+
"header": [
|
| 633 |
+
{
|
| 634 |
+
"key": "Authorization",
|
| 635 |
+
"value": "Bearer {{access_token}}"
|
| 636 |
+
}
|
| 637 |
+
],
|
| 638 |
+
"url": {
|
| 639 |
+
"raw": "{{base_url}}/api/reports/export.csv/",
|
| 640 |
+
"host": [
|
| 641 |
+
"{{base_url}}"
|
| 642 |
+
],
|
| 643 |
+
"path": [
|
| 644 |
+
"api",
|
| 645 |
+
"reports",
|
| 646 |
+
"export.csv",
|
| 647 |
+
""
|
| 648 |
+
]
|
| 649 |
+
},
|
| 650 |
+
"description": "Exports paperwork data to a CSV file."
|
| 651 |
+
},
|
| 652 |
+
"response": []
|
| 653 |
+
},
|
| 654 |
+
{
|
| 655 |
+
"name": "Get All Notifications",
|
| 656 |
+
"request": {
|
| 657 |
+
"method": "GET",
|
| 658 |
+
"header": [
|
| 659 |
+
{
|
| 660 |
+
"key": "Authorization",
|
| 661 |
+
"value": "Bearer {{access_token}}"
|
| 662 |
+
}
|
| 663 |
+
],
|
| 664 |
+
"url": {
|
| 665 |
+
"raw": "{{base_url}}/api/notifications/",
|
| 666 |
+
"host": [
|
| 667 |
+
"{{base_url}}"
|
| 668 |
+
],
|
| 669 |
+
"path": [
|
| 670 |
+
"api",
|
| 671 |
+
"notifications",
|
| 672 |
+
""
|
| 673 |
+
]
|
| 674 |
+
},
|
| 675 |
+
"description": "Retrieves all notifications for the authenticated user."
|
| 676 |
+
},
|
| 677 |
+
"response": []
|
| 678 |
+
},
|
| 679 |
+
{
|
| 680 |
+
"name": "Mark Notification as Read",
|
| 681 |
+
"request": {
|
| 682 |
+
"method": "POST",
|
| 683 |
+
"header": [
|
| 684 |
+
{
|
| 685 |
+
"key": "Authorization",
|
| 686 |
+
"value": "Bearer {{access_token}}"
|
| 687 |
+
}
|
| 688 |
+
],
|
| 689 |
+
"url": {
|
| 690 |
+
"raw": "{{base_url}}/api/notifications/:id/read/",
|
| 691 |
+
"host": [
|
| 692 |
+
"{{base_url}}"
|
| 693 |
+
],
|
| 694 |
+
"path": [
|
| 695 |
+
"api",
|
| 696 |
+
"notifications",
|
| 697 |
+
":id",
|
| 698 |
+
"read",
|
| 699 |
+
""
|
| 700 |
+
],
|
| 701 |
+
"variable": [
|
| 702 |
+
{
|
| 703 |
+
"key": "id",
|
| 704 |
+
"value": ""
|
| 705 |
+
}
|
| 706 |
+
]
|
| 707 |
+
},
|
| 708 |
+
"description": "Marks a specific notification as read."
|
| 709 |
+
},
|
| 710 |
+
"response": []
|
| 711 |
+
},
|
| 712 |
+
{
|
| 713 |
+
"name": "Get Researcher Statistics",
|
| 714 |
+
"request": {
|
| 715 |
+
"method": "GET",
|
| 716 |
+
"header": [
|
| 717 |
+
{
|
| 718 |
+
"key": "Authorization",
|
| 719 |
+
"value": "Bearer {{access_token}}"
|
| 720 |
+
}
|
| 721 |
+
],
|
| 722 |
+
"url": {
|
| 723 |
+
"raw": "{{base_url}}/api/stats/researcher/",
|
| 724 |
+
"host": [
|
| 725 |
+
"{{base_url}}"
|
| 726 |
+
],
|
| 727 |
+
"path": [
|
| 728 |
+
"api",
|
| 729 |
+
"stats",
|
| 730 |
+
"researcher",
|
| 731 |
+
""
|
| 732 |
+
]
|
| 733 |
+
},
|
| 734 |
+
"description": "Gets statistics for the current researcher, including counts of paperworks by status."
|
| 735 |
+
},
|
| 736 |
+
"response": []
|
| 737 |
+
}
|
| 738 |
+
]
|
| 739 |
+
}
|
| 740 |
+
],
|
| 741 |
+
"event": [
|
| 742 |
+
{
|
| 743 |
+
"listen": "prerequest",
|
| 744 |
+
"script": {
|
| 745 |
+
"type": "text/javascript",
|
| 746 |
+
"exec": [
|
| 747 |
+
""
|
| 748 |
+
]
|
| 749 |
+
}
|
| 750 |
+
},
|
| 751 |
+
{
|
| 752 |
+
"listen": "test",
|
| 753 |
+
"script": {
|
| 754 |
+
"type": "text/javascript",
|
| 755 |
+
"exec": [
|
| 756 |
+
""
|
| 757 |
+
]
|
| 758 |
+
}
|
| 759 |
+
}
|
| 760 |
+
],
|
| 761 |
+
"variable": [
|
| 762 |
+
{
|
| 763 |
+
"key": "base_url",
|
| 764 |
+
"value": "http://localhost:8000",
|
| 765 |
+
"type": "string"
|
| 766 |
+
},
|
| 767 |
+
{
|
| 768 |
+
"key": "access_token",
|
| 769 |
+
"value": "",
|
| 770 |
+
"type": "string"
|
| 771 |
+
},
|
| 772 |
+
{
|
| 773 |
+
"key": "admin_access_token",
|
| 774 |
+
"value": "",
|
| 775 |
+
"type": "string"
|
| 776 |
+
}
|
| 777 |
+
]
|
| 778 |
+
}
|
postman_new.json
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"info": {
|
| 3 |
+
"_postman_id": "a_unique_id_for_this_collection",
|
| 4 |
+
"name": "Paper Management System API",
|
| 5 |
+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
| 6 |
+
},
|
| 7 |
+
"item": [
|
| 8 |
+
{
|
| 9 |
+
"name": "Admin Endpoints",
|
| 10 |
+
"item": [
|
| 11 |
+
{
|
| 12 |
+
"name": "Create User",
|
| 13 |
+
"request": {
|
| 14 |
+
"method": "POST",
|
| 15 |
+
"header": [
|
| 16 |
+
{
|
| 17 |
+
"key": "Content-Type",
|
| 18 |
+
"value": "application/json"
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"key": "Authorization",
|
| 22 |
+
"value": "Bearer {{access_token}}"
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"body": {
|
| 26 |
+
"mode": "raw",
|
| 27 |
+
"raw": "{\n \"username\": \"researcher1\",\n \"password\": \"securepass123\",\n \"email\": \"researcher1@example.com\",\n \"role\": \"RESEARCHER\"\n}",
|
| 28 |
+
"options": {
|
| 29 |
+
"raw": {
|
| 30 |
+
"language": "json"
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
},
|
| 34 |
+
"url": {
|
| 35 |
+
"raw": "{{base_url}}/admin_app/createusers/",
|
| 36 |
+
"host": [
|
| 37 |
+
"{{base_url}}"
|
| 38 |
+
],
|
| 39 |
+
"path": [
|
| 40 |
+
"admin_app",
|
| 41 |
+
"createusers",
|
| 42 |
+
""
|
| 43 |
+
]
|
| 44 |
+
},
|
| 45 |
+
"description": "Create a new user (requires admin privileges)"
|
| 46 |
+
},
|
| 47 |
+
"response": []
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"name": "Update User Status",
|
| 51 |
+
"request": {
|
| 52 |
+
"method": "PATCH",
|
| 53 |
+
"header": [
|
| 54 |
+
{
|
| 55 |
+
"key": "Content-Type",
|
| 56 |
+
"value": "application/json"
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"key": "Authorization",
|
| 60 |
+
"value": "Bearer {{access_token}}"
|
| 61 |
+
}
|
| 62 |
+
],
|
| 63 |
+
"body": {
|
| 64 |
+
"mode": "raw",
|
| 65 |
+
"raw": "{\n \"status\": \"ACTIVE\"\n}",
|
| 66 |
+
"options": {
|
| 67 |
+
"raw": {
|
| 68 |
+
"language": "json"
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
},
|
| 72 |
+
"url": {
|
| 73 |
+
"raw": "{{base_url}}/admin_app/updateusers/:username/status/",
|
| 74 |
+
"host": [
|
| 75 |
+
"{{base_url}}"
|
| 76 |
+
],
|
| 77 |
+
"path": [
|
| 78 |
+
"admin_app",
|
| 79 |
+
"updateusers",
|
| 80 |
+
":username",
|
| 81 |
+
"status",
|
| 82 |
+
""
|
| 83 |
+
],
|
| 84 |
+
"variable": [
|
| 85 |
+
{
|
| 86 |
+
"key": "username",
|
| 87 |
+
"value": "researcher1"
|
| 88 |
+
}
|
| 89 |
+
]
|
| 90 |
+
},
|
| 91 |
+
"description": "Update user status (ACTIVE, FROZEN, INACTIVE)"
|
| 92 |
+
},
|
| 93 |
+
"response": []
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"name": "Assign Paperwork",
|
| 97 |
+
"request": {
|
| 98 |
+
"method": "POST",
|
| 99 |
+
"header": [
|
| 100 |
+
{
|
| 101 |
+
"key": "Content-Type",
|
| 102 |
+
"value": "application/json"
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"key": "Authorization",
|
| 106 |
+
"value": "Bearer {{access_token}}"
|
| 107 |
+
}
|
| 108 |
+
],
|
| 109 |
+
"body": {
|
| 110 |
+
"mode": "raw",
|
| 111 |
+
"raw": "{\n \"title\": \"Research on AI Ethics\",\n \"researcher_id\": \"uuid-of-researcher\",\n \"deadline\": \"2025-12-31T23:59:59Z\"\n}",
|
| 112 |
+
"options": {
|
| 113 |
+
"raw": {
|
| 114 |
+
"language": "json"
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
},
|
| 118 |
+
"url": {
|
| 119 |
+
"raw": "{{base_url}}/admin_app/paperworks/",
|
| 120 |
+
"host": [
|
| 121 |
+
"{{base_url}}"
|
| 122 |
+
],
|
| 123 |
+
"path": [
|
| 124 |
+
"admin_app",
|
| 125 |
+
"paperworks",
|
| 126 |
+
""
|
| 127 |
+
]
|
| 128 |
+
},
|
| 129 |
+
"description": "Assign a new paperwork to a researcher"
|
| 130 |
+
},
|
| 131 |
+
"response": []
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"name": "Update Paperwork Deadline",
|
| 135 |
+
"request": {
|
| 136 |
+
"method": "PATCH",
|
| 137 |
+
"header": [
|
| 138 |
+
{
|
| 139 |
+
"key": "Content-Type",
|
| 140 |
+
"value": "application/json"
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"key": "Authorization",
|
| 144 |
+
"value": "Bearer {{access_token}}"
|
| 145 |
+
}
|
| 146 |
+
],
|
| 147 |
+
"body": {
|
| 148 |
+
"mode": "raw",
|
| 149 |
+
"raw": "{\n \"deadline\": \"2025-12-31T23:59:59Z\"\n}",
|
| 150 |
+
"options": {
|
| 151 |
+
"raw": {
|
| 152 |
+
"language": "json"
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
},
|
| 156 |
+
"url": {
|
| 157 |
+
"raw": "{{base_url}}/admin_app/paperworks/:id/deadline/",
|
| 158 |
+
"host": [
|
| 159 |
+
"{{base_url}}"
|
| 160 |
+
],
|
| 161 |
+
"path": [
|
| 162 |
+
"admin_app",
|
| 163 |
+
"paperworks",
|
| 164 |
+
":id",
|
| 165 |
+
"deadline",
|
| 166 |
+
""
|
| 167 |
+
],
|
| 168 |
+
"variable": [
|
| 169 |
+
{
|
| 170 |
+
"key": "id",
|
| 171 |
+
"value": "paperwork-uuid"
|
| 172 |
+
}
|
| 173 |
+
]
|
| 174 |
+
},
|
| 175 |
+
"description": "Update the deadline of a paperwork"
|
| 176 |
+
},
|
| 177 |
+
"response": []
|
| 178 |
+
},
|
| 179 |
+
{
|
| 180 |
+
"name": "Get All Users",
|
| 181 |
+
"request": {
|
| 182 |
+
"method": "GET",
|
| 183 |
+
"header": [
|
| 184 |
+
{
|
| 185 |
+
"key": "Authorization",
|
| 186 |
+
"value": "Bearer {{admin_access_token}}"
|
| 187 |
+
}
|
| 188 |
+
],
|
| 189 |
+
"url": {
|
| 190 |
+
"raw": "{{base_url}}/admin_app/users/",
|
| 191 |
+
"host": [
|
| 192 |
+
"{{base_url}}"
|
| 193 |
+
],
|
| 194 |
+
"path": [
|
| 195 |
+
"admin_app",
|
| 196 |
+
"users",
|
| 197 |
+
""
|
| 198 |
+
]
|
| 199 |
+
},
|
| 200 |
+
"description": "Retrieves a list of all users."
|
| 201 |
+
},
|
| 202 |
+
"response": []
|
| 203 |
+
}
|
| 204 |
+
]
|
| 205 |
+
}
|
| 206 |
+
],
|
| 207 |
+
"variable": [
|
| 208 |
+
{
|
| 209 |
+
"key": "base_url",
|
| 210 |
+
"value": "http://localhost:8000",
|
| 211 |
+
"type": "string",
|
| 212 |
+
"description": "Base URL for the API"
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"key": "access_token",
|
| 216 |
+
"value": "",
|
| 217 |
+
"type": "string",
|
| 218 |
+
"description": "JWT access token for authentication"
|
| 219 |
+
}
|
| 220 |
+
]
|
| 221 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Django
|
| 2 |
+
django-cors-headers
|
| 3 |
+
djangorestframework
|
| 4 |
+
firebase-admin
|
| 5 |
+
djangorestframework-simplejwt
|
| 6 |
+
uvicorn==0.34.0
|
| 7 |
+
asgiref==3.8.1
|
| 8 |
+
dotenv
|