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/frontend/account/licenses/util.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Map } from "immutable";67import { reuseInFlight } from "@cocalc/util/reuse-in-flight";8import { webapp_client } from "@cocalc/frontend/webapp-client";9import { field_cmp, cmp_Date } from "@cocalc/util/misc";10import { SiteLicense } from "@cocalc/util/types/site-licenses";1112type FunctionType = () => Promise<SiteLicense[]>;1314export const getManagedLicenses: FunctionType = reuseInFlight(async () => {15const v = (16await webapp_client.async_query({17query: {18manager_site_licenses: [19{20id: null,21title: null,22description: null,23info: null,24expires: null,25activates: null,26created: null,27last_used: null,28managers: null,29upgrades: null,30quota: null,31run_limit: null,32apply_limit: null,33},34],35},36})37).query.manager_site_licenses;38// Sort by created with newest first39return v.sort((a, b) => cmp_Date(b.created, a.created));40});4142// Return list of id's of projects that have at least one license applied to43// them. The license may or may not be valid, in use, etc.44export function projects_with_licenses(45project_map: undefined | Map<string, any>,46): { last_edited?: Date; project_id: string; num_licenses: number }[] {47if (project_map == null) return [];48const v: {49last_edited?: Date;50project_id: string;51num_licenses: number;52}[] = [];53for (const y of project_map) {54const [project_id, project] = y;55const num_licenses = project.get("site_license")?.size;56if (num_licenses > 0) {57v.push({58last_edited: project.get("last_edited"),59project_id,60num_licenses,61});62}63}64v.sort(field_cmp("last_edited"));65v.reverse();66return v;67}686970