Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b218910476 | ||
|
|
cf0e469465 |
No files matched your search
@@ -16,7 +16,10 @@ export default async function AppEditPage(props: AppEditPageProps) {
|
|||||||
const params = await props.params;
|
const params = await props.params;
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
|
|
||||||
if (!session?.user.permissions.includes("app-modify-all")) {
|
if (
|
||||||
|
!session?.user.permissions.includes("board-modify-all") ||
|
||||||
|
!session?.user.permissions.includes("app-modify-all")
|
||||||
|
) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
const app = await api.app.byId({ id: params.id });
|
const app = await api.app.byId({ id: params.id });
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { DynamicBreadcrumb } from "~/components/navigation/dynamic-breadcrumb";
|
|||||||
export default async function AppNewPage() {
|
export default async function AppNewPage() {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
|
|
||||||
if (!session?.user.permissions.includes("app-create")) {
|
if (!session?.user.permissions.includes("board-modify-all") || !session?.user.permissions.includes("app-create")) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Fragment } from "react";
|
import { Fragment } from "react";
|
||||||
import { redirect } from "next/navigation";
|
import { notFound, redirect } from "next/navigation";
|
||||||
import { ActionIcon, ActionIconGroup, Anchor, Avatar, Card, Group, Stack, Text } from "@mantine/core";
|
import { ActionIcon, ActionIconGroup, Anchor, Avatar, Card, Group, Stack, Text } from "@mantine/core";
|
||||||
import { IconBox, IconPencil } from "@tabler/icons-react";
|
import { IconBox, IconPencil } from "@tabler/icons-react";
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
@@ -33,6 +33,9 @@ export default async function AppsPage(props: AppsPageProps) {
|
|||||||
if (!session) {
|
if (!session) {
|
||||||
redirect("/auth/login");
|
redirect("/auth/login");
|
||||||
}
|
}
|
||||||
|
if (!session.user.permissions.includes("board-modify-all")) {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
|
||||||
const searchParams = searchParamsSchema.parse(await props.searchParams);
|
const searchParams = searchParamsSchema.parse(await props.searchParams);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export default async function ManageLayout({ children }: PropsWithChildren) {
|
|||||||
icon: IconBox,
|
icon: IconBox,
|
||||||
href: "/manage/apps",
|
href: "/manage/apps",
|
||||||
label: t("items.apps"),
|
label: t("items.apps"),
|
||||||
hidden: !session,
|
hidden: !session?.user.permissions.includes("board-modify-all"),
|
||||||
iconProps: {
|
iconProps: {
|
||||||
strokeWidth: 2.5,
|
strokeWidth: 2.5,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ import { AppAccessControl } from "./app/app-access-control";
|
|||||||
const defaultIcon = "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons@master/svg/homarr.svg";
|
const defaultIcon = "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons@master/svg/homarr.svg";
|
||||||
|
|
||||||
export const appRouter = createTRPCRouter({
|
export const appRouter = createTRPCRouter({
|
||||||
getPaginated: protectedProcedure
|
getPaginated: permissionRequiredProcedure
|
||||||
|
.requiresPermission("board-modify-all")
|
||||||
.input(paginatedSchema)
|
.input(paginatedSchema)
|
||||||
.output(z.object({ items: z.array(selectAppSchema), totalCount: z.number() }))
|
.output(z.object({ items: z.array(selectAppSchema), totalCount: z.number() }))
|
||||||
.meta({
|
.meta({
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ export const homeRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.session?.user) {
|
if (ctx.session?.user.permissions.includes("board-modify-all")) {
|
||||||
statistics.push({
|
statistics.push({
|
||||||
titleKey: "app",
|
titleKey: "app",
|
||||||
subtitleKey: "resources",
|
subtitleKey: "resources",
|
||||||
|
|||||||
@@ -76,6 +76,33 @@ describe("all should return all apps", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("getPaginated should require board modification access", () => {
|
||||||
|
test("should throw FORBIDDEN without board-modify-all", async () => {
|
||||||
|
const caller = appRouter.createCaller({
|
||||||
|
db: createDb(),
|
||||||
|
deviceType: undefined,
|
||||||
|
session: createDefaultSession(),
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(caller.getPaginated({ page: 1, pageSize: 10 })).rejects.toThrow("Permission denied");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return apps with board-modify-all", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = appRouter.createCaller({
|
||||||
|
db,
|
||||||
|
deviceType: undefined,
|
||||||
|
session: createDefaultSession(["board-modify-all"]),
|
||||||
|
});
|
||||||
|
await db.insert(apps).values({ id: "1", name: "Homarr", iconUrl: "https://homarr.dev/icon.svg" });
|
||||||
|
|
||||||
|
await expect(caller.getPaginated({ page: 1, pageSize: 10 })).resolves.toMatchObject({
|
||||||
|
totalCount: 1,
|
||||||
|
items: [{ id: "1" }],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("byId should return an app by id", () => {
|
describe("byId should return an app by id", () => {
|
||||||
test("should return an app by id when canUserSeeAppAsync returns true", async () => {
|
test("should return an app by id when canUserSeeAppAsync returns true", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|||||||
@@ -16,4 +16,6 @@ export const mediaRequestStatsRequestHandler = createIntegrationRequestHandler<
|
|||||||
users: await integrationInstance.getUsersAsync(),
|
users: await integrationInstance.getUsersAsync(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
cacheTtlMs: 60_000,
|
||||||
|
fallbackToStaleOnError: true,
|
||||||
});
|
});
|
||||||
@@ -17,6 +17,10 @@ export const appIntegrationBoardMode = {
|
|||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
return groups.concat([appsSearchGroup, integrationsSearchGroup]);
|
return groups.concat(
|
||||||
|
session.user.permissions.includes("board-modify-all")
|
||||||
|
? [appsSearchGroup, integrationsSearchGroup]
|
||||||
|
: [integrationsSearchGroup],
|
||||||
|
);
|
||||||
},
|
},
|
||||||
} satisfies SearchMode;
|
} satisfies SearchMode;
|
||||||
@@ -87,7 +87,8 @@ export const globalCommandGroup = createGroup<Command>({
|
|||||||
icon: IconBox,
|
icon: IconBox,
|
||||||
name: tOption("newApp.label"),
|
name: tOption("newApp.label"),
|
||||||
useInteraction: interaction.link(() => ({ href: "/manage/apps/new" })),
|
useInteraction: interaction.link(() => ({ href: "/manage/apps/new" })),
|
||||||
hidden: !session?.user.permissions.includes("app-create"),
|
hidden:
|
||||||
|
!session?.user.permissions.includes("board-modify-all") || !session?.user.permissions.includes("app-create"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
commandKey: "newIntegration",
|
commandKey: "newIntegration",
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ export const pagesSearchGroup = createGroup<{
|
|||||||
icon: IconBox,
|
icon: IconBox,
|
||||||
path: "/manage/apps",
|
path: "/manage/apps",
|
||||||
name: t("manageApp.label"),
|
name: t("manageApp.label"),
|
||||||
hidden: !session,
|
hidden: !session?.user.permissions.includes("board-modify-all"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: IconPlug,
|
icon: IconPlug,
|
||||||
|
|||||||
Reference in new issue
Block a user