gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit4348dbab4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre4348dbab/lib/migrate.hl

5.0 KB

  1. // lib/migrate.hl — THE MIGRATION OF TICKET #20 (projects as own data, members, new states). Statics only.
  2. // Idempotent: it looks at the SHAPE of the data, so a second run (and every start of the app, project.hl
  3. // calls migrateAll) changes nothing. What it does to a store from before:
  4. // 1. a project record `{ name, created }` becomes `{ title = name, slug = name, description = '', oldSlugs = '' }`
  5. // 2. every ticket points at its project by the project's id (`project`, `path` = '<id>/<number>'), not by name;
  6. // `createdBy` = the user of its 'created' event; the state gets its new name (awaiting creator → review,
  7. // a "Question…" ticket → pending; confirmed → done, rejected → reopened, in progress → progress, on hold →
  8. // pending, anything unknown → open); a ticket in review / pending is ASSIGNED to the creator's user
  9. // 3. the state events of the history get the new names too
  10. // 4. a project without members gets: the creator (TICKETS_CREATOR_IDENTITY, users.hl) as admin; the users
  11. // named Architect and AntColonyScheduler that wrote in it as edit; everybody else who wrote in it as use.
  12. // A project with no admin at all gets the creator as admin as soon as the creator is known.
  13. // TICKETS_CREATOR_IDENTITY is read ONLY here (the creator-only workflow is gone).
  14. // The one file that writes the tables of other topics (projects, members, tickets, events) directly: a data migration.
  15. import { now } from 'hl:time'
  16. import { merged, countOf } from './util.hl'
  17. import { ensureCreatorUser, userRecord } from './users.hl'
  18. import { projectsTable, membersTable, addMember, projectRecord, projectBySlug, projectRecords, adminCount } from './projects.hl'
  19. import { stateOf } from './tickets-helpers.hl'
  20. import { eventsTable } from './events.hl'
  21. import { ticketsTable } from './tickets.hl'
  22. static botNames = ['Architect' 'AntColonyScheduler']
  23. static migrateProjects = (&log) => {
  24. all = projectsTable.find(null, null)
  25. if (countOf(all) == 0) { return 0 }
  26. let n = 0
  27. for (p of all) {
  28. if (p.slug == null) {
  29. projectsTable.update(p.id, { id = p.id title = p.name slug = p.name description = '' oldSlugs = '' created = p.created })
  30. n = n + 1
  31. }
  32. }
  33. if (n > 0) { log.push(n + ' project(s) turned into records') }
  34. return n
  35. }
  36. static createdByOf = (t) => {
  37. all = eventsTable.find('ticket', t.id)
  38. if (countOf(all) == 0) { return '' }
  39. for (e of all) { if (e.kind == 'created' && e.user != null) { return e.user } }
  40. return ''
  41. }
  42. static migrateTickets = (&log, creator) => {
  43. all = ticketsTable.find(null, null)
  44. if (countOf(all) == 0) { return 0 }
  45. let n = 0
  46. for (t of all) {
  47. if (projectRecord(t.project) == null) {
  48. let p = projectBySlug(t.project)
  49. if (p == null) {
  50. let pid = projectsTable.put({ title = t.project slug = t.project description = '' oldSlugs = '' created = now() })
  51. p = projectRecord(pid)
  52. }
  53. let s = stateOf(t.state)
  54. if (t.state == 'awaiting creator' && t.subject != null && t.subject.startsWith('Question')) { s = 'pending' }
  55. if (s == null) { s = 'open' }
  56. let who = ''
  57. if ((s == 'review' || s == 'pending') && creator != null) { who = creator.id }
  58. ticketsTable.update(t.id, merged(t, { project = p.id path = p.id + '/' + t.number state = s createdBy = createdByOf(t) assignee = who }))
  59. n = n + 1
  60. }
  61. }
  62. if (n > 0) { log.push(n + ' ticket(s) linked to their project by id, states renamed') }
  63. return n
  64. }
  65. static migrateEvents = (&log) => {
  66. all = eventsTable.find(null, null)
  67. if (countOf(all) == 0) { return 0 }
  68. let n = 0
  69. for (e of all) {
  70. if (e.kind == 'state') {
  71. let a = stateOf(e.from)
  72. let b = stateOf(e.to)
  73. let nf = a != null ? a : e.from
  74. let nt = b != null ? b : e.to
  75. if (nf != e.from || nt != e.to) {
  76. eventsTable.update(e.id, merged(e, { from = nf to = nt }))
  77. n = n + 1
  78. }
  79. }
  80. }
  81. if (n > 0) { log.push(n + ' state event(s) renamed') }
  82. return n
  83. }
  84. static migrateMembers = (&log, creator) => {
  85. let n = 0
  86. for (p of projectRecords()) {
  87. if (countOf(membersTable.find('project', p.id)) == 0) {
  88. // who wrote in the project: users @id → true
  89. let wrote = {}
  90. let order = []
  91. let tickets = ticketsTable.find('project', p.id)
  92. if (countOf(tickets) > 0) {
  93. for (t of tickets) {
  94. let evs = eventsTable.find('ticket', t.id)
  95. if (countOf(evs) > 0) {
  96. for (e of evs) {
  97. if (e.user != null && e.user != '' && wrote[e.user] != true) {
  98. wrote[e.user] = true
  99. order.push(e.user)
  100. }
  101. }
  102. }
  103. }
  104. }
  105. for (uid of order) {
  106. let u = userRecord(uid)
  107. if (u != null) { addMember(p.id, uid, botNames.includes(u.name) ? 'edit' : 'use') }
  108. }
  109. n = n + 1
  110. }
  111. if (creator != null && adminCount(p.id) == 0) {
  112. addMember(p.id, creator.id, 'admin')
  113. n = n + 1
  114. }
  115. }
  116. if (n > 0) { log.push('members set up in ' + n + ' project(s)') }
  117. return n
  118. }
  119. // answers the lines describing what changed (an empty list = nothing to do)
  120. static migrateAll = () => {
  121. log = []
  122. creator = ensureCreatorUser()
  123. migrateProjects(log)
  124. migrateTickets(log, creator)
  125. migrateEvents(log)
  126. migrateMembers(log, creator)
  127. return log
  128. }

Branches

Latest commits

  • 4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 66ef3005Merge branch 'iw-ident-widget'mre
  • bc0ad663tickets: a gap between your name and Log out in the phone header (they touched); gate checks itmre
  • 2f818d46UX2: report, LOG line, e2e fixes, gate pause after loadmre
  • af3ef7c4gate: the legacy state line says progressmre
  • 62480a00tickets#33: a state change with a note is a comment card in the feed (same framework rendering, can be liked, edited, deleted), its state line stands alone; gate checks for a new comment with and without a state change, at once and after a reloadmre
  • 4ae80007UX: Respond is one composer (state in its footer, button says what happens); New ticket / New project windows in the list heading row; project form shared; theme copied from layouts; gates and a lisbeth e2emre
  • f03b438atickets header: the selector alone top right plus your name and Log out as before the theme missions; the user icon is gonemre
  • 81f10e4eident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • e9f428e7tools: reown-authors (tracker#36: every author that is not Caramboleyo or Apollo becomes the project's conductor; antcolony, miserit-anthar, hybrilior, termuplex stay) and a read-only author surveymre
  • f51029abMerge branch 'sy-sync'mre
  • eae6e8c7sync components.hybriel 4922f9c: comments like / Edit / Delete / 'edited' are 44 px targets; gate: 'edited' hit-area padding, thread targets check (SY)mre
  • 0de4750btheme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)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