UserLdapSyncInfo.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React, { PureComponent } from 'react';
  2. import { dateTimeFormat } from '@grafana/data';
  3. import { Button, LinkButton } from '@grafana/ui';
  4. import { contextSrv } from 'app/core/core';
  5. import { AccessControlAction, SyncInfo, UserDTO } from 'app/types';
  6. interface Props {
  7. ldapSyncInfo: SyncInfo;
  8. user: UserDTO;
  9. onUserSync: () => void;
  10. }
  11. interface State {}
  12. const format = 'dddd YYYY-MM-DD HH:mm zz';
  13. const debugLDAPMappingBaseURL = '/admin/ldap';
  14. export class UserLdapSyncInfo extends PureComponent<Props, State> {
  15. onUserSync = () => {
  16. this.props.onUserSync();
  17. };
  18. render() {
  19. const { ldapSyncInfo, user } = this.props;
  20. const nextSyncSuccessful = ldapSyncInfo && ldapSyncInfo.nextSync;
  21. const nextSyncTime = nextSyncSuccessful ? dateTimeFormat(ldapSyncInfo.nextSync, { format }) : '';
  22. const debugLDAPMappingURL = `${debugLDAPMappingBaseURL}?user=${user && user.login}`;
  23. const canReadLDAPUser = contextSrv.hasPermission(AccessControlAction.LDAPUsersRead);
  24. const canSyncLDAPUser = contextSrv.hasPermission(AccessControlAction.LDAPUsersSync);
  25. return (
  26. <>
  27. <h3 className="page-heading">LDAP Synchronisation</h3>
  28. <div className="gf-form-group">
  29. <div className="gf-form">
  30. <table className="filter-table form-inline">
  31. <tbody>
  32. <tr>
  33. <td>External sync</td>
  34. <td>User synced via LDAP. Some changes must be done in LDAP or mappings.</td>
  35. <td>
  36. <span className="label label-tag">LDAP</span>
  37. </td>
  38. </tr>
  39. <tr>
  40. {ldapSyncInfo.enabled ? (
  41. <>
  42. <td>Next scheduled synchronization</td>
  43. <td colSpan={2}>{nextSyncTime}</td>
  44. </>
  45. ) : (
  46. <>
  47. <td>Next scheduled synchronization</td>
  48. <td colSpan={2}>Not enabled</td>
  49. </>
  50. )}
  51. </tr>
  52. </tbody>
  53. </table>
  54. </div>
  55. <div className="gf-form-button-row">
  56. {canSyncLDAPUser && (
  57. <Button variant="secondary" onClick={this.onUserSync}>
  58. Sync user
  59. </Button>
  60. )}
  61. {canReadLDAPUser && (
  62. <LinkButton variant="secondary" href={debugLDAPMappingURL}>
  63. Debug LDAP Mapping
  64. </LinkButton>
  65. )}
  66. </div>
  67. </div>
  68. </>
  69. );
  70. }
  71. }