feat(widget): add restriction callback to restrict visibility and modification of widget kinds (#2658)
* feat(widget): add restriction callback to restrict visibility and modification of widget kinds * fix: typecheck issue * chore: address pull request feedback
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
export * from "./board-permissions";
|
||||
export * from "./integration-permissions";
|
||||
export * from "./widget-restriction";
|
||||
|
||||
14
packages/auth/permissions/widget-restriction.ts
Normal file
14
packages/auth/permissions/widget-restriction.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { Session } from "next-auth";
|
||||
|
||||
import type { WidgetDefinition } from "../../widgets/src";
|
||||
import type { RestrictionLevel } from "../../widgets/src/definition";
|
||||
|
||||
export const isWidgetRestricted = <TDefinition extends WidgetDefinition>(props: {
|
||||
definition: TDefinition;
|
||||
user: Session["user"] | null;
|
||||
check: (level: RestrictionLevel) => boolean;
|
||||
}) => {
|
||||
if (!("restrict" in props.definition)) return false;
|
||||
if (props.definition.restrict === undefined) return false;
|
||||
return props.check(props.definition.restrict({ user: props.user ?? null }));
|
||||
};
|
||||
Reference in New Issue
Block a user