Skip to content

Commit bb7efb6

Browse files
authored
chore: more adjustments to irm monorepo (#4915)
# What this PR does - remove hardcoded plugin id so it can run from IRM monorepo context - minor e2e tests tweaks ## Which issue(s) this PR closes Related to grafana/irm#41 <!-- *Note*: If you want the issue to be auto-closed once the PR is merged, change "Related to" to "Closes" in the line above. If you have more than one GitHub issue that this PR closes, be sure to preface each issue link with a [closing keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue). This ensures that the issue(s) are auto-closed once the PR has been merged. --> ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes.
1 parent a25d44d commit bb7efb6

File tree

8 files changed

+35
-21
lines changed

8 files changed

+35
-21
lines changed

grafana-plugin/.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ grafana-plugin.yml
2121

2222
# Jest test report
2323
jest_html_reporters.html
24-
jest-html-reporters*
24+
jest-html-reporters*
25+
26+
.turbo
27+
tsconfig.tsbuildinfo

grafana-plugin/e2e-tests/users/usersActions.test.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ import { goToOnCallPage } from '../utils/navigation';
44
import { verifyThatUserCanViewOtherUsers, accessProfileTabs } from '../utils/users';
55

66
test.describe('Users screen actions', () => {
7-
test("Admin is allowed to edit other users' profile", async ({ adminRolePage: { page } }) => {
8-
await goToOnCallPage(page, 'users');
9-
const editableUsers = page.getByTestId('users-table').getByRole('button', { name: 'Edit', disabled: false });
10-
await editableUsers.first().waitFor();
11-
const editableUsersCount = await editableUsers.count();
12-
expect(editableUsersCount).toBeGreaterThan(1);
13-
});
14-
15-
test('Admin is allowed to view the list of users', async ({ adminRolePage: { page } }) => {
16-
await verifyThatUserCanViewOtherUsers(page);
17-
});
18-
197
test('Viewer is not allowed to view the list of users', async ({ viewerRolePage: { page } }) => {
208
await verifyThatUserCanViewOtherUsers(page, false);
219
});
@@ -66,6 +54,18 @@ test.describe('Users screen actions', () => {
6654
expect(usersCountWithDisabledEdit).toBeGreaterThan(1);
6755
});
6856

57+
test("Admin is allowed to edit other users' profile", async ({ adminRolePage: { page } }) => {
58+
await goToOnCallPage(page, 'users');
59+
const editableUsers = page.getByTestId('users-table').getByRole('button', { name: 'Edit', disabled: false });
60+
await editableUsers.first().waitFor();
61+
const editableUsersCount = await editableUsers.count();
62+
expect(editableUsersCount).toBeGreaterThan(1);
63+
});
64+
65+
test('Admin is allowed to view the list of users', async ({ adminRolePage: { page } }) => {
66+
await verifyThatUserCanViewOtherUsers(page);
67+
});
68+
6969
test('Search updates the table view', async ({ adminRolePage }) => {
7070
const { page, userName } = adminRolePage;
7171
await goToOnCallPage(page, 'users');

grafana-plugin/e2e-tests/utils/integrations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const createIntegration = async ({
4747
await searchIntegrationAndAssertItsPresence({ page, integrationName });
4848

4949
await page.getByRole('link', { name: integrationName }).click();
50+
await page.waitForLoadState('networkidle');
5051
};
5152

5253
export const assignEscalationChainToIntegration = async (page: Page, escalationChainName: string): Promise<void> => {

grafana-plugin/pkg/plugin/permissions.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (a *App) GetPermissions(settings *OnCallPluginSettings, onCallUser *OnCallU
4747
if res.StatusCode == 200 {
4848
var filtered []OnCallPermission
4949
for _, permission := range permissions {
50-
if strings.HasPrefix(permission.Action, "grafana-oncall-app") {
50+
if strings.HasPrefix(permission.Action, settings.PluginID) {
5151
filtered = append(filtered, permission)
5252
}
5353
}
@@ -65,7 +65,7 @@ func (a *App) GetAllPermissions(settings *OnCallPluginSettings) (map[string]map[
6565

6666
reqURL.Path += "api/access-control/users/permissions/search"
6767
q := reqURL.Query()
68-
q.Set("actionPrefix", "grafana-oncall-app")
68+
q.Set("actionPrefix", settings.PluginID)
6969
reqURL.RawQuery = q.Encode()
7070

7171
req, err := http.NewRequest("GET", reqURL.String(), nil)

grafana-plugin/pkg/plugin/settings.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type OnCallPluginSettings struct {
4646
StackID int `json:"stack_id"`
4747
OrgID int `json:"org_id"`
4848
License string `json:"license"`
49+
PluginID string `json:"plugin_id"`
4950
GrafanaURL string `json:"grafana_url"`
5051
GrafanaToken string `json:"grafana_token"`
5152
RBACEnabled bool `json:"rbac_enabled"`
@@ -71,6 +72,9 @@ func (a *OnCallPluginSettings) Equal(b *OnCallPluginSettings) bool {
7172
if a.License != b.License {
7273
return false
7374
}
75+
if a.PluginID != b.PluginID {
76+
return false
77+
}
7478
if a.GrafanaURL != b.GrafanaURL {
7579
return false
7680
}
@@ -127,6 +131,11 @@ func (a *App) OnCallSettingsFromContext(ctx context.Context) (*OnCallPluginSetti
127131
GrafanaURL: pluginSettingsJson.GrafanaURL,
128132
}
129133

134+
settings.PluginID = pluginContext.PluginID
135+
if settings.PluginID == "" {
136+
return nil, fmt.Errorf("OnCallSettingsFromContext: couldn't get plugin ID from plugin context")
137+
}
138+
130139
version := pluginContext.PluginVersion
131140
if version == "" {
132141
// older Grafana versions do not have the plugin version in the context
@@ -286,7 +295,7 @@ func (a *App) SaveOnCallSettings(settings *OnCallPluginSettings) error {
286295
return fmt.Errorf("Marshal OnCall settings JSON: %w", err)
287296
}
288297

289-
settingsUrl, err := url.JoinPath(settings.GrafanaURL, fmt.Sprintf("api/plugins/grafana-oncall-app/settings"))
298+
settingsUrl, err := url.JoinPath(settings.GrafanaURL, fmt.Sprintf("api/plugins/%s/settings", settings.PluginID))
290299
if err != nil {
291300
return err
292301
}

grafana-plugin/src/network/grafana-api/http-client.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { getBackendSrv } from '@grafana/runtime';
22
import { OnCallPluginMetaJSONData } from 'types';
33

4+
import { getPluginId } from 'utils/consts';
5+
46
import {
57
ApiAuthKeyDTO,
68
NewApiKeyResult,
@@ -14,7 +16,7 @@ const KEYS_BASE_URL = '/api/auth/keys';
1416
const SERVICE_ACCOUNTS_BASE_URL = '/api/serviceaccounts';
1517
const ONCALL_KEY_NAME = 'OnCall';
1618
const ONCALL_SERVICE_ACCOUNT_NAME = 'sa-autogen-OnCall';
17-
const GRAFANA_PLUGIN_SETTINGS_URL = '/api/plugins/grafana-oncall-app/settings';
19+
const GRAFANA_PLUGIN_SETTINGS_URL = `/api/plugins/${getPluginId()}/settings`;
1820

1921
export class GrafanaApiClient {
2022
static grafanaBackend = getBackendSrv();

grafana-plugin/src/utils/consts.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export const BREAKPOINT_TABS = 1024;
5050
// Default redirect page
5151
export const DEFAULT_PAGE = 'alert-groups';
5252

53-
export const PLUGIN_ID = 'grafana-oncall-app';
5453
export const PLUGIN_ROOT = `/a/${getPluginId()}`;
5554
export const PLUGIN_CONFIG = `/plugins/${getPluginId()}`;
5655

@@ -82,7 +81,7 @@ const getGrafanaSubUrl = () => {
8281

8382
export const getOnCallApiPath = (subpath = '') => {
8483
// We need to consider the grafanaSubUrl in case Grafana is served from subpath, e.g. http://localhost:3000/grafana
85-
return `${getGrafanaSubUrl()}/api/plugins/${PLUGIN_ID}/resources${subpath}`;
84+
return `${getGrafanaSubUrl()}/api/plugins/${getPluginId()}/resources${subpath}`;
8685
};
8786

8887
// Faro

grafana-plugin/src/utils/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { isArray, concat, every, isEmpty, isObject, isPlainObject, flatMap, map,
88

99
import { isNetworkError } from 'network/network';
1010

11-
import { CLOUD_VERSION_REGEX, PLUGIN_ID } from './consts';
11+
import { CLOUD_VERSION_REGEX, getPluginId } from './consts';
1212

1313
export class KeyValuePair<T = string | number> {
1414
key: T;
@@ -153,7 +153,7 @@ export const isCurrentGrafanaVersionEqualOrGreaterThan = ({
153153
);
154154
};
155155

156-
export const getIsRunningOpenSourceVersion = () => !CLOUD_VERSION_REGEX.test(config.apps[PLUGIN_ID]?.version);
156+
export const getIsRunningOpenSourceVersion = () => !CLOUD_VERSION_REGEX.test(config.apps[getPluginId()]?.version);
157157

158158
export const getIsExternalServiceAccountFeatureAvailable = () =>
159159
isCurrentGrafanaVersionEqualOrGreaterThan({ minMajor: 10, minMinor: 3 }) &&

0 commit comments

Comments
 (0)