Skip to content

Commit a5a1846

Browse files
christoph-jerolimovclaudekarthikjeeyar
authored
feat(homepage): add permission-aware default cards backend (#2855)
* chore(homepage): create backend plugin Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * chore(homepage): remove upstream patch Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * chore(homepage): update theme, use RHDH icon and include RBAC plugin Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * feat(homepage): add permission-aware default cards backend with frontend client Add a default-cards feature that reads a recursive card tree from app-config.yaml, evaluates per-node visibility rules (users, groups, permissions — OR semantics), and returns the filtered leaf cards to the frontend. Adds a homepage-common package for shared types, a DefaultCardsApiClient in the frontend plugin and registers it in both the legacy and NFS extension systems. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * chore(homepage): update package.json Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * chore(homepage): update report apis Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * feat(homepage): add titleKey/descriptionKey and rename visibility to if Add i18n support fields (titleKey, descriptionKey) to CardNode and VisibleCard, and rename the visibility field to if to align with Backstage API conventions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * feat(homepage): add resource-based permission for default cards Add a dedicated homepage-default-card resource type with a HAS_CARD_ID rule so that RBAC policies can apply conditions to individual cards. Register via addResourceType instead of addPermissions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * chore(homepage): add dist-dynamic to .prettierignore Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * chore(homepage): add *.local.json to .gitignore Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * refactor(homepage): rename defaultCards to defaultWidgets and simplify card config - Rename defaultCards → defaultWidgets across config, types, API, backend service, routes, permissions, and tests - Remove label, title, titleKey, description, descriptionKey, priority from card/widget node config; replace with generic props attribute - Add debug pages for viewing available and default widgets - Switch from js-yaml to yaml package - Export defaultWidgetsApiRef from the dynamic-home-page plugin Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * refactor(homepage): make ref required and rename Card types to DefaultWidget Add `ref` as optional string on DefaultWidgetNode and required string on VisibleDefaultWidget. Rename CardVisibility to DefaultWidgetVisibility, CardNode to DefaultWidgetNode, and VisibleCard to VisibleDefaultWidget to align naming with the defaultWidgets domain. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * chore(homepage): fix unit tests Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * refactor(homepage): remove customizable flag and rename layouts to layout Drop the `customizable` config option and its plumbing through the backend service, types, and tests. Also add `ref` field and rename `layouts` to `layout` in the app-config for consistency. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * feat(homepage): load default widgets from backend API Add API-driven grid components that fetch default widget configuration from the backend when configured in app-config, falling back to mount-point-only behavior when no default widgets are configured. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * refactor(homepage): rename card to widget in permission resources Rename homepageDefaultCardPermissionResourceRef to homepageDefaultWidgetPermissionResourceRef and hasCardId rule to hasWidgetId for consistency with the widget terminology. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * chore(homepage): remove homepage customizable Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * chore(homepage): update knip-reports Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> * fix customizable card rendering and e2e tests --------- Signed-off-by: Christoph Jerolimov <jerolimov+git@redhat.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Karthik <karthik.jk11@gmail.com>
1 parent d9df5b8 commit a5a1846

72 files changed

Lines changed: 5090 additions & 639 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-dynamic-home-page': patch
3+
---
4+
5+
Updated dependency `@red-hat-developer-hub/backstage-plugin-theme` to `^0.14.1`.

workspaces/homepage/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ dist-types
4242
site
4343

4444
# Local configuration files
45+
*.local.json
4546
*.local.yaml
4647

4748
# Sensitive credentials

workspaces/homepage/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist
2+
dist-dynamic
23
dist-types
34
coverage
45
.vscode

workspaces/homepage/.yarn/patches/@backstage-plugin-home-npm-0.8.11-a127246043.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.

workspaces/homepage/README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
# [Backstage](https://backstage.io)
1+
## The RHDH homepage plugin is a wrapper around the upstream [Home plugin](https://github.com/backstage/backstage/tree/master/plugins/home) from [Backstage](https://backstage.io)
22

3-
This is your newly scaffolded Backstage App, Good Luck!
4-
5-
To start the app, run:
6-
7-
```sh
8-
yarn install
9-
yarn start
10-
```
11-
12-
To generate knip reports for this app, run:
13-
14-
```sh
15-
yarn backstage-repo-tools knip-reports
16-
```
3+
Initially written to add Dynamic Plugin (mount point) support does it adds now
4+
some custom widgets and a backend to configure the default layout in the `app-config.yaml`.

workspaces/homepage/app-config.production.yaml

Lines changed: 0 additions & 55 deletions
This file was deleted.

workspaces/homepage/app-config.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,66 @@ app:
8181
w: 12
8282
h: 14
8383

84+
homepage:
85+
# The widget id is required if a user changes the default layout.
86+
# The widget ref is used to determine which widget is rendered.
87+
# For 1.x this references a mount point (`config.id`).
88+
# For 2.x this references a homepage widget extension (name).
89+
defaultWidgets:
90+
- id: onboarding
91+
ref: 'rhdh-onboarding-section'
92+
layout:
93+
xl: { w: 12, h: 6 }
94+
lg: { w: 12, h: 6 }
95+
md: { w: 12, h: 7 }
96+
sm: { w: 12, h: 8 }
97+
xs: { w: 12, h: 9 }
98+
xxs: { w: 12, h: 14 }
99+
- id: entity-list
100+
ref: 'rhdh-entity-section'
101+
layout:
102+
xl: { w: 12, h: 7 }
103+
lg: { w: 12, h: 7 }
104+
md: { w: 12, h: 8 }
105+
sm: { w: 12, h: 9 }
106+
xs: { w: 12, h: 11 }
107+
xxs: { w: 12, h: 15 }
108+
- id: template-list
109+
ref: 'rhdh-template-section'
110+
layout:
111+
xl: { w: 12, h: 5 }
112+
lg: { w: 12, h: 5 }
113+
md: { w: 12, h: 5 }
114+
sm: { w: 12, h: 5 }
115+
xs: { w: 12, h: 7.5 }
116+
xxs: { w: 12, h: 13.5 }
117+
- id: quickaccess-card
118+
ref: quickaccess-card
119+
layout:
120+
xl: { w: 6, h: 8, x: 6 }
121+
lg: { w: 6, h: 8, x: 6 }
122+
md: { w: 6, h: 8, x: 6 }
123+
sm: { w: 12, h: 8, x: 6 }
124+
xs: { w: 12, h: 8, x: 6 }
125+
xxs: { w: 12, h: 8, x: 6 }
126+
- id: visit-card
127+
ref: VisitCard
128+
layout:
129+
xl: { w: 12, h: 5 }
130+
lg: { w: 12, h: 5 }
131+
md: { w: 12, h: 6 }
132+
sm: { w: 12, h: 7 }
133+
xs: { w: 12, h: 9 }
134+
xxs: { w: 12, h: 14 }
135+
- if:
136+
groups: [group:default/admins]
137+
children:
138+
- id: rbac
139+
ref: RBAC
140+
layout:
141+
xl: { w: 12, h: 6 }
142+
lg: { w: 12, h: 6 }
143+
84144
organization:
85145
name: My Company
86146

@@ -184,3 +244,14 @@ kubernetes:
184244
permission:
185245
# setting this to `false` will disable permissions
186246
enabled: true
247+
rbac:
248+
pluginsWithPermission:
249+
- catalog
250+
- scaffolder
251+
- permission
252+
- homepage
253+
admin:
254+
users:
255+
- name: user:development/guest
256+
superUsers:
257+
- name: user:development/guest

workspaces/homepage/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
},
4747
"devDependencies": {
4848
"@backstage/cli": "^0.36.0",
49+
"@backstage/cli-defaults": "0.1.0",
4950
"@backstage/e2e-test-utils": "^0.1.2",
5051
"@backstage/repo-tools": "^0.17.0",
5152
"@changesets/cli": "^2.27.1",
@@ -58,8 +59,7 @@
5859
"resolutions": {
5960
"@types/react": "^18",
6061
"@types/react-dom": "^18",
61-
"refractor@npm:3.6.0/prismjs": "^1.30.0",
62-
"@backstage/plugin-home@^0.8.11": "patch:@backstage/plugin-home@npm%3A0.8.11#./.yarn/patches/@backstage-plugin-home-npm-0.8.11-a127246043.patch"
62+
"refractor@npm:3.6.0/prismjs": "^1.30.0"
6363
},
6464
"prettier": "@backstage/cli/config/prettier",
6565
"lint-staged": {
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Knip report
22

3-
## Unused dependencies (2)
3+
## Unused dependencies (1)
44

5-
| Name | Location | Severity |
6-
| :-------------------------------------------------------- | :----------- | :------- |
7-
| @red-hat-developer-hub/backstage-plugin-dynamic-home-page | package.json | error |
8-
| react-router | package.json | error |
5+
| Name | Location | Severity |
6+
| :----------- | :---------------- | :------- |
7+
| react-router | package.json:56:6 | error |
98

10-
## Unused devDependencies (4)
9+
## Unused devDependencies (5)
1110

12-
| Name | Location | Severity |
13-
| :-------------------------- | :----------- | :------- |
14-
| @testing-library/user-event | package.json | error |
15-
| @backstage/test-utils | package.json | error |
16-
| @testing-library/dom | package.json | error |
17-
| cross-env | package.json | error |
11+
| Name | Location | Severity |
12+
| :-------------------------- | :---------------- | :------- |
13+
| @testing-library/user-event | package.json:68:6 | error |
14+
| @axe-core/playwright | package.json:62:6 | error |
15+
| @testing-library/dom | package.json:65:6 | error |
16+
| @playwright/test | package.json:64:6 | error |
17+
| cross-env | package.json:70:6 | error |
1818

workspaces/homepage/packages/app-legacy/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"lint": "backstage-cli package lint"
2020
},
2121
"dependencies": {
22+
"@backstage-community/plugin-rbac": "^1.52.1",
2223
"@backstage/app-defaults": "^1.7.6",
2324
"@backstage/catalog-model": "^1.7.7",
2425
"@backstage/cli": "^0.36.0",
@@ -48,12 +49,14 @@
4849
"@material-ui/icons": "^4.9.1",
4950
"@openshift/dynamic-plugin-sdk": "^5.0.1",
5051
"@red-hat-developer-hub/backstage-plugin-dynamic-home-page": "workspace:^",
51-
"@red-hat-developer-hub/backstage-plugin-theme": "^0.12.0",
52+
"@red-hat-developer-hub/backstage-plugin-theme": "^0.14.1",
5253
"@scalprum/react-core": "0.11.1",
5354
"react": "^18.0.2",
5455
"react-dom": "^18.0.2",
5556
"react-router": "^6.3.0",
56-
"react-router-dom": "^6.3.0"
57+
"react-router-dom": "^6.3.0",
58+
"react-use": "17.6.0",
59+
"yaml": "^2.8.3"
5760
},
5861
"devDependencies": {
5962
"@axe-core/playwright": "^4.10.0",

0 commit comments

Comments
 (0)