diff --git a/.changeset/funny-sheep-remain.md b/.changeset/funny-sheep-remain.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/funny-sheep-remain.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/server/public/admin-domain-health.html b/server/public/admin-domain-health.html index ddaa49d77d..6e89af7ddf 100644 --- a/server/public/admin-domain-health.html +++ b/server/public/admin-domain-health.html @@ -636,6 +636,64 @@

Domain Health

} } + async function addUsersToOrg(button, orgId, orgName, userIds) { + // Validate inputs + if (!isValidOrgId(orgId)) { + alert('Invalid organization ID format'); + return; + } + + if (!confirm(`Add ${userIds.length} user(s) to "${orgName}"?\n\nThis will add them to the company organization. They will keep access to their personal workspace.`)) { + return; + } + + const originalText = button.textContent; + button.disabled = true; + button.textContent = 'Adding...'; + + try { + const response = await fetch(`/api/admin/organizations/${encodeURIComponent(orgId)}/add-users`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ user_ids: userIds }) + }); + + if (!response.ok) { + if (response.status === 401) { + window.AdminSidebar?.redirectToLogin(); + return; + } + const errorData = await response.json().catch(() => ({})); + throw new Error(errorData.message || errorData.error || 'Failed to add users'); + } + + const result = await response.json(); + + // Success + button.classList.remove('btn-primary'); + button.classList.add('btn-success'); + button.textContent = `Added ${result.added_count || userIds.length}!`; + + // Reload after brief delay + setTimeout(() => { + loadDomainHealth(); + }, 1500); + } catch (error) { + button.classList.remove('btn-primary'); + button.classList.add('btn-error'); + button.textContent = 'Failed'; + button.title = error.message; + + setTimeout(() => { + button.disabled = false; + button.classList.remove('btn-error'); + button.classList.add('btn-primary'); + button.textContent = originalText; + button.title = ''; + }, 3000); + } + } + function renderSummary() { const { summary } = healthData; const totalIssues = summary.issues.orphan_domains + summary.issues.misaligned_users + @@ -795,7 +853,10 @@

Domain Health

${misaligned_users.map(d => ` - ${escapeHtml(d.domain)} + + ${escapeHtml(d.domain)} + ${d.target_org_name ? `
${escapeHtml(d.target_org_name)}` : ''} + ${d.user_count}