tickets
All repositories: gitoria
4.8 KB
// components/connect.hl — `/connect/:nonce` (ticket #21): another app (first: gitoria) asks to be connected to one// project. The person — logged in through ident, with a display name — picks a project they are ADMIN of, or makes a// new one, and confirms. Then the page links back to the app with a one-time code (connections.hl); the app's server// swaps the code for a key that reaches that one project. Everybody else sees the login hint; a used or expired// request says so. Everything is checked again by the store in the faces.parent './main.hl'import { requestOf, requestView, adminProjects, confirmRequest } from '../lib/connections.hl'import { siteName } from '../project.hl'import { userOfSession, writerOfSession, canWriteSession } from '../lib/users.hl'import { hintLook, messageLook, noticeLook } from '../lib/looks.hl'nonce = nullsession = nullpending = requestOf(nonce)valid = pending != nullgone = pending == nullinfo = pending != null ? requestView(pending) : { app = '' label = '' hasLabel = false host = '' }appName = info.appappLabel = info.labelhasLabel = info.hasLabelappHost = info.hostcanWrite = valid && canWriteSession(session)showForm = valid && canWriteSession(session)mustLogIn = valid && !canWriteSession(session)choices = adminProjects(userOfSession(session))choice = choices.length > 0 ? choices[0].id : ''makeNew = choices.length == 0newTitle = ''message = ''done = falsedoneUrl = ''doneProject = ''__title = siteName + ' | connect ' + (pending != null ? pending.app : 'an app')Style {pHint = hintLook + { }'#connectmessage' = messageLook + { }'#connected' = noticeLook + { }connectPage {display = 'grid'gap = '1rem'maxWidth = '38rem'form {display = 'grid'gap = '.8rem'}}}View {connectPage {if (gone) { p { id = "gone" class = "empty" "This connection request is used up or expired. Start again from the app." } }if (valid) {h1 { id = "connecttitle" "Connect " appName " to a project" }p { id = "connectwho" Style.pHintstrong { appName }if (hasLabel) { " (" appLabel ")" }" at "strong { appHost }" asks for a key to ONE of your projects. With it the app can open tickets, comment and change their state there — for the people who work in it, within their roles. You can disconnect it on the project's page at any time."}}if (mustLogIn) { p { id = "loginhint" Style.pHint "Log in with ident (top right) and choose a display name to connect." } }if (showForm) {form { id = "connectform"on submit(e) {e.preventDefault()emit confirm(e)}label { "Project"select { id = "connectproject" name = "project" value = choice on change(e) { emit setChoice(e.target.value) }for (c of choices) { option { value = c.id c.title } }option { value = "" "A new project" }}}if (makeNew) {label { "Title of the new project"input { id = "connecttitleinput" name = "title" required = "required" maxlength = "100" autocomplete = "off" value = newTitle on input(e) { emit setNewTitle(e.target.value) } }}}button { id = "connectconfirm" type = "submit" "Connect" }p { id = "connectmessage" message }}}if (done) {p { id = "connected" "Connected to " strong { doneProject } ". " }a { id = "connectcontinue" class = "button" href = doneUrl "Continue to " appName }}}}on setChoice(v) {choice = vmakeNew = v == ''}on setNewTitle(v) { newTitle = v }on confirm(e) {if (makeNew && newTitle.trim() == '') { return null }r = emit server connectConfirm(nonce, choice, newTitle)if (r == null || r.error != null) {message = r != null ? r.error : 'could not connect'return null}message = ''showForm = falsedoneUrl = r.urldoneProject = r.projectdone = true}on client signedIn(tag, info) {r = emit server connectChoices()if (r != null && r.projects != null) {choices = r.projectschoice = r.projects.length > 0 ? r.projects[0].id : ''makeNew = r.projects.length == 0}canWrite = valid && info.namedshowForm = valid && info.named && !donemustLogIn = valid && !info.named}on client signedOut(tag) {canWrite = falseshowForm = falsemustLogIn = validchoices = []}on server connectChoices(session) {u = userOfSession(session)if (u == null) { return { error = 'log in first' } }return { projects = adminProjects(u) }}on server connectConfirm(nonce, projectId, title, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }if (hlTypeName(nonce) != 'String' || hlTypeName(projectId) != 'String' || hlTypeName(title) != 'String') { return { error = 'nonce, project and title must be text' } }r = confirmRequest(nonce, w.user, projectId, title)if (r.error != null) { return { error = r.error } }return { url = r.url project = r.project slug = r.slug }}
Branches
Latest commits
- d083535bticket_list: nest Style rules and bare media queriesmre
- c24608ebmarkdown: format Style with nested language rulesmre
- de964b3bsettings: format Style with nested language rulesmre
- 03c1de05new_project: format Style with nested language rulesmre
- bd76cfa6connect: format Style with nested language rulesmre
- 01fad593inbox: format Style with nested language rulesmre
- 79dc9392you: format Style with nested language rulesmre
- 78073baamain: format Style with nested language rulesmre
- 5499c290Sync theme unchanged from layouts 17e0f03mre
- fd33ee21Sync reviewed components from 8176eb1mre
- 93348453Re-vendor tickets to Hybriel set day35mre
- 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
- 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