grafana/public/app/features/admin/UserLdapSyncInfo.tsx
Alexander Zobnin a7e721e987
Access control: Make Admin/Users UI working with the permissions (#33176)
* API: authorize admin/users views

* Render admin/users components based on user's permissions

* Add LDAP permissions (required by admin/user page)

* Extend default admin role by LDAP permissions

* Show/hide LDAP debug views

* Render LDAP debug page if user has access

* Authorize LDAP debug view

* fix permissions definitions

* Add LDAP page permissions

* remove ambiguous permissions check

* Hide logout buttons in sessions table

* Add org/users permissions

* Use org permissions for managing user roles in orgs

* Apply permissions to org/users

* Apply suggestions from review

* Fix tests

* remove scopes from the frontend

* Tweaks according to review

* Handle /invites endpoints
2021-04-22 13:19:41 +03:00

78 lines
2.5 KiB
TypeScript

import React, { PureComponent } from 'react';
import { dateTimeFormat } from '@grafana/data';
import { AccessControlAction, SyncInfo, UserDTO } from 'app/types';
import { Button, LinkButton } from '@grafana/ui';
import { contextSrv } from 'app/core/core';
interface Props {
ldapSyncInfo: SyncInfo;
user: UserDTO;
onUserSync: () => void;
}
interface State {}
const format = 'dddd YYYY-MM-DD HH:mm zz';
const debugLDAPMappingBaseURL = '/admin/ldap';
export class UserLdapSyncInfo extends PureComponent<Props, State> {
onUserSync = () => {
this.props.onUserSync();
};
render() {
const { ldapSyncInfo, user } = this.props;
const nextSyncSuccessful = ldapSyncInfo && ldapSyncInfo.nextSync;
const nextSyncTime = nextSyncSuccessful ? dateTimeFormat(ldapSyncInfo.nextSync, { format }) : '';
const debugLDAPMappingURL = `${debugLDAPMappingBaseURL}?user=${user && user.login}`;
const canReadLDAPUser = contextSrv.hasPermission(AccessControlAction.LDAPUsersRead);
const canSyncLDAPUser = contextSrv.hasPermission(AccessControlAction.LDAPUsersSync);
return (
<>
<h3 className="page-heading">LDAP Synchronisation</h3>
<div className="gf-form-group">
<div className="gf-form">
<table className="filter-table form-inline">
<tbody>
<tr>
<td>External sync</td>
<td>User synced via LDAP. Some changes must be done in LDAP or mappings.</td>
<td>
<span className="label label-tag">LDAP</span>
</td>
</tr>
<tr>
{ldapSyncInfo.enabled ? (
<>
<td>Next scheduled synchronization</td>
<td colSpan={2}>{nextSyncTime}</td>
</>
) : (
<>
<td>Next scheduled synchronization</td>
<td colSpan={2}>Not enabled</td>
</>
)}
</tr>
</tbody>
</table>
</div>
<div className="gf-form-button-row">
{canSyncLDAPUser && (
<Button variant="secondary" onClick={this.onUserSync}>
Sync user
</Button>
)}
{canReadLDAPUser && (
<LinkButton variant="secondary" href={debugLDAPMappingURL}>
Debug LDAP Mapping
</LinkButton>
)}
</div>
</div>
</>
);
}
}