mirror of
https://github.com/grafana/grafana.git
synced 2025-01-27 16:57:14 -06:00
1e85a6f4fd
* First stab at new page layouts behind feature toggle * Simplifying PageHeader * Progress on a new model that can more easily support new and old page layouts * Progress * rename folder * Progress * Minor change * fixes * Fixing tests * Make breadcrumbs work * Add tests for old Page component * Adding tests for new Page component and behavior * fixing page header test * Fixed test * AppChrome outside route * Renaming folder * Minor fix * Updated * Fixing StoragePage * Fix for banners Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
184 lines
5.4 KiB
TypeScript
184 lines
5.4 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import { connect, ConnectedProps } from 'react-redux';
|
|
|
|
import { NavModel } from '@grafana/data';
|
|
import { featureEnabled } from '@grafana/runtime';
|
|
import { Page } from 'app/core/components/Page/Page';
|
|
import { contextSrv } from 'app/core/core';
|
|
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
|
import { getNavModel } from 'app/core/selectors/navModel';
|
|
import { StoreState, UserDTO, UserOrg, UserSession, SyncInfo, UserAdminError, AccessControlAction } from 'app/types';
|
|
|
|
import { UserLdapSyncInfo } from './UserLdapSyncInfo';
|
|
import { UserOrgs } from './UserOrgs';
|
|
import { UserPermissions } from './UserPermissions';
|
|
import { UserProfile } from './UserProfile';
|
|
import { UserSessions } from './UserSessions';
|
|
import {
|
|
loadAdminUserPage,
|
|
revokeSession,
|
|
revokeAllSessions,
|
|
updateUser,
|
|
setUserPassword,
|
|
disableUser,
|
|
enableUser,
|
|
deleteUser,
|
|
updateUserPermissions,
|
|
addOrgUser,
|
|
updateOrgUserRole,
|
|
deleteOrgUser,
|
|
syncLdapUser,
|
|
} from './state/actions';
|
|
|
|
interface OwnProps extends GrafanaRouteComponentProps<{ id: string }> {
|
|
navModel: NavModel;
|
|
user?: UserDTO;
|
|
orgs: UserOrg[];
|
|
sessions: UserSession[];
|
|
ldapSyncInfo?: SyncInfo;
|
|
isLoading: boolean;
|
|
error?: UserAdminError;
|
|
}
|
|
|
|
export class UserAdminPage extends PureComponent<Props> {
|
|
async componentDidMount() {
|
|
const { match, loadAdminUserPage } = this.props;
|
|
loadAdminUserPage(parseInt(match.params.id, 10));
|
|
}
|
|
|
|
onUserUpdate = (user: UserDTO) => {
|
|
this.props.updateUser(user);
|
|
};
|
|
|
|
onPasswordChange = (password: string) => {
|
|
const { user, setUserPassword } = this.props;
|
|
user && setUserPassword(user.id, password);
|
|
};
|
|
|
|
onUserDelete = (userId: number) => {
|
|
this.props.deleteUser(userId);
|
|
};
|
|
|
|
onUserDisable = (userId: number) => {
|
|
this.props.disableUser(userId);
|
|
};
|
|
|
|
onUserEnable = (userId: number) => {
|
|
this.props.enableUser(userId);
|
|
};
|
|
|
|
onGrafanaAdminChange = (isGrafanaAdmin: boolean) => {
|
|
const { user, updateUserPermissions } = this.props;
|
|
user && updateUserPermissions(user.id, isGrafanaAdmin);
|
|
};
|
|
|
|
onOrgRemove = (orgId: number) => {
|
|
const { user, deleteOrgUser } = this.props;
|
|
user && deleteOrgUser(user.id, orgId);
|
|
};
|
|
|
|
onOrgRoleChange = (orgId: number, newRole: string) => {
|
|
const { user, updateOrgUserRole } = this.props;
|
|
user && updateOrgUserRole(user.id, orgId, newRole);
|
|
};
|
|
|
|
onOrgAdd = (orgId: number, role: string) => {
|
|
const { user, addOrgUser } = this.props;
|
|
user && addOrgUser(user, orgId, role);
|
|
};
|
|
|
|
onSessionRevoke = (tokenId: number) => {
|
|
const { user, revokeSession } = this.props;
|
|
user && revokeSession(tokenId, user.id);
|
|
};
|
|
|
|
onAllSessionsRevoke = () => {
|
|
const { user, revokeAllSessions } = this.props;
|
|
user && revokeAllSessions(user.id);
|
|
};
|
|
|
|
onUserSync = () => {
|
|
const { user, syncLdapUser } = this.props;
|
|
user && syncLdapUser(user.id);
|
|
};
|
|
|
|
render() {
|
|
const { navModel, user, orgs, sessions, ldapSyncInfo, isLoading } = this.props;
|
|
const isLDAPUser = user && user.isExternal && user.authLabels && user.authLabels.includes('LDAP');
|
|
const canReadSessions = contextSrv.hasPermission(AccessControlAction.UsersAuthTokenList);
|
|
const canReadLDAPStatus = contextSrv.hasPermission(AccessControlAction.LDAPStatusRead);
|
|
|
|
return (
|
|
<Page navModel={navModel}>
|
|
<Page.Contents isLoading={isLoading}>
|
|
{user && (
|
|
<>
|
|
<UserProfile
|
|
user={user}
|
|
onUserUpdate={this.onUserUpdate}
|
|
onUserDelete={this.onUserDelete}
|
|
onUserDisable={this.onUserDisable}
|
|
onUserEnable={this.onUserEnable}
|
|
onPasswordChange={this.onPasswordChange}
|
|
/>
|
|
{isLDAPUser && featureEnabled('ldapsync') && ldapSyncInfo && canReadLDAPStatus && (
|
|
<UserLdapSyncInfo ldapSyncInfo={ldapSyncInfo} user={user} onUserSync={this.onUserSync} />
|
|
)}
|
|
<UserPermissions isGrafanaAdmin={user.isGrafanaAdmin} onGrafanaAdminChange={this.onGrafanaAdminChange} />
|
|
</>
|
|
)}
|
|
|
|
{orgs && (
|
|
<UserOrgs
|
|
user={user}
|
|
orgs={orgs}
|
|
isExternalUser={user?.isExternal}
|
|
onOrgRemove={this.onOrgRemove}
|
|
onOrgRoleChange={this.onOrgRoleChange}
|
|
onOrgAdd={this.onOrgAdd}
|
|
/>
|
|
)}
|
|
|
|
{sessions && canReadSessions && (
|
|
<UserSessions
|
|
sessions={sessions}
|
|
onSessionRevoke={this.onSessionRevoke}
|
|
onAllSessionsRevoke={this.onAllSessionsRevoke}
|
|
/>
|
|
)}
|
|
</Page.Contents>
|
|
</Page>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = (state: StoreState) => ({
|
|
navModel: getNavModel(state.navIndex, 'global-users'),
|
|
user: state.userAdmin.user,
|
|
sessions: state.userAdmin.sessions,
|
|
orgs: state.userAdmin.orgs,
|
|
ldapSyncInfo: state.ldap.syncInfo,
|
|
isLoading: state.userAdmin.isLoading,
|
|
error: state.userAdmin.error,
|
|
});
|
|
|
|
const mapDispatchToProps = {
|
|
loadAdminUserPage,
|
|
updateUser,
|
|
setUserPassword,
|
|
disableUser,
|
|
enableUser,
|
|
deleteUser,
|
|
updateUserPermissions,
|
|
addOrgUser,
|
|
updateOrgUserRole,
|
|
deleteOrgUser,
|
|
revokeSession,
|
|
revokeAllSessions,
|
|
syncLdapUser,
|
|
};
|
|
|
|
const connector = connect(mapStateToProps, mapDispatchToProps);
|
|
type Props = OwnProps & ConnectedProps<typeof connector>;
|
|
export default connector(UserAdminPage);
|