Combined admin/info endpoint, replaces old separate endpoints.
This commit is contained in:
@@ -165,9 +165,12 @@ function parseHash() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadOrgs() {
|
||||
const data = await apiJson('/auth/api/admin/orgs')
|
||||
orgs.value = Object.entries(data).map(([uuid, o]) => ({ uuid, ...o }))
|
||||
async function loadAdminData() {
|
||||
const data = await apiJson('/auth/api/admin/info')
|
||||
// Convert dicts to arrays with uuid added
|
||||
orgs.value = Object.entries(data.orgs).map(([uuid, o]) => ({ uuid, ...o }))
|
||||
permissions.value = Object.entries(data.permissions).map(([uuid, p]) => ({ uuid, ...p }))
|
||||
oidcClients.value = Object.entries(data.oidc_clients).map(([uuid, c]) => ({ uuid, ...c }))
|
||||
}
|
||||
|
||||
// Helper to get users for a role as sorted array of [uuid, user]
|
||||
@@ -191,29 +194,6 @@ function orgUserCount(org) {
|
||||
return Object.keys(org.users).length
|
||||
}
|
||||
|
||||
async function loadPermissions() {
|
||||
const data = await apiJson('/auth/api/admin/permissions')
|
||||
permissions.value = Object.entries(data).map(([uuid, p]) => ({ uuid, ...p }))
|
||||
}
|
||||
|
||||
async function loadOidcClients() {
|
||||
// Only master admins can view OIDC clients
|
||||
if (!isMasterAdmin.value) {
|
||||
oidcClients.value = []
|
||||
return
|
||||
}
|
||||
try {
|
||||
oidcClients.value = await apiJson('/auth/api/admin/oidc-clients')
|
||||
} catch (e) {
|
||||
// If 403, user is not master admin - silently skip
|
||||
if (e.message?.includes('403') || e.message?.includes('Forbidden')) {
|
||||
oidcClients.value = []
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUserInfo() {
|
||||
const data = await apiJson('/auth/api/validate', { method: 'POST' })
|
||||
info.value = data
|
||||
@@ -251,11 +231,9 @@ async function load() {
|
||||
error.value = null
|
||||
try {
|
||||
// Load admin data first - apiJson will handle 401/403 with iframe authentication
|
||||
await Promise.all([loadOrgs(), loadPermissions()])
|
||||
await loadAdminData()
|
||||
// If we get here, user has admin access - now fetch user info for display
|
||||
await loadUserInfo()
|
||||
// Load OIDC clients after authentication (master admin only)
|
||||
await loadOidcClients()
|
||||
|
||||
if (!isMasterAdmin.value && isOrgAdmin.value && orgs.value.length === 1) {
|
||||
if (!window.location.hash || window.location.hash === '#overview') {
|
||||
@@ -281,7 +259,7 @@ function editUserName(user) { openDialog('user-update-name', { user, name: user.
|
||||
|
||||
async function performOrgDeletion(orgUuid) {
|
||||
await apiJson(`/auth/api/admin/orgs/${orgUuid}`, { method: 'DELETE' })
|
||||
await Promise.all([loadOrgs(), loadPermissions()])
|
||||
await Promise.all([loadAdminData()])
|
||||
}
|
||||
|
||||
function deleteOrg(org) {
|
||||
@@ -339,7 +317,7 @@ async function performUserDeletion(userUuid, userName, orgUuid) {
|
||||
try {
|
||||
await apiJson(`/auth/api/admin/users/${userUuid}`, { method: 'DELETE' })
|
||||
authStore.showMessage(`User "${userName}" deleted.`, 'success', 2500)
|
||||
await loadOrgs()
|
||||
await loadAdminData()
|
||||
window.location.hash = `#org/${orgUuid}`
|
||||
} catch (e) {
|
||||
authStore.showMessage(e.message || 'Failed to delete user', 'error')
|
||||
@@ -353,7 +331,7 @@ async function moveUserToRole(user, targetRoleUuid) {
|
||||
method: 'PATCH',
|
||||
body: { role_uuid: targetRoleUuid }
|
||||
})
|
||||
await loadOrgs()
|
||||
await loadAdminData()
|
||||
} catch (e) {
|
||||
authStore.showMessage(e.message || 'Failed to update user role')
|
||||
}
|
||||
@@ -389,7 +367,7 @@ function deleteRole(role) {
|
||||
apiJson(`/auth/api/admin/roles/${role.uuid}`, { method: 'DELETE' })
|
||||
.then(() => {
|
||||
authStore.showMessage(`Role "${role.display_name}" deleted.`, 'success', 2500)
|
||||
loadOrgs()
|
||||
loadAdminData()
|
||||
})
|
||||
.catch(e => {
|
||||
authStore.showMessage(e.message || 'Failed to delete role', 'error')
|
||||
@@ -412,7 +390,7 @@ async function toggleRolePermission(role, pid, checked) {
|
||||
await apiJson(`/auth/api/admin/roles/${role.uuid}/permissions/${pid}`, {
|
||||
method
|
||||
})
|
||||
await loadOrgs()
|
||||
await loadAdminData()
|
||||
} catch (e) {
|
||||
authStore.showMessage(e.message || 'Failed to update role permission')
|
||||
role.permissions = prevPermissions // revert
|
||||
@@ -423,7 +401,7 @@ async function toggleRolePermission(role, pid, checked) {
|
||||
async function performPermissionDeletion(permissionUuid) {
|
||||
const params = new URLSearchParams({ permission_uuid: permissionUuid })
|
||||
await apiJson(`/auth/api/admin/permission?${params.toString()}`, { method: 'DELETE' })
|
||||
await loadPermissions()
|
||||
await loadAdminData()
|
||||
}
|
||||
|
||||
function deletePermission(p) {
|
||||
@@ -513,7 +491,7 @@ function deleteOidcClient(client) {
|
||||
async function performOidcClientDeletion(clientUuid, clientName) {
|
||||
await apiJson(`/auth/api/admin/oidc-clients/${clientUuid}`, { method: 'DELETE' })
|
||||
authStore.showMessage(`OIDC client "${clientName}" deleted.`, 'success', 2500)
|
||||
await loadOidcClients()
|
||||
await loadAdminData()
|
||||
}
|
||||
|
||||
async function handleOidcSave(data) {
|
||||
@@ -531,7 +509,7 @@ async function handleOidcSave(data) {
|
||||
await apiJson(`/auth/api/admin/oidc-clients/${client_id}`, { method: 'PATCH', body: { name, redirect_uris } })
|
||||
}
|
||||
authStore.showMessage(`OIDC client "${name}" ${isNew ? 'created' : 'updated'}.`, 'success', 2500)
|
||||
await loadOidcClients()
|
||||
await loadAdminData()
|
||||
window.location.hash = '#overview'
|
||||
} catch (e) {
|
||||
authStore.showMessage(e.message || `Failed to ${isNew ? 'create' : 'update'} OIDC client`, 'error')
|
||||
@@ -636,7 +614,7 @@ async function toggleOrgPermission(org, permId, checked) {
|
||||
try {
|
||||
const params = new URLSearchParams({ permission_uuid: permId })
|
||||
await apiJson(`/auth/api/admin/orgs/${org.uuid}/permission?${params.toString()}`, { method: checked ? 'POST' : 'DELETE' })
|
||||
await loadOrgs()
|
||||
await loadAdminData()
|
||||
} catch (e) {
|
||||
authStore.showMessage(e.message || 'Failed to update organization permission', 'error')
|
||||
org.permissions = prev // revert
|
||||
@@ -746,7 +724,7 @@ function handlePanelNavigateOut(direction) {
|
||||
}
|
||||
|
||||
async function refreshUserDetail() {
|
||||
await loadOrgs()
|
||||
await loadAdminData()
|
||||
if (selectedUser.value) {
|
||||
try {
|
||||
userDetail.value = await apiJson(`/auth/api/admin/users/${selectedUser.value.uuid}`)
|
||||
@@ -772,7 +750,7 @@ async function submitDialog() {
|
||||
apiJson('/auth/api/admin/orgs', { method: 'POST', body: { display_name: name, permissions: [] } })
|
||||
.then(() => {
|
||||
authStore.showMessage(`Organization "${name}" created.`, 'success', 2500)
|
||||
Promise.all([loadOrgs(), loadPermissions()])
|
||||
loadAdminData()
|
||||
})
|
||||
.catch(e => {
|
||||
authStore.showMessage(e.message || 'Failed to create organization', 'error')
|
||||
@@ -786,7 +764,7 @@ async function submitDialog() {
|
||||
apiJson(`/auth/api/admin/orgs/${org.uuid}`, { method: 'PATCH', body: { display_name: name } })
|
||||
.then(() => {
|
||||
authStore.showMessage(`Organization renamed to "${name}".`, 'success', 2500)
|
||||
loadOrgs()
|
||||
loadAdminData()
|
||||
})
|
||||
.catch(e => {
|
||||
authStore.showMessage(e.message || 'Failed to update organization', 'error')
|
||||
@@ -800,7 +778,7 @@ async function submitDialog() {
|
||||
apiJson(`/auth/api/admin/orgs/${org.uuid}/roles`, { method: 'POST', body: { display_name: name, permissions: [] } })
|
||||
.then(() => {
|
||||
authStore.showMessage(`Role "${name}" created.`, 'success', 2500)
|
||||
loadOrgs()
|
||||
loadAdminData()
|
||||
})
|
||||
.catch(e => {
|
||||
authStore.showMessage(e.message || 'Failed to create role', 'error')
|
||||
@@ -828,7 +806,7 @@ async function submitDialog() {
|
||||
apiJson(`/auth/api/admin/orgs/${org.uuid}/users`, { method: 'POST', body: { display_name: name, role: role.display_name } })
|
||||
.then(() => {
|
||||
authStore.showMessage(`User "${name}" added to ${role.display_name} role.`, 'success', 2500)
|
||||
loadOrgs()
|
||||
loadAdminData()
|
||||
})
|
||||
.catch(e => {
|
||||
authStore.showMessage(e.message || 'Failed to add user', 'error')
|
||||
@@ -874,7 +852,7 @@ async function submitDialog() {
|
||||
apiJson(`/auth/api/admin/permission?${params.toString()}`, { method: 'PATCH' })
|
||||
.then(() => {
|
||||
authStore.showMessage(`Permission "${newDisplay}" updated.`, 'success', 2500)
|
||||
loadPermissions()
|
||||
loadAdminData()
|
||||
})
|
||||
.catch(e => {
|
||||
authStore.showMessage(e.message || 'Failed to update permission', 'error')
|
||||
@@ -890,7 +868,7 @@ async function submitDialog() {
|
||||
apiJson('/auth/api/admin/permissions', { method: 'POST', body: { scope, display_name, domain: domain || undefined } })
|
||||
.then(() => {
|
||||
authStore.showMessage(`Permission "${display_name}" created.`, 'success', 2500)
|
||||
loadPermissions()
|
||||
loadAdminData()
|
||||
})
|
||||
.catch(e => {
|
||||
authStore.showMessage(e.message || 'Failed to create permission', 'error')
|
||||
@@ -915,7 +893,7 @@ async function submitDialog() {
|
||||
req
|
||||
.then(() => {
|
||||
authStore.showMessage(`OIDC client "${name}" ${isNew ? 'created' : 'updated'}.`, 'success', 2500)
|
||||
loadOidcClients()
|
||||
loadAdminData()
|
||||
})
|
||||
.catch(e => {
|
||||
authStore.showMessage(e.message || `Failed to ${isNew ? 'create' : 'update'} OIDC client`, 'error')
|
||||
|
||||
Reference in New Issue
Block a user