diff --git a/examples/app-with-rbac/.config/Dockerfile b/examples/app-with-rbac/.config/Dockerfile index 2a8a2b1e9..54d3388f3 100644 --- a/examples/app-with-rbac/.config/Dockerfile +++ b/examples/app-with-rbac/.config/Dockerfile @@ -14,7 +14,7 @@ ENV DEV "${development}" # Do NOT enable these settings in a public facing / production grafana instance ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin" ENV GF_AUTH_ANONYMOUS_ENABLED "true" -ENV GF_AUTH_BASIC_ENABLED "false" +ENV GF_AUTH_BASIC_ENABLED "true" # Set development mode so plugins can be loaded without the need to sign ENV GF_DEFAULT_APP_MODE "development" @@ -29,14 +29,14 @@ USER root # Installing supervisor and inotify-tools RUN if [ "${development}" = "true" ]; then \ if grep -i -q alpine /etc/issue; then \ - apk add supervisor inotify-tools git; \ + apk add supervisor inotify-tools git; \ elif grep -i -q ubuntu /etc/issue; then \ - DEBIAN_FRONTEND=noninteractive && \ - apt-get update && \ - apt-get install -y supervisor inotify-tools git && \ - rm -rf /var/lib/apt/lists/*; \ + DEBIAN_FRONTEND=noninteractive && \ + apt-get update && \ + apt-get install -y supervisor inotify-tools git && \ + rm -rf /var/lib/apt/lists/*; \ else \ - echo 'ERROR: Unsupported base image' && /bin/false; \ + echo 'ERROR: Unsupported base image' && /bin/false; \ fi \ fi diff --git a/examples/app-with-rbac/playwright.config.ts b/examples/app-with-rbac/playwright.config.ts index cc35fbcfe..d017dec8e 100644 --- a/examples/app-with-rbac/playwright.config.ts +++ b/examples/app-with-rbac/playwright.config.ts @@ -31,37 +31,46 @@ export default defineConfig({ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', }, - /* Configure projects for major browsers */ projects: [ { - name: 'auth', + name: 'adminUserAuthenticates', testDir: pluginE2eAuth, testMatch: [/.*\.js/], }, { - name: 'run-tests', + name: 'run-tests-for-admin', + testDir: './tests/admin', use: { ...devices['Desktop Chrome'], + // @grafana/plugin-e2e writes the auth state to this file, + // the path should not be modified storageState: 'playwright/.auth/admin.json', }, - dependencies: ['auth'], + dependencies: ['adminUserAuthenticates'], + }, + { + name: 'createViewerUserAndAuthenticate', + testDir: pluginE2eAuth, + testMatch: [/.*\.js/], + use: { + user: { + user: 'viewer', + password: 'password', + role: 'Viewer', + }, + }, + }, + { + name: 'run-tests-for-viewer', + testDir: './tests/viewer', + use: { + ...devices['Desktop Chrome'], + // @grafana/plugin-e2e writes the auth state to this file, + // the path should not be modified + storageState: 'playwright/.auth/viewer.json', + }, + dependencies: ['createViewerUserAndAuthenticate'], }, - // { - // name: 'createAdminUserAndAuthenticate', - // testDir: pluginE2eAuth, - // testMatch: [/.*\.js/], - // }, - // { - // name: 'run-tests-for-admin', - // testDir: './tests', - // use: { - // ...devices['Desktop Chrome'], - // // @grafana/plugin-e2e writes the auth state to this file, - // // the path should not be modified - // storageState: 'playwright/.auth/admin.json', - // }, - // dependencies: ['createAdminUserAndAuthenticate'], - // }, ], }); diff --git a/examples/app-with-rbac/tests/appAuthentication.spec.ts b/examples/app-with-rbac/tests/admin/appAuthentication.spec.ts similarity index 52% rename from examples/app-with-rbac/tests/appAuthentication.spec.ts rename to examples/app-with-rbac/tests/admin/appAuthentication.spec.ts index a55da06aa..e015fb9be 100644 --- a/examples/app-with-rbac/tests/appAuthentication.spec.ts +++ b/examples/app-with-rbac/tests/admin/appAuthentication.spec.ts @@ -1,17 +1,15 @@ -import { test, expect } from './fixtures'; -import { ROUTES } from '../src/constants'; +import { test, expect } from '../fixtures'; +import { ROUTES } from '../../src/constants'; test.describe('navigating app', () => { test('Page patents should be visible for admin', async ({ gotoPage, page }) => { // wait for page to successfully render - await gotoPage('/hello'); - await expect(page).toHaveURL(/.*patents/); - await expect(page.getByText('Welcome')).toBeVisible(); + await gotoPage(`/${ROUTES.Patents}`); + await expect(page.getByText('Normally restricted to Administrators')).toBeVisible(); }); test('Page research docs should be visible for admin', async ({ gotoPage, page }) => { // wait for page to successfully render await gotoPage(`/${ROUTES.ResearchDocs}`); - await expect(page).toHaveURL(/.*research/); - await expect(page.getByText('Welcome')).toBeVisible(); + await expect(page.getByText('Normally accessible to anyone')).toBeVisible(); }); }); diff --git a/examples/app-with-rbac/tests/viewer/appAuthenticationViewer.spec.ts b/examples/app-with-rbac/tests/viewer/appAuthenticationViewer.spec.ts new file mode 100644 index 000000000..7873161d7 --- /dev/null +++ b/examples/app-with-rbac/tests/viewer/appAuthenticationViewer.spec.ts @@ -0,0 +1,15 @@ +import { test, expect } from '../fixtures'; +import { ROUTES } from '../../src/constants'; + +test.describe('navigating app for Viewer', () => { + test('Page patents should not be visible for viewer', async ({ gotoPage, page }) => { + // wait for page to successfully render + await gotoPage(`/${ROUTES.Patents}`); + await expect(page.getByText('Normally restricted to Administrators')).not.toBeVisible(); + }); + test('Page research docs should be visible for viewer', async ({ gotoPage, page }) => { + // wait for page to successfully render + await gotoPage(`/${ROUTES.ResearchDocs}`); + await expect(page.getByText('Normally accessible to anyone')).toBeVisible(); + }); +}); diff --git a/examples/app-with-service-account/.config/Dockerfile b/examples/app-with-service-account/.config/Dockerfile index 2a8a2b1e9..54d3388f3 100644 --- a/examples/app-with-service-account/.config/Dockerfile +++ b/examples/app-with-service-account/.config/Dockerfile @@ -14,7 +14,7 @@ ENV DEV "${development}" # Do NOT enable these settings in a public facing / production grafana instance ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin" ENV GF_AUTH_ANONYMOUS_ENABLED "true" -ENV GF_AUTH_BASIC_ENABLED "false" +ENV GF_AUTH_BASIC_ENABLED "true" # Set development mode so plugins can be loaded without the need to sign ENV GF_DEFAULT_APP_MODE "development" @@ -29,14 +29,14 @@ USER root # Installing supervisor and inotify-tools RUN if [ "${development}" = "true" ]; then \ if grep -i -q alpine /etc/issue; then \ - apk add supervisor inotify-tools git; \ + apk add supervisor inotify-tools git; \ elif grep -i -q ubuntu /etc/issue; then \ - DEBIAN_FRONTEND=noninteractive && \ - apt-get update && \ - apt-get install -y supervisor inotify-tools git && \ - rm -rf /var/lib/apt/lists/*; \ + DEBIAN_FRONTEND=noninteractive && \ + apt-get update && \ + apt-get install -y supervisor inotify-tools git && \ + rm -rf /var/lib/apt/lists/*; \ else \ - echo 'ERROR: Unsupported base image' && /bin/false; \ + echo 'ERROR: Unsupported base image' && /bin/false; \ fi \ fi diff --git a/examples/app-with-service-account/provisioning/dashboards/dashboard.json b/examples/app-with-service-account/provisioning/dashboards/dashboard.json new file mode 100644 index 000000000..0d5357c89 --- /dev/null +++ b/examples/app-with-service-account/provisioning/dashboards/dashboard.json @@ -0,0 +1,133 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "grafana-testdata-datasource", + "uid": "PD8C576611E62080A" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unitScale": true + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "grafana-testdata-datasource", + "uid": "PD8C576611E62080A" + }, + "refId": "A", + "scenarioId": "random_walk", + "seriesCount": 1 + } + ], + "title": "Panel Title", + "type": "timeseries" + } + ], + "refresh": "", + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "New dashboard", + "version": 0, + "weekStart": "" + } \ No newline at end of file diff --git a/examples/app-with-service-account/provisioning/dashboards/default.yaml b/examples/app-with-service-account/provisioning/dashboards/default.yaml new file mode 100644 index 000000000..840c71b55 --- /dev/null +++ b/examples/app-with-service-account/provisioning/dashboards/default.yaml @@ -0,0 +1,7 @@ +apiVersion: 1 + +providers: + - name: Default + type: file + options: + path: /etc/grafana/provisioning/dashboards \ No newline at end of file diff --git a/examples/app-with-service-account/provisioning/datasources/default.yaml b/examples/app-with-service-account/provisioning/datasources/default.yaml new file mode 100644 index 000000000..3def355ec --- /dev/null +++ b/examples/app-with-service-account/provisioning/datasources/default.yaml @@ -0,0 +1,6 @@ +apiVersion: 1 + +datasources: + - name: gdev-testdata + isDefault: true + type: testdata diff --git a/examples/app-with-service-account/provisioning/plugins/apps.yaml b/examples/app-with-service-account/provisioning/plugins/apps.yaml index 494122c7b..de5169ce2 100644 --- a/examples/app-with-service-account/provisioning/plugins/apps.yaml +++ b/examples/app-with-service-account/provisioning/plugins/apps.yaml @@ -2,4 +2,6 @@ apiVersion: 1 apps: - type: 'grafana-appwithserviceaccount-app' + org_id: 1 + org_name: Main Org. disabled: false diff --git a/examples/app-with-service-account/src/pages/PageOne.tsx b/examples/app-with-service-account/src/pages/PageOne.tsx index 30add7922..f963472a0 100644 --- a/examples/app-with-service-account/src/pages/PageOne.tsx +++ b/examples/app-with-service-account/src/pages/PageOne.tsx @@ -52,7 +52,7 @@ export function PageOne() { setApiResponse('Loading...'); let params = {}; params = { ...params, method: method }; - if (method === 'POST' || method === "PUT") { + if (method === 'POST' || method === 'PUT') { let parsedBody = JSON.parse(body); params = { ...params, body: JSON.stringify(parsedBody) }; } @@ -98,7 +98,9 @@ export function PageOne() {
{apiToken}