mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat: filter settings tabs by user permissions, remove admin fallback
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
|||||||
X,
|
X,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
import { useAuth } from "@/hooks/use-auth";
|
||||||
import { apiDelete, apiGet, apiPost, apiPut, clearToken, formatHeaders } from "@/lib/api";
|
import { apiDelete, apiGet, apiPost, apiPut, clearToken, formatHeaders } from "@/lib/api";
|
||||||
import { cn, copyToClipboard } from "@/lib/utils";
|
import { cn, copyToClipboard } from "@/lib/utils";
|
||||||
import { GemLogo } from "../common/gem-logo";
|
import { GemLogo } from "../common/gem-logo";
|
||||||
@@ -46,14 +47,15 @@ interface NavItem {
|
|||||||
id: Section;
|
id: Section;
|
||||||
label: string;
|
label: string;
|
||||||
icon: React.ComponentType<{ className?: string }>;
|
icon: React.ComponentType<{ className?: string }>;
|
||||||
|
requiredPermission?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NAV_ITEMS: NavItem[] = [
|
const NAV_ITEMS: NavItem[] = [
|
||||||
{ id: "general", label: "General", icon: Settings },
|
{ id: "general", label: "General", icon: Settings },
|
||||||
{ id: "system", label: "System Settings", icon: Monitor },
|
{ id: "system", label: "System Settings", icon: Monitor, requiredPermission: "settings:write" },
|
||||||
{ id: "security", label: "Security", icon: Shield },
|
{ id: "security", label: "Security", icon: Shield },
|
||||||
{ id: "people", label: "People", icon: Users },
|
{ id: "people", label: "People", icon: Users, requiredPermission: "users:manage" },
|
||||||
{ id: "teams", label: "Teams", icon: UsersRound },
|
{ id: "teams", label: "Teams", icon: UsersRound, requiredPermission: "teams:manage" },
|
||||||
{ id: "api-keys", label: "API Keys", icon: Key },
|
{ id: "api-keys", label: "API Keys", icon: Key },
|
||||||
{ id: "tools", label: "Tools", icon: Wrench },
|
{ id: "tools", label: "Tools", icon: Wrench },
|
||||||
{ id: "about", label: "About", icon: Info },
|
{ id: "about", label: "About", icon: Info },
|
||||||
@@ -61,6 +63,11 @@ const NAV_ITEMS: NavItem[] = [
|
|||||||
|
|
||||||
export function SettingsDialog({ open, onClose }: SettingsDialogProps) {
|
export function SettingsDialog({ open, onClose }: SettingsDialogProps) {
|
||||||
const [section, setSection] = useState<Section>("general");
|
const [section, setSection] = useState<Section>("general");
|
||||||
|
const { hasPermission } = useAuth();
|
||||||
|
|
||||||
|
const visibleNavItems = NAV_ITEMS.filter(
|
||||||
|
(item) => !item.requiredPermission || hasPermission(item.requiredPermission),
|
||||||
|
);
|
||||||
|
|
||||||
// Close on Escape
|
// Close on Escape
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -90,7 +97,7 @@ export function SettingsDialog({ open, onClose }: SettingsDialogProps) {
|
|||||||
<div className="flex items-center justify-between mb-4 px-2">
|
<div className="flex items-center justify-between mb-4 px-2">
|
||||||
<h2 className="text-sm font-semibold text-foreground">Settings</h2>
|
<h2 className="text-sm font-semibold text-foreground">Settings</h2>
|
||||||
</div>
|
</div>
|
||||||
{NAV_ITEMS.map((item) => (
|
{visibleNavItems.map((item) => (
|
||||||
<button
|
<button
|
||||||
key={item.id}
|
key={item.id}
|
||||||
type="button"
|
type="button"
|
||||||
@@ -175,8 +182,8 @@ function GeneralSection() {
|
|||||||
// Fallback to localStorage if session endpoint fails
|
// Fallback to localStorage if session endpoint fails
|
||||||
setUser({
|
setUser({
|
||||||
id: 0,
|
id: 0,
|
||||||
username: localStorage.getItem("stirling-username") || "admin",
|
username: localStorage.getItem("stirling-username") || "",
|
||||||
role: "admin",
|
role: "unknown",
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
@@ -189,7 +196,7 @@ function GeneralSection() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const username = user?.username || "admin";
|
const username = user?.username || "admin";
|
||||||
const role = user?.role || "admin";
|
const role = user?.role || "unknown";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
|||||||
Reference in New Issue
Block a user