gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita81abdc9a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmrea81abdc9/components/settings.hl

6.6 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. View {
  44. repoPage {
  45. if (hasRepo) {
  46. repoSettings { id = "settings"
  47. section { id = "visibility"
  48. h2 { "Visibility" }
  49. p { id = "privtext" privText }
  50. if (isOwner) { button { id = "togglepriv" type = "button" privButton on click(e) { emit togglePriv() } } }
  51. if (isOwner) {
  52. h2 { "Members" }
  53. 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." }
  54. if (noMembers) { p { id = "nomembers" class = "empty" "No members yet." } }
  55. ul { id = "members"
  56. for (m of members) {
  57. li { span { class = "slug" m.name } button { class = "quiet" type = "button" "Remove" on click(e) { emit removeMember(m.name) } } }
  58. }
  59. }
  60. form { id = "memberform"
  61. on submit(e) {
  62. e.preventDefault()
  63. emit addMember(e)
  64. }
  65. label { "Display name"
  66. input { id = "membername" name = "membername" required = "required" maxlength = "60" autocomplete = "off" }
  67. }
  68. button { id = "memberadd" type = "submit" "Add member" }
  69. p { id = "membererror" class = "message" memberError }
  70. }
  71. }
  72. }
  73. section { id = "ticketsettings"
  74. h2 { "Tickets" }
  75. if (hasConnectNote) { p { id = "connectnote" class = "message" connectNote } }
  76. if (connected) {
  77. p { id = "connectedto" "Connected to the tickets project " a { id = "projectlink" href = projectHref projectTitle } "." }
  78. }
  79. if (notConnected) { p { id = "notconnected" class = "muted" "This repository is not connected to a tickets project yet." } }
  80. if (isOwner) {
  81. p {
  82. a { id = "connecttickets" class = "button" href = connectHref "Tickets: connect" }
  83. }
  84. button { id = "disconnecttickets" class = forgetClass type = "button" "Forget the connection" on click(e) { emit disconnect() } }
  85. p { class = "muted" "Connecting asks tickets which project (you must be its admin there). Tickets can also disconnect gitoria from its side." }
  86. }
  87. if (notOwnerHint) { p { id = "ownerhint" class = "muted" "Only the owner of this repository can connect it." } }
  88. p { id = "settingserror" class = "message" settingsError }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. on togglePriv() {
  95. memberError = ''
  96. r = emit server gitoriaSetPrivate(slug, !isPrivate)
  97. if (r == null || r.error != null) {
  98. memberError = r != null ? r.error : 'could not change the visibility'
  99. return null
  100. }
  101. isPrivate = r.repo.isPrivate
  102. privText = isPrivate ? 'This repository is private: only its owner and its members can see it.' : 'This repository is public: everybody can read it.'
  103. privButton = isPrivate ? 'Make public' : 'Make private'
  104. }
  105. on addMember(e) {
  106. memberError = ''
  107. r = emit server gitoriaChangeMember(slug, e.target.elements.membername.value, true)
  108. if (r == null || r.error != null) {
  109. memberError = r != null ? r.error : 'could not add the member'
  110. return null
  111. }
  112. members = r.members
  113. noMembers = members.length == 0
  114. e.target.elements.membername.value = ''
  115. }
  116. on removeMember(name) {
  117. memberError = ''
  118. r = emit server gitoriaChangeMember(slug, name, false)
  119. if (r == null || r.error != null) {
  120. memberError = r != null ? r.error : 'could not remove the member'
  121. return null
  122. }
  123. members = r.members
  124. noMembers = members.length == 0
  125. }
  126. on server gitoriaSetPrivate(slugOf, priv, session) {
  127. return setRepoPriv(userIdOfSession(session), slugOf, priv)
  128. }
  129. on server gitoriaChangeMember(slugOf, name, add, session) {
  130. return changeMember(userIdOfSession(session), 'r', slugOf, name, add)
  131. }
  132. on disconnect() {
  133. settingsError = ''
  134. r = emit server gitoriaDisconnectTickets(slug)
  135. if (r == null || r.error != null) {
  136. settingsError = r != null ? r.error : 'could not disconnect'
  137. return null
  138. }
  139. connected = false
  140. notConnected = true
  141. forgetClass = 'nomerge'
  142. projectTitle = ''
  143. projectHref = ''
  144. }
  145. on server gitoriaDisconnectTickets(slugOf, session) {
  146. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not disconnect' } }
  147. if (userOfSession(session) == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change this' } }
  148. r = setTicketsConnection(slugOf, '', '', '', '')
  149. if (r.error != null) { return { error = r.error } }
  150. return { ok = true }
  151. }

Branches

Latest commits

  • 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
  • 76e0587aWIP gs 2mre
  • a80da7bdWIP gs: security gate for lazy sessions, g24 browser checksmre
  • 23fb05d8re-vendor Hybriel aaa39e69 (hl:web batch 20: login emit and Sessions.mint, tab follows a login, signed-in session cookie wins among duplicates and is re-issued with the Domain, W85 faster render, lazy sessions)mre