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ACE,aAAW,OACXjC,MAAOiC,EAAKN,KACZZ,UAAWnC,EAAAA,GAAAA,wBAAmCC,EAAAA,GAAAA,cAAmCoD,GACjF+B,SAAWD,GAAYrC,EAAaqC,EAAS9B,OAKlDrD,EAAAA,GAAAA,wBAAmCC,EAAAA,GAAAA,eAAoCoD,KACtE,yBACE,SAAC,EAAAf,OAAD,CACE+C,KAAK,KACLC,QAAQ,cACRC,QAAS,KACP3B,EAAgBP,IAElBmC,KAAK,QACL,aAAW,oBApDT,GAAEnC,EAAKH,UAAUwB,YA6DlCe,QAAQ9B,KACP,SAAC,EAAA+B,aAAD,CACEC,KAAO,wCAAuChC,MAAAA,OAAxC,EAAwCA,EAAcmB,SAC5Dc,YAAY,SACZhD,MAAM,SACNiD,UAAW,KACTjC,EAAgB,OAElBkC,QAAQ,EACRC,UAAW,KACJpC,IAGLL,EAAaK,GACbC,EAAgB","sources":["webpack://grafana/./public/app/features/admin/AdminEditOrgPage.tsx","webpack://grafana/./public/app/features/users/UsersTable.tsx"],"sourcesContent":["import { css } from '@emotion/css';\nimport React, { useState, useEffect } from 'react';\nimport { useSelector } from 'react-redux';\nimport { useAsyncFn } from 'react-use';\n\nimport { UrlQueryValue } from '@grafana/data';\nimport { getBackendSrv } from '@grafana/runtime';\nimport { Form, Field, Input, Button, Legend, Alert } from '@grafana/ui';\nimport Page from 'app/core/components/Page/Page';\nimport { contextSrv } from 'app/core/core';\nimport { GrafanaRouteComponentProps } from 'app/core/navigation/types';\nimport { getNavModel } from 'app/core/selectors/navModel';\nimport { accessControlQueryParam } from 'app/core/utils/accessControl';\nimport { StoreState, OrgUser, AccessControlAction } from 'app/types';\n\nimport UsersTable from '../users/UsersTable';\n\ninterface OrgNameDTO {\n orgName: string;\n}\n\nconst getOrg = async (orgId: UrlQueryValue) => {\n return await getBackendSrv().get('/api/orgs/' + orgId);\n};\n\nconst getOrgUsers = async (orgId: UrlQueryValue) => {\n if (contextSrv.hasPermission(AccessControlAction.OrgUsersRead)) {\n return await getBackendSrv().get(`/api/orgs/${orgId}/users`, accessControlQueryParam());\n }\n return [];\n};\n\nconst updateOrgUserRole = async (orgUser: OrgUser, orgId: UrlQueryValue) => {\n await getBackendSrv().patch('/api/orgs/' + orgId + '/users/' + orgUser.userId, orgUser);\n};\n\nconst removeOrgUser = async (orgUser: OrgUser, orgId: UrlQueryValue) => {\n return await getBackendSrv().delete('/api/orgs/' + orgId + '/users/' + orgUser.userId);\n};\n\ninterface Props extends GrafanaRouteComponentProps<{ id: string }> {}\n\nexport default function AdminEditOrgPage({ match }: Props) {\n const navIndex = useSelector((state: StoreState) => state.navIndex);\n const navModel = getNavModel(navIndex, 'global-orgs');\n const orgId = parseInt(match.params.id, 10);\n const canWriteOrg = contextSrv.hasPermission(AccessControlAction.OrgsWrite);\n const canReadUsers = contextSrv.hasPermission(AccessControlAction.OrgUsersRead);\n\n const [users, setUsers] = useState([]);\n\n const [orgState, fetchOrg] = useAsyncFn(() => getOrg(orgId), []);\n const [, fetchOrgUsers] = useAsyncFn(() => getOrgUsers(orgId), []);\n\n useEffect(() => {\n fetchOrg();\n fetchOrgUsers().then((res) => setUsers(res));\n }, [fetchOrg, fetchOrgUsers]);\n\n const updateOrgName = async (name: string) => {\n return await getBackendSrv().put('/api/orgs/' + orgId, { ...orgState.value, name });\n };\n\n const renderMissingUserListRightsMessage = () => {\n return (\n \n You do not have permission to see users in this organization. To update this organization, contact your server\n administrator.\n \n );\n };\n\n return (\n \n \n <>\n Edit organization\n {orgState.value && (\n await updateOrgName(values.orgName)}\n >\n {({ register, errors }) => (\n <>\n \n \n \n \n \n )}\n \n )}\n\n \n Organization users\n {!canReadUsers && renderMissingUserListRightsMessage()}\n {canReadUsers && !!users.length && (\n {\n updateOrgUserRole({ ...orgUser, role }, orgId);\n setUsers(\n users.map((user) => {\n if (orgUser.userId === user.userId) {\n return { ...orgUser, role };\n }\n return user;\n })\n );\n fetchOrgUsers();\n }}\n onRemoveUser={(orgUser) => {\n removeOrgUser(orgUser, orgId);\n setUsers(users.filter((user) => orgUser.userId !== user.userId));\n fetchOrgUsers();\n }}\n />\n )}\n \n \n \n \n );\n}\n","import React, { FC, useEffect, useState } from 'react';\n\nimport { OrgRole } from '@grafana/data';\nimport { Button, ConfirmModal } from '@grafana/ui';\nimport { UserRolePicker } from 'app/core/components/RolePicker/UserRolePicker';\nimport { fetchBuiltinRoles, fetchRoleOptions } from 'app/core/components/RolePicker/api';\nimport { contextSrv } from 'app/core/core';\nimport { AccessControlAction, OrgUser, Role } from 'app/types';\n\nimport { OrgRolePicker } from '../admin/OrgRolePicker';\n\nexport interface Props {\n users: OrgUser[];\n orgId?: number;\n onRoleChange: (role: OrgRole, user: OrgUser) => void;\n onRemoveUser: (user: OrgUser) => void;\n}\n\nconst UsersTable: FC = (props) => {\n const { users, orgId, onRoleChange, onRemoveUser } = props;\n const [userToRemove, setUserToRemove] = useState(null);\n const [roleOptions, setRoleOptions] = useState([]);\n const [builtinRoles, setBuiltinRoles] = useState<{ [key: string]: Role[] }>({});\n\n useEffect(() => {\n async function fetchOptions() {\n try {\n if (contextSrv.hasPermission(AccessControlAction.ActionRolesList)) {\n let options = await fetchRoleOptions(orgId);\n setRoleOptions(options);\n }\n\n if (\n contextSrv.accessControlBuiltInRoleAssignmentEnabled() &&\n contextSrv.hasPermission(AccessControlAction.ActionBuiltinRolesList)\n ) {\n const builtInRoles = await fetchBuiltinRoles(orgId);\n setBuiltinRoles(builtInRoles);\n }\n } catch (e) {\n console.error('Error loading options');\n }\n }\n if (contextSrv.licensedAccessControlEnabled()) {\n fetchOptions();\n }\n }, [orgId]);\n\n return (\n <>\n \n \n \n \n \n \n \n \n \n \n \n {users.map((user, index) => {\n return (\n \n \n \n\n \n \n \n\n \n\n {contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersRemove, user) && (\n \n )}\n \n );\n })}\n \n
\n LoginEmailNameSeenRole\n
\n \"User\n \n \n {user.login}\n \n \n \n {user.email}\n \n \n \n {user.name}\n \n {user.lastSeenAtAge}\n {contextSrv.licensedAccessControlEnabled() ? (\n onRoleChange(newRole, user)}\n roleOptions={roleOptions}\n builtInRoles={builtinRoles}\n disabled={!contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersWrite, user)}\n />\n ) : (\n onRoleChange(newRole, user)}\n />\n )}\n \n {\n setUserToRemove(user);\n }}\n icon=\"times\"\n aria-label=\"Delete user\"\n />\n
\n {Boolean(userToRemove) && (\n {\n setUserToRemove(null);\n }}\n isOpen={true}\n onConfirm={() => {\n if (!userToRemove) {\n return;\n }\n onRemoveUser(userToRemove);\n setUserToRemove(null);\n }}\n />\n )}\n \n );\n};\n\nexport default UsersTable;\n"],"names":["AdminEditOrgPage","match","navIndex","useSelector","state","navModel","getNavModel","orgId","parseInt","params","id","canWriteOrg","contextSrv","AccessControlAction","canReadUsers","users","setUsers","useState","orgState","fetchOrg","useAsyncFn","async","getBackendSrv","get","getOrg","fetchOrgUsers","accessControlQueryParam","getOrgUsers","useEffect","then","res","Legend","value","Form","defaultValues","orgName","name","onSubmit","put","updateOrgName","values","register","errors","Field","label","invalid","error","disabled","Input","required","Button","type","className","css","Alert","severity","title","length","onRoleChange","role","orgUser","patch","userId","updateOrgUserRole","map","user","onRemoveUser","delete","removeOrgUser","filter","props","userToRemove","setUserToRemove","roleOptions","setRoleOptions","builtinRoles","setBuiltinRoles","options","fetchRoleOptions","builtInRoles","fetchBuiltinRoles","e","console","fetchOptions","style","width","index","src","avatarUrl","alt","login","email","lastSeenAtAge","builtInRole","onBuiltinRoleChange","newRole","onChange","size","variant","onClick","icon","Boolean","ConfirmModal","body","confirmText","onDismiss","isOpen","onConfirm"],"sourceRoot":""}