gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5a996ea85a996ea8gitoria#42: short-lived app tokens, read-only git fetch with them (merge w42-app-token)mre5a996ea8/components/settings.hl

13.8 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. // "Apps" (gitoria#41, lib/apps.hl): the owner connects outside apps to the repo — the confirm card of connect flow A (an app sent the browser
  6. // here; lib/api.hl appConnectStart parked the request in the session), the list (Remove, Rotate secret) and Add (the manual way). Key and secret
  7. // are shown ONCE, in the page state of the click that made them.
  8. // (The main branch is switched on the code page.)
  9. parent './repo.hl'
  10. import { siteName } from '../project.hl'
  11. import { slugOfRequest } from '../lib/orgs.hl'
  12. import { userOfSession, userIdOfSession } from '../lib/users.hl'
  13. import { titleSlug, repoAt, ownsRepo, setTicketsConnection, setRepoPriv, membersOf, changeMember } from '../lib/repos.hl'
  14. import { px } from '../lib/util.hl'
  15. import { pageTitle } from '../lib/repos-helpers.hl'
  16. import { ticketsUrl } from '../lib/tickets-helpers.hl'
  17. import { appRows, addApp, removeApp, rotateSecret } from '../lib/apps.hl'
  18. import { hostOfUrl } from '../lib/apps-helpers.hl'
  19. host = null
  20. orepo = ''
  21. session = null
  22. slug = slugOfRequest(host, orepo)
  23. repo = repoAt(slug, session)
  24. hasRepo = repo != null
  25. pre = px(slug)
  26. connectHref = pre + '/settings/connect'
  27. isOwner = repo != null && ownsRepo(slug, session)
  28. connected = repo != null && repo.ticketsOn
  29. notConnected = repo != null && !repo.ticketsOn
  30. projectTitle = repo != null ? repo.ticketsTitle : ''
  31. projectHref = repo != null && repo.ticketsOn ? ticketsUrl + '/projects/' + repo.ticketsProject : ''
  32. connectNote = session != null && session.data != null && session.data.connectNote != null ? session.data.connectNote : ''
  33. hasConnectNote = connectNote != ''
  34. notOwnerHint = repo != null && !isOwner
  35. settingsError = ''
  36. forgetClass = repo != null && repo.ticketsOn ? 'quiet' : 'nomerge'
  37. __title = pageTitle(siteName, titleSlug(host, orepo, session), 'Settings')
  38. // 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)
  39. isPrivate = repo != null && repo.isPrivate
  40. ownPriv = repo != null && repo.isPrivate && !repo.inOrg
  41. 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.')
  42. privButton = repo != null && repo.isPrivate ? 'Make public' : 'Make private'
  43. listed = isOwner ? membersOf('r', slug, userIdOfSession(session)) : null
  44. members = listed != null && listed.members != null ? listed.members : []
  45. noMembers = isOwner && members.length == 0
  46. memberName = ''
  47. memberError = ''
  48. // APPS (gitoria#41): the owner's list; the connect request an app parked in this session (for this repo only); what was just made (shown once)
  49. apps = isOwner ? appRows(repo.id) : []
  50. noApps = isOwner && apps.length == 0
  51. parked = session != null && session.data != null && session.data.appConnect != null && repo != null && session.data.appConnect.slug == slug ? session.data.appConnect : null
  52. hasParked = parked != null
  53. parkedApp = parked != null ? parked.app : ''
  54. parkedHost = parked != null ? hostOfUrl(parked.ret) : ''
  55. parkedNonce = parked != null ? parked.nonce : ''
  56. confirmAction = pre + '/settings/apps/confirm'
  57. parkedSignedOut = hasParked && session != null && userIdOfSession(session) == null
  58. parkedNotOwner = hasParked && userIdOfSession(session) != null && !isOwner
  59. parkedOwner = hasParked && isOwner
  60. appName = ''
  61. appHook = ''
  62. appError = ''
  63. hasShown = false
  64. shownName = ''
  65. shownKey = ''
  66. hasShownKey = false
  67. shownSecret = ''
  68. shownText = ''
  69. View {
  70. repoPage {
  71. if (hasRepo) {
  72. repoSettings { id = "settings"
  73. section { id = "visibility"
  74. h2 { "Visibility" }
  75. p { id = "privtext" privText }
  76. if (isOwner) { button { id = "togglepriv" type = "button" privButton on click(e) { emit togglePriv() } } }
  77. if (isOwner) {
  78. h2 { "Members" }
  79. 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." }
  80. if (noMembers) { p { id = "nomembers" class = "empty" "No members yet." } }
  81. ul { id = "members"
  82. for (m of members) {
  83. li { span { class = "slug" m.name } button { class = "quiet" type = "button" "Remove" on click(e) { emit removeMember(m.name) } } }
  84. }
  85. }
  86. form { id = "memberform"
  87. on submit(e) {
  88. e.preventDefault()
  89. emit addMember(e)
  90. }
  91. label { "Display name"
  92. input { id = "membername" name = "membername" required = "required" maxlength = "60" autocomplete = "off" }
  93. }
  94. button { id = "memberadd" type = "submit" "Add member" }
  95. p { id = "membererror" class = "message" memberError }
  96. }
  97. }
  98. }
  99. section { id = "apps"
  100. h2 { "Apps" }
  101. if (parkedSignedOut) { p { id = "appsignin" class = "message" "Sign in with the selector at the top to connect " + parkedApp + " to this repository." } }
  102. if (parkedNotOwner) { p { id = "appnotowner" class = "message" "Only the owner of this repository can connect " + parkedApp + "." } }
  103. if (parkedOwner) {
  104. form { id = "connectapp" method = "post" action = confirmAction
  105. p { id = "connectask" "Connect " + parkedApp + " to " + slug + "?" }
  106. p { class = "muted" "It will get read access to this repository and may review its pull requests. When you say Yes you go back to " + parkedHost + "." }
  107. input { name = "nonce" type = "hidden" value = parkedNonce }
  108. button { id = "connectyes" type = "submit" name = "decision" value = "yes" "Yes, connect" }
  109. button { id = "connectno" class = "quiet" type = "submit" name = "decision" value = "no" "No" }
  110. }
  111. }
  112. if (hasShown) {
  113. div { id = "appshown" class = "message"
  114. p { shownText }
  115. if (hasShownKey) { p { "Key: " code { id = "shownkey" shownKey } } }
  116. p { "Secret: " code { id = "shownsecret" shownSecret } }
  117. }
  118. }
  119. if (isOwner) {
  120. p { class = "muted" "An app is an outside program (for example a code reviewer) that works on this repository under its own name. Its key and secret are shown once." }
  121. if (noApps) { p { id = "noapps" class = "empty" "No apps connected." } }
  122. ul { id = "applist"
  123. for (a of apps) {
  124. li {
  125. span { class = "slug" a.name }
  126. span { class = "muted" a.host + " · added " + a.created + " · " + a.status }
  127. button { class = "quiet" type = "button" "Rotate secret" on click(e) { emit rotateApp(a.id) } }
  128. button { class = "quiet" type = "button" "Remove" on click(e) { emit removeAppRow(a.id) } }
  129. }
  130. }
  131. }
  132. form { id = "appform"
  133. on submit(e) {
  134. e.preventDefault()
  135. emit addAppRow(e)
  136. }
  137. label { "App name"
  138. input { id = "appname" name = "appname" required = "required" maxlength = "60" autocomplete = "off" }
  139. }
  140. label { "Receiver address"
  141. input { id = "apphook" name = "apphook" type = "url" required = "required" maxlength = "500" autocomplete = "off" placeholder = "https://…" }
  142. }
  143. button { id = "appadd" type = "submit" "Add app" }
  144. p { id = "apperror" class = "message" appError }
  145. }
  146. }
  147. }
  148. section { id = "ticketsettings"
  149. h2 { "Tickets" }
  150. if (hasConnectNote) { p { id = "connectnote" class = "message" connectNote } }
  151. if (connected) {
  152. p { id = "connectedto" "Connected to the tickets project " a { id = "projectlink" href = projectHref projectTitle } "." }
  153. }
  154. if (notConnected) { p { id = "notconnected" class = "muted" "This repository is not connected to a tickets project yet." } }
  155. if (isOwner) {
  156. p {
  157. a { id = "connecttickets" class = "button" href = connectHref "Tickets: connect" }
  158. }
  159. button { id = "disconnecttickets" class = forgetClass type = "button" "Forget the connection" on click(e) { emit disconnect() } }
  160. p { class = "muted" "Connecting asks tickets which project (you must be its admin there). Tickets can also disconnect gitoria from its side." }
  161. }
  162. if (notOwnerHint) { p { id = "ownerhint" class = "muted" "Only the owner of this repository can connect it." } }
  163. p { id = "settingserror" class = "message" settingsError }
  164. }
  165. }
  166. }
  167. }
  168. }
  169. on togglePriv() {
  170. memberError = ''
  171. r = emit server gitoriaSetPrivate(slug, !isPrivate)
  172. if (r == null || r.error != null) {
  173. memberError = r != null ? r.error : 'could not change the visibility'
  174. return null
  175. }
  176. isPrivate = r.repo.isPrivate
  177. privText = isPrivate ? 'This repository is private: only its owner and its members can see it.' : 'This repository is public: everybody can read it.'
  178. privButton = isPrivate ? 'Make public' : 'Make private'
  179. }
  180. on addMember(e) {
  181. memberError = ''
  182. r = emit server gitoriaChangeMember(slug, e.target.elements.membername.value, true)
  183. if (r == null || r.error != null) {
  184. memberError = r != null ? r.error : 'could not add the member'
  185. return null
  186. }
  187. members = r.members
  188. noMembers = members.length == 0
  189. e.target.elements.membername.value = ''
  190. }
  191. on removeMember(name) {
  192. memberError = ''
  193. r = emit server gitoriaChangeMember(slug, name, false)
  194. if (r == null || r.error != null) {
  195. memberError = r != null ? r.error : 'could not remove the member'
  196. return null
  197. }
  198. members = r.members
  199. noMembers = members.length == 0
  200. }
  201. on server gitoriaSetPrivate(slugOf, priv, session) {
  202. return setRepoPriv(userIdOfSession(session), slugOf, priv)
  203. }
  204. on addAppRow(e) {
  205. appError = ''
  206. r = emit server gitoriaAppAdd(slug, e.target.elements.appname.value, e.target.elements.apphook.value)
  207. if (r == null || r.error != null) {
  208. appError = r != null ? r.error : 'could not add the app'
  209. return null
  210. }
  211. apps = r.rows
  212. noApps = apps.length == 0
  213. hasShown = true
  214. shownText = 'Connected ' + r.name + '. Copy the key and the secret now: they are not shown again.'
  215. shownKey = r.key
  216. hasShownKey = true
  217. shownSecret = r.secret
  218. e.target.elements.appname.value = ''
  219. e.target.elements.apphook.value = ''
  220. }
  221. on removeAppRow(id) {
  222. appError = ''
  223. r = emit server gitoriaAppRemove(slug, id)
  224. if (r == null || r.error != null) {
  225. appError = r != null ? r.error : 'could not remove the app'
  226. return null
  227. }
  228. apps = r.rows
  229. noApps = apps.length == 0
  230. hasShown = false
  231. }
  232. on rotateApp(id) {
  233. appError = ''
  234. r = emit server gitoriaAppRotate(slug, id)
  235. if (r == null || r.error != null) {
  236. appError = r != null ? r.error : 'could not rotate the secret'
  237. return null
  238. }
  239. apps = r.rows
  240. hasShown = true
  241. shownText = 'New secret for ' + r.name + '. Copy it now: it is not shown again. The old secret no longer signs anything.'
  242. shownKey = ''
  243. hasShownKey = false
  244. shownSecret = r.secret
  245. }
  246. on server gitoriaAppAdd(slugOf, name, hook, session) {
  247. return addApp(userIdOfSession(session), session, slugOf, name, hook)
  248. }
  249. on server gitoriaAppRemove(slugOf, id, session) {
  250. return removeApp(userIdOfSession(session), session, slugOf, id)
  251. }
  252. on server gitoriaAppRotate(slugOf, id, session) {
  253. return rotateSecret(userIdOfSession(session), session, slugOf, id)
  254. }
  255. on server gitoriaChangeMember(slugOf, name, add, session) {
  256. return changeMember(userIdOfSession(session), 'r', slugOf, name, add)
  257. }
  258. on disconnect() {
  259. settingsError = ''
  260. r = emit server gitoriaDisconnectTickets(slug)
  261. if (r == null || r.error != null) {
  262. settingsError = r != null ? r.error : 'could not disconnect'
  263. return null
  264. }
  265. connected = false
  266. notConnected = true
  267. forgetClass = 'nomerge'
  268. projectTitle = ''
  269. projectHref = ''
  270. }
  271. on server gitoriaDisconnectTickets(slugOf, session) {
  272. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not disconnect' } }
  273. if (userOfSession(session) == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change this' } }
  274. r = setTicketsConnection(slugOf, '', '', '', '')
  275. if (r.error != null) { return { error = r.error } }
  276. return { ok = true }
  277. }
  278. Style {
  279. repoSettings {
  280. display = 'grid'
  281. gap = '1rem'
  282. minWidth = '0'
  283. '> *' {
  284. margin = '0'
  285. }
  286. }
  287. #ticketsettings {
  288. display = 'grid'
  289. gap = '.75rem'
  290. justifyItems = 'start'
  291. '> *' {
  292. margin = '0'
  293. }
  294. }
  295. '#disconnecttickets.nomerge' {
  296. display = 'none'
  297. }
  298. #connecttickets {
  299. color = 'var(--color-accent-text)'
  300. background = 'var(--color-accent)'
  301. }
  302. #members {
  303. listStyle = 'none'
  304. margin = '0'
  305. padding = '0'
  306. display = 'grid'
  307. gap = '.25rem'
  308. maxWidth = '32rem'
  309. li {
  310. display = 'flex'
  311. alignItems = 'center'
  312. justifyContent = 'space-between'
  313. gap = '.75rem'
  314. minHeight = '2.75rem'
  315. padding = '0 .5rem 0 1rem'
  316. background = 'var(--color-surface)'
  317. borderRadius = 'var(--radius-large)'
  318. }
  319. }
  320. #memberform {
  321. display = 'grid'
  322. gap = '.75rem'
  323. margin = '.75rem 0 1.5rem'
  324. maxWidth = '32rem'
  325. }
  326. #apps {
  327. display = 'grid'
  328. gap = '.75rem'
  329. margin = '0 0 1.5rem'
  330. justifyItems = 'start'
  331. '> *' {
  332. margin = '0'
  333. }
  334. }
  335. #connectapp {
  336. display = 'grid'
  337. gap = '.75rem'
  338. maxWidth = '32rem'
  339. padding = '1rem'
  340. background = 'var(--color-surface)'
  341. borderRadius = 'var(--radius-large)'
  342. }
  343. #appshown {
  344. display = 'grid'
  345. gap = '.5rem'
  346. maxWidth = '100%'
  347. code {
  348. overflowWrap = 'anywhere'
  349. }
  350. }
  351. #applist {
  352. listStyle = 'none'
  353. margin = '0'
  354. padding = '0'
  355. display = 'grid'
  356. gap = '.25rem'
  357. maxWidth = '40rem'
  358. width = '100%'
  359. li {
  360. display = 'flex'
  361. flexWrap = 'wrap'
  362. alignItems = 'center'
  363. gap = '.5rem .75rem'
  364. minHeight = '2.75rem'
  365. padding = '.25rem .5rem .25rem 1rem'
  366. background = 'var(--color-surface)'
  367. borderRadius = 'var(--radius-large)'
  368. }
  369. }
  370. #appform {
  371. display = 'grid'
  372. gap = '.75rem'
  373. maxWidth = '32rem'
  374. }
  375. #togglepriv {
  376. justifySelf = 'start'
  377. }
  378. #visibility {
  379. display = 'grid'
  380. gap = '.75rem'
  381. margin = '0 0 1.5rem'
  382. }
  383. }

Branches

Latest commits

  • 5a996ea8gitoria#42: short-lived app tokens, read-only git fetch with them (merge w42-app-token)mre
  • b5d696fegitoria#42: app tokens (gat_, one hour), appOfRequest, app token as the git read passwordmre
  • 1997e77dgitoria#40: stable PR numbers, refs/pull/N/head, ssh pushes reach the app (merge w40-pr-number)mre
  • 9364fb16gitoria#40: ssh pushes call /__git/pushed before and after (ensurePulls, notifyPush, syncPulls); gate over the sshd imagemre
  • fdb9ed28gitoria#41: repo owners can connect an app (merge w41-apps-connect)mre
  • 2ef23df0gitoria#40: the browser gate reads the title without the #Nmre
  • 9af07ecegitoria#41: connect an app to a repo (apps table, connect flow, manual add, allow-list, settings)mre
  • b9137ff0gitoria#40: pull requests are stored with a number, refs/pull/N/head, syncPulls and pullObject; /pulls shows #Nmre
  • 06d622daown image tag gitoria-runtime:debian12 for gitoria and standby (shared tag lost git)mre
  • 20caa33agitoria#37: media queries in the language's @media block (minWidth = '60rem') in list, codebrowser and repomre
  • c4175e6dgitoria: a startup error prints its message before exit 1 (hybriel#247)mre
  • c50d17efKeep function-route not-found style in shared stylesheetmre
  • e42d78d3Preserve ticket state CSS and document function-route style gapmre
  • c6b7154eWIP gitoria#26: move styles into nested component blocksmre
  • 77a2c31cgitoria#31: plain declarations instead of needless let in lib/ and tools/ (103 let removed, 137 kept because reassigned); no other changemre
  • 4b98ab62gitoria: an ident access key (idt_) works as the git password; read key clones only, bad key 401, ident down 503 (ident#27); gate tests/ident-access-gitoria.mjs in deploy.shmre
  • 1185f686gitoria#36: a failed return from tickets shows a note on the settings page and leaves one log line per outcome; no code is exchangedmre
  • 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