tickets
All repositories: gitoria
6.7 KB
// components/you.hl — `/you` (ticket #7): the logged-in user's own page.// * the display name, and the PER-APP IDENTITY ID ident gave tickets for this identity —// shown ONLY here and only to its owner (an admin adds a person to a project by it). Ticket #20: the// projects the user is a member of, with their role.// * API TOKENS for machine clients (CONCEPT point 5): create (the token is shown ONCE — only// its sha256 is stored), list, revoke. `Authorization: Bearer <token>` acts as this user.// Logged out: a hint. A login in the shell (no reload) fills the page via the face `youData`.parent './main.hl'import { siteName } from '../project.hl'import { youOf, userOfSession, createToken, revokeToken, tokenRows } from '../lib/users.hl'import { projectsOfUser } from '../lib/projects.hl'import { hintLook, messageLook } from '../lib/looks.hl'session = nullyou = youOf(session)present = you != nullabsent = you == nullyouName = you != null ? you.name : ''identity = you != null ? you.identity : ''myProjects = projectsOfUser(userOfSession(session))hasProjects = myProjects.length > 0noProjects = myProjects.length == 0tokens = you != null ? you.tokens : []hasTokens = tokens.length > 0noTokens = tokens.length == 0newLabel = ''newToken = ''hasNewToken = falsetokenMessage = ''__title = siteName + ' | you'Style {pMuted = hintLook + { }'#tokenmessage' = messageLook + { }youView {display = 'grid'gap = '1.2rem'section {display = 'grid'gap = '.6rem'padding = '.8rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}dl {display = 'grid'gap = '.2rem'margin = '0'}dt {fontSize = '.875rem'color = 'var(--color-text-muted)'}dd {margin = '0 0 .4rem'color = 'var(--color-text-strong)'overflowWrap = 'anywhere'}code {overflowWrap = 'anywhere'wordBreak = 'break-all'}}'#tokenform' {display = 'grid'gap = '.5rem'}tokenShown {display = 'grid'gap = '.4rem'padding = '.7rem'borderRadius = 'var(--radius-small)'p {margin = '0'}}'#newtoken' {color = 'var(--color-success)'fontSize = '.95rem'}'#tokenlist' {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.4rem'li {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '.3rem .8rem'padding = '.4rem .6rem'background = 'var(--color-background-sunken)'borderRadius = 'var(--radius-small)'}}'#projectlist' {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.3rem'}spanRole {color = 'var(--color-text-muted)'fontSize = '.875rem'}spanLabel {flex = '1 1 10rem'color = 'var(--color-text-strong)'overflowWrap = 'anywhere'}}View {youView {h1 { "You" }if (absent) { p { id = "youhint" class = "empty" "Log in with ident (top right) to see your account and your API tokens." } }if (present) {section { id = "account"h2 { "Account" }dl {dt { "Display name" }dd { id = "youname" youName }dt { "Your ident id" }dd { code { id = "youidentity" identity } }}p { Style.pMuted "The id ident shows for the identity you logged in with. An admin of a project can add you with it." }}section { id = "myprojects"h2 { "Your projects" }if (noProjects) { p { id = "noprojects" class = "empty" "You are not a member of any project yet." } }ul { id = "projectlist"for (p of myProjects) { li { a { href = p.href p.title } " " span { Style.spanRole p.role } } }}}section { id = "tokens"h2 { "API tokens" }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." }form { id = "tokenform"on submit(e) {e.preventDefault()emit makeToken(e)}label { "Label (optional, e.g. what uses it)"input { id = "tokenlabel" name = "label" maxlength = "60" autocomplete = "off" value = newLabel on input(e) { emit setLabel(e.target.value) } }}button { id = "tokencreate" type = "submit" "Create a token" }}if (hasNewToken) {tokenShown { id = "newtokenbox"p { "Your new token — copy it now, it is not shown again:" }code { id = "newtoken" newToken }button { id = "tokendone" type = "button" class = "quiet" "I copied it" on click(e) { emit hideToken(e) } }}}p { id = "tokenmessage" tokenMessage }if (noTokens) { p { id = "notokens" class = "empty" "No tokens." } }ul { id = "tokenlist"for (t of tokens) {li {span { Style.spanLabel t.label }time { t.created }button { type = "button" class = "quiet danger revoke" value = t.id "Revoke" on click(e) { emit revoke(e.target.value) } }}}}}}}}fill = (y) => {you = ypresent = y != nullabsent = y == nullyouName = y != null ? y.name : ''identity = y != null ? y.identity : ''showTokens(y != null ? y.tokens : [])}showTokens = (list) => {tokens = listhasTokens = list.length > 0noTokens = list.length == 0}on setLabel(v) { newLabel = v }on makeToken(e) {r = emit server tokenCreate(newLabel)if (r == null || r.error != null) {tokenMessage = r != null ? r.error : 'could not create the token'return null}tokenMessage = ''newLabel = ''newToken = r.tokenhasNewToken = trueshowTokens(r.tokens)}on hideToken(e) {newToken = ''hasNewToken = false}on revoke(id) {r = emit server tokenRevoke(id)if (r == null || r.error != null) {tokenMessage = r != null ? r.error : 'could not revoke the token'return null}tokenMessage = ''showTokens(r.tokens)}// a login / name / logout in the shell, without a reloadon client signedIn(tag, info) {y = emit server youData()fill(y)mine = emit server myProjectsData()myProjects = mine != null && mine.projects != null ? mine.projects : []hasProjects = myProjects.length > 0noProjects = myProjects.length == 0}on client signedOut(tag) {fill(null)newToken = ''hasNewToken = false}// ---- the faces (#31: only a real session) -------------------------------------------------on server youData(session) { return youOf(session) }on server myProjectsData(session) { return { projects = projectsOfUser(userOfSession(session)) } }on server tokenCreate(label, session) {u = userOfSession(session)if (u == null) { return { error = 'log in with ident first' } }if (u.name == '') { return { error = 'choose a display name first' } }return createToken(u.id, label)}on server tokenRevoke(id, session) {u = userOfSession(session)if (u == null) { return { error = 'log in with ident first' } }return revokeToken(u.id, id)}
Branches
Latest commits
- b8fdeee9Merge branch 'p39-routes' into mainTickets
- a0187a0a|||PR Remove redundant route-order loopmre
- 369e4b9cMerge branch 'k40-lists' into mainTickets
- 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
- 610d8e8aMerge branch 'records-t39' into mainTickets
- 32bcdf24|||PR records: GO P39 K40mre
- 4123c6d1Merge branch 'records-t38' into mainTickets
- cd3641a1|||PR records: day72 deploy live, tickets closedmre
- 7d44d852Merge branch 'records-t37' into mainTickets
- 926f7061|||PR records: merges, D36 deploymre
- bf58534eMerge branch 'l33-final' into mainTickets
- 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
- 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
- 5822cb3aMerge branch 'o34-clean' into mainTickets
- 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
- 14cf96b4Merge branch 'records-t36' into mainTickets
- 07749fa1|||PR records: day72 + #40 mergedmre
- ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre
- 6dea1c60Merge branch 'r35-day72' into mainTickets
- 7bcfdc22|||PR drop worker edits to conductor recordsmre