Skip to content

admin-analytics: add user administration backend API endpoints

Warren Gifford requested to merge erzhtor/user-administration into main

Created by: erzhtor

Closes https://github.com/sourcegraph/sourcegraph/issues/39820.

  • Add query site.users(... GraphQL API query endpoint
  • Add mutation invalidateSessionsByUserIDs(... GraphQL API bulk mutation endpoint
  • Add mutation deleteUsers(... GraphQL API bulk mutation endpoint
    • It handles both hard and soft deletion of users, similar to the existing mutation deleteUser API endpoint

Test plan

NOTE: the frontend part is still under development (in parallel).

  • sg start
  • Test "site.users" API:
{
  site {
    users(query: "some-username-or-email-or-displayname", siteAdmin: true, username: "user's username", email: "user's email") {
      totalCount
      nodes(first: 100, orderBy: EVENTS_COUNT, descending: true) {
        id
        username
        email
        createdAt
        lastActiveAt
        deletedAt
        siteAdmin
        eventsCount
      }
    }
  }
}
  • Test "invalidateSessionsByUserIDs" GraphQL API bulk mutation endpoint
mutation {
  invalidateSessionsByIDs(userIDs: ["userID1", "userID2"]) {
    alwaysNil
  }
}
  • Test "deleteUsers" GraphQL API bulk mutation endpoint
mutation {
  # soft delete
  softDeleteUsers: deleteUsers(users: ["userID1", "userID2"]) {
    alwaysNil
  }
  # permanently delete from system
  hardDeleteUsers: deleteUsers(users: ["userID1", "userID2"], hard: true) {
    alwaysNil
  }
}

Merge request reports

Loading