gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9334845393348453Re-vendor tickets to Hybriel set day35mre93348453/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. pMessage = messageLook + { }
  36. pNotice = noticeLook + { }
  37. connectPage { display = 'grid' gap = '1rem' maxWidth = '38rem'
  38. form { display = 'grid' gap = '.8rem' }
  39. }
  40. }
  41. View {
  42. connectPage {
  43. if (gone) { p { id = "gone" class = "empty" "This connection request is used up or expired. Start again from the app." } }
  44. if (valid) {
  45. h1 { id = "connecttitle" "Connect " appName " to a project" }
  46. p { id = "connectwho" Style.pHint
  47. strong { appName }
  48. if (hasLabel) { " (" appLabel ")" }
  49. " at "
  50. strong { appHost }
  51. " 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."
  52. }
  53. }
  54. if (mustLogIn) { p { id = "loginhint" Style.pHint "Log in with ident (top right) and choose a display name to connect." } }
  55. if (showForm) {
  56. form { id = "connectform"
  57. on submit(e) {
  58. e.preventDefault()
  59. emit confirm(e)
  60. }
  61. label { "Project"
  62. select { id = "connectproject" name = "project" value = choice on change(e) { emit setChoice(e.target.value) }
  63. for (c of choices) { option { value = c.id c.title } }
  64. option { value = "" "A new project" }
  65. }
  66. }
  67. if (makeNew) {
  68. label { "Title of the new project"
  69. input { id = "connecttitleinput" name = "title" required = "required" maxlength = "100" autocomplete = "off" value = newTitle on input(e) { emit setNewTitle(e.target.value) } }
  70. }
  71. }
  72. button { id = "connectconfirm" type = "submit" "Connect" }
  73. p { id = "connectmessage" Style.pMessage message }
  74. }
  75. }
  76. if (done) {
  77. p { id = "connected" Style.pNotice "Connected to " strong { doneProject } ". " }
  78. a { id = "connectcontinue" class = "button" href = doneUrl "Continue to " appName }
  79. }
  80. }
  81. }
  82. on setChoice(v) {
  83. choice = v
  84. makeNew = v == ''
  85. }
  86. on setNewTitle(v) { newTitle = v }
  87. on confirm(e) {
  88. if (makeNew && newTitle.trim() == '') { return null }
  89. r = emit server connectConfirm(nonce, choice, newTitle)
  90. if (r == null || r.error != null) {
  91. message = r != null ? r.error : 'could not connect'
  92. return null
  93. }
  94. message = ''
  95. showForm = false
  96. doneUrl = r.url
  97. doneProject = r.project
  98. done = true
  99. }
  100. on client signedIn(tag, info) {
  101. r = emit server connectChoices()
  102. if (r != null && r.projects != null) {
  103. choices = r.projects
  104. choice = r.projects.length > 0 ? r.projects[0].id : ''
  105. makeNew = r.projects.length == 0
  106. }
  107. canWrite = valid && info.named
  108. showForm = valid && info.named && !done
  109. mustLogIn = valid && !info.named
  110. }
  111. on client signedOut(tag) {
  112. canWrite = false
  113. showForm = false
  114. mustLogIn = valid
  115. choices = []
  116. }
  117. on server connectChoices(session) {
  118. u = userOfSession(session)
  119. if (u == null) { return { error = 'log in first' } }
  120. return { projects = adminProjects(u) }
  121. }
  122. on server connectConfirm(nonce, projectId, title, session) {
  123. w = writerOfSession(session)
  124. if (w.error != null) { return { error = w.error } }
  125. if (hlTypeName(nonce) != 'String' || hlTypeName(projectId) != 'String' || hlTypeName(title) != 'String') { return { error = 'nonce, project and title must be text' } }
  126. r = confirmRequest(nonce, w.user, projectId, title)
  127. if (r.error != null) { return { error = r.error } }
  128. return { url = r.url project = r.project slug = r.slug }
  129. }

Branches

Latest commits

  • 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
  • 2e1b116ftickets: re-vendor Hybriel master acaceaf3 (framework ec8d6c1d): plugins/web patch queue while a page is built, anonymous session cookies refresh; gate waits for the comment editors to draw (W174) and clicks the form editor when it stands still; security gate: main's code runs on its own binary, lazy-session cookie checksmre
  • 361bc0fetickets: re-vendor Hybriel 7a684920 (WIP, not deployed); on Error exits 1 at startup; migrate passes its log by reference; gate checks follow lazy sessions and the 413 refusalmre
  • 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
  • 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
  • 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre
  • 8179d287tickets: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
  • 0398145ctickets: the table grid rule is marked functional for check-thememre