Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:opencrvs/opencrvs-core into ocrv…
Browse files Browse the repository at this point in the history
…s-2268-scope
  • Loading branch information
anjana6 committed Jan 8, 2025
2 parents d11b51d + 689146f commit 9e5a4b4
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 39 deletions.
8 changes: 2 additions & 6 deletions packages/client/src/src-sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { registerRoute, NavigationRoute } from 'workbox-routing'
import { NetworkFirst, CacheFirst } from 'workbox-strategies'
import { clientsClaim } from 'workbox-core'
import { MINIO_REGEX } from '@opencrvs/commons/client'

// eslint-disable-next-line @typescript-eslint/no-use-before-define
self.__WB_DISABLE_DEV_LOGS = true
Expand Down Expand Up @@ -82,12 +83,7 @@ registerRoute(/http(.+)conditionals\.js$/, new NetworkFirst())
registerRoute(/http(.+)config$/, new NetworkFirst())

// This caches the minio urls
registerRoute(
import.meta.env.DEV
? /http(.+)localhost:3535\/ocrvs\/.+/
: /http(.+)minio\.(.+)\/.*ocrvs.*\/.+/,
new CacheFirst()
)
registerRoute(MINIO_REGEX, new CacheFirst())

/*
* Alternate for navigateFallback & navigateFallbackBlacklist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

import React from 'react'
import { useIntl } from 'react-intl'
import { Summary } from '@opencrvs/components/lib/Summary'
import { SummaryConfig } from '@opencrvs/commons/events'
import { EventIndex } from '@opencrvs/commons/client'
Expand All @@ -26,6 +27,7 @@ export function EventSummary({
event: EventIndex
summary: SummaryConfig
}) {
const intl = useIntl()
const { toString } = useTransformer(event.type)
const data = toString(event.data)
return (
Expand All @@ -36,9 +38,10 @@ export function EventSummary({
<Summary.Row
key={field.id}
data-testid={field.id}
label={field.label?.defaultMessage ?? ''}
label={intl.formatMessage(field.label)}
placeholder={
'@todo: These placeholder values need to be configurable like "No place of birth"'
field.emptyValueMessage &&
intl.formatMessage(field.emptyValueMessage)
}
value={data[field.id]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { orderBy, mapKeys, get } from 'lodash'
import { useTypedSearchParams } from 'react-router-typesafe-routes/dom'
import { Link } from 'react-router-dom'

import { EventIndex, getCurrentEventState } from '@opencrvs/commons/client'
import { EventIndex } from '@opencrvs/commons/client'
import { useWindowSize } from '@opencrvs/components/lib/hooks'
import { WorkqueueConfig } from '@opencrvs/commons'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ import {
import { useNavigate } from 'react-router-dom'
import { ICertificateData } from '@client/utils/referenceApi'
import { fetchImageAsBase64 } from '@client/utils/imageUtils'
import { isMinioUrl } from '@opencrvs/commons/client'

async function replaceMinioUrlWithBase64(template: Record<string, any>) {
const regex = /\/[^\/?]+\.(jpg|png|jpeg|svg)(?=\?|$)/i

async function recursiveTransform(obj: any) {
if (typeof obj !== 'object' || obj === null) {
return obj
Expand All @@ -63,7 +62,7 @@ async function replaceMinioUrlWithBase64(template: Record<string, any>) {

for (const key in obj) {
const value = obj[key]
if (typeof value === 'string' && regex.test(value)) {
if (typeof value === 'string' && isMinioUrl(value)) {
transformedObject[key] = await fetchImageAsBase64(value)
} else if (typeof value === 'object') {
transformedObject[key] = await recursiveTransform(value)
Expand Down
1 change: 1 addition & 0 deletions packages/commons/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export * from './search'
export * from './events'
export * from './conditionals/conditionals'
export * from './conditionals/validate'
export * from './documents'

export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
5 changes: 5 additions & 0 deletions packages/commons/src/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

export const MINIO_REGEX = /\/[^\/?]+\.(jpg|png|jpeg|svg)(?=\?|$)/i

export function isBase64FileString(str: string) {
if (str === '' || str.trim() === '') {
return false
}
const strSplit = str.split(':')
return strSplit.length > 0 && strSplit[0] === 'data'
}

export const isMinioUrl = (url: string) => MINIO_REGEX.test(url)
8 changes: 6 additions & 2 deletions packages/commons/src/events/EventConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { z } from 'zod'
import { ActionConfig } from './ActionConfig'
import { TranslationConfig } from './TranslationConfig'
import { SummaryConfig } from './SummaryConfig'
import { SummaryConfig, SummaryConfigInput } from './SummaryConfig'
import { WorkqueueConfig } from './WorkqueueConfig'
import { FormConfig, FormConfigInput } from './FormConfig'

Expand All @@ -32,8 +32,12 @@ export const EventConfig = z.object({
workqueues: z.array(WorkqueueConfig)
})

export const EventConfigInput = EventConfig.extend({
summary: SummaryConfigInput
})

export type EventConfig = z.infer<typeof EventConfig>
export type EventConfigInput = z.input<typeof EventConfig>
export type EventConfigInput = z.input<typeof EventConfigInput>

export const defineForm = (form: FormConfigInput): FormConfig =>
FormConfig.parse(form)
26 changes: 17 additions & 9 deletions packages/commons/src/events/SummaryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@
import { z } from 'zod'
import { TranslationConfig } from './TranslationConfig'

const Field = z.object({
id: z.string().describe('Id of a field defined under form.'),
label: TranslationConfig,
emptyValueMessage: TranslationConfig.optional()
})

const FieldInput = Field.extend({
// label is enforced during runtime.
label: TranslationConfig.optional()
})

export const SummaryConfig = z
.object({
title: TranslationConfig.describe('Header title of summary'),
fields: z
.array(
z.object({
id: z.string().describe('Id of a field defined under form.'),
label: TranslationConfig.optional()
})
)
.describe('Fields to be rendered under in summary.')
fields: z.array(Field).describe('Fields rendered in summary view.')
})
.describe('Configuration for summary in event.')

export const SummaryConfigInput = SummaryConfig.extend({
fields: z.array(FieldInput)
})

export type SummaryConfig = z.infer<typeof SummaryConfig>
export type SummaryConfigInput = z.input<typeof SummaryConfig>
export type SummaryConfigInput = z.input<typeof SummaryConfigInput>
10 changes: 5 additions & 5 deletions packages/commons/src/events/defineConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ import { findPageFields, resolveFieldLabels } from './utils'
* @param config - Event specific configuration
*/
export const defineConfig = (config: EventConfigInput) => {
const parsed = EventConfig.parse(config)
const input = EventConfigInput.parse(config)

const pageFields = findPageFields(parsed).map(({ id, label }) => ({
const pageFields = findPageFields(input).map(({ id, label }) => ({
id,
label
}))

return EventConfig.parse({
...parsed,
...input,
summary: resolveFieldLabels({
config: parsed.summary,
config: input.summary,
pageFields
}),
workqueues: parsed.workqueues.map((workqueue) =>
workqueues: input.workqueues.map((workqueue) =>
resolveFieldLabels({
config: workqueue,
pageFields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export const tennisClubMembershipEvent = defineConfig({
},
fields: [
{
id: 'applicant.firstname'
id: 'applicant.firstname',
emptyValueMessage: {
defaultMessage: 'First name is not provided',
description: 'This is the message to show when the field is empty',
id: 'event.tennis-club-membership.summary.field.firstname.empty'
}
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions packages/gateway/src/features/fhir/minioAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { DOCUMENTS_URL } from '@gateway/constants'
import { OpenCRVSRESTDataSource } from '@gateway/graphql/data-source'

export default class MinioAPI extends OpenCRVSRESTDataSource {
override baseURL = `${DOCUMENTS_URL}/presigned-url`
override baseURL = `${DOCUMENTS_URL}`

override willSendRequest(
_path: string,
Expand All @@ -25,6 +25,6 @@ export default class MinioAPI extends OpenCRVSRESTDataSource {
}

getStaticData(fileUri: string) {
return this.get(`${fileUri}`)
return this.get(`/presigned-url${fileUri}`)
}
}
2 changes: 1 addition & 1 deletion packages/toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opencrvs/toolkit",
"version": "0.0.7-events",
"version": "0.0.9-events",
"description": "OpenCRVS toolkit for building country configurations",
"license": "MPL-2.0",
"exports": {
Expand Down
27 changes: 20 additions & 7 deletions packages/user-mgnt/src/features/updateUser/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ import {
postFhir,
uploadSignatureToMinio
} from '@user-mgnt/features/createUser/service'
import { logger } from '@opencrvs/commons'
import { isBase64FileString, logger } from '@opencrvs/commons'
import User, { IUser, IUserModel } from '@user-mgnt/model/user'
import { getUserId } from '@user-mgnt/utils/userUtils'
import { QA_ENV } from '@user-mgnt/constants'
import * as Hapi from '@hapi/hapi'
import * as _ from 'lodash'
import { postUserActionToMetrics } from '@user-mgnt/features/changePhone/handler'
import { userRoleScopes } from '@opencrvs/commons/authentication'
import { Practitioner } from '@opencrvs/commons/types'
import {
findExtension,
OPENCRVS_SPECIFICATION_URL,
Practitioner
} from '@opencrvs/commons/types'

export default async function updateUser(
request: Hapi.Request,
Expand Down Expand Up @@ -93,11 +97,20 @@ export default async function updateUser(
throw new Error('Location can be changed only by National System Admin')
}
}
const signatureAttachment = user.signature && {
contentType: user.signature.type,
url: await uploadSignatureToMinio(token, user.signature),
creation: new Date().getTime().toString()
}

const existingSignatureAttachment = findExtension(
`${OPENCRVS_SPECIFICATION_URL}extension/employee-signature`,
existingPractitioner.extension || []
)?.valueAttachment

const signatureAttachment =
(user.signature &&
isBase64FileString(user.signature.data) && {
contentType: user.signature.type,
url: await uploadSignatureToMinio(token, user.signature),
creation: new Date().getTime().toString()
}) ||
existingSignatureAttachment

const practitioner = createFhirPractitioner(
existingUser,
Expand Down

0 comments on commit 9e5a4b4

Please sign in to comment.