Skip to content

feat(widget): add restriction callback to restrict visibility and modification of widget kinds #2658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2025

Conversation

Meierschlumpf
Copy link
Member


Homarr

Thank you for your contribution. Please ensure that your pull request meets the following pull request:

  • Builds without warnings or errors (pnpm build, autofix with pnpm format:fix)
  • Pull request targets dev branch
  • Commits follow the conventional commits guideline
  • No shorthand variable names are used (eg. x, y, i or any abbrevation)

Example usage:

export const { definition, componentLoader } = createWidgetDefinition("dockerContainers", {
	...otherProps,
	restrict({ user }) {
    	return user?.permissions.includes("admin") ? "none" : "all";
  	},
}).withDynamicImport(() => import("./component"));

Available restriction levels:

  • none: The widget is fully available to the user.
  • select: The widget is available to the user but not in the widget picker.
  • all: The widget is not available to the user. As replacement a message will be shown at the widgets position.

Widgets when restricted:
image

Part of #2288

@Meierschlumpf Meierschlumpf added the enhancement New feature or request label Mar 20, 2025
@Meierschlumpf Meierschlumpf self-assigned this Mar 20, 2025
@Meierschlumpf Meierschlumpf requested a review from a team as a code owner March 20, 2025 20:39
Copy link

deepsource-io bot commented Mar 20, 2025

Here's the code health analysis summary for commits 7aa5d2f..ff0846d. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScript✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

Copy link

github-actions bot commented Mar 20, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 22.79% 10298 / 45178
🔵 Statements 22.79% 10298 / 45178
🔵 Functions 30.02% 432 / 1439
🔵 Branches 64.82% 1244 / 1919
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
apps/nextjs/src/components/board/items/item-content.tsx 0% 0% 0% 0% 1-134
apps/nextjs/src/components/board/items/item-menu.tsx 0% 0% 0% 0% 1-139
apps/nextjs/src/components/board/items/item-select-modal.tsx 0% 0% 0% 0% 1-117
apps/nextjs/src/components/board/items/restricted.tsx 0% 0% 0% 0% 1-28
packages/api/src/router/board.ts 64.13% 81.25% 70% 64.13% 53-61, 64-71, 77-102, 178-247, 297-515, 534-538, 551-553, 556-558, 566, 770-780, 869-970, 978-979, 1034-1049, 1123, 1142, 1153-1168, 1173-1174, 1196-1211, 1216-1217, 1236-1238, 1263-1265, 1356-1357, 1381-1382, 1486-1490, 1547-1548, 1556-1557
packages/api/src/router/import/import-router.ts 71.87% 100% 100% 71.87% 18, 29-34, 40-41
packages/auth/permissions/index.ts 100% 100% 100% 100%
packages/auth/permissions/widget-restriction.ts 83.33% 50% 100% 83.33% 12
packages/old-import/src/index.ts 22.22% 100% 0% 22.22% 9-15
packages/old-import/src/import/import-initial-oldmarr.ts 5.4% 100% 0% 5.4% 18-58
packages/old-import/src/import/import-single-oldmarr.ts 6.45% 100% 0% 6.45% 13-44
packages/old-import/src/import/collections/board-collection.ts 2.04% 100% 0% 2.04% 21-132
packages/widgets/src/definition.ts 100% 100% 100% 100%
Generated in workflow #5692 for commit ff0846d by the Vitest Coverage Report Action

@Meierschlumpf Meierschlumpf requested a review from manuel-rw March 27, 2025 22:32
@Meierschlumpf Meierschlumpf merged commit 84f73d3 into dev Mar 28, 2025
13 checks passed
@Meierschlumpf Meierschlumpf deleted the widget-restriction branch March 28, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants