Skip to content

Commit

Permalink
add permission check for getServerStartup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharktheone committed May 31, 2023
1 parent eaf4642 commit 5c9c405
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useWebsocketEvent from '@/plugins/useWebsocketEvent';
import Can from '@/components/elements/Can';
import getServerStartup from '@/api/swr/getServerStartup';
import InputSpinner from '@/components/elements/InputSpinner';
import { usePermissions } from '@/plugins/usePermissions';

const MATCH_ERRORS = [
'minecraft 1.17 requires running the server with java 16 or above',
Expand All @@ -31,14 +32,20 @@ const JavaVersionModalFeature = () => {
const { clearFlashes, clearAndAddHttpError } = useFlash();
const { instance } = ServerContext.useStoreState(state => state.socket);

const { data, isValidating, mutate } = getServerStartup(uuid, undefined, { revalidateOnMount: false });
const hasPermission = usePermissions('startup.docker-image');

const { data, isValidating, mutate } = hasPermission
? getServerStartup(uuid, undefined, { revalidateOnMount: false })
: { data: undefined, isValidating: false, mutate: undefined };

useEffect(() => {
if (!visible) return;

mutate().then(value => {
setSelectedVersion(Object.values(value?.dockerImages || [])[0] || '');
});
if (mutate) {
mutate().then((value) => {
setSelectedVersion(Object.values(value?.dockerImages || [])[0] || '');
});
}
}, [visible]);

useWebsocketEvent(SocketEvent.CONSOLE_OUTPUT, data => {
Expand Down

0 comments on commit 5c9c405

Please sign in to comment.