Scope everything to a team, and route alerts by integration key
The core of #4, and what #1 is for: terdut stops being one shared space. A team owns its incidents, alerts, schedule and integrations; a user sees exactly the teams they are in. Everything that existed moves into one Default team and every existing user becomes an owner of it, so the upgrade is a no-op for the people using it. Ingestion is the load-bearing half. An alert arrives on a team's integration key, and the key is both the credential and the routing: it says that the sender may post, and which team the alerts belong to. That also closes the unauthenticated webhook -- the old path stays for one release, deprecated and routed to the oldest team, so an upgrade does not stop delivering while somebody edits the Alertmanager config. Scoping is enforced in as few places as possible, because the failure mode is silent. serveAs loads the caller's memberships once; list queries carry `team_id = ANY(...)`; and every incident route goes through incidentIDParam, which now parses the id AND checks the team in the same call, so a new handler cannot remember the first half and forget the second. Anything in another team is 404, never 403: whether an incident exists is that team's business. Two bugs this found, both of which would have been silent: * upsertAlerts decided "is this a new occurrence" by looking up the fingerprint alone. Across teams that made team B's first alert look like a re-send of team A's, so it opened no incident at all. The lookups are keyed on (team_id, fingerprint) now, as the index is. * Every uniqueness rule was written for one tenant. Two teams watching two clusters legitimately see the same fingerprint, the same groupKey, and want somebody on call on the same day; all three constraints move to include team_id. Roles inside a team are separate from the system administrator flag: an owner configures the team, a member works its incidents, and an admin is NOT implicitly in every team -- administration is about accounts, not about reading other people's incidents. An admin can still repair a team whose owner has left, which is why requireTeamOwner lets them through. A shift can only be given to somebody in the team. Paging a person who cannot open the incident is worse than paging nobody. The UI is updated only as far as keeping it working: it loads the viewer's teams with the session and uses the first one, since nobody has a second yet. "On call now" shows every team the viewer is in, named only when there is more than one, so the common case reads exactly as before. The team switcher, badges and per-team settings pages are the next step. Breaking for API clients: the schedule endpoints moved under the team, and /api/schedule/current returns an array rather than an object or a 404. terdut-tui will need a version for that. Per-team dead-man configuration is deliberately not here. A heartbeat's incident already opens in the team whose key received it, which is the part that matters for isolation; moving the matchers out of env into per-team rows is a change to how deadman.go is configured rather than to who sees what. Claude-Session: https://claude.ai/code/session_01RHPj4ggeFdEjKKfm4SHbD7
This commit is contained in:
@@ -87,12 +87,11 @@ export const deleteNote = (id, eventID) => call('DELETE', `/incidents/${id}/note
|
||||
export const alerts = (query, opts) => call('GET', '/alerts', { query, ...opts });
|
||||
|
||||
// schedule
|
||||
export const schedule = (from, to) => call('GET', '/schedule', { query: { from, to } });
|
||||
export async function onCallNow() {
|
||||
try {
|
||||
return await call('GET', '/schedule/current');
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError && err.status === 404) return null;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
export const teams = () => call('GET', '/teams');
|
||||
export const schedule = (teamID, from, to) =>
|
||||
call('GET', `/teams/${teamID}/schedule`, { query: { from, to } });
|
||||
|
||||
// One entry per team the viewer belongs to, for the teams that have somebody
|
||||
// scheduled today. An empty array means nobody anywhere, which is a real answer
|
||||
// rather than an error — unlike the pre-teams endpoint, which 404ed.
|
||||
export const onCallNow = () => call('GET', '/schedule/current');
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import * as api from './api.js';
|
||||
import * as ui from './ui.js';
|
||||
import * as poll from './poll.js';
|
||||
import { state, reset } from './state.js';
|
||||
import { state, reset, loadTeams } from './state.js';
|
||||
import * as queue from './queue.js';
|
||||
import * as incident from './incident.js';
|
||||
import * as oncall from './oncall.js';
|
||||
@@ -141,6 +141,7 @@ async function boot() {
|
||||
|
||||
try {
|
||||
state.me = await api.me();
|
||||
await loadTeams();
|
||||
showApp();
|
||||
} catch (err) {
|
||||
if (err.status === 401) showLogin();
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
// On-call: who is on duty now, the week around it, and your own next shifts.
|
||||
// Read-only for now; the TUI edits the schedule.
|
||||
//
|
||||
// One team's rota at a time — the viewer's first team, since a viewer in one
|
||||
// team has nothing to choose between. "On call now" is the exception and shows
|
||||
// every team the viewer is in, because somebody on two rotas wants both.
|
||||
|
||||
import * as api from './api.js';
|
||||
import { h, clear, icon, spinner } from './ui.js';
|
||||
import { isoDate, mondayOf, addDays, isoWeek, initial } from './format.js';
|
||||
import { myID } from './state.js';
|
||||
import { myID, currentTeam } from './state.js';
|
||||
|
||||
const view = () => document.getElementById('view-oncall');
|
||||
|
||||
@@ -24,10 +28,17 @@ export async function refresh() {
|
||||
const start = weekStart;
|
||||
const today = new Date();
|
||||
try {
|
||||
const team = currentTeam();
|
||||
if (!team) {
|
||||
data = { now: [], week: [], upcoming: [] };
|
||||
error = null;
|
||||
render();
|
||||
return;
|
||||
}
|
||||
const [now, week, upcoming] = await Promise.all([
|
||||
api.onCallNow(),
|
||||
api.schedule(isoDate(start), isoDate(addDays(start, 6))),
|
||||
api.schedule(isoDate(today), isoDate(addDays(today, 60))),
|
||||
api.schedule(team.id, isoDate(start), isoDate(addDays(start, 6))),
|
||||
api.schedule(team.id, isoDate(today), isoDate(addDays(today, 60))),
|
||||
]);
|
||||
if (start !== weekStart) return;
|
||||
data = { now, week, upcoming };
|
||||
@@ -60,15 +71,32 @@ function you(userID) {
|
||||
return userID === myID() ? h('span', { class: 'you', text: 'you' }) : null;
|
||||
}
|
||||
|
||||
// One card per team with somebody on call, and a single empty card when there
|
||||
// is nobody anywhere. The team's name is shown only when the viewer is in more
|
||||
// than one, so the common case reads exactly as it did before teams existed.
|
||||
function nowCard() {
|
||||
const n = data.now;
|
||||
return h('div', { class: 'card now-card' },
|
||||
h('div', { class: `avatar ${n ? '' : 'none'}`, text: n ? initial(n.username) : '–' }),
|
||||
h('div', {},
|
||||
h('div', { class: 'now-label', text: 'On call now' }),
|
||||
h('div', { class: 'now-name' }, n ? n.username : 'Nobody', n && you(n.user_id)),
|
||||
),
|
||||
);
|
||||
const entries = data.now || [];
|
||||
const showTeam = entries.length > 1;
|
||||
if (entries.length === 0) {
|
||||
return h('div', { class: 'card now-card' },
|
||||
h('div', { class: 'avatar none', text: '–' }),
|
||||
h('div', {},
|
||||
h('div', { class: 'now-label', text: 'On call now' }),
|
||||
h('div', { class: 'now-name', text: 'Nobody' }),
|
||||
),
|
||||
);
|
||||
}
|
||||
return h('div', {}, ...entries.map((n) =>
|
||||
h('div', { class: 'card now-card' },
|
||||
h('div', { class: 'avatar', text: initial(n.username) }),
|
||||
h('div', {},
|
||||
h('div', {
|
||||
class: 'now-label',
|
||||
text: showTeam ? `On call now · ${n.team_name}` : 'On call now',
|
||||
}),
|
||||
h('div', { class: 'now-name' }, n.username, you(n.user_id)),
|
||||
),
|
||||
)));
|
||||
}
|
||||
|
||||
function weekCard() {
|
||||
|
||||
@@ -6,8 +6,15 @@ import * as api from './api.js';
|
||||
export const state = {
|
||||
me: null, // { user, has_password }
|
||||
open: [], // the default queue: open, not snoozed
|
||||
teams: [], // the teams the viewer belongs to, each with their role
|
||||
};
|
||||
|
||||
// The team whose schedule and settings the views act on. A viewer in one team —
|
||||
// which is everybody until somebody makes a second — never has to choose.
|
||||
export function currentTeam() {
|
||||
return state.teams[0] || null;
|
||||
}
|
||||
|
||||
export function myID() {
|
||||
return state.me ? state.me.user.id : null;
|
||||
}
|
||||
@@ -24,8 +31,14 @@ export async function users() {
|
||||
return usersCache;
|
||||
}
|
||||
|
||||
export async function loadTeams() {
|
||||
state.teams = await api.teams();
|
||||
return state.teams;
|
||||
}
|
||||
|
||||
export function reset() {
|
||||
state.me = null;
|
||||
state.open = [];
|
||||
state.teams = [];
|
||||
usersCache = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user