fix: hide presets behind permissions
This commit is contained in:
@@ -35,6 +35,7 @@ export default async function ServerPage({ params }: ServerPageProps) {
|
|||||||
configurations={configurations}
|
configurations={configurations}
|
||||||
statistics={statistics}
|
statistics={statistics}
|
||||||
leaderboard={leaderboard}
|
leaderboard={leaderboard}
|
||||||
|
user={session.user!}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { ServerLogViewer } from '@/components/server/ServerLogViewer';
|
|||||||
import { PresetPickerModal } from '@/components/server/PresetPickerModal';
|
import { PresetPickerModal } from '@/components/server/PresetPickerModal';
|
||||||
import { SavePresetModal } from '@/components/server/SavePresetModal';
|
import { SavePresetModal } from '@/components/server/SavePresetModal';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { StateHistoryStats } from '@/lib/schemas';
|
import { StateHistoryStats, hasPermission, type User } from '@/lib/schemas';
|
||||||
import { Leaderboard } from '@/lib/schemas/leaderboard';
|
import { Leaderboard } from '@/lib/schemas/leaderboard';
|
||||||
import {
|
import {
|
||||||
bulkUpdateConfigurationsAction,
|
bulkUpdateConfigurationsAction,
|
||||||
@@ -25,6 +25,7 @@ interface ServerConfigurationTabsProps {
|
|||||||
configurations: Configurations;
|
configurations: Configurations;
|
||||||
statistics: StateHistoryStats;
|
statistics: StateHistoryStats;
|
||||||
leaderboard: Leaderboard;
|
leaderboard: Leaderboard;
|
||||||
|
user: User;
|
||||||
}
|
}
|
||||||
const tabs = [
|
const tabs = [
|
||||||
{ id: ServerTab.statistics, name: 'Statistics', icon: '📊' },
|
{ id: ServerTab.statistics, name: 'Statistics', icon: '📊' },
|
||||||
@@ -50,8 +51,11 @@ export function ServerConfigurationTabs({
|
|||||||
serverId,
|
serverId,
|
||||||
configurations,
|
configurations,
|
||||||
statistics,
|
statistics,
|
||||||
leaderboard
|
leaderboard,
|
||||||
|
user
|
||||||
}: ServerConfigurationTabsProps) {
|
}: ServerConfigurationTabsProps) {
|
||||||
|
const canViewPresets = hasPermission(user, 'preset.view');
|
||||||
|
const canCreatePresets = hasPermission(user, 'preset.create');
|
||||||
const [currentTab, setCurrentTab] = useState(ServerTab.statistics);
|
const [currentTab, setCurrentTab] = useState(ServerTab.statistics);
|
||||||
|
|
||||||
const [configData, setConfigData] = useState(configurations.configuration);
|
const [configData, setConfigData] = useState(configurations.configuration);
|
||||||
@@ -243,20 +247,24 @@ export function ServerConfigurationTabs({
|
|||||||
/>
|
/>
|
||||||
Restart after saving
|
Restart after saving
|
||||||
</label>
|
</label>
|
||||||
<button
|
{canCreatePresets && (
|
||||||
onClick={() => setIsSavePresetModalOpen(true)}
|
<button
|
||||||
disabled={isSubmitting}
|
onClick={() => setIsSavePresetModalOpen(true)}
|
||||||
className="border-border text-secondary hover:bg-hover rounded-md border px-4 py-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-40"
|
disabled={isSubmitting}
|
||||||
>
|
className="border-border text-secondary hover:bg-hover rounded-md border px-4 py-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-40"
|
||||||
Save as Preset
|
>
|
||||||
</button>
|
Save as Preset
|
||||||
<button
|
</button>
|
||||||
onClick={() => setIsPresetModalOpen(true)}
|
)}
|
||||||
disabled={isSubmitting}
|
{canViewPresets && (
|
||||||
className="border-border text-secondary hover:bg-hover rounded-md border px-4 py-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-40"
|
<button
|
||||||
>
|
onClick={() => setIsPresetModalOpen(true)}
|
||||||
Load Preset
|
disabled={isSubmitting}
|
||||||
</button>
|
className="border-border text-secondary hover:bg-hover rounded-md border px-4 py-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-40"
|
||||||
|
>
|
||||||
|
Load Preset
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={handleSaveAll}
|
onClick={handleSaveAll}
|
||||||
disabled={isSubmitting || dirtyConfigs.size === 0}
|
disabled={isSubmitting || dirtyConfigs.size === 0}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export type EmbeddedServer = z.infer<typeof embeddedServerSchema>;
|
|||||||
|
|
||||||
export const activityLogSchema = z.object({
|
export const activityLogSchema = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
serverId: z.string(),
|
serverId: z.string().nullable(),
|
||||||
server: embeddedServerSchema.optional(),
|
server: embeddedServerSchema.optional(),
|
||||||
userId: z.string(),
|
userId: z.string(),
|
||||||
username: z.string(),
|
username: z.string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user