gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit59c02e4d59c02e4dMerge e30: preserve edited state note labels in Markdownmre59c02e4d/components/you.hl

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

Branches

Latest commits

  • 59c02e4dMerge e30: preserve edited state note labels in Markdownmre
  • 30970796Log E30 deploy GOmre
  • 7c8e6d83Limit edited state note fix to Markdown renderingmre
  • 910536d0Log E30 reviewmre
  • 36984386Preserve state transitions when their notes are editedmre
  • d75cb946Log E30 startmre
  • 0bf3fefaMission 030: edited state note labelmre
  • 691565c6Log neutral-ticket rule checkmre
  • bc3bdecerecords: day38b live, #94 purgedmre
  • f6c5aa0dMerge main (records)mre
  • e23d42acconnect gate: wait for hydration before clicking Disconnectmre
  • a5d45d00records: D38 cause, GOmre
  • 19eeb938records: D38 gates, two day38b failuresmre
  • f8e42a85Re-vendor tickets to Hybriel set day38b (1e554d7)mre
  • 51645016Merge purge-94 (#94, identity rule)mre
  • 94d6ca2arecords: D38 startedmre
  • 9df09aacmission 029: day38b re-vendor + deploymre
  • d2834f65records: #94 backup planmre
  • 4467d8cbrecords: #94 purge readymre
  • aa2d124eREADME: the #94 purge gatemre