mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
e3e2cd82d7
* rewrite user profile edit to react (#17525) * disableLogin change, still need to fix tooltip * left out disable form for other auth * PR changes - wrapper to render, userId instead of bool, optional user in state, change provider child param order * moved directive to angular_wrappers * catch api error * finally * move user arg back to end- optional * optional type sig
95 lines
2.5 KiB
TypeScript
95 lines
2.5 KiB
TypeScript
import config from 'app/core/config';
|
|
import { coreModule, NavModelSrv } from 'app/core/core';
|
|
import { dateTime } from '@grafana/data';
|
|
import { UserSession } from 'app/types';
|
|
import { BackendSrv } from 'app/core/services/backend_srv';
|
|
|
|
export class ProfileCtrl {
|
|
user: any;
|
|
oldTheme: any;
|
|
teams: any = [];
|
|
orgs: any = [];
|
|
sessions: object[] = [];
|
|
userForm: any;
|
|
showTeamsList = false;
|
|
showOrgsList = false;
|
|
readonlyLoginFields = config.disableLoginForm;
|
|
navModel: any;
|
|
|
|
/** @ngInject */
|
|
constructor(private backendSrv: BackendSrv, navModelSrv: NavModelSrv) {
|
|
this.getUserSessions();
|
|
this.getUserTeams();
|
|
this.getUserOrgs();
|
|
this.navModel = navModelSrv.getNav('profile', 'profile-settings', 0);
|
|
}
|
|
|
|
getUserSessions() {
|
|
this.backendSrv.get('/api/user/auth-tokens').then((sessions: UserSession[]) => {
|
|
sessions.reverse();
|
|
|
|
const found = sessions.findIndex((session: UserSession) => {
|
|
return session.isActive;
|
|
});
|
|
|
|
if (found) {
|
|
const now = sessions[found];
|
|
sessions.splice(found, found);
|
|
sessions.unshift(now);
|
|
}
|
|
|
|
this.sessions = sessions.map((session: UserSession) => {
|
|
return {
|
|
id: session.id,
|
|
isActive: session.isActive,
|
|
seenAt: dateTime(session.seenAt).fromNow(),
|
|
createdAt: dateTime(session.createdAt).format('MMMM DD, YYYY'),
|
|
clientIp: session.clientIp,
|
|
browser: session.browser,
|
|
browserVersion: session.browserVersion,
|
|
os: session.os,
|
|
osVersion: session.osVersion,
|
|
device: session.device,
|
|
};
|
|
});
|
|
});
|
|
}
|
|
|
|
revokeUserSession(tokenId: number) {
|
|
this.backendSrv
|
|
.post('/api/user/revoke-auth-token', {
|
|
authTokenId: tokenId,
|
|
})
|
|
.then(() => {
|
|
this.sessions = this.sessions.filter((session: UserSession) => {
|
|
if (session.id === tokenId) {
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
});
|
|
}
|
|
|
|
getUserTeams() {
|
|
this.backendSrv.get('/api/user/teams').then((teams: any) => {
|
|
this.teams = teams;
|
|
this.showTeamsList = this.teams.length > 0;
|
|
});
|
|
}
|
|
|
|
getUserOrgs() {
|
|
this.backendSrv.get('/api/user/orgs').then((orgs: any) => {
|
|
this.orgs = orgs;
|
|
this.showOrgsList = orgs.length > 1;
|
|
});
|
|
}
|
|
|
|
setUsingOrg(org: any) {
|
|
this.backendSrv.post('/api/user/using/' + org.orgId).then(() => {
|
|
window.location.href = config.appSubUrl + '/profile';
|
|
});
|
|
}
|
|
}
|
|
|
|
coreModule.controller('ProfileCtrl', ProfileCtrl);
|