gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitbd94cc7ebd94cc7elog: #25 cause found (run() leak)mrebd94cc7e/components/settings.hl

18.9 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. import { requiredList, requireContext, dropRequired } from '../lib/statuses.hl'
  20. host = null
  21. orepo = ''
  22. session = null
  23. slug = slugOfRequest(host, orepo)
  24. repo = repoAt(slug, session)
  25. hasRepo = repo != null
  26. pre = px(slug)
  27. connectHref = pre + '/settings/connect'
  28. isOwner = repo != null && ownsRepo(slug, session)
  29. connected = repo != null && repo.ticketsOn
  30. notConnected = repo != null && !repo.ticketsOn
  31. projectTitle = repo != null ? repo.ticketsTitle : ''
  32. projectHref = repo != null && repo.ticketsOn ? ticketsUrl + '/projects/' + repo.ticketsProject : ''
  33. connectNote = session != null && session.data != null && session.data.connectNote != null ? session.data.connectNote : ''
  34. hasConnectNote = connectNote != ''
  35. notOwnerHint = repo != null && !isOwner
  36. settingsError = ''
  37. forgetClass = repo != null && repo.ticketsOn ? 'quiet' : 'nomerge'
  38. __title = pageTitle(siteName, titleSlug(host, orepo, session), 'Settings')
  39. // 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)
  40. isPrivate = repo != null && repo.isPrivate
  41. ownPriv = repo != null && repo.isPrivate && !repo.inOrg
  42. 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.')
  43. privButton = repo != null && repo.isPrivate ? 'Make public' : 'Make private'
  44. listed = isOwner ? membersOf('r', slug, userIdOfSession(session)) : null
  45. members = listed != null && listed.members != null ? listed.members : []
  46. noMembers = isOwner && members.length == 0
  47. memberName = ''
  48. memberError = ''
  49. // 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)
  50. apps = isOwner ? appRows(repo.id) : []
  51. noApps = isOwner && apps.length == 0
  52. parked = session != null && session.data != null && session.data.appConnect != null && repo != null && session.data.appConnect.slug == slug ? session.data.appConnect : null
  53. hasParked = parked != null
  54. parkedApp = parked != null ? parked.app : ''
  55. parkedHost = parked != null ? hostOfUrl(parked.ret) : ''
  56. parkedNonce = parked != null ? parked.nonce : ''
  57. confirmAction = pre + '/settings/apps/confirm'
  58. parkedSignedOut = hasParked && session != null && userIdOfSession(session) == null
  59. parkedNotOwner = hasParked && userIdOfSession(session) != null && !isOwner
  60. parkedOwner = hasParked && isOwner
  61. // the Apps section is the owner's; a signed-in non-owner who came to connect an app still gets its message (gitoria#45)
  62. showApps = isOwner || hasParked
  63. appName = ''
  64. appHook = ''
  65. appError = ''
  66. hasShown = false
  67. shownName = ''
  68. shownKey = ''
  69. hasShownKey = false
  70. shownSecret = ''
  71. shownText = ''
  72. // REQUIRED BEFORE MERGE (gitoria#46): the contexts the owner requires to be success on a pull request's head
  73. required = isOwner ? requiredList(repo.id) : []
  74. noRequired = isOwner && required.length == 0
  75. requiredApp = apps.length > 0 ? apps[0].id : ''
  76. requiredContext = ''
  77. requiredError = ''
  78. View {
  79. repoPage {
  80. if (hasRepo) {
  81. repoSettings { id = "settings"
  82. section { id = "visibility"
  83. h2 { "Visibility" }
  84. p { id = "privtext" privText }
  85. if (isOwner) { button { id = "togglepriv" type = "button" privButton on click(e) { emit togglePriv() } } }
  86. if (isOwner) {
  87. h2 { "Members" }
  88. 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." }
  89. if (noMembers) { p { id = "nomembers" class = "empty" "No members yet." } }
  90. ul { id = "members"
  91. for (m of members) {
  92. li { span { class = "slug" m.name } button { class = "quiet" type = "button" "Remove" on click(e) { emit removeMember(m.name) } } }
  93. }
  94. }
  95. form { id = "memberform"
  96. on submit(e) {
  97. e.preventDefault()
  98. emit addMember(e)
  99. }
  100. label { "Display name"
  101. input { id = "membername" name = "membername" required = "required" maxlength = "60" autocomplete = "off" value = memberName on input(e) { memberName = e.target.value } }
  102. }
  103. button { id = "memberadd" type = "submit" "Add member" }
  104. p { id = "membererror" memberError }
  105. }
  106. }
  107. }
  108. if (showApps) {
  109. section { id = "apps"
  110. h2 { "Apps" }
  111. if (parkedSignedOut) { p { id = "appsignin" "Sign in with the selector at the top to connect " + parkedApp + " to this repository." } }
  112. if (parkedNotOwner) { p { id = "appnotowner" "Only the owner of this repository can connect " + parkedApp + "." } }
  113. if (parkedOwner) {
  114. form { id = "connectapp" method = "post" action = confirmAction
  115. p { id = "connectask" "Connect " + parkedApp + " to " + slug + "?" }
  116. 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 + "." }
  117. input { name = "nonce" type = "hidden" value = parkedNonce }
  118. button { id = "connectyes" type = "submit" name = "decision" value = "yes" "Yes, connect" }
  119. button { id = "connectno" class = "quiet" type = "submit" name = "decision" value = "no" "No" }
  120. }
  121. }
  122. if (hasShown) {
  123. div { id = "appshown"
  124. p { shownText }
  125. if (hasShownKey) { p { "Key: " code { id = "shownkey" shownKey } } }
  126. p { "Secret: " code { id = "shownsecret" shownSecret } }
  127. }
  128. }
  129. if (isOwner) {
  130. 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." }
  131. if (noApps) { p { id = "noapps" class = "empty" "No apps connected." } }
  132. ul { id = "applist"
  133. for (a of apps) {
  134. li {
  135. span { class = "slug" a.name }
  136. span { class = "muted" a.host + " · added " + a.created + " · " + a.status }
  137. button { class = "quiet" type = "button" "Send ping" on click(e) { emit pingApp(a.id) } }
  138. button { class = "quiet" type = "button" "Rotate secret" on click(e) { emit rotateApp(a.id) } }
  139. button { class = "quiet" type = "button" "Remove" on click(e) { emit removeAppRow(a.id) } }
  140. }
  141. }
  142. }
  143. form { id = "appform"
  144. on submit(e) {
  145. e.preventDefault()
  146. emit addAppRow(e)
  147. }
  148. label { "App name"
  149. input { id = "appname" name = "appname" required = "required" maxlength = "60" autocomplete = "off" value = appName on input(e) { appName = e.target.value } }
  150. }
  151. label { "Receiver address"
  152. input { id = "apphook" name = "apphook" type = "url" required = "required" maxlength = "500" autocomplete = "off" placeholder = "https://…" value = appHook on input(e) { appHook = e.target.value } }
  153. }
  154. button { id = "appadd" type = "submit" "Add app" }
  155. p { id = "apperror" appError }
  156. }
  157. }
  158. }
  159. }
  160. section { id = "required"
  161. if (isOwner) {
  162. h2 { "Required before merge" }
  163. p { class = "muted" "Pick a connected app and the status context it must set to success on a pull request's current head before it can be merged. Another app's success with the same context name does not count. A push gives the pull request a new head, so the check starts again." }
  164. if (noRequired) { p { id = "norequired" class = "empty" "Nothing is required: every pull request can be merged." } }
  165. ul { id = "requiredlist"
  166. for (r of required) {
  167. li {
  168. span { class = "slug" r.name }
  169. button { class = "quiet" type = "button" "Remove" on click(e) { emit dropRequiredRow(r.id) } }
  170. }
  171. }
  172. }
  173. form { id = "requiredform"
  174. on submit(e) {
  175. e.preventDefault()
  176. emit addRequiredRow(e)
  177. }
  178. label { "App"
  179. select { id = "requiredapp" name = "requiredapp" value = requiredApp on change(e) { requiredApp = e.target.value }
  180. for (a of apps) { option { value = a.id a.name } }
  181. }
  182. }
  183. label { "Status context the app sets"
  184. input { id = "requiredcontext" name = "requiredcontext" required = "required" maxlength = "100" autocomplete = "off" value = requiredContext on input(e) { requiredContext = e.target.value } }
  185. }
  186. button { id = "requiredadd" type = "submit" "Require it" }
  187. p { id = "requirederror" requiredError }
  188. }
  189. }
  190. }
  191. section { id = "ticketsettings"
  192. h2 { "Tickets" }
  193. if (hasConnectNote) { p { id = "connectnote" connectNote } }
  194. if (connected) {
  195. p { id = "connectedto" "Connected to the tickets project " a { id = "projectlink" href = projectHref projectTitle } "." }
  196. }
  197. if (notConnected) { p { id = "notconnected" class = "muted" "This repository is not connected to a tickets project yet." } }
  198. if (isOwner) {
  199. p {
  200. a { id = "connecttickets" class = "button" href = connectHref "Tickets: connect" }
  201. }
  202. // Connection-state classes are computed and have no Style-rule selection form.
  203. button { id = "disconnecttickets" class = forgetClass type = "button" "Forget the connection" on click(e) { emit disconnect() } }
  204. p { class = "muted" "Connecting asks tickets which project (you must be its admin there). Tickets can also disconnect gitoria from its side." }
  205. }
  206. if (notOwnerHint) { p { id = "ownerhint" class = "muted" "Only the owner of this repository can connect it." } }
  207. p { id = "settingserror" settingsError }
  208. }
  209. }
  210. }
  211. }
  212. }
  213. on togglePriv() {
  214. memberError = ''
  215. r = emit server gitoriaSetPrivate(slug, !isPrivate)
  216. if (r == null || r.error != null) {
  217. memberError = r != null ? r.error : 'could not change the visibility'
  218. return null
  219. }
  220. isPrivate = r.repo.isPrivate
  221. privText = isPrivate ? 'This repository is private: only its owner and its members can see it.' : 'This repository is public: everybody can read it.'
  222. privButton = isPrivate ? 'Make public' : 'Make private'
  223. }
  224. on addMember(e) {
  225. memberError = ''
  226. r = emit server gitoriaChangeMember(slug, memberName, true)
  227. if (r == null || r.error != null) {
  228. memberError = r != null ? r.error : 'could not add the member'
  229. return null
  230. }
  231. members = r.members
  232. noMembers = members.length == 0
  233. memberName = ''
  234. }
  235. on removeMember(name) {
  236. memberError = ''
  237. r = emit server gitoriaChangeMember(slug, name, false)
  238. if (r == null || r.error != null) {
  239. memberError = r != null ? r.error : 'could not remove the member'
  240. return null
  241. }
  242. members = r.members
  243. noMembers = members.length == 0
  244. }
  245. on server gitoriaSetPrivate(slugOf, priv, session) {
  246. return setRepoPriv(userIdOfSession(session), slugOf, priv)
  247. }
  248. on addAppRow(e) {
  249. appError = ''
  250. r = emit server gitoriaAppAdd(slug, appName, appHook)
  251. if (r == null || r.error != null) {
  252. appError = r != null ? r.error : 'could not add the app'
  253. return null
  254. }
  255. apps = r.rows
  256. noApps = apps.length == 0
  257. hasShown = true
  258. shownText = 'Connected ' + r.name + '. Copy the key and the secret now: they are not shown again.'
  259. shownKey = r.key
  260. hasShownKey = true
  261. shownSecret = r.secret
  262. appName = ''
  263. appHook = ''
  264. }
  265. on removeAppRow(id) {
  266. appError = ''
  267. r = emit server gitoriaAppRemove(slug, id)
  268. if (r == null || r.error != null) {
  269. appError = r != null ? r.error : 'could not remove the app'
  270. return null
  271. }
  272. apps = r.rows
  273. noApps = apps.length == 0
  274. hasShown = false
  275. }
  276. on pingApp(id) {
  277. appError = ''
  278. r = emit server gitoriaAppPing(slug, id)
  279. if (r == null || r.error != null) {
  280. appError = r != null ? r.error : 'could not send the ping'
  281. return null
  282. }
  283. appError = 'Ping to ' + r.name + ' is on its way. The status of the app shows the answer.'
  284. }
  285. on rotateApp(id) {
  286. appError = ''
  287. r = emit server gitoriaAppRotate(slug, id)
  288. if (r == null || r.error != null) {
  289. appError = r != null ? r.error : 'could not rotate the secret'
  290. return null
  291. }
  292. apps = r.rows
  293. hasShown = true
  294. shownText = 'New secret for ' + r.name + '. Copy it now: it is not shown again. The old secret no longer signs anything.'
  295. shownKey = ''
  296. hasShownKey = false
  297. shownSecret = r.secret
  298. }
  299. on addRequiredRow(e) {
  300. requiredError = ''
  301. r = emit server gitoriaRequiredAdd(slug, requiredApp, requiredContext)
  302. if (r == null || r.error != null) {
  303. requiredError = r != null ? r.error : 'could not save the setting'
  304. return null
  305. }
  306. required = r.rows
  307. noRequired = required.length == 0
  308. requiredContext = ''
  309. }
  310. on dropRequiredRow(id) {
  311. requiredError = ''
  312. r = emit server gitoriaRequiredRemove(slug, id)
  313. if (r == null || r.error != null) {
  314. requiredError = r != null ? r.error : 'could not save the setting'
  315. return null
  316. }
  317. required = r.rows
  318. noRequired = required.length == 0
  319. }
  320. on server gitoriaRequiredAdd(slugOf, appId, ctxName, session) {
  321. return requireContext(userIdOfSession(session), session, slugOf, appId, ctxName)
  322. }
  323. on server gitoriaRequiredRemove(slugOf, id, session) {
  324. return dropRequired(userIdOfSession(session), session, slugOf, id)
  325. }
  326. on server gitoriaAppAdd(slugOf, name, hook, session) {
  327. return addApp(userIdOfSession(session), session, slugOf, name, hook)
  328. }
  329. on server gitoriaAppRemove(slugOf, id, session) {
  330. return removeApp(userIdOfSession(session), session, slugOf, id)
  331. }
  332. on server gitoriaAppPing(slugOf, id, session) {
  333. return sendPing(userIdOfSession(session), session, slugOf, id)
  334. }
  335. on server gitoriaAppRotate(slugOf, id, session) {
  336. return rotateSecret(userIdOfSession(session), session, slugOf, id)
  337. }
  338. on server gitoriaChangeMember(slugOf, name, add, session) {
  339. return changeMember(userIdOfSession(session), 'r', slugOf, name, add)
  340. }
  341. on disconnect() {
  342. settingsError = ''
  343. r = emit server gitoriaDisconnectTickets(slug)
  344. if (r == null || r.error != null) {
  345. settingsError = r != null ? r.error : 'could not disconnect'
  346. return null
  347. }
  348. connected = false
  349. notConnected = true
  350. forgetClass = 'nomerge'
  351. projectTitle = ''
  352. projectHref = ''
  353. }
  354. on server gitoriaDisconnectTickets(slugOf, session) {
  355. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not disconnect' } }
  356. if (userOfSession(session) == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change this' } }
  357. r = setTicketsConnection(slugOf, '', '', '', '')
  358. if (r.error != null) { return { error = r.error } }
  359. return { ok = true }
  360. }
  361. Style {
  362. repoSettings {
  363. display = 'grid'
  364. gap = '1rem'
  365. minWidth = '0'
  366. // Direct-child and sibling combinators have no bare language form.
  367. '> *' {
  368. margin = '0'
  369. }
  370. }
  371. #ticketsettings {
  372. display = 'grid'
  373. gap = '.75rem'
  374. justifyItems = 'start'
  375. // Direct-child and sibling combinators have no bare language form.
  376. '> *' {
  377. margin = '0'
  378. }
  379. }
  380. // Runtime and theme class predicates have no bare selector form.
  381. '#disconnecttickets.nomerge' {
  382. display = 'none'
  383. }
  384. #connecttickets {
  385. color = 'var(--color-accent-text)'
  386. background = 'var(--color-accent)'
  387. }
  388. #members {
  389. listStyle = 'none'
  390. margin = '0'
  391. padding = '0'
  392. display = 'grid'
  393. gap = '.25rem'
  394. maxWidth = '32rem'
  395. li {
  396. display = 'flex'
  397. alignItems = 'center'
  398. justifyContent = 'space-between'
  399. gap = '.75rem'
  400. minHeight = '2.75rem'
  401. padding = '0 .5rem 0 1rem'
  402. background = 'var(--color-surface)'
  403. borderRadius = 'var(--radius-large)'
  404. }
  405. }
  406. #memberform {
  407. display = 'grid'
  408. gap = '.75rem'
  409. margin = '.75rem 0 1.5rem'
  410. maxWidth = '32rem'
  411. }
  412. #apps {
  413. display = 'grid'
  414. gap = '.75rem'
  415. margin = '0 0 1.5rem'
  416. justifyItems = 'start'
  417. // Direct-child and sibling combinators have no bare language form.
  418. '> *' {
  419. margin = '0'
  420. }
  421. }
  422. #connectapp {
  423. display = 'grid'
  424. gap = '.75rem'
  425. maxWidth = '32rem'
  426. padding = '1rem'
  427. background = 'var(--color-surface)'
  428. borderRadius = 'var(--radius-large)'
  429. }
  430. #appshown {
  431. margin = '0'
  432. color = 'var(--color-danger)'
  433. empty { display = 'none' }
  434. display = 'grid'
  435. gap = '.5rem'
  436. maxWidth = '100%'
  437. code {
  438. overflowWrap = 'anywhere'
  439. }
  440. }
  441. #applist {
  442. listStyle = 'none'
  443. margin = '0'
  444. padding = '0'
  445. display = 'grid'
  446. gap = '.25rem'
  447. maxWidth = '40rem'
  448. width = '100%'
  449. li {
  450. display = 'flex'
  451. flexWrap = 'wrap'
  452. alignItems = 'center'
  453. gap = '.5rem .75rem'
  454. minHeight = '2.75rem'
  455. padding = '.25rem .5rem .25rem 1rem'
  456. background = 'var(--color-surface)'
  457. borderRadius = 'var(--radius-large)'
  458. }
  459. }
  460. #required {
  461. display = 'grid'
  462. gap = '.75rem'
  463. margin = '0 0 1.5rem'
  464. justifyItems = 'start'
  465. // Direct-child and sibling combinators have no bare language form.
  466. '> *' {
  467. margin = '0'
  468. }
  469. }
  470. #requiredlist {
  471. listStyle = 'none'
  472. margin = '0'
  473. padding = '0'
  474. display = 'grid'
  475. gap = '.25rem'
  476. maxWidth = '40rem'
  477. width = '100%'
  478. li {
  479. display = 'flex'
  480. flexWrap = 'wrap'
  481. alignItems = 'center'
  482. justifyContent = 'space-between'
  483. gap = '.5rem .75rem'
  484. minHeight = '2.75rem'
  485. padding = '.25rem .5rem .25rem 1rem'
  486. background = 'var(--color-surface)'
  487. borderRadius = 'var(--radius-large)'
  488. }
  489. }
  490. #requiredform {
  491. display = 'grid'
  492. gap = '.75rem'
  493. maxWidth = '32rem'
  494. }
  495. #appform {
  496. display = 'grid'
  497. gap = '.75rem'
  498. maxWidth = '32rem'
  499. }
  500. #togglepriv {
  501. justifySelf = 'start'
  502. }
  503. #visibility {
  504. display = 'grid'
  505. gap = '.75rem'
  506. margin = '0 0 1.5rem'
  507. }
  508. #membererror {
  509. margin = '0'
  510. color = 'var(--color-danger)'
  511. empty { display = 'none' }
  512. }
  513. #appsignin {
  514. margin = '0'
  515. color = 'var(--color-danger)'
  516. empty { display = 'none' }
  517. }
  518. #appnotowner {
  519. margin = '0'
  520. color = 'var(--color-danger)'
  521. empty { display = 'none' }
  522. }
  523. #apperror {
  524. margin = '0'
  525. color = 'var(--color-danger)'
  526. empty { display = 'none' }
  527. }
  528. #requirederror {
  529. margin = '0'
  530. color = 'var(--color-danger)'
  531. empty { display = 'none' }
  532. }
  533. #connectnote {
  534. margin = '0'
  535. color = 'var(--color-danger)'
  536. empty { display = 'none' }
  537. }
  538. #settingserror {
  539. margin = '0'
  540. color = 'var(--color-danger)'
  541. empty { display = 'none' }
  542. }
  543. }

Branches

Latest commits

  • bd94cc7elog: #25 cause found (run() leak)mre
  • 565cb508log: H25 round 1mre
  • 90a0af84log: H25 startedmre
  • 87bd53b8mission H25mre
  • 71a746cflog: day48 livemre
  • bf568e14log: V48 mergedmre
  • 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
  • f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
  • 5d0834e7log: Apollo model rulemre
  • fe8e5bd5log: #25 sample, V48 missionmre
  • 8580c5d9log: theme fix from Atlasmre
  • 46823d93log: Apollo budget correctionmre
  • f6d32341log: Apollo on budget and #25 nextmre
  • d7184f53log: batch live, #25 evidencemre
  • 5e25e816log: W61 mergedmre
  • aafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmre
  • aca1fda1Merge W61: theme from layouts 17e0f03, Views refer to Style rules (gitoria#37 #27)mre
  • 03cb650blog: W61 theme decisionmre
  • 248bce85Report final style gates, CSS mappings and 136 whole-image comparisonsmre
  • 153c344bRestore organization metadata exposed by the whole-image comparisonmre