Skip to content

Commit

Permalink
HOSTSD-209 Fix all servers and auth bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fosol committed Jan 19, 2024
1 parent c88e5f1 commit e75108f
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 54 deletions.
9 changes: 7 additions & 2 deletions src/dashboard/src/app/client/admin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use client';

import { useSecureRoute } from '@/hooks';
import { useAuth } from '@/hooks';
import { redirect } from 'next/navigation';

export default function Page() {
useSecureRoute((state) => state.isOrganizationAdmin, '/');
const state = useAuth();

// Only allow Organization Admin role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isOrganizationAdmin) redirect('/');

return <div>Client Admin</div>;
}
8 changes: 8 additions & 0 deletions src/dashboard/src/app/client/admin/users/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
'use client';

import { Button } from '@/components';
import { useAuth } from '@/hooks';
import { redirect } from 'next/navigation';

interface IPageProps {
params: { id: string; searchParams: any };
}

export default function Page({ params }: IPageProps) {
const state = useAuth();

// Only allow Organization Admin role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isOrganizationAdmin) redirect('/');

return (
<div>
{params.id}:{params.searchParams}
Expand Down
9 changes: 7 additions & 2 deletions src/dashboard/src/app/client/admin/users/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use client';

import { useSecureRoute } from '@/hooks';
import { useAuth } from '@/hooks';
import { redirect } from 'next/navigation';

export default function Page() {
useSecureRoute((state) => state.isOrganizationAdmin, '/');
const state = useAuth();

// Only allow Organization Admin role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isOrganizationAdmin) redirect('/');

return <div>Client User Admin</div>;
}
9 changes: 7 additions & 2 deletions src/dashboard/src/app/client/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
'use client';

import { Dashboard } from '@/components';
import { useSecureRoute } from '@/hooks';
import { useAuth } from '@/hooks';
import { redirect } from 'next/navigation';

export default function Page() {
useSecureRoute((state) => state.isClient, '/');
const state = useAuth();

// Only allow Client role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isClient) redirect('/');

return <Dashboard />;
}
15 changes: 9 additions & 6 deletions src/dashboard/src/app/client/servers/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
'use client';

import { AllocationTable, Col } from '@/components';
import { useSecureRoute } from '@/hooks';
import { useFilteredOrganizations, useFilteredServerItems } from '@/hooks/filter';
import { useAuth } from '@/hooks';
import { useServerItems } from '@/hooks/data';
import { redirect } from 'next/navigation';

export default function Page() {
useSecureRoute((state) => state.isClient, '/');
const state = useAuth();
const { isReady, serverItems } = useServerItems();

const { organizations } = useFilteredOrganizations();
const { serverItems } = useFilteredServerItems();
// Only allow Client role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isClient) redirect('/');

return (
<Col>
<h1>All Servers</h1>
<AllocationTable operatingSystem={''} serverItems={serverItems} />
<AllocationTable serverItems={serverItems} loading={!isReady} />
</Col>
);
}
8 changes: 8 additions & 0 deletions src/dashboard/src/app/hsb/admin/organizations/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
'use client';

import { Button } from '@/components';
import { useAuth } from '@/hooks';
import { redirect } from 'next/navigation';

interface IPageProps {
params: { id: string; searchParams: any };
}

export default function Page({ params }: IPageProps) {
const state = useAuth();

// Only allow System Admin role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isSystemAdmin) redirect('/');

return (
<div>
{params.id}:{params.searchParams}
Expand Down
9 changes: 7 additions & 2 deletions src/dashboard/src/app/hsb/admin/organizations/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use client';

import { useSecureRoute } from '@/hooks';
import { useAuth } from '@/hooks';
import { redirect } from 'next/navigation';

export default function Page() {
useSecureRoute((state) => state.isSystemAdmin, '/');
const state = useAuth();

// Only allow System Admin role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isSystemAdmin) redirect('/');

return <div>HSB Organization Admin</div>;
}
9 changes: 9 additions & 0 deletions src/dashboard/src/app/hsb/admin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { useAuth } from '@/hooks';
import { redirect } from 'next/navigation';

export default function Page() {
const state = useAuth();

// Only allow System Admin role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isSystemAdmin) redirect('/');

return <div>HSB Admin</div>;
}
8 changes: 8 additions & 0 deletions src/dashboard/src/app/hsb/admin/users/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
'use client';

import { Button } from '@/components';
import { useAuth } from '@/hooks';
import { redirect } from 'next/navigation';

interface IPageProps {
params: { id: string; searchParams: any };
}

export default function Page({ params }: IPageProps) {
const state = useAuth();

// Only allow System Admin role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isSystemAdmin) redirect('/');

return (
<div>
{params.id}:{params.searchParams}
Expand Down
9 changes: 7 additions & 2 deletions src/dashboard/src/app/hsb/admin/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import styles from './Users.module.scss';

import { Button, Checkbox, Info, Overlay, Select, Sheet, Spinner, Table, Text } from '@/components';
import { IUserModel, useSecureRoute } from '@/hooks';
import { IUserModel, useAuth } from '@/hooks';
import { useApiUsers } from '@/hooks/api/admin';
import { useGroups, useUsers } from '@/hooks/data';
import { redirect } from 'next/navigation';
import React from 'react';
import { IUserForm } from './IUserForm';

export default function Page() {
useSecureRoute((state) => state.isSystemAdmin, '/');
const state = useAuth();
const { isReady: isReadyUsers, users } = useUsers({ includeGroups: true });
const { isReady: isReadyGroups, groups, options: groupOptions } = useGroups();
const { update: updateUser } = useApiUsers();
Expand Down Expand Up @@ -70,6 +71,10 @@ export default function Page() {
setRecords(results);
}, [updateUser, records]);

// Only allow System Admin role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isSystemAdmin) redirect('/');

return (
<Sheet>
<div className={styles.container}>
Expand Down
9 changes: 7 additions & 2 deletions src/dashboard/src/app/hsb/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
'use client';

import { Dashboard } from '@/components';
import { useSecureRoute } from '@/hooks';
import { useAuth } from '@/hooks';
import { redirect } from 'next/navigation';

export default function Page() {
useSecureRoute((state) => state.isHSB, '/');
const state = useAuth();

// Only allow HSB role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isHSB) redirect('/');

return <Dashboard />;
}
15 changes: 9 additions & 6 deletions src/dashboard/src/app/hsb/servers/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
'use client';

import { AllocationTable, Col } from '@/components';
import { useSecureRoute } from '@/hooks';
import { useFilteredOrganizations, useFilteredServerItems } from '@/hooks/filter';
import { useAuth } from '@/hooks';
import { useServerItems } from '@/hooks/data';
import { redirect } from 'next/navigation';

export default function Page() {
useSecureRoute((state) => state.isHSB, '/');
const state = useAuth();
const { isReady, serverItems } = useServerItems();

const { organizations } = useFilteredOrganizations();
const { serverItems } = useFilteredServerItems();
// Only allow HSB role to view this page.
if (state.status === 'loading') return <div>Loading...</div>;
if (!state.isHSB) redirect('/');

return (
<Col>
<h1>All Servers</h1>
<AllocationTable operatingSystem={''} serverItems={serverItems} />
<AllocationTable serverItems={serverItems} loading={!isReady} />
</Col>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ export const AllocationByVolume = ({
title="Drive Space"
data={{
...defaultData,
datasets: fileSystemItems.map<IBarChartRowData<IFileSystemItemModel>>((fsi) => ({
key: fsi.name,
label: fsi.name,
capacity: fsi.capacity,
available: fsi.availableSpace,
data: fsi,
})),
datasets: fileSystemItems
.map<IBarChartRowData<IFileSystemItemModel>>((fsi) => ({
key: fsi.name,
label: fsi.name,
capacity: fsi.capacity,
available: fsi.availableSpace,
data: fsi,
}))
.sort((a, b) =>
a.capacity < b.capacity
? 1
: a.capacity > b.capacity
? -1
: a.label < b.label
? -1
: a.label > b.label
? 1
: 0,
),
}}
exportDisabled={true}
onExport={() => {}}
Expand Down
12 changes: 6 additions & 6 deletions src/dashboard/src/components/dashboard/useDashboardFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,28 @@ export const useDashboardFilter = () => {
filter?.operatingSystemItem ?? filteredOperatingSystemItem;
const selectedServerItem = filter?.serverItem ?? filteredServerItem;

if (filter?.tenant) setFilteredTenant(filter?.tenant);
if (filter?.tenant) setFilteredTenant(filter.tenant);
if (selectedTenant) setDashboardTenants([selectedTenant]);
else setDashboardTenants(filteredTenants);

if (filter?.organization) setFilteredOrganization(filter?.organization);
if (filter?.organization) setFilteredOrganization(filter.organization);
if (selectedOrganization) setDashboardOrganizations([selectedOrganization]);
else setDashboardOrganizations(filteredOrganizations);

if (filter?.operatingSystemItem) setFilteredOperatingSystemItem(filter?.operatingSystemItem);
if (filter?.operatingSystemItem) setFilteredOperatingSystemItem(filter.operatingSystemItem);
if (selectedOperatingSystemItem)
setDashboardOperatingSystemItems([selectedOperatingSystemItem]);
else setDashboardOperatingSystemItems(filteredOperatingSystemItems);

if (filter?.serverItem) setFilteredServerItem(filter?.serverItem);
if (filter?.serverItem) setFilteredServerItem(filter.serverItem);
if (selectedServerItem) setDashboardServerItems([selectedServerItem]);
else setDashboardServerItems(filteredServerItems);

setDashboardDateRange(filteredDateRange);

if (filteredServerItem)
if (selectedServerItem)
await findFileSystemItems({
serverItemServiceNowKey: filteredServerItem.serviceNowKey,
serverItemServiceNowKey: selectedServerItem.serviceNowKey,
});

await findServerHistoryItems({
Expand Down
1 change: 0 additions & 1 deletion src/dashboard/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './api';
export * from './constants';
export * from './useAuth';
export * from './useSecureRoute';
16 changes: 0 additions & 16 deletions src/dashboard/src/hooks/useSecureRoute.ts

This file was deleted.

0 comments on commit e75108f

Please sign in to comment.