ident
All repositories: gitoria
21.7 KB
// components/access.hl — `/access`: WHO MAY ACT IN WHICH OF YOUR APPS (ident#27; the screens he approved 2026-10-29, mockups 027-01…08).// The matrix (identity × app), "Give access" in three steps (who → which apps, level, label → the key, shown once), a cell's sheet// (since, last use, level, rotate, revoke). The account stays signed in as itself: no logging out and in. The server side is lib/access.hl.//// The faces' names start with `acc…`: a face is found by its EVENT NAME across all files (hl:web).parent './main.hl'import { accountOfSession } from '../lib/accounts.hl'import { matrix, pickList, cellOf, giveAccess, revokeAccess, setLevel, rotateKey } from '../lib/access.hl'import { siteName } from '../project.hl'import { messageLook, noticeLook } from './styles.hl'session = nullme = accountOfSession(&session)signedIn = me != nullsignedOut = me == nulldata = me != null ? matrix(me.id) : { apps = [] rows = [] never = [] hasNever = false }apps = data.appsrows = data.rowsnever = data.neverhasNever = data.hasNevernoApps = apps.length == 0hasApps = apps.length > 0__title = siteName + ' | access'// WHICH SCREEN: 'overview' | 'who' (step 1) | 'where' (step 2) | 'key' (step 3)screen = 'overview'isOverview = trueisWho = falseisWhere = falseisKey = falsepickRows = []pickId = ''newMode = falsenewName = ''tickRows = []allOn = falselevel = 'write'writeCls = 'seg on'readCls = 'seg'newCls = 'newone'doneLabel = 'Done'label = ''// THE KEY, shown once (never kept by the server)keyText = ''keyWho = ''keyApps = []hasKey = falsenewKeyNeeded = truehasKeyText = falsenoKeyText = truedoneText = ''// the cell's sheetsheetOpen = falsesheet = nullmessage = ''notice = ''View {accessPage {if (signedOut) {h1 { "Access" }p { id = "signinfirst" "Sign in to ident first: " a { href = "/" "sign in" } "." }}if (signedIn) {if (isOverview) {section { id = "accesssection"h1 { "Access" }p { "Which identity may act in which of your apps." }if (noApps) { p { id = "noapps" "No apps yet. Register an app first, then give an identity access to it: " a { href = "/apps" "your apps" } "." } }if (hasApps) {accessMatrix { table { id = "matrix"thead { tr { th { } for (a of apps) { th { a.name } } } }tbody {for (r of rows) {tr {th { a { href = r.href r.label } whoSub { r.sub } }for (c of r.cells) {td { button { type = "button" class = c.cls value = c.value title = c.tip 'aria-label' = c.tipon click(e) { emit accOpenCell(e.target.value) }c.glyph } }}}}}} }matrixKey { id = "legend" "● agent key works · ◐ you log in there · ○ no access. Tap a cell for since / last use / revoke." }}if (hasNever) {h2 { "Never used" }ul { id = "neverused"for (n of never) {li {neverMain { neverName { n.text } neverLine { n.line } }button { type = "button" class = "quiet small" name = "revoke" value = n.value "Revoke" on click(e) { emit accRevokeNever(e.target.value) } }}}}}if (hasApps) { button { id = "give" type = "button" class = "primary" "+ Give access" on click(e) { emit accStartGive(e) } } }}}if (isWho) {section { id = "whosection"stepLabel { "STEP 1 OF 3" }h1 { "Who gets access?" }ul { id = "picklist"for (p of pickRows) {li { class = p.clsbutton { type = "button" Style.pickCard value = p.id on click(e) { emit accPick(e.currentTarget.value) }avatarDot { class = p.dot p.initial }pickMain { pickName { p.label } pickSub { p.sub } }pickMark { p.mark }}}}li { class = newClsbutton { type = "button" id = "newidentity" Style.pickCard on click(e) { emit accPickNew(e) }avatarDot { "+" }pickMain { pickName { "New identity" } pickSub { "just a name, nothing else needed" } }}}}if (newMode) {label { "Name"input { id = "newname" name = "newname" maxlength = "60" autocomplete = "off" placeholder = "e.g. Hermes" value = newName on input(e) { emit accSetNewName(e.target.value) } }}}p { id = "message" Style.pMessage message }button { id = "next" type = "button" class = "primary" "Next" on click(e) { emit accNext(e) } }button { id = "cancelgive" type = "button" class = "quiet" "Cancel" on click(e) { emit accCancel(e) } }}}if (isWhere) {section { id = "wheresection"stepLabel { "STEP 2 OF 3" }h1 { "Where can " keyWho " act?" }ul { id = "ticklist"li {label {input { id = "allapps" type = "checkbox" checked = allOn on change(e) { emit accToggleAll(e.target.checked) } }tickMain { tickName { "All my apps (" + apps.length + ")" } tickSub { "today’s apps; new apps ask again" } }}}for (t of tickRows) {li {label {input { type = "checkbox" name = "app" value = t.id checked = t.on on change(e) { emit accToggleApp(e.target.value) } }tickMain { tickName { t.name } }}}}}h2 { "Level" }levelRow {button { type = "button" id = "levelwrite" class = writeCls "Read + write" on click(e) { emit accLevel('write') } }button { type = "button" id = "levelread" class = readCls "Read only" on click(e) { emit accLevel('read') } }}if (newKeyNeeded) {h2 { "Key label" }input { id = "keylabel" name = "keylabel" maxlength = "60" autocomplete = "off" value = label on input(e) { emit accSetLabel(e.target.value) } }}if (hasKey) { p { keyWho " already has a key: it works in the new apps too, nothing new to copy." } }p { "In each app " keyWho " can still only do what its project roles allow." }p { id = "message" Style.pMessage message }button { id = "givego" type = "button" class = "primary" "Give access" on click(e) { emit accGive(e) } }button { id = "backwho" type = "button" class = "quiet" "Back" on click(e) { emit accBackToWho(e) } }}}if (isKey) {section { id = "keysection"if (hasKeyText) {stepLabel { "STEP 3 OF 3 · SHOWN ONCE" }h1 { keyWho "’s key" }keyBox { id = "thekey" keyText }button { id = "copykey" type = "button" class = "primary" "Copy key" on click(e) { emit accCopyKey(e) } }button { id = "copyenv" type = "button" "Copy as .env line" on click(e) { emit accCopyEnv(e) } }warnBox { "ident keeps only a hash. Once you leave this screen the key cannot be shown again — rotate to get a new one." }h2 { "Works in" }chips { for (n of keyApps) { chip { n } } }h2 { "The conductor uses it as" }pre { "Authorization: Bearer idt_…\ngit clone https://x:idt_…@gitoria…" }}if (noKeyText) {h1 { doneText }}p { id = "notice" Style.pNotice notice }button { id = "keydone" type = "button" class = "primary" doneLabel on click(e) { emit accDone(e) } }}}if (sheetOpen) {cellSheet { id = "cellsheet"h2 { id = "sheettitle" sheet.who " in " sheet.appName }if (sheet.hasGrant) {sheetRow { sheetLabel { "Since" } sheetValue { id = "sheetsince" sheet.since } }sheetRow { sheetLabel { "Last use" } sheetValue { id = "sheetlast" sheet.last } }sheetRow { sheetLabel { "Level" } sheetValue { id = "sheetlevel" sheet.level }button { type = "button" id = "changelevel" class = "quiet small" "change" on click(e) { emit accChangeLevel(e) } } }button { type = "button" id = "rotate" class = "quiet" "Rotate key" on click(e) { emit accRotate(e) } }button { type = "button" id = "revoke" class = "quiet danger" "Revoke access to " sheet.appName on click(e) { emit accRevoke(e) } }}if (sheet.noGrant) {if (sheet.login) { p { sheet.who " logs in to " sheet.appName " as a person. No key is involved." } }if (sheet.noLogin) { p { sheet.who " has no access to " sheet.appName "." } }button { type = "button" id = "giveone" class = "primary" "Give " sheet.who " access to " sheet.appName on click(e) { emit accGiveOne(e) } }}p { id = "sheetmessage" Style.pMessage message }button { type = "button" id = "closesheet" class = "quiet" "Close" on click(e) { emit accCloseSheet(e) } }}}}}}// the page's own look: nested rules named after its elements; colours only through the theme's tokensStyle {pMessage = messageLookpNotice = noticeLookaccessMatrix { display = 'block' overflowX = 'auto'table { width = '100%' borderCollapse = 'separate' borderSpacing = '0 .4rem'th { padding = '.3rem .2rem' fontWeight = '400' textAlign = 'center' fontSize = '.875rem' color = 'var(--color-text-muted)' background = 'transparent' }tbody { th { padding = '.5rem .8rem' textAlign = 'left' fontWeight = '700' background = 'var(--color-surface)' borderRadius = 'var(--radius-large) 0 0 var(--radius-large)' a { color = 'var(--color-text-strong)' } }td { background = 'var(--color-surface)' lastChild { borderRadius = '0 var(--radius-large) var(--radius-large) 0' }button { width = '100%' minWidth = 'var(--layout-tap)' minHeight = '3rem' padding = '0' fontSize = '1.1rem' } }}td { padding = '0' textAlign = 'center' background = 'var(--color-surface)' }}}// THE STATE OF A CELL is a class the data chooses ('cell key' | 'cell login' | 'cell none'): quoted selectors, nothing else can say it'td button.key' { color = 'var(--color-success)' }'td button.login' { color = 'var(--color-action)' }'td button.none' { color = 'var(--color-text-muted)' }accessPage { display = 'grid' gap = '1rem' maxWidth = '46rem' margin = '0 auto'h1 { margin = '0' }h2 { margin = '.6rem 0 0' }p { margin = '0' }section { display = 'grid' gap = '.8rem' position = 'relative' }ul { listStyle = 'none' margin = '0' padding = '0' display = 'grid' gap = '.5rem'li { display = 'flex' alignItems = 'center' justifyContent = 'space-between' gap = '.5rem' margin = '0' padding = '.4rem .8rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)'button { minHeight = 'var(--layout-tap)' }}}label { display = 'flex' alignItems = 'center' gap = '.8rem' minHeight = 'var(--layout-tap)' width = '100%' margin = '0' }input { flex = 'none' }}// from 60rem the main button sits at the top right, beside the title (the 1280 mockup); on the phone it is the last thing on the page@media { minWidth = '60rem' accessPage { '#give' { position = 'absolute' top = '0' right = '0' width = 'auto' } } }// the pick buttons of step 1: the card is the tap areapickCard { flex = '1 1 auto' display = 'flex' justifyContent = 'flex-start' gap = '.7rem' textAlign = 'left' }// the chosen identity of step 1 (a class the data chooses) and the dashed "New identity"'li.on' { outline = '2px solid var(--color-accent)' outlineOffset = '-2px' }'li.newone' { background = 'transparent' outline = '2px dashed var(--color-text-muted)' outlineOffset = '-2px' }'li.newone.on' { outline = '2px solid var(--color-accent)' }// the level buttons: the chosen one is the accent'button.seg' { background = 'var(--color-surface)' }'button.seg.on' { color = 'var(--color-accent-text)' background = 'var(--color-accent)' }whoSub { display = 'block' fontSize = '.875rem' fontWeight = '400' color = 'var(--color-text-muted)' }matrixKey { fontSize = '.875rem' color = 'var(--color-text-muted)' }stepLabel { fontSize = '.875rem' fontWeight = '700' letterSpacing = '.06em' color = 'var(--color-accent)' }neverMain { display = 'grid' flex = '1 1 auto' minWidth = '0' }neverName { fontWeight = '700' color = 'var(--color-text-strong)' }neverLine { fontSize = '.875rem' color = 'var(--color-text-muted)' }pickMain { display = 'grid' flex = '1 1 auto' minWidth = '0' textAlign = 'left' }pickName { fontWeight = '700' color = 'var(--color-text-strong)' }pickSub { fontSize = '.875rem' fontWeight = '400' color = 'var(--color-text-muted)' }pickMark { color = 'var(--color-success)' }avatarDot { display = 'inline-flex' alignItems = 'center' justifyContent = 'center' flex = '0 0 auto' width = '2.25rem' height = '2.25rem' borderRadius = '50%' fontWeight = '700' color = 'var(--color-accent-text)' background = 'var(--color-accent)' }tickMain { display = 'grid' }tickName { fontWeight = '600' color = 'var(--color-text-strong)' }tickSub { fontSize = '.875rem' color = 'var(--color-text-muted)' }levelRow { display = 'grid' gridTemplateColumns = '1fr 1fr' gap = '.5rem' }keyBox { display = 'block' padding = '.7rem .8rem' fontFamily = 'ui-monospace, monospace' fontSize = '.875rem' color = 'var(--color-text-strong)' background = 'var(--color-background-sunken)' borderRadius = 'var(--radius-small)' overflowWrap = 'anywhere' userSelect = 'all' }warnBox { display = 'block' padding = '.7rem .8rem' color = 'var(--color-warning)' background = 'var(--color-surface)' borderRadius = 'var(--radius-small)' }chips { display = 'flex' flexWrap = 'wrap' gap = '.4rem' }chip { padding = '.2rem .6rem' fontSize = '.875rem' color = 'var(--color-success)' background = 'var(--color-background-sunken)' borderRadius = 'var(--radius-small)' }cellSheet { position = 'fixed' left = '0' right = '0' bottom = '0' zIndex = '30' display = 'grid' gap = '.5rem' maxWidth = '34rem' margin = '0 auto' padding = '1rem var(--layout-gutter) 1.2rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large) var(--radius-large) 0 0' boxShadow = '0 -.5rem 2rem var(--color-background-sunken)' }sheetRow { display = 'flex' alignItems = 'center' justifyContent = 'space-between' gap = '.5rem' padding = '.5rem .8rem' background = 'var(--color-background-sunken)' borderRadius = 'var(--radius-small)' }sheetLabel { display = 'block' fontWeight = '700' color = 'var(--color-text-strong)' }sheetValue { display = 'block' fontSize = '.875rem' color = 'var(--color-text-muted)' }}// ---- the screens ------------------------------------------------------------------------------------------------setScreen = (name) => {screen = nameisOverview = name == 'overview'isWho = name == 'who'isWhere = name == 'where'isKey = name == 'key'message = ''return null}setData = (d) => {data = dapps = d.appsrows = d.rowsnever = d.neverhasNever = d.hasNevernoApps = d.apps.length == 0hasApps = d.apps.length > 0return null}pickView = () => {out = []for (p of pickRows) { out.push(p) }return out}// the step-1 list with the chosen one markedmarkPicks = (list) => {out = []for (p of list) {let chosen = !newMode && '' + p.id == '' + pickIdout.push({ id = p.id label = p.label sub = p.sub initial = p.initial isAgent = p.isAgent dot = p.isAgent ? 'agent' : 'person' hasKey = p.hasKey cls = chosen ? 'on' : '' mark = chosen ? '✓' : '' })}return out}// step 2's list: each app with its ticktickView = (ids) => {out = []for (a of apps) { out.push({ id = a.id name = a.name on = ids.includes(a.id) }) }return out}tickedIds = () => {out = []for (t of tickRows) { if (t.on) { out.push(t.id) } }return out}on accStartGive(e) {notice = ''pickId = ''newMode = falsenewCls = 'newone'newName = ''r = emit server accPickList()if (r == null) { message = 'the server did not answer — try again' return null }pickRaw = rpickRows = markPicks(r)setScreen('who')}pickRaw = []on accPick(id) {newMode = falsenewCls = 'newone'pickId = '' + idpickRows = markPicks(pickRaw)message = ''}on accPickNew(e) {newMode = truenewCls = 'newone on'pickId = ''pickRows = markPicks(pickRaw)message = ''}on accSetNewName(v) { newName = v }on accCancel(e) { setScreen('overview') }// step 1 → 2: who is chosen (or a name typed)on accNext(e) {if (newMode) {if (newName.trim() == '') { message = 'type a name for the new identity' return null }keyWho = newName.trim()hasKey = falsenewKeyNeeded = truelabel = keyWho} else {let who = nullfor (p of pickRaw) { if ('' + p.id == pickId) { who = p } }if (who == null) { message = 'pick an identity' return null }keyWho = who.labelhasKey = who.hasKeynewKeyNeeded = !who.hasKeylabel = who.label}ids = []for (a of apps) { ids.push(a.id) }tickRows = tickView(ids)allOn = truelevel = 'write'writeCls = 'seg on'readCls = 'seg'setScreen('where')}on accBackToWho(e) { setScreen('who') }on accToggleAll(ticked) {ids = []if (ticked) { for (a of apps) { ids.push(a.id) } }tickRows = tickView(ids)allOn = ticked}on accToggleApp(id) {ids = tickedIds()next = []let had = falsefor (x of ids) { if ('' + x == '' + id) { had = true } else { next.push(x) } }if (!had) { next.push('' + id) }tickRows = tickView(next)allOn = next.length == apps.length}on accLevel(v) {level = vwriteCls = v == 'write' ? 'seg on' : 'seg'readCls = v == 'read' ? 'seg on' : 'seg'}on accSetLabel(v) { label = v }// step 2 → 3: give access; the key (when a new one was made) is on the screen and nowhere elseon accGive(e) {ids = tickedIds()if (ids.length == 0) { message = 'tick at least one app' return null }input = { apps = ids level = level label = label }if (newMode) { input.newName = newName } else { input.identity = pickId }r = emit server accGiveAccess(input)if (r == null) { message = 'the server did not answer — try again' return null }if (r.error != null) { message = r.error return null }setData(r.data)showKey(r)}showKey = (r) => {keyWho = r.whokeyApps = r.appskeyText = r.key == null ? '' : r.keyhasKeyText = r.key != nullnoKeyText = r.key == nulldoneText = r.key == null ? r.who + ' now has access to ' + r.apps.join(', ') + '.' : ''doneLabel = r.key == null ? 'Done' : 'I saved it — done'sheetOpen = falsesetScreen('key')return null}on accCopyKey(e) {window.navigator.clipboard.writeText(keyText)notice = 'Key copied.'}on accCopyEnv(e) {window.navigator.clipboard.writeText('WORLDAPI_TOKEN=' + keyText)notice = '.env line copied.'}// done: the key is gone from the pageon accDone(e) {keyText = ''hasKeyText = falsenoKeyText = truekeyWho = ''keyApps = []notice = ''setScreen('overview')}// ---- a cell's sheet ---------------------------------------------------------------------------------------------on accOpenCell(v) {parts = ('' + v).split(':')r = emit server accCell(parts[0], parts[1])if (r == null || r.error != null) { return null }sheet = rmessage = ''sheetOpen = true}on accCloseSheet(e) {sheetOpen = falsemessage = ''}on accChangeLevel(e) {next = sheet.levelRaw == 'write' ? 'read' : 'write'r = emit server accSetLevel(sheet.identity, sheet.app, next)if (r == null || r.error != null) { message = r == null ? 'the server did not answer — try again' : r.error return null }setData(r.data)sheet = r.cell}on accRevoke(e) {if (!confirm('Revoke ' + sheet.who + '’s access to ' + sheet.appName + '? It stops working there within 30 seconds.')) { return null }r = emit server accRevokeCell(sheet.identity, sheet.app)if (r == null || r.error != null) { message = r == null ? 'the server did not answer — try again' : r.error return null }setData(r.data)sheetOpen = false}on accRevokeNever(v) {parts = ('' + v).split(':')r = emit server accRevokeCell(parts[0], parts[1])if (r == null || r.error != null) { return null }setData(r.data)}on accRotate(e) {if (!confirm('Rotate the key of ' + sheet.who + '? The old key stops working at once, in every app.')) { return null }r = emit server accRotateKey(sheet.identity)if (r == null || r.error != null) { message = r == null ? 'the server did not answer — try again' : r.error return null }showKey(r)}// a ○ or ◐ cell: give that identity access to that app (step 2, prefilled)on accGiveOne(e) {r = emit server accPickList()if (r == null) { return null }pickRaw = rpickId = sheet.identitynewMode = falsekeyWho = sheet.whohasKey = falsenewKeyNeeded = truefor (p of r) { if ('' + p.id == pickId) { hasKey = p.hasKey newKeyNeeded = !p.hasKey label = p.label } }tickRows = tickView([sheet.app])allOn = apps.length == 1sheetOpen = falsesetScreen('where')}// ---- the faces ----------------------------------------------------------------------------------------------------on server accPickList(session) {let me = accountOfSession(&session)if (me == null) { return [] }return pickList(me.id)}on server accGiveAccess(input, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = giveAccess(me.id, input)if (r.error != null) { return r }r.data = matrix(me.id)return r}on server accCell(identity, app, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }c = cellOf(me.id, identity, app)if (c == null) { return { error = 'no such cell' } }return c}on server accSetLevel(identity, app, lv, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = setLevel(me.id, identity, app, lv)if (r.error != null) { return r }return { data = matrix(me.id) cell = cellOf(me.id, identity, app) }}on server accRevokeCell(identity, app, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = revokeAccess(me.id, identity, app)if (r.error != null) { return r }return { data = matrix(me.id) }}on server accRotateKey(identity, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }return rotateKey(me.id, identity)}
Branches
Latest commits
- 0f6d1592Merge branch 'f18b-shell-session' into mainIdent
- 19868218|||PR ident#39 shell reads its session member instead of a cross-file emitmre
- 5d1b3fedMerge branch 'v61-day61' into mainIdent
- 83faeb15|||PR ident: vendor Hybriel day61mre
- b2572b34Merge branch 'v59-day59' into mainIdent
- 67cf016d|||PR ident: vendor Hybriel day59mre
- 600c043dMerge branch 'v58-day58' into mainIdent
- 365f8c80|||PR ident: vendor Hybriel day58mre
- 585126e5Merge branch 'f16-setf' into mainIdent
- 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
- a1419d9cMerge branch 'f15-navigate' into mainIdent
- 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
- e36f4516Merge branch 'f14-online' into mainIdent
- 2c5eac91|||PR ident#38 online state without probe timermre
- bf1980f2Merge branch 'v56-day56' into mainIdent
- 62ae0adf|||PR ident: vendor Hybriel day56mre
- 0d18abc4Merge branch 'f13-avatar' into mainIdent
- 2a99730a|||PR ident#37 avatar in hlmre
- fa4ed25bMerge branch 'f11-upsert' into mainIdent
- 8f3d9bc9|||PR ident#42 keyed upsert and removemre