gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit090ee809090ee809tickets: 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)mre090ee809/components/you.hl

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

Branches

Latest commits

  • 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
  • 40fddc20tickets takes components e54f83a: tables get thin grey lines from the theme, desktop toolbar stays one row with the Table button, F4 check counts 11 buttonsmre
  • c1b77d61tickets#35: text typed before the editor is built is taken in once by the build (the input handler no longer writes it to the field first, which doubled the first letters); the gate failure shows the surfacemre
  • 32bf1873tickets#35: the gate types right after the load with the CPU slowed, no waitingmre
  • 64ea9ca2tickets#35: text typed into the reply editor before the page has finished starting is kept; the gate types right after loadmre
  • ccd3a327tickets: the security gate expects frame-src to be exactly the ident address (the sign-in frame), still no wildcard or selfmre
  • 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