Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/api/v2/accounts/ban.ts
Views: 687
/*1Ban a user. This is ONLY allowed for admins.2*/34import getAccountId from "lib/account/get-account";5import getParams from "lib/api/get-params";6import userIsInGroup from "@cocalc/server/accounts/is-in-group";7import { banUser } from "@cocalc/server/accounts/ban";89import { apiRoute, apiRouteOperation } from "lib/api";10import { SuccessStatus } from "lib/api/status";11import {12BanAccountInputSchema,13BanAccountOutputSchema,14} from "lib/api/schema/accounts/ban";1516async function handle(req, res) {17try {18res.json(await get(req));19} catch (err) {20res.json({ error: `${err.message}` });21return;22}23}2425async function get(req) {26const account_id0 = await getAccountId(req);27if (account_id0 == null) {28throw Error("must be signed in");29}30// This user MUST be an admin:31if (!(await userIsInGroup(account_id0, "admin"))) {32throw Error("only admins can ban users");33}3435const { account_id } = getParams(req);36await banUser(account_id);37return SuccessStatus;38}3940export default apiRoute({41ban: apiRouteOperation({42method: "POST",43openApiOperation: {44tags: ["Accounts", "Admin"],45},46})47.input({48contentType: "application/json",49body: BanAccountInputSchema,50})51.outputs([52{53status: 200,54contentType: "application/json",55body: BanAccountOutputSchema,56},57])58.handler(handle),59});606162