-
-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Open
Copy link
Labels
APIauthbackendenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersonlydust-waveContribute to awesome OSS repos during OnlyDust's open source weekContribute to awesome OSS repos during OnlyDust's open source week
Description
Extend the backend to support Admin role management by adding secure APIs that allow:
- ✅ Fetching all users with the Admin role
- ❌ Revoking the Admin role from a user by email
These APIs are essential for supporting the Admin Role Management Page on the frontend, allowing Admins to view and manage other Admin users in the system.
📝 Description
Add two new endpoints to manage Admin roles:
-
GET /api/v1/role/admins
- Returns a list of all users who currently have the Admin role.
- Response should include each user’s name and email.
-
DELETE /api/v1/role/admin/:email
- Removes the Admin role from a user based on their email address.
- Should respond with a success message or an appropriate error if the user is not found or not an Admin.
📌 Objectives
- ✅ Create the following endpoints:
GET /api/v1/role/admins → Fetch all Admin users
DELETE /api/v1/role/admin/:email → Remove Admin role by email- ✅ Ensure responses include relevant messages and handle common errors (e.g. user not found, already not an Admin, etc.).
1️⃣ Get All Admins
GET /api/v1/role/adminsExpected Response
{
"status": 200,
"message": "Admins fetched successfully",
"data": [
{
"name": "Jane Doe",
"email": "jane@example.com",
"role": "admin"
},
...
]
}2️⃣ Delete Admin Role by Email
DELETE /api/v1/role/admin/:emailExpected Response
{
"status": 200,
"message": "Admin role revoked successfully",
"data": {
"email": "target@example.com"
}
}
✅ Acceptance Criteria
To ensure the Admin Role Management backend APIs are implemented correctly, the following criteria must be met:
-
📄 GET /api/v1/role/admins
- Returns all users with the Admin role.
- Each user object includes required fields: name, email, and optionally user ID.
-
❌ DELETE /api/v1/role/admin/:email
- Successfully removes the Admin role for the user with the given email (if valid).
- Returns a clear success or error message.
-
🔐 Access Control & Validation
- Both routes are protected using
AuthMiddleware.Admin. - Only authenticated Admin users can access these routes.
- Email is validated before attempting to revoke a role.
- Prevent errors when email does not exist or user is not an Admin.
- Both routes are protected using
-
⚠️ Error Handling- Handles invalid inputs, unauthorized access, and unexpected server errors gracefully.
- Proper HTTP status codes are returned (e.g. 200, 400, 403, 404, 500).
-
🧪 Testing
- Unit tests written (if a testing framework like Jest, Mocha, etc., is set up).
- Tests cover both success and failure cases.
-
📦 Response Format
- All responses use the standard response utility:
SendResponse.success()for successful responses.SendResponse.error()for error handling.
- All responses use the standard response utility:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
APIauthbackendenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersonlydust-waveContribute to awesome OSS repos during OnlyDust's open source weekContribute to awesome OSS repos during OnlyDust's open source week