Skip to content

Commit

Permalink
fix: skipAudit warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Sep 9, 2024
1 parent c3c7195 commit ee181e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/view/submit-modal/submit-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
ModalActions,
ModalContent,
ModalTitle,
NoticeBox,
} from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import { useExchangeContext } from '../../../context/index.js'
import { useExchangeContext, useUserContext } from '../../../context/index.js'
import { Warning } from '../../common/index.js'
import styles from './submit-modal.module.css'
import { SuccessContent } from './success-content.js'
Expand Down Expand Up @@ -146,13 +147,15 @@ const ConfirmModalContent = ({ exchange, requests, onClose, onSubmit }) => {
// this is very wordy, but did not have luck with i18nextscanner picking up from more compact versions...
let reportTranslationsString
const { systemInfo } = useConfig()
const { hasSkipAuditInfoAuthority } = useUserContext()
const reportCount = requests.length
const exchangeName = exchange?.displayName
const exchangeURL =
exchange?.target?.type === 'INTERNAL'
? systemInfo?.contextPath
: exchange?.target?.api?.url
const exchangeHostName = exchangeURL?.split('//')[1] ?? exchangeURL // remove protocol
const exchangeSkipAudit = Boolean(exchange?.target?.request?.skipAudit)

if (exchange?.target?.type === 'INTERNAL') {
if (requests.length > 1) {
Expand Down Expand Up @@ -212,6 +215,17 @@ const ConfirmModalContent = ({ exchange, requests, onClose, onSubmit }) => {
})}
</ul>
</div>

{exchangeSkipAudit && !hasSkipAuditInfoAuthority && (
<div className={styles.skipAuditWarning}>
<NoticeBox warning>
{i18n.t(
'This exchange is configured to skip audit information on submit, but you do not have the Skip data import audit authority. If you submit this exchange, the data will be ignored.'
)}
</NoticeBox>
</div>
)}

<div>
{i18n.t('Are you sure you want to submit this data?')}
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/components/view/submit-modal/submit-modal.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@
margin: var(--spacers-dp8) 0 var(--spacers-dp16) 0;
font-style: italic;
}

.skipAuditWarning {
margin-block: var(--spacers-dp8);
}
7 changes: 7 additions & 0 deletions src/context/user-context/user-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const EXCHANGE_AUTHORITIES_ADD = [
'F_AGGREGATE_DATA_EXCHANGE_PUBLIC_ADD',
]
const EXCHANGE_AUTHORITIES_DELETE = ['F_AGGREGATE_DATA_EXCHANGE_DELETE']
const SKIP_DATA_IMPORT_AUDIT_AUTHORITIES = ['F_SKIP_DATA_IMPORT_AUDIT']
const ALL_AUTHORITY = ['ALL']

const query = {
Expand Down Expand Up @@ -59,10 +60,16 @@ const UserProvider = ({ children }) => {
...EXCHANGE_AUTHORITIES_DELETE,
].some((auth) => authorities.includes(auth))

const hasSkipAuditInfoAuthority = [
...ALL_AUTHORITY,
...SKIP_DATA_IMPORT_AUDIT_AUTHORITIES,
].some((auth) => authorities.includes(auth))

const providerValue = {
id,
canAddExchange,
canDeleteExchange,
hasSkipAuditInfoAuthority,
organisationUnits,
keyUiLocale: settings.keyUiLocale,
}
Expand Down

0 comments on commit ee181e1

Please sign in to comment.