-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restrict access with app permissions
- Loading branch information
1 parent
924de96
commit 9d85642
Showing
17 changed files
with
211 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import "server-only"; | ||
|
||
import { notFound, redirect } from "next/navigation"; | ||
import { TRPCError } from "@trpc/server"; | ||
|
||
export const catchTrpcNotFound = (err: unknown) => { | ||
if (err instanceof TRPCError && err.code === "NOT_FOUND") { | ||
notFound(); | ||
} | ||
|
||
throw err; | ||
}; | ||
|
||
export const catchTrpcUnauthorized = (err: unknown) => { | ||
if (err instanceof TRPCError && err.code === "UNAUTHORIZED") { | ||
redirect("/auth/login"); | ||
} | ||
|
||
throw err; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import SuperJSON from "superjson"; | ||
|
||
import type { Session } from "@homarr/auth"; | ||
import { db, eq, or } from "@homarr/db"; | ||
import { items } from "@homarr/db/schema/sqlite"; | ||
|
||
import type { WidgetComponentProps } from "../../../../widgets/src"; | ||
|
||
export const canUserSeeAppAsync = async (user: Session["user"] | null, appId: string) => { | ||
return await canUserSeeAppsAsync(user, [appId]); | ||
}; | ||
|
||
export const canUserSeeAppsAsync = async (user: Session["user"] | null, appIds: string[]) => { | ||
if (user) return true; | ||
|
||
const appIdsOnPublicBoards = await getAllAppIdsOnPublicBoardsAsync(); | ||
return appIds.every((appId) => appIdsOnPublicBoards.includes(appId)); | ||
}; | ||
|
||
const getAllAppIdsOnPublicBoardsAsync = async () => { | ||
const itemsWithApps = await db.query.items.findMany({ | ||
where: or(eq(items.kind, "app"), eq(items.kind, "bookmarks")), | ||
with: { | ||
section: { | ||
columns: {}, // Nothing | ||
with: { | ||
board: { | ||
columns: { | ||
isPublic: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
return itemsWithApps | ||
.filter((item) => item.section.board.isPublic) | ||
.flatMap((item) => { | ||
if (item.kind === "app") { | ||
const parsedOptions = SuperJSON.parse<WidgetComponentProps<"app">["options"]>(item.options); | ||
return [parsedOptions.appId]; | ||
} else if (item.kind === "bookmarks") { | ||
const parsedOptions = SuperJSON.parse<WidgetComponentProps<"bookmarks">["options"]>(item.options); | ||
return parsedOptions.items; | ||
} | ||
|
||
throw new Error("Invalid item kind"); | ||
}); | ||
}; |
Oops, something went wrong.