mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 16:45:43 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import { getBackendSrv } from '@grafana/runtime';
|
|
|
|
import { Team, UserDTO, UserOrg, UserSession } from '../../types';
|
|
|
|
import { ChangePasswordFields, ProfileUpdateFields } from './types';
|
|
|
|
async function changePassword(payload: ChangePasswordFields): Promise<void> {
|
|
try {
|
|
await getBackendSrv().put('/api/user/password', payload);
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
function loadUser(): Promise<UserDTO> {
|
|
return getBackendSrv().get('/api/user');
|
|
}
|
|
|
|
function loadTeams(): Promise<Team[]> {
|
|
return getBackendSrv().get('/api/user/teams');
|
|
}
|
|
|
|
function loadOrgs(): Promise<UserOrg[]> {
|
|
return getBackendSrv().get('/api/user/orgs');
|
|
}
|
|
|
|
function loadSessions(): Promise<UserSession[]> {
|
|
return getBackendSrv().get('/api/user/auth-tokens');
|
|
}
|
|
|
|
async function revokeUserSession(tokenId: number): Promise<void> {
|
|
await getBackendSrv().post('/api/user/revoke-auth-token', {
|
|
authTokenId: tokenId,
|
|
});
|
|
}
|
|
|
|
async function setUserOrg(org: UserOrg): Promise<void> {
|
|
await getBackendSrv().post('/api/user/using/' + org.orgId, {});
|
|
}
|
|
|
|
async function updateUserProfile(payload: ProfileUpdateFields): Promise<void> {
|
|
try {
|
|
await getBackendSrv().put('/api/user', payload);
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
export const api = {
|
|
changePassword,
|
|
revokeUserSession,
|
|
loadUser,
|
|
loadSessions,
|
|
loadOrgs,
|
|
loadTeams,
|
|
setUserOrg,
|
|
updateUserProfile,
|
|
};
|