mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AccessControl: Refactor addAccessControlQueryParam
(#44191)
Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
This commit is contained in:
parent
99cdb56f72
commit
ba839d1f7c
@ -1,9 +1,9 @@
|
||||
import config from '../../core/config';
|
||||
|
||||
// addAccessControlQueryParam appends ?accesscontrol=true to a url when accesscontrol is enabled
|
||||
export function addAccessControlQueryParam(url: string): string {
|
||||
// accessControlQueryParam adds an additional accesscontrol=true param to params when accesscontrol is enabled
|
||||
export function accessControlQueryParam(params = {}) {
|
||||
if (!config.featureToggles['accesscontrol']) {
|
||||
return url;
|
||||
return params;
|
||||
}
|
||||
return url + '?accesscontrol=true';
|
||||
return { ...params, accesscontrol: true };
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import {
|
||||
} from './reducers';
|
||||
import { debounce } from 'lodash';
|
||||
import { contextSrv } from 'app/core/core';
|
||||
import { addAccessControlQueryParam } from 'app/core/utils/accessControl';
|
||||
import { accessControlQueryParam } from 'app/core/utils/accessControl';
|
||||
// UserAdminPage
|
||||
|
||||
export function loadAdminUserPage(userId: number): ThunkResult<void> {
|
||||
@ -54,7 +54,7 @@ export function loadAdminUserPage(userId: number): ThunkResult<void> {
|
||||
|
||||
export function loadUserProfile(userId: number): ThunkResult<void> {
|
||||
return async (dispatch) => {
|
||||
const user = await getBackendSrv().get(addAccessControlQueryParam(`/api/users/${userId}`));
|
||||
const user = await getBackendSrv().get(`/api/users/${userId}`, accessControlQueryParam());
|
||||
dispatch(userProfileLoadedAction(user));
|
||||
};
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import {
|
||||
testDataSourceSucceeded,
|
||||
} from './reducers';
|
||||
import { getDataSource, getDataSourceMeta } from './selectors';
|
||||
import { addAccessControlQueryParam } from 'app/core/utils/accessControl';
|
||||
import { accessControlQueryParam } from 'app/core/utils/accessControl';
|
||||
|
||||
export interface DataSourceTypesLoadedPayload {
|
||||
plugins: DataSourcePluginMeta[];
|
||||
@ -155,7 +155,8 @@ export async function getDataSourceUsingUidOrId(uid: string | number): Promise<D
|
||||
const byUid = await lastValueFrom(
|
||||
getBackendSrv().fetch<DataSourceSettings>({
|
||||
method: 'GET',
|
||||
url: addAccessControlQueryParam(`/api/datasources/uid/${uid}`),
|
||||
url: `/api/datasources/uid/${uid}`,
|
||||
params: accessControlQueryParam(),
|
||||
showErrorAlert: false,
|
||||
})
|
||||
);
|
||||
@ -173,7 +174,8 @@ export async function getDataSourceUsingUidOrId(uid: string | number): Promise<D
|
||||
const response = await lastValueFrom(
|
||||
getBackendSrv().fetch<DataSourceSettings>({
|
||||
method: 'GET',
|
||||
url: addAccessControlQueryParam(`/api/datasources/${id}`),
|
||||
url: `/api/datasources/${id}`,
|
||||
params: accessControlQueryParam(),
|
||||
showErrorAlert: false,
|
||||
})
|
||||
);
|
||||
|
@ -3,11 +3,11 @@ import { getBackendSrv } from '@grafana/runtime';
|
||||
import { OrgUser } from 'app/types';
|
||||
import { inviteesLoaded, usersLoaded } from './reducers';
|
||||
import { contextSrv } from 'app/core/core';
|
||||
import { addAccessControlQueryParam } from 'app/core/utils/accessControl';
|
||||
import { accessControlQueryParam } from 'app/core/utils/accessControl';
|
||||
|
||||
export function loadUsers(): ThunkResult<void> {
|
||||
return async (dispatch) => {
|
||||
const users = await getBackendSrv().get(addAccessControlQueryParam('/api/org/users'));
|
||||
const users = await getBackendSrv().get('/api/org/users', accessControlQueryParam());
|
||||
dispatch(usersLoaded(users));
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user