Проверка прав для импорта, измерений и аналитики

This commit is contained in:
Александр Сироткин 2022-02-08 19:19:00 +05:00
parent f3d4197e49
commit 437746a5d5
4 changed files with 15 additions and 8 deletions

View File

@ -18,6 +18,7 @@ import { View } from './View'
import '@styles/index.css' import '@styles/index.css'
import '@styles/measure.css' import '@styles/measure.css'
import { hasPermission } from '@asb/utils/permissions'
const createEditingColumns = (cols, renderDelegate) => const createEditingColumns = (cols, renderDelegate) =>
cols.map(col => ({ render: renderDelegate, ...col })) cols.map(col => ({ render: renderDelegate, ...col }))
@ -64,7 +65,9 @@ export const MeasureTable = memo(({idWell, group, updateMeasuresFunc, additional
'Удаление записи для скважины' 'Удаление записи для скважины'
) )
const isDataDefault = () => !!displayedValues?.isDefaultData const disabled = !hasPermission('Measure.edit')
const editingDisabled = disabled || !!displayedValues?.isDefaultData
const deleteDisabled = !hasPermission('Measure.delete') || !!displayedValues?.isDefaultData
const editTable = (action) => { const editTable = (action) => {
setEditingActionName(action) setEditingActionName(action)
@ -116,14 +119,14 @@ export const MeasureTable = memo(({idWell, group, updateMeasuresFunc, additional
</> </>
) : ( ) : (
<> <>
<Button key={'add'} className={'flex-1'} onClick={() => editTable('add')}> <Button key={'add'} className={'flex-1'} onClick={() => editTable('add')} disabled={disabled}>
<PlusOutlined /> <PlusOutlined />
</Button> </Button>
<Button key={'edit'} className={'flex-1'} onClick={() => editTable('edit')} disabled={isDataDefault()}> <Button key={'edit'} className={'flex-1'} onClick={() => editTable('edit')} disabled={editingDisabled}>
<EditOutlined /> <EditOutlined />
</Button> </Button>
<Popconfirm style={{ flex: '1' }} title={'Удалить данные?'} onConfirm={markMeasuresAsDeleted} disabled={isDataDefault()}> <Popconfirm style={{ flex: '1' }} title={'Удалить данные?'} onConfirm={markMeasuresAsDeleted} disabled={deleteDisabled}>
<Button key={'delete'} onClick={() => setEditingActionName('delete')} disabled={isDataDefault()}> <Button key={'delete'} onClick={() => setEditingActionName('delete')} disabled={deleteDisabled}>
<DeleteOutlined style={{ margin:'auto 28px' }}/> <DeleteOutlined style={{ margin:'auto 28px' }}/>
</Button> </Button>
</Popconfirm> </Popconfirm>

View File

@ -3,6 +3,7 @@ import { Button, Tooltip, Modal } from 'antd'
import { FileOutlined, ImportOutlined, ExportOutlined } from '@ant-design/icons' import { FileOutlined, ImportOutlined, ExportOutlined } from '@ant-design/icons'
import { download } from '@components/factory' import { download } from '@components/factory'
import { hasPermission } from '@utils/permissions'
import { ImportOperations } from './ImportOperations' import { ImportOperations } from './ImportOperations'
@ -23,7 +24,7 @@ export const ImportExportBar = memo(({ idWell, onImported, disabled }) => {
<> <>
<Tooltip title={'Импорт - загрузить файл с операциями на сервер'}> <Tooltip title={'Импорт - загрузить файл с операциями на сервер'}>
<Button <Button
disabled={disabled} disabled={!hasPermission('WellOperation.edit') || disabled}
icon={<ImportOutlined/>} icon={<ImportOutlined/>}
style={style} style={style}
onClick={() => setIsImportModalVisible(true)}/> onClick={() => setIsImportModalVisible(true)}/>

View File

@ -8,6 +8,7 @@ import LoaderPortal from '@components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { makeTextColumn, makeNumericColumnPlanFact } from '@components/Table' import { makeTextColumn, makeNumericColumnPlanFact } from '@components/Table'
import { DrillParamsService, WellCompositeService } from '@api' import { DrillParamsService, WellCompositeService } from '@api'
import { hasPermission } from '@utils/permissions'
import { import {
calcAndUpdateStatsBySections, calcAndUpdateStatsBySections,
@ -172,7 +173,7 @@ export const WellCompositeSections = memo(({ idWell, statsWells, selectedSection
const rowSelection = { const rowSelection = {
selectedRowKeys: selectedWellsKeys, selectedRowKeys: selectedWellsKeys,
onChange: (keys, items) => invokeWebApiWrapperAsync( onChange: (keys, items) => hasPermission('WellOperation.edit') && invokeWebApiWrapperAsync(
async () => { async () => {
const selectedSections = items.map((row) => ({idWell, idWellSrc: row.id, idWellSectionType: row.sectionId})) const selectedSections = items.map((row) => ({idWell, idWellSrc: row.id, idWellSectionType: row.sectionId}))
await WellCompositeService.save(idWell, selectedSections) await WellCompositeService.save(idWell, selectedSections)

View File

@ -8,6 +8,7 @@ import {
WellCompositeService, WellCompositeService,
} from '@api' } from '@api'
import { arrayOrDefault } from '@utils' import { arrayOrDefault } from '@utils'
import { hasPermission } from '@utils/permissions'
import LoaderPortal from '@components/LoaderPortal' import LoaderPortal from '@components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { PrivateDefaultRoute, PrivateMenuItemLink, PrivateRoute } from '@components/Private' import { PrivateDefaultRoute, PrivateMenuItemLink, PrivateRoute } from '@components/Private'
@ -103,6 +104,7 @@ export const WellCompositeEditor = memo(({ idWell }) => {
tagRender={(props) => ( tagRender={(props) => (
<Tag {...props}>{wellLabels[props.value] ?? props.label}</Tag> <Tag {...props}>{wellLabels[props.value] ?? props.label}</Tag>
)} )}
disabled={!hasPermission('WellOperation.edit')}
/> />
</Col> </Col>
<Col span={6}> <Col span={6}>