gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit24b479e724b479e7W60: record final gates, Chrome failures and AE evidencemre24b479e7/components/settings.hl

17.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" class = "message" memberError }
  105. }
  106. }
  107. }
  108. if (showApps) {
  109. section { id = "apps"
  110. h2 { "Apps" }
  111. if (parkedSignedOut) { p { id = "appsignin" class = "message" "Sign in with the selector at the top to connect " + parkedApp + " to this repository." } }
  112. if (parkedNotOwner) { p { id = "appnotowner" class = "message" "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" class = "message"
  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" class = "message" 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" class = "message" requiredError }
  188. }
  189. }
  190. }
  191. section { id = "ticketsettings"
  192. h2 { "Tickets" }
  193. if (hasConnectNote) { p { id = "connectnote" class = "message" 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. button { id = "disconnecttickets" class = forgetClass type = "button" "Forget the connection" on click(e) { emit disconnect() } }
  203. p { class = "muted" "Connecting asks tickets which project (you must be its admin there). Tickets can also disconnect gitoria from its side." }
  204. }
  205. if (notOwnerHint) { p { id = "ownerhint" class = "muted" "Only the owner of this repository can connect it." } }
  206. p { id = "settingserror" class = "message" settingsError }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. on togglePriv() {
  213. memberError = ''
  214. r = emit server gitoriaSetPrivate(slug, !isPrivate)
  215. if (r == null || r.error != null) {
  216. memberError = r != null ? r.error : 'could not change the visibility'
  217. return null
  218. }
  219. isPrivate = r.repo.isPrivate
  220. privText = isPrivate ? 'This repository is private: only its owner and its members can see it.' : 'This repository is public: everybody can read it.'
  221. privButton = isPrivate ? 'Make public' : 'Make private'
  222. }
  223. on addMember(e) {
  224. memberError = ''
  225. r = emit server gitoriaChangeMember(slug, memberName, true)
  226. if (r == null || r.error != null) {
  227. memberError = r != null ? r.error : 'could not add the member'
  228. return null
  229. }
  230. members = r.members
  231. noMembers = members.length == 0
  232. memberName = ''
  233. }
  234. on removeMember(name) {
  235. memberError = ''
  236. r = emit server gitoriaChangeMember(slug, name, false)
  237. if (r == null || r.error != null) {
  238. memberError = r != null ? r.error : 'could not remove the member'
  239. return null
  240. }
  241. members = r.members
  242. noMembers = members.length == 0
  243. }
  244. on server gitoriaSetPrivate(slugOf, priv, session) {
  245. return setRepoPriv(userIdOfSession(session), slugOf, priv)
  246. }
  247. on addAppRow(e) {
  248. appError = ''
  249. r = emit server gitoriaAppAdd(slug, appName, appHook)
  250. if (r == null || r.error != null) {
  251. appError = r != null ? r.error : 'could not add the app'
  252. return null
  253. }
  254. apps = r.rows
  255. noApps = apps.length == 0
  256. hasShown = true
  257. shownText = 'Connected ' + r.name + '. Copy the key and the secret now: they are not shown again.'
  258. shownKey = r.key
  259. hasShownKey = true
  260. shownSecret = r.secret
  261. appName = ''
  262. appHook = ''
  263. }
  264. on removeAppRow(id) {
  265. appError = ''
  266. r = emit server gitoriaAppRemove(slug, id)
  267. if (r == null || r.error != null) {
  268. appError = r != null ? r.error : 'could not remove the app'
  269. return null
  270. }
  271. apps = r.rows
  272. noApps = apps.length == 0
  273. hasShown = false
  274. }
  275. on pingApp(id) {
  276. appError = ''
  277. r = emit server gitoriaAppPing(slug, id)
  278. if (r == null || r.error != null) {
  279. appError = r != null ? r.error : 'could not send the ping'
  280. return null
  281. }
  282. appError = 'Ping to ' + r.name + ' is on its way. The status of the app shows the answer.'
  283. }
  284. on rotateApp(id) {
  285. appError = ''
  286. r = emit server gitoriaAppRotate(slug, id)
  287. if (r == null || r.error != null) {
  288. appError = r != null ? r.error : 'could not rotate the secret'
  289. return null
  290. }
  291. apps = r.rows
  292. hasShown = true
  293. shownText = 'New secret for ' + r.name + '. Copy it now: it is not shown again. The old secret no longer signs anything.'
  294. shownKey = ''
  295. hasShownKey = false
  296. shownSecret = r.secret
  297. }
  298. on addRequiredRow(e) {
  299. requiredError = ''
  300. r = emit server gitoriaRequiredAdd(slug, requiredApp, requiredContext)
  301. if (r == null || r.error != null) {
  302. requiredError = r != null ? r.error : 'could not save the setting'
  303. return null
  304. }
  305. required = r.rows
  306. noRequired = required.length == 0
  307. requiredContext = ''
  308. }
  309. on dropRequiredRow(id) {
  310. requiredError = ''
  311. r = emit server gitoriaRequiredRemove(slug, id)
  312. if (r == null || r.error != null) {
  313. requiredError = r != null ? r.error : 'could not save the setting'
  314. return null
  315. }
  316. required = r.rows
  317. noRequired = required.length == 0
  318. }
  319. on server gitoriaRequiredAdd(slugOf, appId, ctxName, session) {
  320. return requireContext(userIdOfSession(session), session, slugOf, appId, ctxName)
  321. }
  322. on server gitoriaRequiredRemove(slugOf, id, session) {
  323. return dropRequired(userIdOfSession(session), session, slugOf, id)
  324. }
  325. on server gitoriaAppAdd(slugOf, name, hook, session) {
  326. return addApp(userIdOfSession(session), session, slugOf, name, hook)
  327. }
  328. on server gitoriaAppRemove(slugOf, id, session) {
  329. return removeApp(userIdOfSession(session), session, slugOf, id)
  330. }
  331. on server gitoriaAppPing(slugOf, id, session) {
  332. return sendPing(userIdOfSession(session), session, slugOf, id)
  333. }
  334. on server gitoriaAppRotate(slugOf, id, session) {
  335. return rotateSecret(userIdOfSession(session), session, slugOf, id)
  336. }
  337. on server gitoriaChangeMember(slugOf, name, add, session) {
  338. return changeMember(userIdOfSession(session), 'r', slugOf, name, add)
  339. }
  340. on disconnect() {
  341. settingsError = ''
  342. r = emit server gitoriaDisconnectTickets(slug)
  343. if (r == null || r.error != null) {
  344. settingsError = r != null ? r.error : 'could not disconnect'
  345. return null
  346. }
  347. connected = false
  348. notConnected = true
  349. forgetClass = 'nomerge'
  350. projectTitle = ''
  351. projectHref = ''
  352. }
  353. on server gitoriaDisconnectTickets(slugOf, session) {
  354. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not disconnect' } }
  355. if (userOfSession(session) == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change this' } }
  356. r = setTicketsConnection(slugOf, '', '', '', '')
  357. if (r.error != null) { return { error = r.error } }
  358. return { ok = true }
  359. }
  360. Style {
  361. repoSettings {
  362. display = 'grid'
  363. gap = '1rem'
  364. minWidth = '0'
  365. '> *' {
  366. margin = '0'
  367. }
  368. }
  369. #ticketsettings {
  370. display = 'grid'
  371. gap = '.75rem'
  372. justifyItems = 'start'
  373. '> *' {
  374. margin = '0'
  375. }
  376. }
  377. '#disconnecttickets.nomerge' {
  378. display = 'none'
  379. }
  380. #connecttickets {
  381. color = 'var(--color-accent-text)'
  382. background = 'var(--color-accent)'
  383. }
  384. #members {
  385. listStyle = 'none'
  386. margin = '0'
  387. padding = '0'
  388. display = 'grid'
  389. gap = '.25rem'
  390. maxWidth = '32rem'
  391. li {
  392. display = 'flex'
  393. alignItems = 'center'
  394. justifyContent = 'space-between'
  395. gap = '.75rem'
  396. minHeight = '2.75rem'
  397. padding = '0 .5rem 0 1rem'
  398. background = 'var(--color-surface)'
  399. borderRadius = 'var(--radius-large)'
  400. }
  401. }
  402. #memberform {
  403. display = 'grid'
  404. gap = '.75rem'
  405. margin = '.75rem 0 1.5rem'
  406. maxWidth = '32rem'
  407. }
  408. #apps {
  409. display = 'grid'
  410. gap = '.75rem'
  411. margin = '0 0 1.5rem'
  412. justifyItems = 'start'
  413. '> *' {
  414. margin = '0'
  415. }
  416. }
  417. #connectapp {
  418. display = 'grid'
  419. gap = '.75rem'
  420. maxWidth = '32rem'
  421. padding = '1rem'
  422. background = 'var(--color-surface)'
  423. borderRadius = 'var(--radius-large)'
  424. }
  425. #appshown {
  426. display = 'grid'
  427. gap = '.5rem'
  428. maxWidth = '100%'
  429. code {
  430. overflowWrap = 'anywhere'
  431. }
  432. }
  433. #applist {
  434. listStyle = 'none'
  435. margin = '0'
  436. padding = '0'
  437. display = 'grid'
  438. gap = '.25rem'
  439. maxWidth = '40rem'
  440. width = '100%'
  441. li {
  442. display = 'flex'
  443. flexWrap = 'wrap'
  444. alignItems = 'center'
  445. gap = '.5rem .75rem'
  446. minHeight = '2.75rem'
  447. padding = '.25rem .5rem .25rem 1rem'
  448. background = 'var(--color-surface)'
  449. borderRadius = 'var(--radius-large)'
  450. }
  451. }
  452. #required {
  453. display = 'grid'
  454. gap = '.75rem'
  455. margin = '0 0 1.5rem'
  456. justifyItems = 'start'
  457. '> *' {
  458. margin = '0'
  459. }
  460. }
  461. #requiredlist {
  462. listStyle = 'none'
  463. margin = '0'
  464. padding = '0'
  465. display = 'grid'
  466. gap = '.25rem'
  467. maxWidth = '40rem'
  468. width = '100%'
  469. li {
  470. display = 'flex'
  471. flexWrap = 'wrap'
  472. alignItems = 'center'
  473. justifyContent = 'space-between'
  474. gap = '.5rem .75rem'
  475. minHeight = '2.75rem'
  476. padding = '.25rem .5rem .25rem 1rem'
  477. background = 'var(--color-surface)'
  478. borderRadius = 'var(--radius-large)'
  479. }
  480. }
  481. #requiredform {
  482. display = 'grid'
  483. gap = '.75rem'
  484. maxWidth = '32rem'
  485. }
  486. #appform {
  487. display = 'grid'
  488. gap = '.75rem'
  489. maxWidth = '32rem'
  490. }
  491. #togglepriv {
  492. justifySelf = 'start'
  493. }
  494. #visibility {
  495. display = 'grid'
  496. gap = '.75rem'
  497. margin = '0 0 1.5rem'
  498. }
  499. }

Branches

Latest commits

  • 24b479e7W60: record final gates, Chrome failures and AE evidencemre
  • 5e11184cW60: record partial validation, framework gaps and cleanupmre
  • 20fe13fagitoria#33: centralize login and tickets connection statemre
  • 859754c0gitoria#29: retain the offline note and record the framework gapmre
  • d140bc04gitoria#30: reproduce the upsert ordering constraintmre
  • 6960e8f8gitoria#28: keep form values in bound component membersmre
  • 0db27200gitoria#32: share character checks and environment lookupmre
  • 452f6a1amission W60: logic clean-upsmre
  • 1448c899log: cleanup, #49 GPTBot, tracker mentions on #36mre
  • fcf95936log: v1.5.1 provenmre
  • 22105420log: W51b livemre
  • 7e8aabeareport: W51b pull source verificationmre
  • 6c18de76fix: preserve pull sources across containing branchesmre
  • fc36fa2elog: W51b pull source bugmre
  • 56bc1220log: v1.5.1 livemre
  • 845fc0aareport: W51mre
  • 83127391fix: return v1.5.1 app and merge error detailsmre
  • b07d0e97log: W51 v1.5.1 startedmre
  • 0b417d06docs: apps-api v1.5 user tokens (#48, W49)mre
  • d046940alog: vinzenz contract note sentmre