gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitafdb0cbfafdb0cbfgitoria#43: rename the moved helper (name clash in the browser build)mreafdb0cbf/components/settings.hl

14.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. // "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, sendPing } 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" "Send ping" on click(e) { emit pingApp(a.id) } }
  128. button { class = "quiet" type = "button" "Rotate secret" on click(e) { emit rotateApp(a.id) } }
  129. button { class = "quiet" type = "button" "Remove" on click(e) { emit removeAppRow(a.id) } }
  130. }
  131. }
  132. }
  133. form { id = "appform"
  134. on submit(e) {
  135. e.preventDefault()
  136. emit addAppRow(e)
  137. }
  138. label { "App name"
  139. input { id = "appname" name = "appname" required = "required" maxlength = "60" autocomplete = "off" }
  140. }
  141. label { "Receiver address"
  142. input { id = "apphook" name = "apphook" type = "url" required = "required" maxlength = "500" autocomplete = "off" placeholder = "https://…" }
  143. }
  144. button { id = "appadd" type = "submit" "Add app" }
  145. p { id = "apperror" class = "message" appError }
  146. }
  147. }
  148. }
  149. section { id = "ticketsettings"
  150. h2 { "Tickets" }
  151. if (hasConnectNote) { p { id = "connectnote" class = "message" connectNote } }
  152. if (connected) {
  153. p { id = "connectedto" "Connected to the tickets project " a { id = "projectlink" href = projectHref projectTitle } "." }
  154. }
  155. if (notConnected) { p { id = "notconnected" class = "muted" "This repository is not connected to a tickets project yet." } }
  156. if (isOwner) {
  157. p {
  158. a { id = "connecttickets" class = "button" href = connectHref "Tickets: connect" }
  159. }
  160. button { id = "disconnecttickets" class = forgetClass type = "button" "Forget the connection" on click(e) { emit disconnect() } }
  161. p { class = "muted" "Connecting asks tickets which project (you must be its admin there). Tickets can also disconnect gitoria from its side." }
  162. }
  163. if (notOwnerHint) { p { id = "ownerhint" class = "muted" "Only the owner of this repository can connect it." } }
  164. p { id = "settingserror" class = "message" settingsError }
  165. }
  166. }
  167. }
  168. }
  169. }
  170. on togglePriv() {
  171. memberError = ''
  172. r = emit server gitoriaSetPrivate(slug, !isPrivate)
  173. if (r == null || r.error != null) {
  174. memberError = r != null ? r.error : 'could not change the visibility'
  175. return null
  176. }
  177. isPrivate = r.repo.isPrivate
  178. privText = isPrivate ? 'This repository is private: only its owner and its members can see it.' : 'This repository is public: everybody can read it.'
  179. privButton = isPrivate ? 'Make public' : 'Make private'
  180. }
  181. on addMember(e) {
  182. memberError = ''
  183. r = emit server gitoriaChangeMember(slug, e.target.elements.membername.value, true)
  184. if (r == null || r.error != null) {
  185. memberError = r != null ? r.error : 'could not add the member'
  186. return null
  187. }
  188. members = r.members
  189. noMembers = members.length == 0
  190. e.target.elements.membername.value = ''
  191. }
  192. on removeMember(name) {
  193. memberError = ''
  194. r = emit server gitoriaChangeMember(slug, name, false)
  195. if (r == null || r.error != null) {
  196. memberError = r != null ? r.error : 'could not remove the member'
  197. return null
  198. }
  199. members = r.members
  200. noMembers = members.length == 0
  201. }
  202. on server gitoriaSetPrivate(slugOf, priv, session) {
  203. return setRepoPriv(userIdOfSession(session), slugOf, priv)
  204. }
  205. on addAppRow(e) {
  206. appError = ''
  207. r = emit server gitoriaAppAdd(slug, e.target.elements.appname.value, e.target.elements.apphook.value)
  208. if (r == null || r.error != null) {
  209. appError = r != null ? r.error : 'could not add the app'
  210. return null
  211. }
  212. apps = r.rows
  213. noApps = apps.length == 0
  214. hasShown = true
  215. shownText = 'Connected ' + r.name + '. Copy the key and the secret now: they are not shown again.'
  216. shownKey = r.key
  217. hasShownKey = true
  218. shownSecret = r.secret
  219. e.target.elements.appname.value = ''
  220. e.target.elements.apphook.value = ''
  221. }
  222. on removeAppRow(id) {
  223. appError = ''
  224. r = emit server gitoriaAppRemove(slug, id)
  225. if (r == null || r.error != null) {
  226. appError = r != null ? r.error : 'could not remove the app'
  227. return null
  228. }
  229. apps = r.rows
  230. noApps = apps.length == 0
  231. hasShown = false
  232. }
  233. on pingApp(id) {
  234. appError = ''
  235. r = emit server gitoriaAppPing(slug, id)
  236. if (r == null || r.error != null) {
  237. appError = r != null ? r.error : 'could not send the ping'
  238. return null
  239. }
  240. appError = 'Ping to ' + r.name + ' is on its way. The status of the app shows the answer.'
  241. }
  242. on rotateApp(id) {
  243. appError = ''
  244. r = emit server gitoriaAppRotate(slug, id)
  245. if (r == null || r.error != null) {
  246. appError = r != null ? r.error : 'could not rotate the secret'
  247. return null
  248. }
  249. apps = r.rows
  250. hasShown = true
  251. shownText = 'New secret for ' + r.name + '. Copy it now: it is not shown again. The old secret no longer signs anything.'
  252. shownKey = ''
  253. hasShownKey = false
  254. shownSecret = r.secret
  255. }
  256. on server gitoriaAppAdd(slugOf, name, hook, session) {
  257. return addApp(userIdOfSession(session), session, slugOf, name, hook)
  258. }
  259. on server gitoriaAppRemove(slugOf, id, session) {
  260. return removeApp(userIdOfSession(session), session, slugOf, id)
  261. }
  262. on server gitoriaAppPing(slugOf, id, session) {
  263. return sendPing(userIdOfSession(session), session, slugOf, id)
  264. }
  265. on server gitoriaAppRotate(slugOf, id, session) {
  266. return rotateSecret(userIdOfSession(session), session, slugOf, id)
  267. }
  268. on server gitoriaChangeMember(slugOf, name, add, session) {
  269. return changeMember(userIdOfSession(session), 'r', slugOf, name, add)
  270. }
  271. on disconnect() {
  272. settingsError = ''
  273. r = emit server gitoriaDisconnectTickets(slug)
  274. if (r == null || r.error != null) {
  275. settingsError = r != null ? r.error : 'could not disconnect'
  276. return null
  277. }
  278. connected = false
  279. notConnected = true
  280. forgetClass = 'nomerge'
  281. projectTitle = ''
  282. projectHref = ''
  283. }
  284. on server gitoriaDisconnectTickets(slugOf, session) {
  285. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not disconnect' } }
  286. if (userOfSession(session) == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change this' } }
  287. r = setTicketsConnection(slugOf, '', '', '', '')
  288. if (r.error != null) { return { error = r.error } }
  289. return { ok = true }
  290. }
  291. Style {
  292. repoSettings {
  293. display = 'grid'
  294. gap = '1rem'
  295. minWidth = '0'
  296. '> *' {
  297. margin = '0'
  298. }
  299. }
  300. #ticketsettings {
  301. display = 'grid'
  302. gap = '.75rem'
  303. justifyItems = 'start'
  304. '> *' {
  305. margin = '0'
  306. }
  307. }
  308. '#disconnecttickets.nomerge' {
  309. display = 'none'
  310. }
  311. #connecttickets {
  312. color = 'var(--color-accent-text)'
  313. background = 'var(--color-accent)'
  314. }
  315. #members {
  316. listStyle = 'none'
  317. margin = '0'
  318. padding = '0'
  319. display = 'grid'
  320. gap = '.25rem'
  321. maxWidth = '32rem'
  322. li {
  323. display = 'flex'
  324. alignItems = 'center'
  325. justifyContent = 'space-between'
  326. gap = '.75rem'
  327. minHeight = '2.75rem'
  328. padding = '0 .5rem 0 1rem'
  329. background = 'var(--color-surface)'
  330. borderRadius = 'var(--radius-large)'
  331. }
  332. }
  333. #memberform {
  334. display = 'grid'
  335. gap = '.75rem'
  336. margin = '.75rem 0 1.5rem'
  337. maxWidth = '32rem'
  338. }
  339. #apps {
  340. display = 'grid'
  341. gap = '.75rem'
  342. margin = '0 0 1.5rem'
  343. justifyItems = 'start'
  344. '> *' {
  345. margin = '0'
  346. }
  347. }
  348. #connectapp {
  349. display = 'grid'
  350. gap = '.75rem'
  351. maxWidth = '32rem'
  352. padding = '1rem'
  353. background = 'var(--color-surface)'
  354. borderRadius = 'var(--radius-large)'
  355. }
  356. #appshown {
  357. display = 'grid'
  358. gap = '.5rem'
  359. maxWidth = '100%'
  360. code {
  361. overflowWrap = 'anywhere'
  362. }
  363. }
  364. #applist {
  365. listStyle = 'none'
  366. margin = '0'
  367. padding = '0'
  368. display = 'grid'
  369. gap = '.25rem'
  370. maxWidth = '40rem'
  371. width = '100%'
  372. li {
  373. display = 'flex'
  374. flexWrap = 'wrap'
  375. alignItems = 'center'
  376. gap = '.5rem .75rem'
  377. minHeight = '2.75rem'
  378. padding = '.25rem .5rem .25rem 1rem'
  379. background = 'var(--color-surface)'
  380. borderRadius = 'var(--radius-large)'
  381. }
  382. }
  383. #appform {
  384. display = 'grid'
  385. gap = '.75rem'
  386. maxWidth = '32rem'
  387. }
  388. #togglepriv {
  389. justifySelf = 'start'
  390. }
  391. #visibility {
  392. display = 'grid'
  393. gap = '.75rem'
  394. margin = '0 0 1.5rem'
  395. }
  396. }

Branches

Latest commits

  • afdb0cbfgitoria#43: rename the moved helper (name clash in the browser build)mre
  • 15e01e94gitoria#43: tests/events.mjs and its probemre
  • 77829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre
  • 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