Добавлена доп проверка на права для dev билда

This commit is contained in:
goodmice 2022-06-02 14:45:28 +05:00
parent cdfbc2d25a
commit 26a288c3de
5 changed files with 16 additions and 8 deletions

View File

@ -1,8 +1,10 @@
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
import { Upload, Button } from 'antd'
import { UploadOutlined } from '@ant-design/icons'
import { UploadFile } from 'antd/lib/upload/interface'
import { UploadOutlined } from '@ant-design/icons'
import { RcFile } from 'antd/lib/upload'
import { Upload, Button } from 'antd'
import { isDev } from '@utils'
import { notify, upload } from './factory'
import { ErrorFetch } from './ErrorFetch'
@ -53,7 +55,7 @@ export const UploadForm = memo<UploadFormProps>(({ url, disabled, style, formDat
onUploadSuccess?.()
}
} catch(error) {
if(process.env.NODE_ENV === 'development')
if(isDev())
console.error(error)
onUploadError?.(error)
} finally {

View File

@ -1,8 +1,9 @@
import { notification } from 'antd'
import { Dispatch, ReactNode, SetStateAction } from 'react'
import { ApiError, FileInfoDto } from '@api'
import { isDev } from '@utils'
import { getUserToken } from '@utils/storage'
import { ApiError, FileInfoDto } from '@api'
const notificationTypeDictionary = new Map([
['error' , { notifyInstance: notification.error , caption: 'Ошибка' }],
@ -45,7 +46,7 @@ export const invokeWebApiWrapperAsync = async (
try{
await funcAsync()
} catch (ex) {
if(process.env.NODE_ENV === 'development')
if(isDev())
console.error(ex)
if (ex instanceof ApiError && ex.status === 403) {
if (actionName)

View File

@ -1,6 +1,8 @@
import { getUserToken } from '@asb/utils/storage'
import { HubConnection, HubConnectionBuilder, HubConnectionState } from '@microsoft/signalr'
import { getUserToken } from '@utils/storage'
import { isDev } from '@utils'
// SignalR js api:
//https://docs.microsoft.com/ru-ru/javascript/api/@aspnet/signalr/?view=signalr-js-latest
@ -12,7 +14,7 @@ const ConnectionOptions = {
type ConnectionsDict = Record<string, HubConnection>
//var baseUrl = `http://192.168.1.70:5000`
const baseUrl = process.env.NODE_ENV === 'development' ? require('../../../package.json').proxy : ''
const baseUrl = isDev() ? require('../../../package.json').proxy : ''
const Connections: ConnectionsDict = {
'hubs/telemetry': new HubConnectionBuilder()

View File

@ -62,3 +62,5 @@ export const range = (end: number, start: number = 0) => Array.from({ length: en
* @returns Общий тип с полным `T` и несовпадающими полями из `R`
*/
export type OmitExtends<T, R> = T & Omit<R, keyof T>
export const isDev = () => process.env.NODE_ENV === 'development'

View File

@ -1,3 +1,4 @@
import { isDev } from '.'
import { getUserLogin, getUserPermissions, getUserRoles } from './storage'
export type Role = string
@ -17,7 +18,7 @@ export const getPermissions = (...values: PermissionRequest[]) => {
const [service, type] = key.toLowerCase().split('.')
if (!isRequestType(type)) return
permissions[service] = permissions[service] ?? {}
permissions[service][type] = getUserLogin() === 'dev' || hasPermission(key)
permissions[service][type] = hasPermission(key) || (isDev() && getUserLogin() === 'dev')
})
return permissions
}