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/remove-ban.ts
Views: 687
/*1Remove ban from 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 { removeUserBan } from "@cocalc/server/accounts/ban";89import { apiRoute, apiRouteOperation } from "lib/api";10import { SuccessStatus } from "lib/api/status";11import {12RemoveAccountBanInputSchema,13RemoveAccountBanOutputSchema,14} from "lib/api/schema/accounts/remove-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 removeUserBan(account_id);37return SuccessStatus;38}3940export default apiRoute({41removeBan: apiRouteOperation({42method: "POST",43openApiOperation: {44tags: ["Accounts", "Admin"],45},46})47.input({48contentType: "application/json",49body: RemoveAccountBanInputSchema,50})51.outputs([52{53status: 200,54contentType: "application/json",55body: RemoveAccountBanOutputSchema,56},57])58.handler(handle),59});606162