gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5d2c385a5d2c385agitoria: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 71+5 failing → 76 passed; deploy.sh runs tests/private.mjs toomre5d2c385a/components/settings.hl

7.3 KB

  1. // components/settings.hl — THE SETTINGS of a repo (gitoria#18): `/settings` on <slug>.<domain>. For now one section,
  2. // "Tickets": connect the repo to a tickets.worldapi.org project (the owner clicks "Tickets: connect", tickets asks which
  3. // project, and brings them back — lib/api.hl /settings/connect and /settings/connected; lib/tickets.hl). Anyone sees
  4. // whether the repo is connected; only the owner sees the buttons. Rendered on the server from the request's host.
  5. // (The main branch is switched on the code page.)
  6. parent './repo.hl'
  7. import { siteName } from '../project.hl'
  8. import { slugOfRequest } from '../lib/orgs.hl'
  9. import { userOfSession, userIdOfSession } from '../lib/users.hl'
  10. import { titleSlug, repoAt, ownsRepo, setTicketsConnection, setRepoPriv, membersOf, changeMember } from '../lib/repos.hl'
  11. import { px } from '../lib/util.hl'
  12. import { pageTitle } from '../lib/repos-helpers.hl'
  13. import { ticketsUrl } from '../lib/tickets-helpers.hl'
  14. host = null
  15. orepo = ''
  16. session = null
  17. slug = slugOfRequest(host, orepo)
  18. repo = repoAt(slug, session)
  19. hasRepo = repo != null
  20. pre = px(slug)
  21. connectHref = pre + '/settings/connect'
  22. isOwner = repo != null && ownsRepo(slug, session)
  23. connected = repo != null && repo.ticketsOn
  24. notConnected = repo != null && !repo.ticketsOn
  25. projectTitle = repo != null ? repo.ticketsTitle : ''
  26. projectHref = repo != null && repo.ticketsOn ? ticketsUrl + '/projects/' + repo.ticketsProject : ''
  27. connectNote = session != null && session.data != null && session.data.connectNote != null ? session.data.connectNote : ''
  28. hasConnectNote = connectNote != ''
  29. notOwnerHint = repo != null && !isOwner
  30. settingsError = ''
  31. forgetClass = repo != null && repo.ticketsOn ? 'quiet' : 'nomerge'
  32. __title = pageTitle(siteName, titleSlug(host, orepo, session), 'Settings')
  33. // 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)
  34. isPrivate = repo != null && repo.isPrivate
  35. ownPriv = repo != null && repo.isPrivate && !repo.inOrg
  36. privText = 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.')
  37. privButton = repo != null && repo.isPrivate ? 'Make public' : 'Make private'
  38. listed = isOwner ? membersOf('r', slug, userIdOfSession(session)) : null
  39. members = listed != null && listed.members != null ? listed.members : []
  40. noMembers = isOwner && members.length == 0
  41. memberName = ''
  42. memberError = ''
  43. Style {
  44. // the member list: a dense row per person with its Remove button at the end, no bullets
  45. '#members' { listStyle = 'none' margin = '0' padding = '0' display = 'grid' gap = '.25rem' maxWidth = '32rem'
  46. 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)' }
  47. }
  48. '#memberform' { display = 'grid' gap = '.75rem' margin = '.75rem 0 1.5rem' maxWidth = '32rem' }
  49. '#togglepriv' { justifySelf = 'start' }
  50. '#visibility' { display = 'grid' gap = '.75rem' margin = '0 0 1.5rem' }
  51. }
  52. View {
  53. repoPage {
  54. if (hasRepo) {
  55. repoSettings { id = "settings"
  56. section { id = "visibility"
  57. h2 { "Visibility" }
  58. p { id = "privtext" privText }
  59. if (isOwner) { button { id = "togglepriv" type = "button" privButton on click(e) { emit togglePriv() } } }
  60. if (isOwner) {
  61. h2 { "Members" }
  62. 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." }
  63. if (noMembers) { p { id = "nomembers" class = "empty" "No members yet." } }
  64. ul { id = "members"
  65. for (m of members) {
  66. li { span { class = "slug" m.name } button { class = "quiet" type = "button" "Remove" on click(e) { emit removeMember(m.name) } } }
  67. }
  68. }
  69. form { id = "memberform"
  70. on submit(e) {
  71. e.preventDefault()
  72. emit addMember(e)
  73. }
  74. label { "Display name"
  75. input { id = "membername" name = "membername" required = "required" maxlength = "60" autocomplete = "off" }
  76. }
  77. button { id = "memberadd" type = "submit" "Add member" }
  78. p { id = "membererror" class = "message" memberError }
  79. }
  80. }
  81. }
  82. section { id = "ticketsettings"
  83. h2 { "Tickets" }
  84. if (hasConnectNote) { p { id = "connectnote" class = "message" connectNote } }
  85. if (connected) {
  86. p { id = "connectedto" "Connected to the tickets project " a { id = "projectlink" href = projectHref projectTitle } "." }
  87. }
  88. if (notConnected) { p { id = "notconnected" class = "muted" "This repository is not connected to a tickets project yet." } }
  89. if (isOwner) {
  90. p {
  91. a { id = "connecttickets" class = "button" href = connectHref "Tickets: connect" }
  92. }
  93. button { id = "disconnecttickets" class = forgetClass type = "button" "Forget the connection" on click(e) { emit disconnect() } }
  94. p { class = "muted" "Connecting asks tickets which project (you must be its admin there). Tickets can also disconnect gitoria from its side." }
  95. }
  96. if (notOwnerHint) { p { id = "ownerhint" class = "muted" "Only the owner of this repository can connect it." } }
  97. p { id = "settingserror" class = "message" settingsError }
  98. }
  99. }
  100. }
  101. }
  102. }
  103. on togglePriv() {
  104. memberError = ''
  105. r = emit server gitoriaSetPrivate(slug, !isPrivate)
  106. if (r == null || r.error != null) {
  107. memberError = r != null ? r.error : 'could not change the visibility'
  108. return null
  109. }
  110. isPrivate = r.repo.isPrivate
  111. privText = isPrivate ? 'This repository is private: only its owner and its members can see it.' : 'This repository is public: everybody can read it.'
  112. privButton = isPrivate ? 'Make public' : 'Make private'
  113. }
  114. on addMember(e) {
  115. memberError = ''
  116. r = emit server gitoriaChangeMember(slug, e.target.elements.membername.value, true)
  117. if (r == null || r.error != null) {
  118. memberError = r != null ? r.error : 'could not add the member'
  119. return null
  120. }
  121. members = r.members
  122. noMembers = members.length == 0
  123. e.target.elements.membername.value = ''
  124. }
  125. on removeMember(name) {
  126. memberError = ''
  127. r = emit server gitoriaChangeMember(slug, name, false)
  128. if (r == null || r.error != null) {
  129. memberError = r != null ? r.error : 'could not remove the member'
  130. return null
  131. }
  132. members = r.members
  133. noMembers = members.length == 0
  134. }
  135. on server gitoriaSetPrivate(slugOf, priv, session) {
  136. return setRepoPriv(userIdOfSession(session), slugOf, priv)
  137. }
  138. on server gitoriaChangeMember(slugOf, name, add, session) {
  139. return changeMember(userIdOfSession(session), 'r', slugOf, name, add)
  140. }
  141. on disconnect() {
  142. settingsError = ''
  143. r = emit server gitoriaDisconnectTickets(slug)
  144. if (r == null || r.error != null) {
  145. settingsError = r != null ? r.error : 'could not disconnect'
  146. return null
  147. }
  148. connected = false
  149. notConnected = true
  150. forgetClass = 'nomerge'
  151. projectTitle = ''
  152. projectHref = ''
  153. }
  154. on server gitoriaDisconnectTickets(slugOf, session) {
  155. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not disconnect' } }
  156. if (userOfSession(session) == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change this' } }
  157. r = setTicketsConnection(slugOf, '', '', '', '')
  158. if (r.error != null) { return { error = r.error } }
  159. return { ok = true }
  160. }

Branches

Latest commits

  • 5d2c385agitoria: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 71+5 failing → 76 passed; deploy.sh runs tests/private.mjs toomre
  • 241ef3f9deploy.sh: rebuild the sshd image before up -d (GO34c)mre
  • 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