gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8517d14c8517d14cTickets conductor: Hermes push endpointmre8517d14c/components/connect.hl

4.8 KB

  1. // components/connect.hl — `/connect/:nonce` (ticket #21): another app (first: gitoria) asks to be connected to one
  2. // project. The person — logged in through ident, with a display name — picks a project they are ADMIN of, or makes a
  3. // new one, and confirms. Then the page links back to the app with a one-time code (connections.hl); the app's server
  4. // swaps the code for a key that reaches that one project. Everybody else sees the login hint; a used or expired
  5. // request says so. Everything is checked again by the store in the faces.
  6. parent './main.hl'
  7. import { requestOf, requestView, adminProjects, confirmRequest } from '../lib/connections.hl'
  8. import { siteName } from '../project.hl'
  9. import { userOfSession, writerOfSession, canWriteSession } from '../lib/users.hl'
  10. import { hintLook, messageLook, noticeLook } from '../lib/looks.hl'
  11. nonce = null
  12. session = null
  13. pending = requestOf(nonce)
  14. valid = pending != null
  15. gone = pending == null
  16. info = pending != null ? requestView(pending) : { app = '' label = '' hasLabel = false host = '' }
  17. appName = info.app
  18. appLabel = info.label
  19. hasLabel = info.hasLabel
  20. appHost = info.host
  21. canWrite = valid && canWriteSession(session)
  22. showForm = valid && canWriteSession(session)
  23. mustLogIn = valid && !canWriteSession(session)
  24. choices = adminProjects(userOfSession(session))
  25. choice = choices.length > 0 ? choices[0].id : ''
  26. makeNew = choices.length == 0
  27. newTitle = ''
  28. message = ''
  29. done = false
  30. doneUrl = ''
  31. doneProject = ''
  32. __title = siteName + ' | connect ' + (pending != null ? pending.app : 'an app')
  33. Style {
  34. pHint = hintLook + { }
  35. '#connectmessage' = messageLook + { }
  36. '#connected' = noticeLook + { }
  37. connectPage {
  38. display = 'grid'
  39. gap = '1rem'
  40. maxWidth = '38rem'
  41. form {
  42. display = 'grid'
  43. gap = '.8rem'
  44. }
  45. }
  46. }
  47. View {
  48. connectPage {
  49. if (gone) { p { id = "gone" class = "empty" "This connection request is used up or expired. Start again from the app." } }
  50. if (valid) {
  51. h1 { id = "connecttitle" "Connect " appName " to a project" }
  52. p { id = "connectwho" Style.pHint
  53. strong { appName }
  54. if (hasLabel) { " (" appLabel ")" }
  55. " at "
  56. strong { appHost }
  57. " asks for a key to ONE of your projects. With it the app can open tickets, comment and change their state there — for the people who work in it, within their roles. You can disconnect it on the project's page at any time."
  58. }
  59. }
  60. if (mustLogIn) { p { id = "loginhint" Style.pHint "Log in with ident (top right) and choose a display name to connect." } }
  61. if (showForm) {
  62. form { id = "connectform"
  63. on submit(e) {
  64. e.preventDefault()
  65. emit confirm(e)
  66. }
  67. label { "Project"
  68. select { id = "connectproject" name = "project" value = choice on change(e) { emit setChoice(e.target.value) }
  69. for (c of choices) { option { value = c.id c.title } }
  70. option { value = "" "A new project" }
  71. }
  72. }
  73. if (makeNew) {
  74. label { "Title of the new project"
  75. input { id = "connecttitleinput" name = "title" required = "required" maxlength = "100" autocomplete = "off" value = newTitle on input(e) { emit setNewTitle(e.target.value) } }
  76. }
  77. }
  78. button { id = "connectconfirm" type = "submit" "Connect" }
  79. p { id = "connectmessage" message }
  80. }
  81. }
  82. if (done) {
  83. p { id = "connected" "Connected to " strong { doneProject } ". " }
  84. a { id = "connectcontinue" class = "button" href = doneUrl "Continue to " appName }
  85. }
  86. }
  87. }
  88. on setChoice(v) {
  89. choice = v
  90. makeNew = v == ''
  91. }
  92. on setNewTitle(v) { newTitle = v }
  93. on confirm(e) {
  94. if (makeNew && newTitle.trim() == '') { return null }
  95. r = emit server connectConfirm(nonce, choice, newTitle)
  96. if (r == null || r.error != null) {
  97. message = r != null ? r.error : 'could not connect'
  98. return null
  99. }
  100. message = ''
  101. showForm = false
  102. doneUrl = r.url
  103. doneProject = r.project
  104. done = true
  105. }
  106. on client signedIn(tag, info) {
  107. r = emit server connectChoices()
  108. if (r != null && r.projects != null) {
  109. choices = r.projects
  110. choice = r.projects.length > 0 ? r.projects[0].id : ''
  111. makeNew = r.projects.length == 0
  112. }
  113. canWrite = valid && info.named
  114. showForm = valid && info.named && !done
  115. mustLogIn = valid && !info.named
  116. }
  117. on client signedOut(tag) {
  118. canWrite = false
  119. showForm = false
  120. mustLogIn = valid
  121. choices = []
  122. }
  123. on server connectChoices(session) {
  124. u = userOfSession(session)
  125. if (u == null) { return { error = 'log in first' } }
  126. return { projects = adminProjects(u) }
  127. }
  128. on server connectConfirm(nonce, projectId, title, session) {
  129. w = writerOfSession(session)
  130. if (w.error != null) { return { error = w.error } }
  131. if (hlTypeName(nonce) != 'String' || hlTypeName(projectId) != 'String' || hlTypeName(title) != 'String') { return { error = 'nonce, project and title must be text' } }
  132. r = confirmRequest(nonce, w.user, projectId, title)
  133. if (r.error != null) { return { error = r.error } }
  134. return { url = r.url project = r.project slug = r.slug }
  135. }

Branches

Latest commits

  • 8517d14cTickets conductor: Hermes push endpointmre
  • aa4e192cTickets conductor: brief 027 push protocol changemre
  • c5d28fb5Tickets conductor: S51 startedmre
  • fd6ca1e6Tickets conductor: brief 027 waker design, push-test projectmre
  • e448e656Tickets conductor: STATUS #51mre
  • 1c10857bTickets conductor: P51 eval, brief 027mre
  • e725969dTickets conductor: #51 directionmre
  • 1b5c63ddTickets conductor: P51 startedmre
  • 9f13fbdaTickets conductor: brief 026 prioritymre
  • acc477d9Tickets conductor: brief 026 + Vinzenz recommendationsmre
  • 9233a734Tickets conductor: brief 026 completemre
  • 5da589fdTickets conductor: brief 026 + Gitoria's answermre
  • a3cd5329Tickets conductor: tickets#51 opened, brief 026 draftmre
  • 6f6e5797Tickets conductor: STATUS wordingmre
  • 957de51fTickets conductor: T36 live, #36 review, #50 donemre
  • bc2fde32Merge branch 'main' into t36-stylemre
  • b7ca093atests: wait for the new row and normalize editor marker spacesmre
  • 41da3525Tickets conductor: flake cause, T36 deploy stepmre
  • 64c477e6Tickets conductor: deploy waits for Arachnemre
  • 467d7286Tickets conductor: T36 done, deploy questionmre