Add computer settings pages and restore workspace pages
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import userAuth from "@/src/functions/backend/auth/user-auth";
|
||||
import grabUserWorkspace from "@/src/functions/backend/db/workspaces/grab-user-workspace";
|
||||
import grabBots from "@/src/functions/backend/db/bots/grab-bots";
|
||||
import grabUserComputers from "@/src/functions/backend/db/computers/grab-user-computers";
|
||||
import grabBotHarnessOverview from "@/src/functions/backend/db/harness/grab-bot-harness-overview";
|
||||
import grabUserWorkspaces from "@/src/functions/backend/db/workspaces/grab-user-workspaces";
|
||||
import grabWorkspaceBots from "@/src/functions/backend/db/workspaces/grab-workspace-bots";
|
||||
import grabWorkspaceComputers from "@/src/functions/backend/db/workspaces/grab-workspace-computers";
|
||||
import { AdminHomePath } from "@/src/dict/admin-sections-dict";
|
||||
import type { PagePropsType, PageQueryObject } from "@/src/types";
|
||||
import canManageCrew from "@/src/utils/rbac/can-manage-crew";
|
||||
import type { PagePropsType, PageQueryObject } from "@/src/types";
|
||||
import type { BunextPageServerFn } from "@moduletrace/bunext/types";
|
||||
|
||||
/**
|
||||
* The workspace's old landing page. Management moved to
|
||||
* `/admin/settings/workspaces/<id>`: managers go there, members go to the
|
||||
* workspace's first bot. No page renders.
|
||||
* A workspace's page: its details, crew, computers and models, with the
|
||||
* rail showing its crew. Only super admins and admins manage it; a member
|
||||
* opens its first bot instead. Its settings live under Settings.
|
||||
*/
|
||||
export const server: BunextPageServerFn<PagePropsType> = async (params) => {
|
||||
const query: PageQueryObject = params.query;
|
||||
@@ -19,37 +23,68 @@ export const server: BunextPageServerFn<PagePropsType> = async (params) => {
|
||||
return { redirect: { destination: "/auth/login" } };
|
||||
}
|
||||
|
||||
const workspace = await grabUserWorkspace({
|
||||
workspace_id: String(query.workspace_id),
|
||||
user_id: user.id,
|
||||
});
|
||||
const workspaces = await grabUserWorkspaces({ user_id: user.id });
|
||||
const workspace = workspaces.find(
|
||||
(item) => String(item.id) == String(query.workspace_id),
|
||||
);
|
||||
|
||||
if (!workspace?.id) {
|
||||
return { redirect: { destination: AdminHomePath, permanent: false } };
|
||||
return { redirect: { destination: AdminHomePath } };
|
||||
}
|
||||
|
||||
const workspace_id = Number(workspace.id);
|
||||
|
||||
if (canManageCrew({ user_types })) {
|
||||
/**
|
||||
* Members don't manage it: they go straight to its first bot.
|
||||
*/
|
||||
if (!canManageCrew({ user_types })) {
|
||||
const workspace_bots = await grabWorkspaceBots({
|
||||
user_id: user.id,
|
||||
workspace_id,
|
||||
});
|
||||
|
||||
if (workspace_bots[0]?.id) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: `/admin/workspaces/${workspace_id}/bots/${workspace_bots[0].id}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
redirect: {
|
||||
destination: `/admin/settings/workspaces/${workspace_id}`,
|
||||
permanent: false,
|
||||
props: {
|
||||
workspaces,
|
||||
workspace,
|
||||
bots: workspace_bots,
|
||||
workspace_bots,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const workspace_bots = await grabWorkspaceBots({
|
||||
user_id: user.id,
|
||||
workspace_id,
|
||||
});
|
||||
const [
|
||||
workspace_bots,
|
||||
all_bots,
|
||||
workspace_computers,
|
||||
computers,
|
||||
workspace_harness_overview,
|
||||
] = await Promise.all([
|
||||
grabWorkspaceBots({ user_id: user.id, workspace_id }),
|
||||
grabBots({ user_id: user.id }),
|
||||
grabWorkspaceComputers({ workspace_id }),
|
||||
grabUserComputers({ user_id: user.id }),
|
||||
grabBotHarnessOverview({ workspace_id }).catch(() => null),
|
||||
]);
|
||||
|
||||
return {
|
||||
redirect: {
|
||||
destination: workspace_bots[0]?.id
|
||||
? `/admin/workspaces/${workspace_id}/bots/${workspace_bots[0].id}`
|
||||
: AdminHomePath,
|
||||
permanent: false,
|
||||
props: {
|
||||
workspaces,
|
||||
workspace,
|
||||
bots: workspace_bots,
|
||||
workspace_bots,
|
||||
all_bots,
|
||||
workspace_computers,
|
||||
computers,
|
||||
workspace_harness_overview,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import type { BunextPageModuleMeta } from "@moduletrace/bunext/types";
|
||||
import type { PagePropsType } from "@/src/types";
|
||||
import type { BunextPageModuleMetaFn } from "@moduletrace/bunext/types";
|
||||
import { SiteData } from "@/src/data/site-data";
|
||||
import WorkspaceOverview from "@/src/pages/admin/settings/workspaces/[workspace_id]/(sections)/workspace-overview";
|
||||
|
||||
/**
|
||||
* Never rendered: `index.server.ts` always redirects. Workspace settings
|
||||
* live at `/admin/settings/workspaces/<id>`.
|
||||
*/
|
||||
export default function WorkspacePage() {
|
||||
return null;
|
||||
return <WorkspaceOverview show_settings_link />;
|
||||
}
|
||||
|
||||
export const meta: BunextPageModuleMeta = {
|
||||
title: `Workspaces | ${SiteData["SiteName"]}`,
|
||||
description: `Your workspaces.`,
|
||||
export const meta: BunextPageModuleMetaFn = async (params) => {
|
||||
const workspace = (params.serverRes?.props as PagePropsType | undefined)
|
||||
?.workspace;
|
||||
|
||||
return {
|
||||
title: `${workspace?.name || "Workspace"} | ${SiteData["SiteName"]}`,
|
||||
description: workspace?.description || `A workspace.`,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,15 +2,13 @@ import userAuth from "@/src/functions/backend/auth/user-auth";
|
||||
import grabUserWorkspaces from "@/src/functions/backend/db/workspaces/grab-user-workspaces";
|
||||
import { AdminHomePath } from "@/src/dict/admin-sections-dict";
|
||||
import type { PagePropsType } from "@/src/types";
|
||||
import canManageCrew from "@/src/utils/rbac/can-manage-crew";
|
||||
import type { BunextPageServerFn } from "@moduletrace/bunext/types";
|
||||
|
||||
/**
|
||||
* Opens the user's first workspace: its settings page for managers, its
|
||||
* first bot for members. The bots when they have no workspaces.
|
||||
* Opens the user's first workspace, or the bots when they have none.
|
||||
*/
|
||||
export const server: BunextPageServerFn<PagePropsType> = async ({ req }) => {
|
||||
const { user, user_types } = await userAuth({ req });
|
||||
const { user } = await userAuth({ req });
|
||||
|
||||
if (!user?.id) {
|
||||
return { redirect: { destination: "/auth/login" } };
|
||||
@@ -18,15 +16,11 @@ export const server: BunextPageServerFn<PagePropsType> = async ({ req }) => {
|
||||
|
||||
const first = (await grabUserWorkspaces({ user_id: user.id }))[0];
|
||||
|
||||
if (!first?.id) {
|
||||
return { redirect: { destination: AdminHomePath } };
|
||||
}
|
||||
|
||||
return {
|
||||
redirect: {
|
||||
destination: canManageCrew({ user_types })
|
||||
? `/admin/settings/workspaces/${first.id}`
|
||||
: `/admin/workspaces/${first.id}`,
|
||||
destination: first?.id
|
||||
? `/admin/workspaces/${first.id}`
|
||||
: AdminHomePath,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user