Skip to content

Commit 3a2050c

Browse files
JonasBaclaude
andauthored
feat(cmdk): Add admin actions group for staff users (#112244)
Adds a new 'Admin' group to the command palette, visible only to Sentry staff (`user.isStaff`). The group appears after the 'Go to...' section and contains: - **Open _admin** — opens `/_admin/` in a new tab - **Open `<org>` in _admin** — opens the org's admin page in a new tab - **Exit Superuser** — only shown when a superuser session is active (`isActiveSuperuser()`); calls `DELETE /auth/superuser/` via `useMutation` and reloads the page Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
1 parent 416654e commit 3a2050c

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

static/app/components/commandPalette/useGlobalCommandPaletteActions.tsx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ import {
3737
} from 'sentry/icons';
3838
import {t} from 'sentry/locale';
3939
import {apiOptions} from 'sentry/utils/api/apiOptions';
40-
import {queryOptions} from 'sentry/utils/queryClient';
40+
import {isActiveSuperuser} from 'sentry/utils/isActiveSuperuser';
41+
import {QUERY_API_CLIENT, queryOptions, useMutation} from 'sentry/utils/queryClient';
4142
import {useMutateUserOptions} from 'sentry/utils/useMutateUserOptions';
4243
import {useOrganization} from 'sentry/utils/useOrganization';
4344
import {useProjects} from 'sentry/utils/useProjects';
45+
import {useUser} from 'sentry/utils/useUser';
4446
import {useGetStarredDashboards} from 'sentry/views/dashboards/hooks/useGetStarredDashboards';
4547
import {AGENTS_LANDING_SUB_PATH} from 'sentry/views/insights/pages/agents/settings';
4648
import {BACKEND_LANDING_SUB_PATH} from 'sentry/views/insights/pages/backend/settings';
@@ -320,6 +322,12 @@ function useNavigationToggleCollapsed(): CommandPaletteAction {
320322
*/
321323
export function useGlobalCommandPaletteActions() {
322324
const organization = useOrganization();
325+
const user = useUser();
326+
const {mutate: exitSuperuser} = useMutation({
327+
mutationFn: () =>
328+
QUERY_API_CLIENT.requestPromise('/auth/superuser/', {method: 'DELETE'}),
329+
onSuccess: () => window.location.reload(),
330+
});
323331
const hasDsnLookup = organization.features.includes('cmd-k-dsn-lookup');
324332
const {projects} = useProjects();
325333
const navigateActions = useNavigationActions();
@@ -330,8 +338,51 @@ export function useGlobalCommandPaletteActions() {
330338

331339
const navPrefix = `/organizations/${organization.slug}`;
332340

341+
const adminActions: CommandPaletteAction[] = user.isStaff
342+
? [
343+
{
344+
display: {
345+
label: t('Admin'),
346+
},
347+
actions: [
348+
{
349+
display: {
350+
label: t('Open _admin'),
351+
icon: <IconOpen />,
352+
},
353+
onAction: () => window.open('/_admin/', '_blank', 'noreferrer'),
354+
},
355+
{
356+
display: {
357+
label: t('Open %s in _admin', organization.name),
358+
icon: <IconOpen />,
359+
},
360+
onAction: () =>
361+
window.open(
362+
`/_admin/organizations/${organization.slug}/`,
363+
'_blank',
364+
'noreferrer'
365+
),
366+
},
367+
...(isActiveSuperuser()
368+
? [
369+
{
370+
display: {
371+
label: t('Exit Superuser'),
372+
icon: <IconLock locked={false} />,
373+
},
374+
onAction: () => exitSuperuser(),
375+
},
376+
]
377+
: []),
378+
],
379+
},
380+
]
381+
: [];
382+
333383
useCommandPaletteActionsRegister([
334384
...navigateActions,
385+
...adminActions,
335386
// BEGIN ADD ACTIONS
336387
{
337388
display: {

0 commit comments

Comments
 (0)