pisha-server 0.0.0-stage → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +40 -2
- package/accounts/accounts.js +754 -0
- package/accounts/index.js +1 -0
- package/accounts/passwords.js +41 -0
- package/accounts/totp.js +54 -0
- package/boards/boards.js +1087 -0
- package/boards/github.js +212 -0
- package/boards/index.js +1 -0
- package/boards/sync.js +980 -0
- package/companies.js +294 -0
- package/company-export.js +101 -0
- package/company.js +82 -0
- package/dashboard/dashboard.js +408 -0
- package/dashboard/index.js +1 -0
- package/data-upgrade.js +69 -0
- package/install/linux.sh +181 -0
- package/install/macos.sh +121 -0
- package/install/windows.bat +54 -0
- package/machines/index.js +3 -0
- package/machines/machines.js +910 -0
- package/messaging/inbox.js +252 -0
- package/messaging/index.js +3 -0
- package/messaging/messaging.js +551 -0
- package/messaging/plans.js +67 -0
- package/observation/index.js +1 -0
- package/observation/observation.js +231 -0
- package/organization/index.js +1 -0
- package/organization/organization.js +218 -0
- package/package.json +55 -4
- package/permissions/index.js +1 -0
- package/permissions/permissions.js +211 -0
- package/pisha-host.mjs +3303 -0
- package/pisha-host.mjs.sig +1 -0
- package/platform/acme.js +207 -0
- package/platform/basics.js +14 -0
- package/platform/config.js +154 -0
- package/platform/control.js +93 -0
- package/platform/credentials.js +151 -0
- package/platform/database.js +251 -0
- package/platform/errors.js +13 -0
- package/platform/files.js +50 -0
- package/platform/http.js +207 -0
- package/platform/index.js +58 -0
- package/platform/limits.js +122 -0
- package/platform/listen.js +183 -0
- package/platform/roles.js +6 -0
- package/platform/stream.js +19 -0
- package/platform/text.js +83 -0
- package/platform/ws.js +186 -0
- package/routes.js +405 -0
- package/server.js +65 -0
- package/sessions/index.js +1 -0
- package/sessions/sessions.js +533 -0
- package/ui/LICENSE-affectui.txt +26 -0
- package/ui/addmachine.js +151 -0
- package/ui/api.js +20 -0
- package/ui/app.js +143 -0
- package/ui/attention.js +78 -0
- package/ui/back.js +168 -0
- package/ui/boards.js +958 -0
- package/ui/chat.js +388 -0
- package/ui/content.js +157 -0
- package/ui/dialogs.js +135 -0
- package/ui/doing.js +112 -0
- package/ui/dom.js +6 -0
- package/ui/ds-base.css +146 -0
- package/ui/ds-components.css +229 -0
- package/ui/fonts/LICENSE-space-grotesk.txt +93 -0
- package/ui/fonts/space-grotesk-latin-700-normal.woff2 +0 -0
- package/ui/fonts/space-grotesk-latin-ext-700-normal.woff2 +0 -0
- package/ui/format.js +25 -0
- package/ui/i18n.js +2145 -0
- package/ui/icons/apple-touch-icon.png +0 -0
- package/ui/icons/icon-192.png +0 -0
- package/ui/icons/icon-512.png +0 -0
- package/ui/icons/maskable-512.png +0 -0
- package/ui/icons.js +41 -0
- package/ui/inbox.js +535 -0
- package/ui/index.html +105 -0
- package/ui/machines.js +261 -0
- package/ui/manifest.webmanifest +16 -0
- package/ui/mosaic.js +189 -0
- package/ui/nav.js +142 -0
- package/ui/newteam.js +223 -0
- package/ui/org.js +669 -0
- package/ui/overlays.css +126 -0
- package/ui/palette.js +180 -0
- package/ui/people.js +371 -0
- package/ui/permissions.js +202 -0
- package/ui/qr.js +158 -0
- package/ui/router.js +173 -0
- package/ui/routes.js +47 -0
- package/ui/screen-boards.css +241 -0
- package/ui/screen-inbox.css +201 -0
- package/ui/screen-machines.css +76 -0
- package/ui/screen-mosaic.css +26 -0
- package/ui/screen-newteam.css +90 -0
- package/ui/screen-org.css +119 -0
- package/ui/screen-session.css +99 -0
- package/ui/screen-signin.css +28 -0
- package/ui/screen-team.css +80 -0
- package/ui/screen-teams.css +41 -0
- package/ui/screen-usage.css +60 -0
- package/ui/session.js +42 -0
- package/ui/shell.css +122 -0
- package/ui/signin.js +120 -0
- package/ui/squads.js +371 -0
- package/ui/state.js +59 -0
- package/ui/stream.js +269 -0
- package/ui/styles.css +343 -0
- package/ui/team.js +115 -0
- package/ui/teams.js +58 -0
- package/ui/terminal.js +261 -0
- package/ui/theme.js +32 -0
- package/ui/timeline.js +163 -0
- package/ui/topbar.js +211 -0
- package/ui/usage.js +175 -0
- package/ui/voice-parse.js +98 -0
- package/ui/voice.js +320 -0
- package/usage/index.js +1 -0
- package/usage/usage.js +127 -0
- package/vendor/InterVariable.woff2 +0 -0
- package/vendor/LICENSE-inter +92 -0
- package/vendor/LICENSE-xterm +21 -0
- package/vendor/README.md +8 -0
- package/vendor/addon-fit.js +2 -0
- package/vendor/xterm.css +218 -0
- package/vendor/xterm.js +2 -0
package/ui/people.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { $, store } from './dom.js'
|
|
2
|
+
import { T, LOCALE, LANG } from './i18n.js'
|
|
3
|
+
import { state, can, profileListeners, switchCompany } from './state.js'
|
|
4
|
+
import { call, inCompany } from './api.js'
|
|
5
|
+
import { esc } from './format.js'
|
|
6
|
+
import { alertBox } from './mosaic.js'
|
|
7
|
+
import { icon } from './icons.js'
|
|
8
|
+
import { themeChoice, setTheme, onTheme } from './theme.js'
|
|
9
|
+
import { notifyChoice, setNotify, notifySupported, notifyBlocked } from './attention.js'
|
|
10
|
+
|
|
11
|
+
const ROLES = ['observer', 'operator', 'manager', 'owner']
|
|
12
|
+
// Only owners give or take the role of owner.
|
|
13
|
+
const grantable = () => ROLES.filter(r => r !== 'owner' || can('owner'))
|
|
14
|
+
const roleSelect = (value, attrs = '') => `<select ${attrs}>${grantable().map(r => `<option value="${r}" ${r === value ? 'selected' : ''}>${esc(T.roles[r])}</option>`).join('')}</select>`
|
|
15
|
+
const fmtTime = ms => new Date(ms).toLocaleString(LOCALE, { dateStyle: 'medium', timeStyle: 'short' })
|
|
16
|
+
// Nobody gives more than they have; only owners give or take the role of owner.
|
|
17
|
+
const canGive = (mine, role) => ROLES.indexOf(mine) >= ROLES.indexOf(role) && (mine === 'owner' || role !== 'owner')
|
|
18
|
+
// What each role can do, said where roles are chosen.
|
|
19
|
+
const rolesHelp = () => `<details class="roles-help"><summary>${esc(T.rolesWhat)}</summary><dl>${ROLES.map(r => `<dt>${esc(T.roles[r])}</dt><dd>${esc(T.roleHelp[r])}</dd>`).join('')}</dl></details>`
|
|
20
|
+
const linkBox = l => `<div class="cmdrow"><pre class="cmd">${esc(l.link)}</pre><button class="btn" data-copy>${esc(T.copy)}</button></div><p class="note">${esc(T.linkOnce)}</p>`
|
|
21
|
+
|
|
22
|
+
// Settings: over the whole dashboard, without its sidebar, in three groups by
|
|
23
|
+
// whom they affect: you, this company, the whole server. Only what this
|
|
24
|
+
// user's role allows is there. Esc, or the button at the top, closes them.
|
|
25
|
+
let closeOpen = null
|
|
26
|
+
let redrawPermissions = null
|
|
27
|
+
export function openSettings(start) {
|
|
28
|
+
closeOpen?.()
|
|
29
|
+
const admin = state.me?.user.is_platform_admin
|
|
30
|
+
const manager = can('manager')
|
|
31
|
+
const here = state.me?.companies.find(c => c.id === state.company)
|
|
32
|
+
// People across companies: for an administrator, or whoever manages several.
|
|
33
|
+
const everywhere = admin || (state.me?.companies ?? []).filter(c => c.role === 'manager' || c.role === 'owner').length > 1
|
|
34
|
+
const groups = [
|
|
35
|
+
[T.setMine, [['account', T.setProfile], ['appearance', T.setAppearance]]],
|
|
36
|
+
...(everywhere ? [[T.setAllCompanies, [['everyone', T.people]]]] : []),
|
|
37
|
+
...(manager && here ? [[here.name, [['members', T.people], ['permissions', T.tabPermissions], ['company', T.tabCompany]]]] : []),
|
|
38
|
+
...(admin ? [[T.setServer, [['companies', T.tabCompanies], ['users', T.tabUsers], ['machines', T.tabMachines]]]] : []),
|
|
39
|
+
]
|
|
40
|
+
const tabs = groups.flatMap(g => g[1])
|
|
41
|
+
const root = $('settings')
|
|
42
|
+
const opener = document.activeElement
|
|
43
|
+
root.innerHTML = `<div class="settings" role="dialog" aria-modal="true" aria-labelledby="settingsTitle">
|
|
44
|
+
<aside class="settings-side"><nav class="settings-nav" aria-label="${esc(T.settingsSections)}">
|
|
45
|
+
${(state.me?.companies.length ?? 0) > 1 ? `<label class="field settings-co"><span>${esc(T.company)}</span><select data-company>${state.me.companies.map(c => `<option value="${esc(c.id)}"${c.id === state.company ? ' selected' : ''}>${esc(c.name)}</option>`).join('')}</select></label>` : ''}
|
|
46
|
+
${groups.map(([title, items]) => `<div class="settings-group"><div class="settings-group-h">${esc(title)}</div>${items.map(([k, label]) => `<button type="button" data-tab="${k}">${esc(label)}</button>`).join('')}</div>`).join('')}
|
|
47
|
+
<div class="settings-sep"></div>
|
|
48
|
+
<button type="button" class="settings-out" data-logout>${icon('logout')}${esc(T.logout)}</button>
|
|
49
|
+
</nav></aside>
|
|
50
|
+
<div class="settings-body"><div class="settings-content">
|
|
51
|
+
<h2 class="settings-title" id="settingsTitle"></h2>
|
|
52
|
+
<div class="err" role="alert"></div><div data-body></div>
|
|
53
|
+
</div></div>
|
|
54
|
+
<button type="button" class="settings-close" data-close aria-label="${esc(T.closeSettings)}"><span class="x">${icon('close')}</span><kbd>Esc</kbd></button>
|
|
55
|
+
</div>`
|
|
56
|
+
root.hidden = false
|
|
57
|
+
$('app').inert = true
|
|
58
|
+
const d = { el: root }
|
|
59
|
+
const stopTheme = onTheme(() => { if (current === 'appearance') { current = null; show('appearance') } })
|
|
60
|
+
function close() {
|
|
61
|
+
root.hidden = true
|
|
62
|
+
root.innerHTML = ''
|
|
63
|
+
$('app').inert = false
|
|
64
|
+
stopTheme()
|
|
65
|
+
document.removeEventListener('keydown', keys, true)
|
|
66
|
+
closeOpen = null
|
|
67
|
+
if (opener?.isConnected) opener.focus()
|
|
68
|
+
}
|
|
69
|
+
closeOpen = close
|
|
70
|
+
// Esc closes it, unless a dialog or menu is open over it; Tab stays inside.
|
|
71
|
+
function keys(e) {
|
|
72
|
+
if (root.hidden) return
|
|
73
|
+
if (e.key === 'Escape' && !document.querySelector('.modal-bg, .menu') && $('palette').hidden) { e.preventDefault(); close() }
|
|
74
|
+
if (e.key === 'Tab' && !document.querySelector('.modal-bg')) {
|
|
75
|
+
const f = [...root.querySelectorAll('button, [href], input, select, textarea')].filter(x => !x.disabled && x.offsetParent)
|
|
76
|
+
if (!f.length) return
|
|
77
|
+
if (e.shiftKey && document.activeElement === f[0]) { e.preventDefault(); f.at(-1).focus() }
|
|
78
|
+
else if (!e.shiftKey && document.activeElement === f.at(-1)) { e.preventDefault(); f[0].focus() }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
document.addEventListener('keydown', keys, true)
|
|
82
|
+
root.querySelector('[data-close]').onclick = close
|
|
83
|
+
const co = root.querySelector('[data-company]')
|
|
84
|
+
if (co) co.onchange = () => switchCompany(co.value)
|
|
85
|
+
root.querySelector('[data-logout]').onclick = async () => { close(); (await import('./app.js')).logOut() }
|
|
86
|
+
const body = d.el.querySelector('[data-body]')
|
|
87
|
+
const fail = err => { d.el.querySelector('.err').textContent = err.status === 429 ? T.tooManyTries : err.message.replace(/^(Unauthorized|Bad Request|Not Found|Conflict|Forbidden): /, '') }
|
|
88
|
+
const ok = () => { d.el.querySelector('.err').textContent = '' }
|
|
89
|
+
|
|
90
|
+
// Only what was asked for last is drawn, and a tab already open isn't drawn
|
|
91
|
+
// again: what is being typed in it stays.
|
|
92
|
+
let current = null
|
|
93
|
+
let drawing = 0
|
|
94
|
+
async function show(tab) {
|
|
95
|
+
if (tab === current) return
|
|
96
|
+
current = tab
|
|
97
|
+
ok()
|
|
98
|
+
for (const b of d.el.querySelectorAll('[data-tab]')) {
|
|
99
|
+
b.classList.toggle('on', b.dataset.tab === tab)
|
|
100
|
+
if (b.dataset.tab === tab) b.setAttribute('aria-current', 'page'); else b.removeAttribute('aria-current')
|
|
101
|
+
}
|
|
102
|
+
root.querySelector('#settingsTitle').textContent = tab === 'everyone' ? T.evSeeAll : tabs.find(t => t[0] === tab)?.[1] ?? ''
|
|
103
|
+
try { await ({ everyone, members, permissions, company, companies, users, machines, account, appearance })[tab]() } catch (err) { fail(err) }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// The permission profiles of this company: drawn again when they change
|
|
107
|
+
// (their dialogs are apart, so nothing being typed is lost).
|
|
108
|
+
async function permissions() {
|
|
109
|
+
drawing++
|
|
110
|
+
const { permissionsTab } = await import('./permissions.js')
|
|
111
|
+
profileListeners.delete(redrawPermissions)
|
|
112
|
+
redrawPermissions = () => {
|
|
113
|
+
if (root.hidden || current !== 'permissions') { profileListeners.delete(redrawPermissions); return }
|
|
114
|
+
permissionsTab(body, fail)
|
|
115
|
+
}
|
|
116
|
+
profileListeners.add(redrawPermissions)
|
|
117
|
+
permissionsTab(body, fail)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// How the dashboard looks to you, in this browser.
|
|
121
|
+
function appearance() {
|
|
122
|
+
drawing++
|
|
123
|
+
const choice = themeChoice()
|
|
124
|
+
const seg = (name, value, label, on) => `<button type="button" data-${name}="${value}" aria-pressed="${on}"${on ? ' class="on"' : ''}>${esc(label)}</button>`
|
|
125
|
+
body.innerHTML = `<div class="settings-row"><b id="themeLbl">${esc(T.theme)}</b><div class="seg" role="group" aria-labelledby="themeLbl">${[['system', T.themeSystem], ['light', T.themeLight], ['dark', T.themeDark]].map(([v, l]) => seg('theme', v, l, v === choice)).join('')}</div></div>
|
|
126
|
+
<div class="settings-row"><b id="langLbl">${esc(T.language)}</b><div class="seg" role="group" aria-labelledby="langLbl">${[['en', 'English'], ['es', 'Español']].map(([v, l]) => seg('lang', v, l, v === LANG)).join('')}</div></div>
|
|
127
|
+
<div class="settings-row"><div><b id="notifyLbl">${esc(T.notifyTitle)}</b><p class="note">${esc(!notifySupported() ? T.notifyUnsupported : notifyBlocked() ? T.notifyBlocked : T.notifyHint)}</p></div>${notifySupported() ? `<div class="seg" role="group" aria-labelledby="notifyLbl">${[['off', T.notifyOff], ['on', T.notifyOn], ['sound', T.notifySound]].map(([v, l]) => seg('notify', v, l, v === notifyChoice())).join('')}</div>` : ''}</div>
|
|
128
|
+
<p class="note settings-ver">${esc(document.querySelector('.ver')?.textContent ?? '')}</p>`
|
|
129
|
+
for (const b of body.querySelectorAll('[data-theme]')) b.onclick = () => setTheme(b.dataset.theme)
|
|
130
|
+
for (const b of body.querySelectorAll('[data-notify]')) b.onclick = async () => { await setNotify(b.dataset.notify); appearance() }
|
|
131
|
+
for (const b of body.querySelectorAll('[data-lang]')) b.onclick = () => { if (b.dataset.lang !== LANG) { store.set('pishaLang', b.dataset.lang); location.reload() } }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Everyone in the companies you manage, a column each: their role there,
|
|
135
|
+
// changed right in the table, and one invitation for several at once.
|
|
136
|
+
async function everyone() {
|
|
137
|
+
const turn = ++drawing
|
|
138
|
+
const p = await call('/api/people')
|
|
139
|
+
if (turn !== drawing) return
|
|
140
|
+
const cos = p.companies
|
|
141
|
+
const cell = (u, c) => {
|
|
142
|
+
const role = u.roles[c.id] ?? ''
|
|
143
|
+
const can = role ? canGive(c.my_role, role) : true
|
|
144
|
+
const options = ['', ...ROLES].filter(r => !r || r === role || canGive(c.my_role, r))
|
|
145
|
+
return `<td><select data-person="${esc(u.id)}" data-co="${esc(c.id)}" aria-label="${esc(T.evRoleIn(u.name, c.name))}" ${can ? '' : 'disabled'}>${options.map(r => `<option value="${r}" ${r === role ? 'selected' : ''}>${r ? esc(T.roles[r]) : '—'}</option>`).join('')}</select></td>`
|
|
146
|
+
}
|
|
147
|
+
const pick = c => `<label class="field"><span>${esc(c.name)}</span><select name="co:${esc(c.id)}"><option value="">—</option>${ROLES.filter(r => canGive(c.my_role, r)).map(r => `<option value="${r}">${esc(T.roles[r])}</option>`).join('')}</select></label>`
|
|
148
|
+
body.innerHTML = `<div class="set-card ev-wrap"><table class="people ev"><thead><tr><th scope="col">${esc(T.evPerson)}</th>${cos.map(c => `<th scope="col">${esc(c.name)}</th>`).join('')}</tr></thead><tbody>
|
|
149
|
+
${p.users.map(u => `<tr><td><b>${esc(u.name)}</b>${u.is_platform_admin ? ` <span class="tag">${esc(T.administrator)}</span>` : ''}${u.id === state.me.user.id ? ` <span class="note">${esc(T.evYou)}</span>` : ''}<br><span class="note">${esc(u.email)}${u.disabled ? ` · ${esc(T.disabled)}` : ''}</span></td>${cos.map(c => cell(u, c)).join('')}</tr>`).join('')}
|
|
150
|
+
</tbody></table></div>
|
|
151
|
+
${rolesHelp()}
|
|
152
|
+
<h4>${esc(T.inviteTitle)}</h4><div class="set-card"><form data-evinvite>
|
|
153
|
+
<label class="field"><span>${esc(T.email)}</span><input type="text" name="email" required autocomplete="off"></label>
|
|
154
|
+
${cos.length > 1 ? `<label class="field"><span>${esc(T.evSameRole)}</span><select data-same><option value="">—</option>${ROLES.map(r => `<option value="${r}">${esc(T.roles[r])}</option>`).join('')}</select></label>` : ''}
|
|
155
|
+
<div class="ev-picks">${cos.map(pick).join('')}</div>
|
|
156
|
+
${p.admin ? `<label class="check"><input type="checkbox" name="admin"> <span>${esc(T.evAdmin)}</span></label>` : ''}
|
|
157
|
+
<p class="note">${esc(T.evInviteHint)}</p>
|
|
158
|
+
<button class="btn primary">${esc(T.invite)}</button></form><div data-link></div></div>
|
|
159
|
+
${p.invitations.length ? `<h4>${esc(T.pendingInvites)}</h4><table class="people"><tbody>${p.invitations.map(i => `<tr><td>${esc(i.email)}<br><span class="note">${esc(Object.entries(i.roles).map(([id, r]) => `${cos.find(c => c.id === id)?.name ?? id}: ${T.roles[r] ?? r}`).join(' · '))}</span></td><td><button class="btn danger" data-evcancel="${esc(i.id)}">${esc(T.cancelInvite)}</button></td></tr>`).join('')}</tbody></table>` : ''}`
|
|
160
|
+
for (const s of body.querySelectorAll('[data-person]')) {
|
|
161
|
+
s.onchange = async () => {
|
|
162
|
+
ok()
|
|
163
|
+
try { await call('/api/people/set', { user: s.dataset.person, company: s.dataset.co, role: s.value || null }); current = null; await show('everyone') } catch (err) { fail(err); current = null; await show('everyone') }
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const form = body.querySelector('[data-evinvite]')
|
|
167
|
+
form.querySelector('[data-same]')?.addEventListener('change', e => { for (const s of form.querySelectorAll('select[name^="co:"]')) if ([...s.options].some(o => o.value === e.target.value)) s.value = e.target.value })
|
|
168
|
+
form.onsubmit = async e => {
|
|
169
|
+
e.preventDefault()
|
|
170
|
+
ok()
|
|
171
|
+
const roles = [...form.querySelectorAll('select[name^="co:"]')].filter(s => s.value).map(s => ({ company: s.name.slice(3), role: s.value }))
|
|
172
|
+
try {
|
|
173
|
+
const r = await call('/api/people/invite', { email: form.elements.email.value, roles, is_platform_admin: !!form.elements.admin?.checked })
|
|
174
|
+
current = null
|
|
175
|
+
await show('everyone')
|
|
176
|
+
body.querySelector('[data-link]').innerHTML = linkBox(r)
|
|
177
|
+
} catch (err) { fail(err) }
|
|
178
|
+
}
|
|
179
|
+
for (const b of body.querySelectorAll('[data-evcancel]')) b.onclick = async () => { ok(); try { await call('/api/people/invitations/cancel', { id: b.dataset.evcancel }); current = null; await show('everyone') } catch (err) { fail(err) } }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function members() {
|
|
183
|
+
const turn = ++drawing
|
|
184
|
+
const [list, pending, { join_token }] = await Promise.all([call(inCompany('/api/members')), call(inCompany('/api/invitations')), call(inCompany('/api/join-token'))])
|
|
185
|
+
if (turn !== drawing) return
|
|
186
|
+
// What can't be changed is only shown: someone else's owner, or the only owner.
|
|
187
|
+
const owners = list.filter(m => m.role === 'owner').length
|
|
188
|
+
const fixed = m => m.role === 'owner' && (!can('owner') || owners < 2)
|
|
189
|
+
body.innerHTML = `<table class="people"><tbody>${list.map(m => `<tr><td><b>${esc(m.name)}</b><br><span class="note">${esc(m.email)}${m.disabled ? ` · ${esc(T.disabled)}` : ''}</span></td>
|
|
190
|
+
<td>${fixed(m) ? esc(T.roles[m.role]) : roleSelect(m.role, `data-role-of="${esc(m.id)}"`)}</td><td>${fixed(m) ? '' : `<button class="btn danger" data-remove="${esc(m.id)}">${esc(T.remove)}</button>`}</td></tr>`).join('')}</tbody></table>
|
|
191
|
+
${rolesHelp()}
|
|
192
|
+
<h4>${esc(T.inviteTitle)}</h4><div class="set-card"><form data-invite class="people-form"><label class="field"><span>${esc(T.email)}</span><input type="text" name="email" required></label>
|
|
193
|
+
<label class="field"><span>${esc(T.role)}</span>${roleSelect('operator', 'name="role"')}</label>
|
|
194
|
+
<button class="btn primary">${esc(T.invite)}</button></form><p class="note" data-rolehint>${esc(T.roleHelp.operator)} ${esc(T.evOnlyHere)}</p><div data-link></div></div>
|
|
195
|
+
${everywhere ? `<p class="note"><button type="button" class="btn quiet" data-tab-go="everyone">${esc(T.evSeeAll)}</button></p>` : ''}
|
|
196
|
+
${pending.length ? `<h4>${esc(T.pendingInvites)}</h4><table class="people"><tbody>${pending.map(i => `<tr><td>${esc(i.email)} <span class="note">${esc(T.roles[i.role] ?? i.role)}</span></td><td><button class="btn danger" data-cancel-invite="${esc(i.id)}">${esc(T.cancelInvite)}</button></td></tr>`).join('')}</tbody></table>` : ''}
|
|
197
|
+
<h4>${esc(T.joinToken)}</h4><div class="set-card"><p class="note">${esc(T.joinTokenHint)}</p>
|
|
198
|
+
<div class="cmdrow"><pre class="cmd">${esc(join_token)}</pre><button class="btn" data-copy>${esc(T.copy)}</button></div>
|
|
199
|
+
<button class="btn danger" data-rotate>${esc(T.rotate)}</button></div>`
|
|
200
|
+
body.querySelector('[data-invite] select[name=role]').onchange = e => { body.querySelector('[data-rolehint]').textContent = `${T.roleHelp[e.target.value] ?? ''} ${T.evOnlyHere}` }
|
|
201
|
+
body.querySelector('[data-tab-go]')?.addEventListener('click', () => show('everyone'))
|
|
202
|
+
body.querySelector('[data-invite]').onsubmit = async e => {
|
|
203
|
+
e.preventDefault()
|
|
204
|
+
ok()
|
|
205
|
+
try {
|
|
206
|
+
const r = await call(inCompany('/api/members/invite'), Object.fromEntries(new FormData(e.target)))
|
|
207
|
+
await members()
|
|
208
|
+
body.querySelector('[data-link]').innerHTML = linkBox(r)
|
|
209
|
+
} catch (err) { fail(err) }
|
|
210
|
+
}
|
|
211
|
+
for (const s of body.querySelectorAll('[data-role-of]')) {
|
|
212
|
+
s.onchange = async () => {
|
|
213
|
+
ok()
|
|
214
|
+
try { await call(inCompany('/api/members/role'), { user: s.dataset.roleOf, role: s.value }) } catch (err) { fail(err); await members() }
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Who did what here; and, for its owners, how long things are kept, and the
|
|
220
|
+
// company as a file, or deleted.
|
|
221
|
+
async function company() {
|
|
222
|
+
const turn = ++drawing
|
|
223
|
+
const [log, kept] = await Promise.all([call(inCompany('/api/company/audit?limit=50')), call(inCompany('/api/company/retention'))])
|
|
224
|
+
if (turn !== drawing) return
|
|
225
|
+
const here = state.me.companies.find(c => c.id === state.company)
|
|
226
|
+
const rows = log.map(e => `<tr><td><span class="note">${esc(fmtTime(e.at))}</span></td><td>${esc(e.who ?? '—')}</td><td>${esc(e.action)}${e.target ? ` · ${esc(e.target)}` : ''}</td></tr>`).join('')
|
|
227
|
+
body.innerHTML = `<h4>${esc(T.auditTitle)}</h4>${rows ? `<table class="people audit"><tbody>${rows}</tbody></table>` : `<p class="note">${esc(T.auditEmpty)}</p>`}
|
|
228
|
+
${can('owner') ? `<h4>${esc(T.retentionTitle)}</h4>
|
|
229
|
+
<div class="set-card"><form data-retention class="people-form"><label class="field"><span>${esc(T.retentionDays)}</span><input type="text" inputmode="numeric" name="retention_days" value="${esc(kept.retention_days)}"></label>
|
|
230
|
+
<label class="field"><span>${esc(T.eventHours)}</span><input type="text" inputmode="numeric" name="event_hours" value="${esc(kept.event_hours)}"></label>
|
|
231
|
+
<label class="field"><span>${esc(T.retentionInbox)}</span><input type="text" inputmode="numeric" name="inbox_days" value="${esc(kept.inbox_days ?? 90)}"></label>
|
|
232
|
+
<label class="field"><span>${esc(T.retentionUsage)}</span><input type="text" inputmode="numeric" name="usage_days" value="${esc(kept.usage_days ?? 400)}"></label>
|
|
233
|
+
<button class="btn primary">${esc(T.save)}</button></form><p class="note" data-saved></p></div>
|
|
234
|
+
<h4>${esc(T.exportTitle)}</h4><div class="set-card set-row"><p class="note">${esc(T.exportHint)}</p>
|
|
235
|
+
<a class="btn" href="${esc(inCompany('/api/company/export'))}" download>${esc(T.exportBtn)}</a></div>
|
|
236
|
+
${state.company === 'default' ? '' : `<h4>${esc(T.deleteCompanyTitle)}</h4><div class="set-card"><p class="note">${esc(T.deleteCompanyHint)}</p>
|
|
237
|
+
<form data-delete-company class="people-form"><label class="field"><span>${esc(T.deleteCompanyConfirm(here?.name ?? ''))}</span><input type="text" name="confirm" autocomplete="off" required></label>
|
|
238
|
+
<button class="btn danger">${esc(T.deleteCompanyBtn)}</button></form></div>`}` : ''}`
|
|
239
|
+
const retention = body.querySelector('[data-retention]')
|
|
240
|
+
if (retention) {
|
|
241
|
+
retention.onsubmit = async e => {
|
|
242
|
+
e.preventDefault()
|
|
243
|
+
ok()
|
|
244
|
+
const v = Object.fromEntries(new FormData(e.target))
|
|
245
|
+
try {
|
|
246
|
+
await call(inCompany('/api/company/retention/set'), { retention_days: Number(v.retention_days), event_hours: Number(v.event_hours), inbox_days: Number(v.inbox_days), usage_days: Number(v.usage_days) })
|
|
247
|
+
body.querySelector('[data-saved]').textContent = T.saved
|
|
248
|
+
} catch (err) { fail(err) }
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const del = body.querySelector('[data-delete-company]')
|
|
252
|
+
if (del) {
|
|
253
|
+
del.onsubmit = async e => {
|
|
254
|
+
e.preventDefault()
|
|
255
|
+
ok()
|
|
256
|
+
if (new FormData(e.target).get('confirm') !== here?.name) { d.el.querySelector('.err').textContent = T.deleteCompanyWrong; return }
|
|
257
|
+
try {
|
|
258
|
+
await call(inCompany('/api/company/delete'), Object.fromEntries(new FormData(e.target)))
|
|
259
|
+
location.href = location.origin + location.pathname
|
|
260
|
+
} catch (err) { fail(err) }
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function companies() {
|
|
266
|
+
const turn = ++drawing
|
|
267
|
+
const list = await call('/api/companies')
|
|
268
|
+
if (turn !== drawing) return
|
|
269
|
+
const mine = new Set(state.me.companies.map(c => c.id))
|
|
270
|
+
body.innerHTML = `<table class="people"><tbody>${list.map(c => `<tr><td><b>${esc(c.name)}</b><br><span class="note">${esc(c.id)}${c.status === 'unavailable' ? ` · ${esc(T.unavailable)}` : ''}</span></td>
|
|
271
|
+
<td>${c.status === 'deleting' ? `<span class="note">${esc(T.deletesOn(fmtTime(c.delete_after)))}</span> <button class="btn ok" data-restore="${esc(c.id)}">${esc(T.restore)}</button>` : mine.has(c.id) ? `<a class="btn" href="?company=${encodeURIComponent(c.id)}">${esc(T.openCompany)}</a>` : `<button class="btn" data-join="${esc(c.id)}">${esc(T.joinCompany)}</button>`}</td></tr>`).join('')}</tbody></table>
|
|
272
|
+
<div class="set-card"><form data-create class="people-form"><label class="field"><span>${esc(T.companyName)}</span><input type="text" name="name" required maxlength="80"></label>
|
|
273
|
+
<button class="btn primary">${esc(T.createCompany)}</button></form><div data-link></div></div>`
|
|
274
|
+
body.querySelector('[data-create]').onsubmit = async e => {
|
|
275
|
+
e.preventDefault()
|
|
276
|
+
ok()
|
|
277
|
+
try {
|
|
278
|
+
const r = await call('/api/companies/create', Object.fromEntries(new FormData(e.target)))
|
|
279
|
+
await call('/api/companies/join', { company: r.id })
|
|
280
|
+
state.me.companies.push({ id: r.id, name: r.name, role: 'owner' })
|
|
281
|
+
await companies()
|
|
282
|
+
} catch (err) { fail(err) }
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async function users() {
|
|
287
|
+
const turn = ++drawing
|
|
288
|
+
const [list, links] = await Promise.all([call('/api/users'), call('/api/pending-links')])
|
|
289
|
+
if (turn !== drawing) return
|
|
290
|
+
body.innerHTML = `<table class="people"><tbody>${list.map(u => `<tr><td><b>${esc(u.name)}</b>${u.is_platform_admin ? ` <span class="note">${esc(T.administrator)}</span>` : ''}<br><span class="note">${esc(u.email)}${u.disabled ? ` · ${esc(T.disabled)}` : ''}</span></td>
|
|
291
|
+
<td><button class="btn" data-reset="${esc(u.id)}">${esc(T.resetLink)}</button>
|
|
292
|
+
${u.id === state.me.user.id ? '' : `<button class="btn ${u.disabled ? 'ok' : 'danger'}" data-${u.disabled ? 'enable' : 'disable'}="${esc(u.id)}">${esc(u.disabled ? T.enable : T.disable)}</button>`}</td></tr>`).join('')}</tbody></table><div data-link></div>
|
|
293
|
+
${links.length ? `<h4>${esc(T.pendingLinks)}</h4><table class="people"><tbody>${links.map(l => `<tr><td>${esc(l.email)} <span class="note">${esc(l.kind === 'reset' ? T.linkReset : T.linkInvite)} · ${esc(fmtTime(l.expires_at))}</span></td><td><button class="btn danger" data-cancel-link="${esc(l.id)}">${esc(T.cancelInvite)}</button></td></tr>`).join('')}</tbody></table>` : ''}`
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// What runs where: several companies on one machine, and how far apart they are.
|
|
297
|
+
async function machines() {
|
|
298
|
+
const turn = ++drawing
|
|
299
|
+
const list = await call('/api/machines')
|
|
300
|
+
if (turn !== drawing) return
|
|
301
|
+
body.innerHTML = list.length ? `<table class="people"><tbody>${list.map(m => `<tr><td><b>${esc(m.hostname)}</b> <span class="note">${esc(T.machineSessions(m.sessions))}</span><br>
|
|
302
|
+
<span class="note">${esc(T.isolation[m.isolation])}</span>${m.isolation === 'same-user' ? ` <span class="note warn-text">${esc(T.sharedUserWarn)}</span>` : ''}
|
|
303
|
+
${m.instances.map(i => `<br><span class="dot ${i.online ? 'ok' : ''}"></span> ${esc(i.company_name)} · ${esc(i.name)}${i.os_user ? ` <span class="note">(${esc(i.os_user)})</span>` : ''} <span class="note">${esc(T.instanceSessions(i.sessions, i.max_sessions))}</span>`).join('')}</td></tr>`).join('')}</tbody></table>` : `<p class="note">${esc(T.noMachines)}</p>`
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function account() {
|
|
307
|
+
drawing++
|
|
308
|
+
const me = state.me.user
|
|
309
|
+
const waiting = state.me.deleting ?? []
|
|
310
|
+
body.innerHTML = `<div class="set-card set-me"><span class="set-avatar" aria-hidden="true">${esc((me.name || me.email || '?').trim().charAt(0).toUpperCase())}</span><div><b>${esc(me.name)}</b><span class="note">${esc(me.email)}</span></div></div>
|
|
311
|
+
${waiting.length ? `<table class="people"><tbody>${waiting.map(c => `<tr><td><b>${esc(c.name)}</b><br><span class="note">${esc(T.deletesOn(fmtTime(c.delete_after)))}</span></td><td><button class="btn ok" data-restore="${esc(c.id)}">${esc(T.restore)}</button></td></tr>`).join('')}</tbody></table>` : ''}
|
|
312
|
+
<h4>${esc(T.ghUserTitle)}</h4><div class="set-card"><form data-ghuser class="people-form"><label class="field"><span>${esc(T.ghUserLabel)}</span><input type="text" name="github" maxlength="40" autocomplete="off" spellcheck="false" placeholder="octocat" value="${esc(me.github ?? '')}"></label>
|
|
313
|
+
<button class="btn primary">${esc(T.save)}</button></form><p class="note">${esc(T.ghUserHint)}</p><p class="note" data-ghdone></p></div>
|
|
314
|
+
<h4>${esc(T.passwordTitle)}</h4><div class="set-card"><form data-password class="people-stack"><label class="field"><span>${esc(T.currentPassword)}</span><input type="password" name="current" autocomplete="current-password" required></label>
|
|
315
|
+
<label class="field"><span>${esc(T.newPassword)}</span><input type="password" name="password" autocomplete="new-password" minlength="12" required></label>
|
|
316
|
+
<button class="btn primary">${esc(T.setPassword)}</button></form><p class="note" data-done></p></div>`
|
|
317
|
+
body.querySelector('[data-ghuser]').onsubmit = async e => {
|
|
318
|
+
e.preventDefault()
|
|
319
|
+
ok()
|
|
320
|
+
try {
|
|
321
|
+
const r = await call('/auth/profile', { github: e.target.elements.github.value })
|
|
322
|
+
state.me.user = r.user
|
|
323
|
+
e.target.elements.github.value = r.user.github ?? ''
|
|
324
|
+
body.querySelector('[data-ghdone]').textContent = T.ghUserSaved
|
|
325
|
+
} catch (err) { fail(err) }
|
|
326
|
+
}
|
|
327
|
+
body.querySelector('[data-password]').onsubmit = async e => {
|
|
328
|
+
e.preventDefault()
|
|
329
|
+
ok()
|
|
330
|
+
try {
|
|
331
|
+
await call('/auth/password', Object.fromEntries(new FormData(e.target)))
|
|
332
|
+
e.target.reset()
|
|
333
|
+
body.querySelector('[data-done]').textContent = T.passwordSet
|
|
334
|
+
} catch (err) { fail(err) }
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
body.addEventListener('click', async e => {
|
|
339
|
+
const b = e.target.closest('button')
|
|
340
|
+
if (!b) return
|
|
341
|
+
ok()
|
|
342
|
+
try {
|
|
343
|
+
if (b.dataset.copy !== undefined) await navigator.clipboard?.writeText(b.previousElementSibling.textContent)
|
|
344
|
+
if (b.dataset.remove) {
|
|
345
|
+
const r = await call(inCompany('/api/members/remove'), { user: b.dataset.remove })
|
|
346
|
+
await members()
|
|
347
|
+
if (r.rotate_join_token) d.el.querySelector('.err').textContent = T.rotateAdvice
|
|
348
|
+
}
|
|
349
|
+
if (b.dataset.cancelLink) { await call('/api/pending-links/cancel', { id: b.dataset.cancelLink }); await users() }
|
|
350
|
+
if (b.dataset.cancelInvite) { await call(inCompany('/api/invitations/cancel'), { id: b.dataset.cancelInvite }); await members() }
|
|
351
|
+
if (b.dataset.rotate !== undefined) { await call(inCompany('/api/join-token/rotate'), {}); await members() }
|
|
352
|
+
if (b.dataset.join) { await call('/api/companies/join', { company: b.dataset.join }); state.me.companies.push({ id: b.dataset.join, role: 'owner' }); await companies() }
|
|
353
|
+
if (b.dataset.restore) { await call('/api/companies/restore', { company: b.dataset.restore }); location.href = `?company=${encodeURIComponent(b.dataset.restore)}` }
|
|
354
|
+
if (b.dataset.reset) {
|
|
355
|
+
const made = await call('/api/users/reset', { user: b.dataset.reset })
|
|
356
|
+
await users()
|
|
357
|
+
body.querySelector('[data-link]').innerHTML = linkBox(made)
|
|
358
|
+
}
|
|
359
|
+
if (b.dataset.disable) {
|
|
360
|
+
const r = await call('/api/users/disable', { user: b.dataset.disable })
|
|
361
|
+
await users()
|
|
362
|
+
if (r.rotate_join_token?.length) alertBox(T.rotateAdviceIn(r.rotate_join_token.join(', ')))
|
|
363
|
+
}
|
|
364
|
+
if (b.dataset.enable) { await call('/api/users/enable', { user: b.dataset.enable }); await users() }
|
|
365
|
+
} catch (err) { fail(err) }
|
|
366
|
+
})
|
|
367
|
+
for (const b of d.el.querySelectorAll('[data-tab]')) b.onclick = () => show(b.dataset.tab)
|
|
368
|
+
const first = tabs.some(t => t[0] === start) ? start : manager && here ? 'members' : admin && !here ? 'companies' : tabs[0][0]
|
|
369
|
+
show(first).then(() => root.querySelector(`[data-tab="${first}"]`)?.focus())
|
|
370
|
+
}
|
|
371
|
+
export const openPeople = openSettings
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { T } from './i18n.js'
|
|
2
|
+
import { state, can, sessions, hosts } from './state.js'
|
|
3
|
+
import { esc } from './format.js'
|
|
4
|
+
import { dialog, confirmDialog } from './dialogs.js'
|
|
5
|
+
import { call as post, inCompany } from './api.js'
|
|
6
|
+
|
|
7
|
+
// Permission profiles: what the agents of a team may do without asking.
|
|
8
|
+
// Written here (Settings › Agent permissions), followed by a team or by one
|
|
9
|
+
// session; each machine turns them into Claude Code's own rules when it opens
|
|
10
|
+
// a session from the dashboard, as far as it takes them. The server keeps
|
|
11
|
+
// them (server/permissions/) and says which capability is which rules.
|
|
12
|
+
|
|
13
|
+
export const CAPS = ['edit', 'tests', 'install', 'commit', 'push', 'history', 'remove', 'web', 'docker', 'sudo']
|
|
14
|
+
const STATES = ['default', 'allow', 'ask', 'deny']
|
|
15
|
+
const NONE = 'none'
|
|
16
|
+
|
|
17
|
+
export const profiles = () => state.permissions?.profiles ?? []
|
|
18
|
+
export const profileById = id => profiles().find(p => p.id === id) ?? null
|
|
19
|
+
export const profileName = p => (p ? (p.builtin ? T.permBuiltin[p.id] ?? p.name : p.name) : '')
|
|
20
|
+
|
|
21
|
+
// Which profile a session follows, and why: its own, its team's, or none.
|
|
22
|
+
export function profileOf(s) {
|
|
23
|
+
if (!s) return { profile: null, from: null }
|
|
24
|
+
const own = state.permissions?.sessions?.[s.name] ?? null
|
|
25
|
+
if (own === NONE) return { profile: null, from: 'session' }
|
|
26
|
+
if (own) return { profile: profileById(own), from: 'session' }
|
|
27
|
+
const role = s.role ?? s.opened_role
|
|
28
|
+
const team = role === 'coordinator' ? s.name : role === 'worker' ? s.coordinator : null
|
|
29
|
+
const id = team ? state.permissions?.teams?.[team] : null
|
|
30
|
+
return { profile: id ? profileById(id) : null, from: id ? 'team' : null }
|
|
31
|
+
}
|
|
32
|
+
export const teamProfile = coordinator => profileById(state.permissions?.teams?.[coordinator] ?? '')
|
|
33
|
+
|
|
34
|
+
// What a profile lets them do, in a few words: what it allows and forbids.
|
|
35
|
+
export function profileSummary(p) {
|
|
36
|
+
if (!p) return T.permNoProfile
|
|
37
|
+
const by = st => CAPS.filter(c => p.caps?.[c] === st).map(c => T.permCapShort[c])
|
|
38
|
+
const own = (p.extra?.allow?.length ?? 0) + (p.extra?.ask?.length ?? 0) + (p.extra?.deny?.length ?? 0)
|
|
39
|
+
return [
|
|
40
|
+
by('allow').length ? `${T.permStates.allow}: ${by('allow').join(', ')}` : '',
|
|
41
|
+
by('ask').length ? `${T.permStates.ask}: ${by('ask').join(', ')}` : '',
|
|
42
|
+
by('deny').length ? `${T.permStates.deny}: ${by('deny').join(', ')}` : '',
|
|
43
|
+
own ? T.permOwnCount(own) : '',
|
|
44
|
+
].filter(Boolean).join(' · ') || T.permNothingSet
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The lines below filled in from what the user wrote: a guess, shown for them
|
|
48
|
+
// to check before saving (nothing is asked of any model). Each clause says
|
|
49
|
+
// one thing ("commit, but never push"): a "no" in it forbids what it names.
|
|
50
|
+
const CUES = {
|
|
51
|
+
history: /\bforce\b|\bforzar\b|--force|reset\s+--hard|reescrib\w*\s+(?:la\s+)?historia|rewrit\w*\s+(?:the\s+)?history|\brebase\b/i,
|
|
52
|
+
push: /\bpush\w*\b|\bsub(?:ir|an|e)\s+(?:los\s+)?cambios\b|\bsubir\s+(?:a|al)\s+(?:remoto|github|gitlab|origin)\b/i,
|
|
53
|
+
commit: /\bcommit\w*\b|\bcomite\w*\b/i,
|
|
54
|
+
install: /\bdependenc\w*|\binstal\w*\s+(?:paquetes|librer[ií]as|dependencias)|\binstall\w*\s+(?:packages|dependencies|libraries)|\bnpm\s+install\b|\bpip\s+install\b/i,
|
|
55
|
+
tests: /\btests?\b|\btesting\b|\bpruebas?\b|\bcompil\w*|\bbuild\w*\b|\blint\w*\b/i,
|
|
56
|
+
edit: /\bedit\w*\b|\bmodific\w*\b|\bescrib\w*\s+(?:c[oó]digo|ficheros|archivos)|\bcambi\w*\s+(?:el\s+)?(?:c[oó]digo|ficheros|archivos)|\bwrite\s+(?:code|files)|\bchange\s+(?:the\s+)?(?:code|files)/i,
|
|
57
|
+
remove: /\b(?:borr|elimin)\w*\s+(?:ficheros|archivos|carpetas|files)|\b(?:delete|remove)\s+(?:files|folders)|\brm\b/i,
|
|
58
|
+
web: /\bweb\b|\binternet\b|\bnaveg\w*|\bbrows\w*|\bonline\b/i,
|
|
59
|
+
docker: /\bdocker\w*\b|\bcontenedor\w*|\bcontainers?\b/i,
|
|
60
|
+
sudo: /\bsudo\b|\broot\b|\badministrador\w*\b|\badmin\s+rights\b/i,
|
|
61
|
+
}
|
|
62
|
+
const NEG = /\b(?:no|nunca|jam[aá]s|ni|sin|prohib\w*|never|not|don['’]?t|doesn['’]?t|cannot|can['’]?t|mustn['’]?t|forbid\w*|nothing)\b/i
|
|
63
|
+
const ASK = /\bpregunt\w*|\bconsult\w*|\bpid\w*\s+permiso|\bcon\s+permiso|\bpermiso\s+(?:antes|primero)|\bask\w*\b|\bwith\s+permission|\bconfirm\w*/i
|
|
64
|
+
export function guessCaps(text) {
|
|
65
|
+
const out = {}
|
|
66
|
+
const clauses = String(text ?? '').split(/[.;,:\n!?]+|\s+(?:pero|aunque|sino|excepto|salvo|but|except|although|though)\s+/i)
|
|
67
|
+
for (const clause of clauses) {
|
|
68
|
+
const found = Object.keys(CUES).filter(c => CUES[c].test(clause))
|
|
69
|
+
// ("never force push" is about rewriting history, not about pushing.)
|
|
70
|
+
const caps = found.includes('history') ? found.filter(c => c !== 'push') : found
|
|
71
|
+
if (!caps.length) continue
|
|
72
|
+
const st = NEG.test(clause) ? 'deny' : ASK.test(clause) ? 'ask' : 'allow'
|
|
73
|
+
for (const c of caps) out[c] = st
|
|
74
|
+
}
|
|
75
|
+
return out
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const call = (what, body) => post(inCompany(`/api/permissions/${what}`), body)
|
|
79
|
+
.catch(err => { throw Object.assign(new Error(err.message.replace(/^(Bad Request|Conflict|Forbidden): /, '')), { status: err.status }) })
|
|
80
|
+
const lines = v => String(v ?? '').split('\n').map(l => l.trim()).filter(Boolean)
|
|
81
|
+
|
|
82
|
+
// Settings › Agent permissions: the profiles, who follows each, and how to
|
|
83
|
+
// change them.
|
|
84
|
+
export function permissionsTab(body, fail) {
|
|
85
|
+
const usedBy = id => Object.values(state.permissions?.teams ?? {}).filter(x => x === id).length + Object.values(state.permissions?.sessions ?? {}).filter(x => x === id).length
|
|
86
|
+
const machines = [...hosts.values()]
|
|
87
|
+
const takes = machines.map(h => [h, h.info?.permission_profiles ?? null])
|
|
88
|
+
const row = p => `<tr data-profile="${esc(p.id)}"><td><b>${esc(profileName(p))}</b>${p.builtin ? ` <span class="tag">${esc(T.permBuiltinTag)}</span>` : ''}<br><span class="note">${esc(profileSummary(p))}</span>${usedBy(p.id) ? `<br><span class="note">${esc(T.permUsedBy(usedBy(p.id)))}</span>` : ''}</td>
|
|
89
|
+
<td class="perm-acts">${p.builtin ? `<button type="button" class="btn" data-copy-profile="${esc(p.id)}">${esc(T.permCopy)}</button>` : `<button type="button" class="btn" data-edit-profile="${esc(p.id)}">${esc(T.permEdit)}</button><button type="button" class="btn danger" data-delete-profile="${esc(p.id)}">${esc(T.permDelete)}</button>`}</td></tr>`
|
|
90
|
+
body.innerHTML = `<p class="note">${esc(T.permIntro)}</p>
|
|
91
|
+
<table class="people perm-list"><tbody>${profiles().map(row).join('')}</tbody></table>
|
|
92
|
+
<p><button type="button" class="btn primary" data-new-profile>${esc(T.permNew)}</button></p>
|
|
93
|
+
<h4>${esc(T.permMachinesH)}</h4><div class="set-card"><p class="note">${T.permMachinesHint}</p>
|
|
94
|
+
${takes.length ? `<table class="people"><tbody>${takes.map(([h, t]) => `<tr><td>${esc(h.name)}</td><td><span class="note">${esc(T.permTakes[t ?? 'old'])}</span></td></tr>`).join('')}</tbody></table>` : `<p class="note">${esc(T.permNoMachines)}</p>`}</div>`
|
|
95
|
+
body.onclick = e => {
|
|
96
|
+
const b = e.target.closest('button')
|
|
97
|
+
if (!b) return
|
|
98
|
+
if (b.dataset.newProfile != null) return profileDialog(null)
|
|
99
|
+
if (b.dataset.copyProfile) { const p = profileById(b.dataset.copyProfile); return profileDialog({ ...p, id: null, builtin: false, name: `${profileName(p)} (${T.permCopyWord})` }) }
|
|
100
|
+
if (b.dataset.editProfile) return profileDialog(profileById(b.dataset.editProfile))
|
|
101
|
+
if (b.dataset.deleteProfile) {
|
|
102
|
+
const p = profileById(b.dataset.deleteProfile)
|
|
103
|
+
return confirmDialog({ title: T.permDeleteTitle(profileName(p)), text: esc(T.permDeleteText(usedBy(p.id))), confirm: T.permDelete, danger: true, run: () => call('delete', { id: p.id }).catch(err => { fail(err); throw err }) })
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// A profile, new or changed: in the user's words, then each capability, then
|
|
109
|
+
// rules of its own.
|
|
110
|
+
export function profileDialog(p) {
|
|
111
|
+
const v = p ?? { id: null, name: '', notes: '', caps: {}, extra: { allow: [], ask: [], deny: [] } }
|
|
112
|
+
const select = c => `<select name="cap-${c}" data-cap="${c}">${STATES.map(st => `<option value="${st}" ${(v.caps?.[c] ?? 'default') === st ? 'selected' : ''}>${esc(T.permStates[st])}</option>`).join('')}</select>`
|
|
113
|
+
const d = dialog(`<h3>${esc(v.id ? T.permEditTitle(profileName(v)) : T.permNew)}</h3>
|
|
114
|
+
<div class="perm-dialog">
|
|
115
|
+
<label class="field"><span>${esc(T.permName)}</span><input name="name" maxlength="40" value="${esc(v.name ?? '')}" required></label>
|
|
116
|
+
<label class="field"><span>${esc(T.permNotes)}</span><textarea name="notes" rows="3" maxlength="2000" placeholder="${esc(T.permNotesPlaceholder)}">${esc(v.notes ?? '')}</textarea></label>
|
|
117
|
+
<p class="note perm-fillrow"><button type="button" class="btn" data-fill>${esc(T.permFill)}</button> <span data-filled>${esc(T.permNotesHint)}</span></p>
|
|
118
|
+
<h4>${esc(T.permCapsH)}</h4>
|
|
119
|
+
<table class="people perm-caps"><tbody>${CAPS.map(c => `<tr><td><label for="cap-${c}-${v.id ?? 'new'}">${esc(T.permCaps[c])}</label><br><span class="note">${esc(T.permCapHint[c])}</span></td><td>${select(c).replace('<select ', `<select id="cap-${c}-${v.id ?? 'new'}" `)}</td></tr>`).join('')}</tbody></table>
|
|
120
|
+
<details class="perm-own"${(v.extra?.allow?.length || v.extra?.ask?.length || v.extra?.deny?.length) ? ' open' : ''}><summary>${esc(T.permOwnRules)}</summary>
|
|
121
|
+
<p class="note">${esc(T.permOwnHint)}</p>
|
|
122
|
+
${['allow', 'ask', 'deny'].map(k => `<label class="field"><span>${esc(T.permStates[k])}</span><textarea name="own-${k}" rows="2" class="mono" spellcheck="false">${esc((v.extra?.[k] ?? []).join('\n'))}</textarea></label>`).join('')}
|
|
123
|
+
</details>
|
|
124
|
+
<p class="note">${esc(T.permAppliesWhen)}</p>
|
|
125
|
+
</div>
|
|
126
|
+
<div class="err" role="alert"></div>
|
|
127
|
+
<div class="actions"><button type="button" class="btn plain" data-cancel>${esc(T.cancel)}</button><button type="button" class="btn primary" data-save>${esc(T.save)}</button></div>`, { wide: true })
|
|
128
|
+
const f = n => d.el.querySelector(`[name="${n}"]`)
|
|
129
|
+
f('name').focus()
|
|
130
|
+
d.el.querySelector('[data-fill]').onclick = () => {
|
|
131
|
+
const g = guessCaps(f('notes').value)
|
|
132
|
+
for (const [c, st] of Object.entries(g)) f(`cap-${c}`).value = st
|
|
133
|
+
for (const c of CAPS) f(`cap-${c}`).closest('tr').classList.toggle('perm-filled', c in g)
|
|
134
|
+
d.el.querySelector('[data-filled]').textContent = Object.keys(g).length ? T.permFilled(Object.keys(g).length) : T.permFillNone
|
|
135
|
+
}
|
|
136
|
+
const save = async () => {
|
|
137
|
+
const btn = d.el.querySelector('[data-save]')
|
|
138
|
+
btn.disabled = true
|
|
139
|
+
try {
|
|
140
|
+
await call('save', {
|
|
141
|
+
...(v.id ? { id: v.id } : {}),
|
|
142
|
+
name: f('name').value,
|
|
143
|
+
notes: f('notes').value,
|
|
144
|
+
caps: Object.fromEntries(CAPS.map(c => [c, f(`cap-${c}`).value]).filter(([, st]) => st !== 'default')),
|
|
145
|
+
extra: { allow: lines(f('own-allow').value), ask: lines(f('own-ask').value), deny: lines(f('own-deny').value) },
|
|
146
|
+
})
|
|
147
|
+
d.close()
|
|
148
|
+
} catch (err) {
|
|
149
|
+
d.el.querySelector('.err').textContent = err.message
|
|
150
|
+
btn.disabled = false
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
d.el.querySelector('[data-save]').onclick = save
|
|
154
|
+
f('name').addEventListener('keydown', e => { if (e.key === 'Enter') { e.preventDefault(); save() } })
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Which profile a team follows ({ coordinator }) or one session ({ session }).
|
|
158
|
+
export function assignDialog(target) {
|
|
159
|
+
const team = target.coordinator ?? null
|
|
160
|
+
const s = target.session ? sessions.get(target.session) : null
|
|
161
|
+
const current = team ? state.permissions?.teams?.[team] ?? '' : state.permissions?.sessions?.[target.session] ?? ''
|
|
162
|
+
const teamOf = s ? ((s.role ?? s.opened_role) === 'coordinator' ? s.name : s.coordinator) : null
|
|
163
|
+
const inherited = teamOf ? teamProfile(teamOf) : null
|
|
164
|
+
const options = [
|
|
165
|
+
...(team ? [['', T.permNone]] : [['', T.permFromTeam(inherited ? profileName(inherited) : null)], [NONE, T.permNone]]),
|
|
166
|
+
...profiles().map(p => [p.id, profileName(p)]),
|
|
167
|
+
]
|
|
168
|
+
const d = dialog(`<h3>${esc(T.permAssignTitle(team ? (state.squadMeta.get(team)?.title || team) : target.session))}</h3>
|
|
169
|
+
<label class="field"><span>${esc(T.permProfile)}</span><select name="profile">${options.map(([id, label]) => `<option value="${esc(id)}" ${id === current ? 'selected' : ''}>${esc(label)}</option>`).join('')}</select></label>
|
|
170
|
+
<p class="note" data-summary></p>
|
|
171
|
+
<p class="note">${esc(team ? T.permAssignTeamHint : T.permAssignSessionHint)} ${esc(T.permAppliesWhen)}</p>
|
|
172
|
+
<div class="err" role="alert"></div>
|
|
173
|
+
<div class="actions"><button type="button" class="btn plain" data-cancel>${esc(T.cancel)}</button><button type="button" class="btn primary" data-ok>${esc(T.save)}</button></div>`)
|
|
174
|
+
const sel = d.el.querySelector('[name=profile]')
|
|
175
|
+
const show = () => { d.el.querySelector('[data-summary]').textContent = sel.value === NONE ? T.permNoProfile : sel.value ? profileSummary(profileById(sel.value)) : team ? T.permNoProfile : profileSummary(inherited) }
|
|
176
|
+
sel.onchange = show
|
|
177
|
+
show()
|
|
178
|
+
sel.focus()
|
|
179
|
+
d.el.querySelector('[data-ok]').onclick = async () => {
|
|
180
|
+
try {
|
|
181
|
+
await call('assign', team ? { coordinator: team, profile: sel.value } : { session: target.session, profile: sel.value })
|
|
182
|
+
d.close()
|
|
183
|
+
} catch (err) { d.el.querySelector('.err').textContent = err.message }
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// A section for the side of a team's page or a session's: what it follows,
|
|
188
|
+
// and (for a manager) a button to change it.
|
|
189
|
+
export function permissionsSection({ coordinator, session }) {
|
|
190
|
+
const s = session ? sessions.get(session) : null
|
|
191
|
+
const { profile, from } = coordinator ? { profile: teamProfile(coordinator), from: 'team' } : profileOf(s)
|
|
192
|
+
const running = s ? [...hosts.values()].flatMap(h => h.info?.terminals ?? []).find(t => t.id === s.name) : null
|
|
193
|
+
const said = profile ? (from === 'team' && session ? T.permFollowsTeam(profileName(profile)) : T.permFollows(profileName(profile))) : T.permNoProfile
|
|
194
|
+
return `<section class="perm-side"><h3 class="tq-label">${esc(T.tqPermissions)}</h3><p class="tq-small">${esc(said)}</p>${profile ? `<p class="tq-small sv-quiet">${esc(profileSummary(profile))}</p>` : ''}${running?.profile && running.profile !== profile?.name ? `<p class="tq-small sv-quiet">${esc(T.permRunningWith(running.profile))}</p>` : ''}
|
|
195
|
+
${can('manager') ? `<button type="button" class="btn quiet tq-act" data-perm-assign="${esc(coordinator ?? '')}" data-perm-session="${esc(session ?? '')}">${esc(T.permChange)}</button>` : ''}</section>`
|
|
196
|
+
}
|
|
197
|
+
// (Wired once, wherever such a section is drawn.)
|
|
198
|
+
document.addEventListener('click', e => {
|
|
199
|
+
const b = e.target.closest('[data-perm-assign]')
|
|
200
|
+
if (!b) return
|
|
201
|
+
assignDialog(b.dataset.permAssign ? { coordinator: b.dataset.permAssign } : { session: b.dataset.permSession })
|
|
202
|
+
})
|