gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2a5b8b912a5b8b91Tickets conductor: T36 cap stop, resumed for proofmre2a5b8b91/components/you.hl

6.6 KB

  1. // components/you.hl — `/you` (ticket #7): the logged-in user's own page.
  2. // * the display name, and the PER-APP IDENTITY ID ident gave tickets for this identity —
  3. // shown ONLY here and only to its owner (an admin adds a person to a project by it). Ticket #20: the
  4. // projects the user is a member of, with their role.
  5. // * API TOKENS for machine clients (CONCEPT point 5): create (the token is shown ONCE — only
  6. // its sha256 is stored), list, revoke. `Authorization: Bearer <token>` acts as this user.
  7. // Logged out: a hint. A login in the shell (no reload) fills the page via the face `youData`.
  8. parent './main.hl'
  9. import { siteName } from '../project.hl'
  10. import { youOf, userOfSession, createToken, revokeToken, tokenRows } from '../lib/users.hl'
  11. import { projectsOfUser } from '../lib/projects.hl'
  12. import { hintLook, messageLook } from '../lib/looks.hl'
  13. session = null
  14. you = youOf(session)
  15. present = you != null
  16. absent = you == null
  17. youName = you != null ? you.name : ''
  18. identity = you != null ? you.identity : ''
  19. myProjects = projectsOfUser(userOfSession(session))
  20. hasProjects = myProjects.length > 0
  21. noProjects = myProjects.length == 0
  22. tokens = you != null ? you.tokens : []
  23. hasTokens = tokens.length > 0
  24. noTokens = tokens.length == 0
  25. newLabel = ''
  26. newToken = ''
  27. hasNewToken = false
  28. tokenMessage = ''
  29. __title = siteName + ' | you'
  30. Style {
  31. pMuted = hintLook + { }
  32. pMessage = messageLook + { }
  33. youView { display = 'grid' gap = '1.2rem'
  34. section { display = 'grid' gap = '.6rem' padding = '.8rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' }
  35. dl { display = 'grid' gap = '.2rem' margin = '0' }
  36. dt { fontSize = '.875rem' color = 'var(--color-text-muted)' }
  37. dd { margin = '0 0 .4rem' color = 'var(--color-text-strong)' overflowWrap = 'anywhere' }
  38. code { overflowWrap = 'anywhere' wordBreak = 'break-all' }
  39. }
  40. '#tokenform' { display = 'grid' gap = '.5rem' }
  41. tokenShown { display = 'grid' gap = '.4rem' padding = '.7rem' borderRadius = 'var(--radius-small)'
  42. p { margin = '0' }
  43. }
  44. '#newtoken' { color = 'var(--color-success)' fontSize = '.95rem' }
  45. '#tokenlist' { listStyle = 'none' margin = '0' padding = '0' display = 'grid' gap = '.4rem'
  46. li { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.3rem .8rem' padding = '.4rem .6rem' background = 'var(--color-background-sunken)' borderRadius = 'var(--radius-small)' }
  47. }
  48. '#projectlist' { listStyle = 'none' margin = '0' padding = '0' display = 'grid' gap = '.3rem' }
  49. spanRole { color = 'var(--color-text-muted)' fontSize = '.875rem' }
  50. spanLabel { flex = '1 1 10rem' color = 'var(--color-text-strong)' overflowWrap = 'anywhere' }
  51. }
  52. View {
  53. youView {
  54. h1 { "You" }
  55. if (absent) { p { id = "youhint" class = "empty" "Log in with ident (top right) to see your account and your API tokens." } }
  56. if (present) {
  57. section { id = "account"
  58. h2 { "Account" }
  59. dl {
  60. dt { "Display name" }
  61. dd { id = "youname" youName }
  62. dt { "Your ident id" }
  63. dd { code { id = "youidentity" identity } }
  64. }
  65. p { Style.pMuted "The id ident shows for the identity you logged in with. An admin of a project can add you with it." }
  66. }
  67. section { id = "myprojects"
  68. h2 { "Your projects" }
  69. if (noProjects) { p { id = "noprojects" class = "empty" "You are not a member of any project yet." } }
  70. ul { id = "projectlist"
  71. for (p of myProjects) { li { a { href = p.href p.title } " " span { Style.spanRole p.role } } }
  72. }
  73. }
  74. section { id = "tokens"
  75. h2 { "API tokens" }
  76. p { Style.pMuted "For machine clients (the architect, the scheduler): a token acts as you on every API write — send it as " code { "Authorization: Bearer <token>" } ". It is shown once." }
  77. form { id = "tokenform"
  78. on submit(e) {
  79. e.preventDefault()
  80. emit makeToken(e)
  81. }
  82. label { "Label (optional, e.g. what uses it)"
  83. input { id = "tokenlabel" name = "label" maxlength = "60" autocomplete = "off" value = newLabel on input(e) { emit setLabel(e.target.value) } }
  84. }
  85. button { id = "tokencreate" type = "submit" "Create a token" }
  86. }
  87. if (hasNewToken) {
  88. tokenShown { id = "newtokenbox"
  89. p { "Your new token — copy it now, it is not shown again:" }
  90. code { id = "newtoken" newToken }
  91. button { id = "tokendone" type = "button" class = "quiet" "I copied it" on click(e) { emit hideToken(e) } }
  92. }
  93. }
  94. p { id = "tokenmessage" Style.pMessage tokenMessage }
  95. if (noTokens) { p { id = "notokens" class = "empty" "No tokens." } }
  96. ul { id = "tokenlist"
  97. for (t of tokens) {
  98. li {
  99. span { Style.spanLabel t.label }
  100. time { t.created }
  101. button { type = "button" class = "quiet danger revoke" value = t.id "Revoke" on click(e) { emit revoke(e.target.value) } }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. fill = (y) => {
  110. you = y
  111. present = y != null
  112. absent = y == null
  113. youName = y != null ? y.name : ''
  114. identity = y != null ? y.identity : ''
  115. showTokens(y != null ? y.tokens : [])
  116. }
  117. showTokens = (list) => {
  118. tokens = list
  119. hasTokens = list.length > 0
  120. noTokens = list.length == 0
  121. }
  122. on setLabel(v) { newLabel = v }
  123. on makeToken(e) {
  124. r = emit server tokenCreate(newLabel)
  125. if (r == null || r.error != null) {
  126. tokenMessage = r != null ? r.error : 'could not create the token'
  127. return null
  128. }
  129. tokenMessage = ''
  130. newLabel = ''
  131. newToken = r.token
  132. hasNewToken = true
  133. showTokens(r.tokens)
  134. }
  135. on hideToken(e) {
  136. newToken = ''
  137. hasNewToken = false
  138. }
  139. on revoke(id) {
  140. r = emit server tokenRevoke(id)
  141. if (r == null || r.error != null) {
  142. tokenMessage = r != null ? r.error : 'could not revoke the token'
  143. return null
  144. }
  145. tokenMessage = ''
  146. showTokens(r.tokens)
  147. }
  148. // a login / name / logout in the shell, without a reload
  149. on client signedIn(tag, info) {
  150. y = emit server youData()
  151. fill(y)
  152. mine = emit server myProjectsData()
  153. myProjects = mine != null && mine.projects != null ? mine.projects : []
  154. hasProjects = myProjects.length > 0
  155. noProjects = myProjects.length == 0
  156. }
  157. on client signedOut(tag) {
  158. fill(null)
  159. newToken = ''
  160. hasNewToken = false
  161. }
  162. // ---- the faces (#31: only a real session) -------------------------------------------------
  163. on server youData(session) { return youOf(session) }
  164. on server myProjectsData(session) { return { projects = projectsOfUser(userOfSession(session)) } }
  165. on server tokenCreate(label, session) {
  166. u = userOfSession(session)
  167. if (u == null) { return { error = 'log in with ident first' } }
  168. if (u.name == '') { return { error = 'choose a display name first' } }
  169. return createToken(u.id, label)
  170. }
  171. on server tokenRevoke(id, session) {
  172. u = userOfSession(session)
  173. if (u == null) { return { error = 'log in with ident first' } }
  174. return revokeToken(u.id, id)
  175. }

Branches

Latest commits

  • 2a5b8b91Tickets conductor: T36 cap stop, resumed for proofmre
  • 6a82097fTickets conductor: Arachne W228 on day35 flakemre
  • 0ee5a6f2Tickets conductor: T36 resumedmre
  • 9149c165Tickets conductor: T36 diagnosismre
  • 91713313Tickets conductor: T36 report 1mre
  • 756315d2Tickets conductor: T36 startedmre
  • 0814ce6bTickets conductor: brief 025 tickets#36 style formmre
  • 1b6916c4Tickets conductor: Atlas handover tickets#36mre
  • aab95226Tickets conductor: worldapi-conductor paths, deploy blocker = read-only diskmre
  • 6372b06dTickets conductor: worker port slotmre
  • 836af31cTickets conductor: token pathsmre
  • b03f11b6Tickets conductor: CONDUCTOR.md (project part), short STATUS.md, old STATUS to archive/2026-10-31mre
  • 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