gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit71b2fa4b71b2fa4blog: hybriel#335mre71b2fa4b/lib/orgs.hl

2.4 KB

  1. // lib/orgs.hl — ORGANIZATIONS (ticket gitoria#34, GO34). An organization is a name that is its own address <org>.<domain>; its repos live at
  2. // <org>.<domain>/<repo> and look like a repo page on <repo>.<domain>. One hl:mpackdb table, storage/mpackdb/orgs.db:
  3. // pk @id index !slug, owner { slug, owner (users @id), priv (true = every repo of it is private, also new ones), created }
  4. // An organization's name and a repo's name share one namespace (both are subdomains): lib/repos.hl checks both. Who belongs to an
  5. // organization is the one member list of lib/members.hl. Statics only; no page code.
  6. import { MPackDB } from 'hl:mpackdb'
  7. import { now } from 'hl:time'
  8. import { storageDir, firstOf, slugOfHost } from './util.hl'
  9. static orgsTable = new MPackDB(file = storageDir + '/orgs.db', primaryKey = '@id', indexes = ['!slug', 'owner'])
  10. static orgBySlug = (slug) => {
  11. if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }
  12. return firstOf(orgsTable.find('slug', slug))
  13. }
  14. static putOrg = (slug, owner, priv) => {
  15. id = orgsTable.put({ slug = slug owner = owner priv = priv created = now() })
  16. return id == null ? null : orgsTable.fetch(id)
  17. }
  18. static setOrgPriv = (o, priv) => {
  19. orgsTable.update(o.id, { id = o.id slug = o.slug owner = o.owner priv = priv created = o.created })
  20. after = orgsTable.fetch(o.id)
  21. return after != null && after.priv == priv
  22. }
  23. // every organization record
  24. static allOrgs = () => {
  25. all = orgsTable.find(null, null)
  26. return all == null || all.length == null ? [] : all
  27. }
  28. // THE REPO NAME OF A REQUEST: `host` (no port) and `orepo` (the first path segment of an organization's address, '' elsewhere).
  29. // '' = the main address; `name` = a repo's own address; `org/name` = a repo inside an organization; '!x' = a path that names
  30. // no repo (a first segment on a host that is not an organization) — "No such repository".
  31. static slugOfRequest = (host, orepo) => {
  32. label = slugOfHost(host)
  33. if (orepo == null || orepo == '') { return label }
  34. if (label != '' && orgBySlug(label) != null) { return label + '/' + orepo }
  35. return '!'
  36. }
  37. // the first path segment of an organization's address (the repo inside it), '' on every other host or at the organization's root
  38. static orepoOfPath = (host, path) => {
  39. label = slugOfHost(host)
  40. if (label == '' || path == null || orgBySlug(label) == null) { return '' }
  41. rest = path.startsWith('/') ? path.slice(1) : path
  42. i = rest.indexOf('/')
  43. return i < 0 ? rest : rest.slice(0, i)
  44. }

Branches

Latest commits

  • 71b2fa4blog: hybriel#335mre
  • bd94cc7elog: #25 cause found (run() leak)mre
  • 565cb508log: H25 round 1mre
  • 90a0af84log: H25 startedmre
  • 87bd53b8mission H25mre
  • 71a746cflog: day48 livemre
  • bf568e14log: V48 mergedmre
  • 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
  • f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
  • 5d0834e7log: Apollo model rulemre
  • fe8e5bd5log: #25 sample, V48 missionmre
  • 8580c5d9log: theme fix from Atlasmre
  • 46823d93log: Apollo budget correctionmre
  • f6d32341log: Apollo on budget and #25 nextmre
  • d7184f53log: batch live, #25 evidencemre
  • 5e25e816log: W61 mergedmre
  • aafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmre
  • aca1fda1Merge W61: theme from layouts 17e0f03, Views refer to Style rules (gitoria#37 #27)mre
  • 03cb650blog: W61 theme decisionmre
  • 248bce85Report final style gates, CSS mappings and 136 whole-image comparisonsmre