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CC,EAAAA,GAAAA,cAAmCoD,MAGnF,SAAC,IAAD,CACE,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<OrgUser[]>([]);\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 <Alert severity=\"info\" title=\"Access denied\">\n You do not have permission to see users in this organization. To update this organization, contact your server\n administrator.\n </Alert>\n );\n };\n\n return (\n <Page navModel={navModel}>\n <Page.Contents>\n <>\n <Legend>Edit organization</Legend>\n {orgState.value && (\n <Form\n defaultValues={{ orgName: orgState.value.name }}\n onSubmit={async (values: OrgNameDTO) => await updateOrgName(values.orgName)}\n >\n {({ register, errors }) => (\n <>\n <Field label=\"Name\" invalid={!!errors.orgName} error=\"Name is required\" disabled={!canWriteOrg}>\n <Input {...register('orgName', { required: true })} id=\"org-name-input\" />\n </Field>\n <Button type=\"submit\" disabled={!canWriteOrg}>\n Update\n </Button>\n </>\n )}\n </Form>\n )}\n\n <div\n className={css`\n margin-top: 20px;\n `}\n >\n <Legend>Organization users</Legend>\n {!canReadUsers && renderMissingUserListRightsMessage()}\n {canReadUsers && !!users.length && (\n <UsersTable\n users={users}\n orgId={orgId}\n onRoleChange={(role, orgUser) => {\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 </div>\n </>\n </Page.Contents>\n </Page>\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> = (props) => {\n const { users, orgId, onRoleChange, onRemoveUser } = props;\n const [userToRemove, setUserToRemove] = useState<OrgUser | null>(null);\n const [roleOptions, setRoleOptions] = useState<Role[]>([]);\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 <table className=\"filter-table form-inline\">\n <thead>\n <tr>\n <th />\n <th>Login</th>\n <th>Email</th>\n <th>Name</th>\n <th>Seen</th>\n <th>Role</th>\n <th style={{ width: '34px' }} />\n </tr>\n </thead>\n <tbody>\n {users.map((user, index) => {\n return (\n <tr key={`${user.userId}-${index}`}>\n <td className=\"width-2 text-center\">\n <img className=\"filter-table__avatar\" src={user.avatarUrl} alt=\"User avatar\" />\n </td>\n <td className=\"max-width-6\">\n <span className=\"ellipsis\" title={user.login}>\n {user.login}\n </span>\n </td>\n\n <td className=\"max-width-5\">\n <span className=\"ellipsis\" title={user.email}>\n {user.email}\n </span>\n </td>\n <td className=\"max-width-5\">\n <span className=\"ellipsis\" title={user.name}>\n {user.name}\n </span>\n </td>\n <td className=\"width-1\">{user.lastSeenAtAge}</td>\n\n <td className=\"width-8\">\n {contextSrv.licensedAccessControlEnabled() ? (\n <UserRolePicker\n userId={user.userId}\n orgId={orgId}\n builtInRole={user.role}\n onBuiltinRoleChange={(newRole) => onRoleChange(newRole, user)}\n roleOptions={roleOptions}\n builtInRoles={builtinRoles}\n disabled={!contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersWrite, user)}\n />\n ) : (\n <OrgRolePicker\n aria-label=\"Role\"\n value={user.role}\n disabled={!contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersWrite, user)}\n onChange={(newRole) => onRoleChange(newRole, user)}\n />\n )}\n </td>\n\n {contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersRemove, user) && (\n <td>\n <Button\n size=\"sm\"\n variant=\"destructive\"\n onClick={() => {\n setUserToRemove(user);\n }}\n icon=\"times\"\n aria-label=\"Delete user\"\n />\n </td>\n )}\n </tr>\n );\n })}\n </tbody>\n </table>\n {Boolean(userToRemove) && (\n <ConfirmModal\n body={`Are you sure you want to delete user ${userToRemove?.login}?`}\n confirmText=\"Delete\"\n title=\"Delete\"\n onDismiss={() => {\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":""}