Path: blob/master/src/packages/util/db-schema/registration-tokens.ts
5963 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// An account token is a piece of additional information,6// which might be necessary to create an account.7// In the future, this might be extended to dispatch some action,8// like adding a student to a course, similar to account creation actions.910import {11Table,12RegistrationTokenSetFields,13RegistrationTokenGetFields,14} from "./types";1516// this covers 3 cases: selecting all, updating one, and deleting one17async function instead_of_query(db, opts: any, cb: Function): Promise<void> {18const { options, query } = opts;19try {20cb(undefined, await db.registrationTokens(options, query));21} catch (err) {22cb(err);23}24}2526Table({27name: "registration_tokens",28rules: {29primary_key: "token",30anonymous: false,31user_query: {32set: {33admin: true,34instead_of_query,35delete: true,36fields: {37token: null,38descr: null,39expires: null,40limit: null,41disabled: null,42ephemeral: null,43customize: null,44} as { [key in RegistrationTokenSetFields]: null },45},46get: {47admin: true,48instead_of_query,49pg_where: [], // no limits50fields: {51token: null,52descr: null,53expires: null,54counter: null,55limit: null,56disabled: null,57ephemeral: null,58customize: null,59} as { [key in RegistrationTokenGetFields]: null },60},61},62},63fields: {64token: { type: "string" },65descr: { type: "string" },66counter: { type: "number", desc: "how many accounts are created" },67expires: {68type: "timestamp",69desc: "optional – the time, when this token is no longer valid",70},71limit: { type: "number", desc: "optional – maximum number of accounts" },72disabled: { type: "boolean", desc: "set to true to disable this token" },73ephemeral: {74type: "number",75desc: "optional – lifetime in milliseconds for accounts/projects created via this token",76},77customize: {78type: "map",79desc: "Optional account customization overrides applied when redeeming this token.",80},81},82});838485