gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commiteae6e8c7eae6e8c7sync components.hybriel 4922f9c: comments like / Edit / Delete / 'edited' are 44 px targets; gate: 'edited' hit-area padding, thread targets check (SY)mreeae6e8c7/project.hl

14.1 KB

  1. // project.hl — tickets.worldapi.org: THE MAP. Config, routes and WHO HEARS WHAT; the logic lives in lib/.
  2. //
  3. // WHERE THINGS ARE (one line per feature; README.md "Files" has the full list):
  4. // tickets, their states and relations (parent / blocked-by) lib/tickets.hl (state names, page shapes: lib/tickets-helpers.hl)
  5. // the history of a ticket (events) lib/events.hl
  6. // comments: edit, delete, like (mission 016) lib/comments.hl (the page draws them: components/comments/)
  7. // files attached to a comment (tickets#27, mission 017) lib/attachments.hl (the API's multipart body: lib/multipart.hl)
  8. // projects, members, roles, slugs lib/projects.hl
  9. // users, login through ident, API tokens, sessions lib/users.hl
  10. // invites to a project (ident#22) lib/invites.hl
  11. // connecting an app to a project (ticket #21) lib/connections.hl
  12. // Markdown in text fields / the Markdown read view lib/markdown.hl / lib/mdview.hl
  13. // the JSON API + /login/callback, /connect, /tickets/:ref lib/api.hl (plumbing: lib/api-helpers.hl, lib/jsoncheck.hl)
  14. // the event stream for programs, GET /api/events (#26) lib/stream.hl (numbered rows, filters, SSE)
  15. // the ticket #20 data migration (every start) lib/migrate.hl
  16. // the ticket-file format of the import lib/import.hl (the import tool: tools/import.hl)
  17. // shared small helpers (env, storage dir, URLs, sorting, Vienna time) lib/util.hl
  18. // pages: shell, list, ticket, inbox, you, new project, settings, connect components/*.hl; CSS components/styles.hl
  19. import WebFramework from 'hl:web'
  20. import { env } from 'hl:proc'
  21. import Styles from './components/styles.hl'
  22. import { dark, darker } from './shared/tokens.hl'
  23. import { migrateAll } from './lib/migrate.hl'
  24. import { tagOf, identUrl, publicUrl } from './lib/users.hl'
  25. import { getAttachment, getEvents, postTicket, getTicket, postComment, postCommentEdit, postCommentDelete, postCommentLike, postState, postEdit, postAssign, postParent, postBlockers, getProjects, getInbox, getProject, postMembers, postMemberRemove, postInvites, connectExchange, projectConnections, projectDisconnect, connectStart, projectTickets, getProjectTicket, postProjectComment, postProjectCommentEdit, postProjectCommentDelete, postProjectCommentLike, postProjectState, postProjectEdit, postProjectAssign, postProjectParent, postProjectBlockers, oldTicketPage, oldProjectPage, oldProjectTicketPage, loginCallback } from './lib/api.hl'
  26. import TicketList from './components/ticket_list.hl'
  27. import Ticket from './components/ticket.hl'
  28. import Inbox from './components/inbox.hl'
  29. import You from './components/you.hl'
  30. import NewProject from './components/new_project.hl'
  31. import Settings from './components/settings.hl'
  32. import Connect from './components/connect.hl'
  33. static siteName = "tickets"
  34. appTitle = siteName
  35. styles = Styles
  36. // THE PAGES' POLICY, as <meta> (hl:web sets no response header on a page yet: reports/ST-sec.md). No <base>, no plugins, no forms to other sites;
  37. // scripts: hl:web's boot module is inline ('unsafe-inline'), ident's selector.js and its fetches go to IDENT_URL; images: this site only
  38. // (attachments are served by /api/attachments/:id). `frame-ancestors` cannot be set from a meta (Byrodin's nginx / hl:web's header hook).
  39. meta = [
  40. { 'http-equiv' = 'Content-Security-Policy' content = "default-src 'self'; script-src 'self' 'unsafe-inline' " + identUrl + "; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' " + identUrl + "; object-src 'none'; base-uri 'none'; form-action 'self' " + identUrl + "; frame-src 'none'; worker-src 'self'; manifest-src 'self'" }
  41. { name = 'referrer' content = 'same-origin' }
  42. ]
  43. // ---- THE INSTALLABLE APP (mission 046), the same way calendar.worldapi.org does it: hl:web's own web app manifest
  44. // (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service worker
  45. // (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg, a ticket stub, is the source;
  46. // the PNGs and favicon.ico are rendered from it with rsvg-convert / magick, README "PWA"). The theme colour is the
  47. // header's background (darker, as tracker), the splash background the page's (dark) — both off the tokens, not written out again.
  48. appThemeColor = darker.value
  49. appBackgroundColor = dark.value
  50. appIcons = [
  51. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  52. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  53. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  54. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  55. ]
  56. appTouchIcon = '/icons/apple-touch-icon.png'
  57. appFavicon = '/icons/icon.svg'
  58. // OFFLINE: the shell and `/` — `/` IS the ticket list, so offline it shows the list as this browser last loaded it,
  59. // and the shell (components/main.hl) says "You are offline". Its value-form emits are never queued. Other pages are
  60. // not kept, except a project list (/<slug>, same component) this browser visited; the rest get hl:web's
  61. // "Unavailable offline" page.
  62. offline = [ TicketList ]
  63. // ---- THE ROUTES: files, the function routes (lib/api.hl), the pages (components/) ----------------
  64. routes = [
  65. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }
  66. // the installable app (mission 046): the icons (manifest and service worker are hl:web's own, from appIcons / offline)
  67. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }
  68. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }
  69. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }
  70. { pattern = "/icons/icon.svg" file = "./icons/icon.svg" headers = { 'Cache-Control' = 'no-cache' } }
  71. // the login button's return (ticket #7): it needs the request's session and the framework's session store, BY REFERENCE
  72. { pattern = "/login/callback" function = (route, req) => { return loginCallback(route, &req, &server.sessions) } }
  73. { pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }
  74. // ticket #26: every change, live, for programs (Server-Sent Events; lib/stream.hl)
  75. { pattern = "/api/events" function = getEvents }
  76. { pattern = "/api/tickets" function = postTicket }
  77. { pattern = "/api/tickets/:ref" function = getTicket }
  78. { pattern = "/api/tickets/:ref/comments" function = postComment }
  79. // mission 016: a comment's author edits / deletes it, a member likes it (lib/comments.hl); :comment = its event id
  80. { pattern = "/api/tickets/:ref/comments/:comment/edit" function = postCommentEdit }
  81. { pattern = "/api/tickets/:ref/comments/:comment/delete" function = postCommentDelete }
  82. { pattern = "/api/tickets/:ref/comments/:comment/like" function = postCommentLike }
  83. { pattern = "/api/tickets/:ref/state" function = postState }
  84. // tickets#27: an attached file, for the members of its project (lib/attachments.hl)
  85. { pattern = "/api/attachments/:id" function = getAttachment }
  86. { pattern = "/api/tickets/:ref/edit" function = postEdit }
  87. { pattern = "/api/tickets/:ref/assign" function = postAssign }
  88. { pattern = "/api/tickets/:ref/parent" function = postParent }
  89. { pattern = "/api/tickets/:ref/blocked-by" function = postBlockers }
  90. { pattern = "/api/projects" function = getProjects }
  91. { pattern = "/api/inbox" function = getInbox }
  92. { pattern = "/api/projects/:slug" function = getProject }
  93. { pattern = "/api/projects/:slug/members" function = postMembers }
  94. { pattern = "/api/projects/:slug/members/remove" function = postMemberRemove }
  95. { pattern = "/api/projects/:slug/invites" function = postInvites }
  96. { pattern = "/api/connect/exchange" function = connectExchange }
  97. { pattern = "/api/projects/:slug/connections" function = projectConnections }
  98. { pattern = "/api/projects/:slug/connections/remove" function = projectDisconnect }
  99. { pattern = "/connect" function = connectStart }
  100. { pattern = "/api/projects/:slug/tickets" function = projectTickets }
  101. { pattern = "/api/projects/:slug/tickets/:number" function = getProjectTicket }
  102. { pattern = "/api/projects/:slug/tickets/:number/comments" function = postProjectComment }
  103. { pattern = "/api/projects/:slug/tickets/:number/comments/:comment/edit" function = postProjectCommentEdit }
  104. { pattern = "/api/projects/:slug/tickets/:number/comments/:comment/delete" function = postProjectCommentDelete }
  105. { pattern = "/api/projects/:slug/tickets/:number/comments/:comment/like" function = postProjectCommentLike }
  106. { pattern = "/api/projects/:slug/tickets/:number/state" function = postProjectState }
  107. { pattern = "/api/projects/:slug/tickets/:number/edit" function = postProjectEdit }
  108. { pattern = "/api/projects/:slug/tickets/:number/assign" function = postProjectAssign }
  109. { pattern = "/api/projects/:slug/tickets/:number/parent" function = postProjectParent }
  110. { pattern = "/api/projects/:slug/tickets/:number/blocked-by" function = postProjectBlockers }
  111. { pattern = "/" component = TicketList }
  112. { pattern = "/project/:projectName" component = TicketList }
  113. { pattern = "/state/:stateSlug" component = TicketList }
  114. { pattern = "/project/:projectName/state/:stateSlug" component = TicketList }
  115. { pattern = "/inbox" component = Inbox }
  116. { pattern = "/new-project" component = NewProject }
  117. { pattern = "/connect/:nonce" component = Connect }
  118. { pattern = "/projects/:projectSlug/settings" component = Settings }
  119. { pattern = "/you" component = You }
  120. // OLD PAGE URLS → 301 to the short ones (ticket #25): `/tickets/<old global number or uuid>`, `/projects/<slug>`,
  121. // `/projects/<slug>/<number>`, `/projects/<slug>/tickets/<number>`
  122. { pattern = "/tickets/:ref" function = oldTicketPage }
  123. { pattern = "/projects/:slug" function = oldProjectPage }
  124. { pattern = "/projects/:slug/:number" function = oldProjectTicketPage }
  125. { pattern = "/projects/:slug/tickets/:number" function = oldProjectTicketPage }
  126. // THE SHORT PAGE URLS (ticket #25): the project `/<slug>`, a ticket `/<slug>/<number>`. They match any first
  127. // segment, so they come last — and below, after the construction, behind hl:web's own urls too (`lastPage`)
  128. { pattern = "/:projectName" component = TicketList lastPage = true }
  129. { pattern = "/:projectSlug/:ticketNumber" component = Ticket lastPage = true }
  130. ]
  131. // WHO GETS THE PUSH: tickets and events are public (reading needs no login). A frame
  132. // reaches a connection only if a mounted component listens for it.
  133. // `signedIn` / `signedOut` (ticket #7) go to the tabs of ONE session: the one whose login
  134. // carries that random tag (session.data.tag, set at login) — every page of it switches to
  135. // logged in / out without a reload.
  136. audience = {
  137. ticketCreated = (row, session) => { return true }
  138. ticketEvent = (ticketId, ev, row, session) => { return true }
  139. // mission 016: a comment was edited, deleted or (un)liked — the ticket page swaps that history row
  140. commentChanged = (ticketId, ev, session) => { return true }
  141. // ticket #4: the relation views (tickets-helpers.hl relationViewOf) of a ticket and its related ones
  142. ticketsRelated = (views, session) => { return true }
  143. // ticket #21: an app was connected / disconnected — the project page refreshes its line
  144. connectionsChanged = (slug, session) => { return true }
  145. signedIn = (tag, info, session) => { return tag != null && tagOf(session) == tag }
  146. signedOut = (tag, session) => { return tag != null && tagOf(session) == tag }
  147. }
  148. sessionDir = env('TICKETS_SESSIONS') != null ? env('TICKETS_SESSIONS') : null
  149. port = env('TICKETS_PORT') != null ? toNumber(env('TICKETS_PORT')) : 8350
  150. // THE LISTENER's interface (mission 010, deploy to Byrodin): hl:web reads HL_HOST (or HOST)
  151. // itself (hybriel#24): 127.0.0.1 on Byrodin behind nginx; unset = 0.0.0.0 (dev on Loreana).
  152. // TICKETS_WATCH=0 turns the dev watcher off (the container: a deploy is an rsync + restart,
  153. // half-copied .hl files must not be re-analysed); unset = on, as before.
  154. watching = env('TICKETS_WATCH') != '0'
  155. // THE MIGRATION of ticket #20 (lib/migrate.hl): idempotent, runs at every start
  156. for (line of migrateAll()) { console.log('migrated: ' + line) }
  157. // uploadMax (tickets#27): the largest file a page's emit may carry = lib/attachments.hl maxFileBytes (10 MiB; inlined, as a manifest value)
  158. // SECURITY (mission ST, ST2): behind https (TICKETS_PUBLIC_URL, https on Byrodin) the session cookie gets the `Secure` flag. Its NAME stays hl:web's
  159. // default (hlsid) and it has no new lifetime: a session cookie issued before stays valid, nobody is signed out (creator 2026-10-23: logins never expire).
  160. behindHttps = publicUrl.startsWith('https://')
  161. server = new WebFramework(routes = routes, styles = styles, minify = true, port = port, watchMode = watching, uploadMax = 10485760, sessionMaxAge = 3122064000, sessionSecure = behindHttps)
  162. // THE SHORT PAGE URLS GO BEHIND hl:web's OWN (ticket #25). The first match answers, and hl:web APPENDS its urls
  163. // (/__hl/app.css, /__hl/emit, /__hl/sw.js …, the component modules /components/<file>.hl) to the table while it is
  164. // constructed: left where they are, `/:projectSlug/:ticketNumber` answered /__hl/app.css and /components/ticket.hl
  165. // with a ticket page. They stay in the table above (hl:web serves the modules of the components routes mount, and
  166. // the service worker knows them as pages) and are moved to the end of the router's table here — the one that
  167. // answers requests and that the browser gets for its links. A first segment any route answers is a reserved slug
  168. // (lib/projects.hl reservedSlugs; the gate checks both).
  169. pagesFirst = []
  170. pagesLast = []
  171. for (r of server.router.routes) { if (r.lastPage == true) { pagesLast[] = r } else { pagesFirst[] = r } }
  172. for (r of pagesLast) { pagesFirst[] = r }
  173. server.router.routes = pagesFirst
  174. // THE GLOBAL ERROR HANDLER (ticket #7): a plugin's failure — above all hl:fetch's refused /
  175. // timed-out exchange with ident (users.hl exchangeCode, invites.hl) — arrives here instead of aborting the
  176. // request with a 500 that shows source paths; the failed call yields null and the caller answers
  177. // it ("ident did not answer"). Every absorbed error is logged.
  178. on Error(e) { console.log('error absorbed: ' + e.message) }

Branches

Latest commits

  • eae6e8c7sync components.hybriel 4922f9c: comments like / Edit / Delete / 'edited' are 44 px targets; gate: 'edited' hit-area padding, thread targets check (SY)mre
  • 4eeb7bfeST2 report wordingmre
  • 2558f56cst2-sec: keep the hlsid session cookie name (no one is signed out), Secure flag only; gate: a cookie issued by main stays signed in; ident stub serves selector.js; security.mjs in deploy GATESmre
  • ea2e440esecurity audit (ST): JSON body cap, relation rights, login session rotation, __Host- Secure cookie, API security headers, CSP+referrer meta, /connect cap, one-line subjects, tests/security.mjs, reportmre
  • 7c8c2282sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • b6277497report MT-mobile, LOGmre
  • 6709398blist paging: the newest rows come first (the sorted array was not used); filter rows hide their scrollbar; gate checks the ordermre
  • 31736a80gate: member-name check fails on the old row layout toomre
  • e03ae537gate: the phone checks run on without the Show more button (so old code reports every failed check)mre
  • adf7f132gate: 390 px checks for the mobile audit fixes (row number, filters, field widths, Edit, member names, relation taps, paging)mre
  • 28e9c938ticket list: draw the newest 50 rows and a Show more button (500 rows were a 2-4 s first paint, 740 KB, a 90 000 px phone page)mre
  • ccebb0c7mobile: ticket number stays on one line, filter chips one scrolling row, fields full width under their caption, Edit/action buttons, member names whole, 44 px relation linksmre
  • f2dc7741gate: the phone toolbar is two even rows (E2)mre
  • 20f7c33async components.hybriel 214c318: MdEditor on a phone, two even toolbar rows of 44 px targets, label 15 px, table head 16 px (E2)mre
  • d74a5482sync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
  • 9d02c540sync components.hybriel 6b0936a: the 'edited' foldable drops the theme's border and marginmre
  • 22751914sync components.hybriel 8d79ff7: bubble hugs its content, quiet 'edited' label; gate checksmre
  • c8452453sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
  • 52ba11e8sync-components: copy icons/icons.hl + README (F4); testsmre
  • 138d198dmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre