gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit03c1de0503c1de05new_project: format Style with nested language rulesmre03c1de05/lib/migrate.hl

4.6 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. // Writes no table itself (tickets#47): each topic file exposes the write as a function (projects.hl rewriteSlug / addProjectNamed /
  15. // addMember, tickets.hl moveToProject, events.hl renameStates) and this file calls those.
  16. import { countOf } from './util.hl'
  17. import { ensureCreatorUser, userRecord } from './users.hl'
  18. import { rewriteSlug, addProjectNamed, hasMembers, addMember, projectRecord, projectBySlug, projectRecords, adminCount } from './projects.hl'
  19. import { stateOf } from './tickets-helpers.hl'
  20. import { eventRecords, eventRecordsOf, renameStates } from './events.hl'
  21. import { ticketRecords, ticketRecordsOf, moveToProject } from './tickets.hl'
  22. static botNames = ['Architect' 'AntColonyScheduler']
  23. static migrateProjects = (&log) => {
  24. all = projectRecords()
  25. if (countOf(all) == 0) { return 0 }
  26. let n = 0
  27. for (p of all) {
  28. if (p.slug == null) {
  29. rewriteSlug(p)
  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 = eventRecordsOf(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 = ticketRecords()
  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. p = addProjectNamed(t.project)
  51. }
  52. let s = stateOf(t.state)
  53. if (t.state == 'awaiting creator' && t.subject != null && t.subject.startsWith('Question')) { s = 'pending' }
  54. if (s == null) { s = 'open' }
  55. let who = ''
  56. if ((s == 'review' || s == 'pending') && creator != null) { who = creator.id }
  57. moveToProject(t, p, s, createdByOf(t), who)
  58. n = n + 1
  59. }
  60. }
  61. if (n > 0) { log.push(n + ' ticket(s) linked to their project by id, states renamed') }
  62. return n
  63. }
  64. static migrateEvents = (&log) => {
  65. all = eventRecords()
  66. if (countOf(all) == 0) { return 0 }
  67. let n = 0
  68. for (e of all) {
  69. if (e.kind == 'state') {
  70. a = stateOf(e.from)
  71. b = stateOf(e.to)
  72. nf = a != null ? a : e.from
  73. nt = b != null ? b : e.to
  74. if (nf != e.from || nt != e.to) {
  75. renameStates(e, nf, nt)
  76. n = n + 1
  77. }
  78. }
  79. }
  80. if (n > 0) { log.push(n + ' state event(s) renamed') }
  81. return n
  82. }
  83. static migrateMembers = (&log, creator) => {
  84. let n = 0
  85. for (p of projectRecords()) {
  86. if (!hasMembers(p.id)) {
  87. // who wrote in the project: users @id → true
  88. wrote = {}
  89. order = []
  90. tickets = ticketRecordsOf(p.id)
  91. if (countOf(tickets) > 0) {
  92. for (t of tickets) {
  93. evs = eventRecordsOf(t.id)
  94. if (countOf(evs) > 0) {
  95. for (e of evs) {
  96. if (e.user != null && e.user != '' && wrote[e.user] != true) {
  97. wrote[e.user] = true
  98. order.push(e.user)
  99. }
  100. }
  101. }
  102. }
  103. }
  104. for (uid of order) {
  105. u = userRecord(uid)
  106. if (u != null) { addMember(p.id, uid, botNames.includes(u.name) ? 'edit' : 'use') }
  107. }
  108. n = n + 1
  109. }
  110. if (creator != null && adminCount(p.id) == 0) {
  111. addMember(p.id, creator.id, 'admin')
  112. n = n + 1
  113. }
  114. }
  115. if (n > 0) { log.push('members set up in ' + n + ' project(s)') }
  116. return n
  117. }
  118. // answers the lines describing what changed (an empty list = nothing to do)
  119. static migrateAll = () => {
  120. log = []
  121. creator = ensureCreatorUser()
  122. migrateProjects(&log)
  123. migrateTickets(&log, creator)
  124. migrateEvents(&log)
  125. migrateMembers(&log, creator)
  126. return log
  127. }

Branches

Latest commits

  • 03c1de05new_project: format Style with nested language rulesmre
  • bd76cfa6connect: format Style with nested language rulesmre
  • 01fad593inbox: format Style with nested language rulesmre
  • 79dc9392you: format Style with nested language rulesmre
  • 78073baamain: format Style with nested language rulesmre
  • 5499c290Sync theme unchanged from layouts 17e0f03mre
  • fd33ee21Sync reviewed components from 8176eb1mre
  • 93348453Re-vendor tickets to Hybriel set day35mre
  • a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
  • cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
  • 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
  • b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
  • f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
  • 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
  • 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
  • d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
  • afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre
  • 48c1ba79tickets: md-paste-files gate with the file manager casesmre
  • f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mre
  • 06599fa0tickets: MdEditor from components b0f1ec2 (a clipboard with text always pastes the text, tickets#49); real Ctrl+V gatemre