Skip to content

Admin API

wonyk edited this page May 9, 2019 · 13 revisions

Here holds the endpoints that are exclusive to superAdmin. All endpoints here require the token to confirm one is a superAdmin.

Change log:
1. Self password reset is moved to auth wiki page.
2. Change password is moved to auth wiki page.
3. Admin creation of special accounts are removed. Instead, they are expected to create via conventional methods 
   and simply change the status and roles to the necessary ones.
(v0.2.0-beta)
4. Added User Responsive Search for all the different status
(v0.5.0-beta)
5. Added ability to clone a class as required by the organisation
(v0.6.0-beta)
6. Aligns to new Schemas. The response will differ from older patch.

Content List

  1. Change user status and roles
  2. Show all pending users (who have just signed up and confirmed their email)
  3. Get Suspended and Deleted users
  4. Mass deletion of users
  5. Get All Users based on name search (Responsive)
  6. Clone a Class

1. Change user status and roles

  1. This endpoint allows the admin to change the status of a user (E.g from Pending to Active and vice versa) and set their roles as [SuperAdmin, Admin, Mentor, Supervisor, Volunteer, Adhoc, Temporary].

  2. API could permit one to change User Status to and fro Suspended and Deleted. For mass deletion during spring cleaning, please use the DELETE API. This API is available as a tick and delete option on the volunteer view page of the admin panel.

  3. It is to note that similar to volunteer delete, all status other than Active will remove the volunteer's name from all classes. However, under the Profile page, he still has that classID as a record, allowing him to be automatically re-added when the status changes back to Active.

HTTP Request

POST http://localhost:3000/api/admin/userStatusPermissions

Query Parameter

Parameter Required Description
token true Obtained from login or register. Place in x-access-token header
userId true _id of the user
newStatus false A string to describe the status of the user. Pending users would not have access to most of the functions
newRoles false An array of roles. Possible roles: [Superadmin, Admin, Mentor, Supervisor, Volunteer, Adhoc, Temporary]

2. Show all pending users (who have just signed up and confirmed their email)

HTTP Request

GET http://localhost:3000/api/admin/pendingUsers

Response (Sample)

{
    "users": [
        {
            "_id": "5a23c38802e5572184176bb1",
            "email": "windowstest@gmail.com",
            "roles": [
                "Tutor"
            ],
            "name": "Batman1",
            "status": "Pending"
        {
            "_id": "5a23e392c69db63be4984cc7",
            "email": "windows@gmail.com",
            "roles": [
                "Tutor"
            ],
            "name": "Batman2",
            "status": "Pending"
        }
    ]
}

3. Get Suspended and Deleted users

This 2 endpoints retrieve the suspended and deleted users list for admin to perform further actions respectively

  • Suspended: GET http://localhost:3000/api/admin/suspended
  • Deleted: GEThttp://localhost:3000/api/admin/deleted

Response

The response are similar to the API used to retrieve pending users.


4. Mass deletion of users

The superAdmin might want to perform a large deletion.

Request (Sample)

DELETE http://localhost:3000/api/admin/user

{
	"userId": ["5a23e47775822d4e7c7a69a4", "321983831831931938122", "and many more..."]
}

The response would tell you the number that is successfully deleted. If a deletion request is sent to an already "deleted" user, there will be a response that the user does not exist.


5. Get All Users based on name search (Responsive)

This endpoints retrieve the users list for admin to perform further actions respectively based on name searched. This function is Case Insensitive

GET http://localhost:3000/api/admin/search/:name

Response (Example name === 'Admin')

{
    "pendingMatched": [],
    "activeMatched": [
        {
            "name": "Admin",
            "status": "Active",
            "roles": [
                "SuperAdmin"
            ],
            "_id": "59c65c7d860b5d3fce0096b2"
        }
    ],
    "suspendedMatched": [],
    "deletedMatched": []
}

6. Clone a Class

This API allows an admin to clone a class in a new year. The class will be quick and automatically adds a "Clone" word at the back of the class name. The admin will then receive a link to visit and update the class accordingly.

HTTP Request

GET http://localhost:3000/api/class/clone/:id


Clone this wiki locally