grafana/public/app/features/admin/UserSessions.tsx
Alexander Zobnin 8505d90768 Admin: New Admin User page (#20498)
* admin: user page to react WIP

* admin user page: basic view

* admin user page: refactor, extract orgs and permissions components

* admin user: change sessions actions styles

* admin user: add disable button

* user admin: add change grafana admin action

* user admin: able to change org role and remove org

* user admin: confirm force logout

* user admin: change org button style

* user admin: add confirm modals for critical actions

* user admin: lock down ldap user info

* user admin: align with latest design changes

* user admin: add LDAP sync

* admin user: confirm button

* user admin: add to org modal

* user admin: fix ConfirmButton story

* admin user: handle grafana admin change

* ConfirmButton: make styled component

* ConfirmButton: completely styled component

* User Admin: permissions section refactor

* admin user: refactor (orgs and sessions)

* ConfirmButton: able to set confirm variant

* admin user: inline org removal

* admin user: show ldap sync info only for ldap users

* admin user: edit profile

* ConfirmButton: some fixes after review

* Chore: fix storybook build

* admin user: rename handlers

* admin user: remove LdapUserPage import from routes

* Chore: fix ConfirmButton tests

* Chore: fix user api endpoint tests

* Chore: update failed test snapshots

* admin user: redux actions WIP

* admin user: use new ConfirmModal component for user profile

* admin user: use new ConfirmModal component for sessions

* admin user: use lockMessage

* ConfirmButton: use primary button as default

* admin user: fix ActionButton color

* UI: use Icon component for Modal

* UI: refactor ConfirmModal after Modal changes

* UI: add link button variant

* UI: able to use custom ConfirmButton

* Chore: fix type errors after ConfirmButton refactor

* Chore: revert Graph component changes (works with TS 3.7)

* Chore: use Forms.Button instead of ActionButton

* admin user: align items

* admin user: align add to org modal

* UI: organization picker component

* admin user: use org picker for AddToOrgModal

* admin user: org actions

* admin user: connect sessions actions

* admin user: updateUserPermissions action

* admin user: enable delete user action

* admin user: sync ldap user

* Chore: refactor, remove unused code

* Chore: refactor, move api calls to actions

* admin user: set user password action

* Chore: refactor, remove unused components

* admin user: set input focus on edit

* admin user: pass user into debug LDAP mapping

* UserAdminPage: Ux changes

* UserAdminPage: align buttons to the left

* UserAdminPage: align delete user button

* UserAdminPage: swap add to org modal buttons

* UserAdminPage: set password field to empty when editing

* UserAdminPage: fix tests

* Updated button border

* Chore: fix ConfirmButton after changes introduced in #21092

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2020-01-13 17:10:19 +01:00

103 lines
3.1 KiB
TypeScript

import React, { PureComponent } from 'react';
import { css } from 'emotion';
import { ConfirmButton, ConfirmModal, Forms } from '@grafana/ui';
import { UserSession } from 'app/types';
interface Props {
sessions: UserSession[];
onSessionRevoke: (id: number) => void;
onAllSessionsRevoke: () => void;
}
interface State {
showLogoutModal: boolean;
}
export class UserSessions extends PureComponent<Props, State> {
state: State = {
showLogoutModal: false,
};
showLogoutConfirmationModal = (show: boolean) => () => {
this.setState({ showLogoutModal: show });
};
onSessionRevoke = (id: number) => {
return () => {
this.props.onSessionRevoke(id);
};
};
onAllSessionsRevoke = () => {
this.setState({ showLogoutModal: false });
this.props.onAllSessionsRevoke();
};
render() {
const { sessions } = this.props;
const { showLogoutModal } = this.state;
const logoutFromAllDevicesClass = css`
margin-top: 0.8rem;
`;
return (
<>
<h3 className="page-heading">Sessions</h3>
<div className="gf-form-group">
<div className="gf-form">
<table className="filter-table form-inline">
<thead>
<tr>
<th>Last seen</th>
<th>Logged on</th>
<th>IP address</th>
<th colSpan={2}>Browser &amp; OS</th>
</tr>
</thead>
<tbody>
{sessions &&
sessions.map((session, index) => (
<tr key={`${session.id}-${index}`}>
<td>{session.isActive ? 'Now' : session.seenAt}</td>
<td>{session.createdAt}</td>
<td>{session.clientIp}</td>
<td>{`${session.browser} on ${session.os} ${session.osVersion}`}</td>
<td>
<div className="pull-right">
<ConfirmButton
confirmText="Confirm logout"
confirmVariant="danger"
onConfirm={this.onSessionRevoke(session.id)}
>
Force logout
</ConfirmButton>
</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
<div className={logoutFromAllDevicesClass}>
{sessions.length > 0 && (
<Forms.Button variant="secondary" onClick={this.showLogoutConfirmationModal(true)}>
Force logout from all devices
</Forms.Button>
)}
<ConfirmModal
isOpen={showLogoutModal}
title="Force logout from all devices"
body="Are you sure you want to force logout from all devices?"
confirmText="Force logout"
onConfirm={this.onAllSessionsRevoke}
onDismiss={this.showLogoutConfirmationModal(false)}
/>
</div>
</div>
</>
);
}
}