gitoria
All repositories: gitoria
7.3 KB
// components/settings.hl — THE SETTINGS of a repo (gitoria#18): `/settings` on <slug>.<domain>. For now one section,// "Tickets": connect the repo to a tickets.worldapi.org project (the owner clicks "Tickets: connect", tickets asks which// project, and brings them back — lib/api.hl /settings/connect and /settings/connected; lib/tickets.hl). Anyone sees// whether the repo is connected; only the owner sees the buttons. Rendered on the server from the request's host.// (The main branch is switched on the code page.)parent './repo.hl'import { siteName } from '../project.hl'import { slugOfRequest } from '../lib/orgs.hl'import { userOfSession, userIdOfSession } from '../lib/users.hl'import { titleSlug, repoAt, ownsRepo, setTicketsConnection, setRepoPriv, membersOf, changeMember } from '../lib/repos.hl'import { px } from '../lib/util.hl'import { pageTitle } from '../lib/repos-helpers.hl'import { ticketsUrl } from '../lib/tickets-helpers.hl'host = nullorepo = ''session = nullslug = slugOfRequest(host, orepo)repo = repoAt(slug, session)hasRepo = repo != nullpre = px(slug)connectHref = pre + '/settings/connect'isOwner = repo != null && ownsRepo(slug, session)connected = repo != null && repo.ticketsOnnotConnected = repo != null && !repo.ticketsOnprojectTitle = repo != null ? repo.ticketsTitle : ''projectHref = repo != null && repo.ticketsOn ? ticketsUrl + '/projects/' + repo.ticketsProject : ''connectNote = session != null && session.data != null && session.data.connectNote != null ? session.data.connectNote : ''hasConnectNote = connectNote != ''notOwnerHint = repo != null && !isOwnersettingsError = ''forgetClass = repo != null && repo.ticketsOn ? 'quiet' : 'nomerge'__title = pageTitle(siteName, titleSlug(host, orepo, session), 'Settings')// VISIBILITY AND MEMBERS (GO34): the owner makes the repo private / public and keeps the member list (people who see a private repo and may push)isPrivate = repo != null && repo.isPrivateownPriv = repo != null && repo.isPrivate && !repo.inOrgprivText = repo == null ? '' : (repo.isPrivate ? 'This repository is private: only its owner and its members can see it.' : 'This repository is public: everybody can read it.')privButton = repo != null && repo.isPrivate ? 'Make public' : 'Make private'listed = isOwner ? membersOf('r', slug, userIdOfSession(session)) : nullmembers = listed != null && listed.members != null ? listed.members : []noMembers = isOwner && members.length == 0memberName = ''memberError = ''Style {// the member list: a dense row per person with its Remove button at the end, no bullets'#members' { listStyle = 'none' margin = '0' padding = '0' display = 'grid' gap = '.25rem' maxWidth = '32rem'li { display = 'flex' alignItems = 'center' justifyContent = 'space-between' gap = '.75rem' minHeight = '2.75rem' padding = '0 .5rem 0 1rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' }}'#memberform' { display = 'grid' gap = '.75rem' margin = '.75rem 0 1.5rem' maxWidth = '32rem' }'#togglepriv' { justifySelf = 'start' }'#visibility' { display = 'grid' gap = '.75rem' margin = '0 0 1.5rem' }}View {repoPage {if (hasRepo) {repoSettings { id = "settings"section { id = "visibility"h2 { "Visibility" }p { id = "privtext" privText }if (isOwner) { button { id = "togglepriv" type = "button" privButton on click(e) { emit togglePriv() } } }if (isOwner) {h2 { "Members" }p { class = "muted" "Members see this repository even when it is private, and may push to it. Add somebody by the display name they chose." }if (noMembers) { p { id = "nomembers" class = "empty" "No members yet." } }ul { id = "members"for (m of members) {li { span { class = "slug" m.name } button { class = "quiet" type = "button" "Remove" on click(e) { emit removeMember(m.name) } } }}}form { id = "memberform"on submit(e) {e.preventDefault()emit addMember(e)}label { "Display name"input { id = "membername" name = "membername" required = "required" maxlength = "60" autocomplete = "off" }}button { id = "memberadd" type = "submit" "Add member" }p { id = "membererror" class = "message" memberError }}}}section { id = "ticketsettings"h2 { "Tickets" }if (hasConnectNote) { p { id = "connectnote" class = "message" connectNote } }if (connected) {p { id = "connectedto" "Connected to the tickets project " a { id = "projectlink" href = projectHref projectTitle } "." }}if (notConnected) { p { id = "notconnected" class = "muted" "This repository is not connected to a tickets project yet." } }if (isOwner) {p {a { id = "connecttickets" class = "button" href = connectHref "Tickets: connect" }}button { id = "disconnecttickets" class = forgetClass type = "button" "Forget the connection" on click(e) { emit disconnect() } }p { class = "muted" "Connecting asks tickets which project (you must be its admin there). Tickets can also disconnect gitoria from its side." }}if (notOwnerHint) { p { id = "ownerhint" class = "muted" "Only the owner of this repository can connect it." } }p { id = "settingserror" class = "message" settingsError }}}}}}on togglePriv() {memberError = ''r = emit server gitoriaSetPrivate(slug, !isPrivate)if (r == null || r.error != null) {memberError = r != null ? r.error : 'could not change the visibility'return null}isPrivate = r.repo.isPrivateprivText = isPrivate ? 'This repository is private: only its owner and its members can see it.' : 'This repository is public: everybody can read it.'privButton = isPrivate ? 'Make public' : 'Make private'}on addMember(e) {memberError = ''r = emit server gitoriaChangeMember(slug, e.target.elements.membername.value, true)if (r == null || r.error != null) {memberError = r != null ? r.error : 'could not add the member'return null}members = r.membersnoMembers = members.length == 0e.target.elements.membername.value = ''}on removeMember(name) {memberError = ''r = emit server gitoriaChangeMember(slug, name, false)if (r == null || r.error != null) {memberError = r != null ? r.error : 'could not remove the member'return null}members = r.membersnoMembers = members.length == 0}on server gitoriaSetPrivate(slugOf, priv, session) {return setRepoPriv(userIdOfSession(session), slugOf, priv)}on server gitoriaChangeMember(slugOf, name, add, session) {return changeMember(userIdOfSession(session), 'r', slugOf, name, add)}on disconnect() {settingsError = ''r = emit server gitoriaDisconnectTickets(slug)if (r == null || r.error != null) {settingsError = r != null ? r.error : 'could not disconnect'return null}connected = falsenotConnected = trueforgetClass = 'nomerge'projectTitle = ''projectHref = ''}on server gitoriaDisconnectTickets(slugOf, session) {if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not disconnect' } }if (userOfSession(session) == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change this' } }r = setTicketsConnection(slugOf, '', '', '', '')if (r.error != null) { return { error = r.error } }return { ok = true }}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 821cdbb1gitoria#34b: styles, create-repo tool, docs, push/ssh gates sign in through the selector, shots scriptmre
- a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre
- 17f031f0gitoria#34: private repos, organizations, members, move tool, gatemre
- 71b69343gitoria#23: the sidebar's Repositories link was a 404 after any in-page navigation (static menu re-evaluated publicUrl in the browser); the menu is an instance property now; gate taps it after a tab, folder, filemre
- 90b4f728gitoria#25: restore the homepage cache and the parsed-blocks cache (they store data under immutable keys, no HTML); the page key, the framework readme key and the textHash key stay removedmre
- a487248cgitoria#25: remove every cache that hid the page build (page key, Markdown render key, homepage cache, parsed-blocks cache) and the gate that only tested themmre
- 12f2f4fegitoria: re-vendor Hybriel set-day27b, a startup fault in on Error exits 1mre
- c21c084egitoria: write the standby service out in full so the boot gate can read the main servicemre
- e307d69agitoria: say what is per process during the hand-overmre
- f0cbe6a6gitoria: standby service on port 45014 and a deploy that hands over through it without a gapmre
- 727cd083gitoria#25: README: vendor notes for Hybriel c1b1010f and the page cachemre
- 61b72dedgitoria#25: re-vendor Hybriel master c1b1010f (W149 page cache), key the repo Readme page by slug and main commit, extend the readme-cache gatemre
- 5b0b4b9ereadme-cache gate: use the security gate's ports when no own ports are givenmre
- bc8f20d9gitoria#25: re-vendor Hybriel c09538bb with the W141 render cache, cache the homepage per commit, add the readme-cache gatemre
- 9feebbd3Re-vendor Hybriel to ded47c13 (W145: Firefox start script fix)mre
- 28ed41e5gitoria#24: one sign-in comes from hl:web batch 20, the /session/share workaround is gonemre
- 3b2669e4gs: drop the unbuildable legacy check, fix pwa fetchmre
- 2a2fdd77gs: C2 check before cookie experimentsmre
- 76e0587aWIP gs 2mre
- a80da7bdWIP gs: security gate for lazy sessions, g24 browser checksmre