diff --git a/public/app/features/admin/ldap/LdapDrawer.tsx b/public/app/features/admin/ldap/LdapDrawer.tsx index 53e1eb6a96f..e267abf1c15 100644 --- a/public/app/features/admin/ldap/LdapDrawer.tsx +++ b/public/app/features/admin/ldap/LdapDrawer.tsx @@ -5,6 +5,7 @@ import { useFormContext } from 'react-hook-form'; import { GrafanaTheme2, SelectableValue } from '@grafana/data'; import { useStyles2, + Button, CollapsableSection, Divider, Drawer, @@ -25,6 +26,8 @@ import { import { t, Trans } from 'app/core/internationalization'; import { LdapPayload, MapKeyCertConfigured } from 'app/types'; +import { GroupMappingComponent } from './LdapGroupMapping'; + interface Props { onClose: () => void; mapKeyCertConfigured: MapKeyCertConfigured; @@ -90,6 +93,23 @@ export const LdapDrawerComponent = ({ ); + const onAddGroupMapping = () => { + setValue(`${serverConfig}.group_mappings`, [ + ...getValues(`${serverConfig}.group_mappings`), + { + group_dn: '', + org_id: 1, + org_role: 'Viewer', + grafana_admin: false, + }, + ]); + }; + + const onRemoveGroupMapping = (index: number) => { + const groupMappings = getValues(`${serverConfig}.group_mappings`); + setValue(`${serverConfig}.group_mappings`, [...groupMappings.slice(0, index), ...groupMappings.slice(index + 1)]); + }; + return ( @@ -204,7 +224,13 @@ export const LdapDrawerComponent = ({ {...register(`${serverConfig}.group_search_filter_user_attribute`)} /> + {watch('settings.config.servers.0.group_mappings')?.map((_, i) => { + return onRemoveGroupMapping(i)} />; + })} + > = Object.keys(OrgRole).map((key) => { + return { label: key, value: key }; +}); + +interface GroupMappingProps { + onRemove: () => void; + groupMappingIndex: number; +} + +export const GroupMappingComponent = ({ groupMappingIndex, onRemove }: GroupMappingProps) => { + const { getValues, register, setValue } = useFormContext(); + return ( + + + + + + setValue(`settings.config.servers.0.group_mappings.${groupMappingIndex}.org_role`, v)} + /> + + + + + {contextSrv.isGrafanaAdmin && ( + + + + )} + + + ); +}; diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index 20bbe9e596d..ad59517f703 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -1045,7 +1045,30 @@ "use-ssl-label": "Use SSL", "use-ssl-tooltip": "For a complete list of supported ciphers and TLS versions, refer to: {\n \n https://go.dev/src/crypto/tls/cipher_suites.go\n }" }, + "group-mapping": { + "grafana-admin": { + "description": "If enabled, all users from this group will be Grafana Admins", + "label": "Grafana Admin" + }, + "group-dn": { + "description": "The name of the key used to extract the ID token from the returned OAuth2 token.", + "label": "Group DN" + }, + "org-id": { + "description": "The Grafana organization database id. Default org (ID 1) will be used if left out", + "label": "Org ID" + }, + "org-role": { + "label": "Org role *" + }, + "remove": { + "button": "Remove group mapping" + } + }, "group-mapping-section": { + "add": { + "button": "Add group mapping" + }, "description": "Map LDAP groups to Grafana org roles", "group-search-base-dns-description": "Separate by commas or spaces", "group-search-base-dns-label": "Group search base DNS", diff --git a/public/locales/pseudo-LOCALE/grafana.json b/public/locales/pseudo-LOCALE/grafana.json index e4a718a3cc9..7edc131b2ce 100644 --- a/public/locales/pseudo-LOCALE/grafana.json +++ b/public/locales/pseudo-LOCALE/grafana.json @@ -1045,7 +1045,30 @@ "use-ssl-label": "Ůşę ŜŜĿ", "use-ssl-tooltip": "Főř ä čőmpľęŧę ľįşŧ őƒ şūppőřŧęđ čįpĥęřş äʼnđ ŦĿŜ vęřşįőʼnş, řęƒęř ŧő: {\n <ŦęχŧĿįʼnĸ şŧyľę={{ fontSize: 'inherit' }} ĥřęƒ=\"ĥŧŧpş://ģő.đęv/şřč/čřypŧő/ŧľş/čįpĥęř_şūįŧęş.ģő\" ęχŧęřʼnäľ>\n ĥŧŧpş://ģő.đęv/şřč/čřypŧő/ŧľş/čįpĥęř_şūįŧęş.ģő\n }" }, + "group-mapping": { + "grafana-admin": { + "description": "Ĩƒ ęʼnäþľęđ, äľľ ūşęřş ƒřőm ŧĥįş ģřőūp ŵįľľ þę Ğřäƒäʼnä Åđmįʼnş", + "label": "Ğřäƒäʼnä Åđmįʼn" + }, + "group-dn": { + "description": "Ŧĥę ʼnämę őƒ ŧĥę ĸęy ūşęđ ŧő ęχŧřäčŧ ŧĥę ĨĐ ŧőĸęʼn ƒřőm ŧĥę řęŧūřʼnęđ ØÅūŧĥ2 ŧőĸęʼn.", + "label": "Ğřőūp ĐŃ" + }, + "org-id": { + "description": "Ŧĥę Ğřäƒäʼnä őřģäʼnįžäŧįőʼn đäŧäþäşę įđ. Đęƒäūľŧ őřģ (ĨĐ 1) ŵįľľ þę ūşęđ įƒ ľęƒŧ őūŧ", + "label": "Øřģ ĨĐ" + }, + "org-role": { + "label": "Øřģ řőľę *" + }, + "remove": { + "button": "Ŗęmővę ģřőūp mäppįʼnģ" + } + }, "group-mapping-section": { + "add": { + "button": "Åđđ ģřőūp mäppįʼnģ" + }, "description": "Mäp ĿĐÅP ģřőūpş ŧő Ğřäƒäʼnä őřģ řőľęş", "group-search-base-dns-description": "Ŝępäřäŧę þy čőmmäş őř şpäčęş", "group-search-base-dns-label": "Ğřőūp şęäřčĥ þäşę ĐŃŜ",