Skip to content

Commit

Permalink
(User roles) Assignment update (#8348)
Browse files Browse the repository at this point in the history
* fix: update searched record assignment to be read from redux in audit

* fix: update assignment reading in resolver from full bundle

* fix: remove assignment check in issuing event query
  • Loading branch information
Nil20 authored Jan 21, 2025
1 parent b85d411 commit 6e30787
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 40 deletions.
4 changes: 3 additions & 1 deletion packages/client/src/views/RecordAudit/RecordAudit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,9 @@ const BodyContent = ({
}
} else {
declaration = getGQLDeclaration(data.fetchRegistration, language)
declaration.assignment = draft?.assignmentStatus
/* draft might not be in store for unassigned record,
in that case use the one from the short declaration info query */
declaration.assignment ??= draft?.assignmentStatus
}

return (
Expand Down
39 changes: 18 additions & 21 deletions packages/gateway/src/features/registration/root-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,13 @@ export const resolvers: GQLResolver = {
return markEventAsCertified(id, details, authHeader, EVENT_TYPE.BIRTH)
}
),
markBirthAsIssued: requireAssignment(
(_, { id, details }, { headers: authHeader }) => {
if (!hasScope(authHeader, SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES)) {
throw new Error('User does not have enough scope')
}
return markEventAsIssued(id, details, authHeader, EVENT_TYPE.BIRTH)
// @todo: add new query for certify and issue later where require assignment wrapper will be used
markBirthAsIssued: (_, { id, details }, { headers: authHeader }) => {
if (!hasScope(authHeader, SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES)) {
throw new Error('User does not have enough scope')
}
),
return markEventAsIssued(id, details, authHeader, EVENT_TYPE.BIRTH)
},
markDeathAsCertified: requireAssignment(
(_, { id, details }, { headers: authHeader }) => {
if (!hasScope(authHeader, SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES)) {
Expand All @@ -534,14 +533,13 @@ export const resolvers: GQLResolver = {
return markEventAsCertified(id, details, authHeader, EVENT_TYPE.DEATH)
}
),
markDeathAsIssued: requireAssignment(
(_, { id, details }, { headers: authHeader }) => {
if (!hasScope(authHeader, SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES)) {
throw new Error('User does not have enough scope')
}
return markEventAsIssued(id, details, authHeader, EVENT_TYPE.DEATH)
// @todo: add new query for certify and issue later where require assignment wrapper will be used
markDeathAsIssued: (_, { id, details }, { headers: authHeader }) => {
if (!hasScope(authHeader, SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES)) {
throw new Error('User does not have enough scope')
}
),
return markEventAsIssued(id, details, authHeader, EVENT_TYPE.DEATH)
},
markMarriageAsCertified: requireAssignment(
(_, { id, details }, { headers: authHeader }) => {
if (!hasScope(authHeader, SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES)) {
Expand All @@ -555,14 +553,13 @@ export const resolvers: GQLResolver = {
)
}
),
markMarriageAsIssued: requireAssignment(
(_, { id, details }, { headers: authHeader }) => {
if (!hasScope(authHeader, SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES)) {
throw new Error('User does not have enough scope')
}
return markEventAsIssued(id, details, authHeader, EVENT_TYPE.MARRIAGE)
// @todo: add new query for certify and issue later where require assignment wrapper will be used
markMarriageAsIssued: (_, { id, details }, { headers: authHeader }) => {
if (!hasScope(authHeader, SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES)) {
throw new Error('User does not have enough scope')
}
),
return markEventAsIssued(id, details, authHeader, EVENT_TYPE.MARRIAGE)
},
async markEventAsNotDuplicate(_, { id }, { headers: authHeader }) {
const isAssignedToThisUser = await checkUserAssignment(id, authHeader)
if (!isAssignedToThisUser) {
Expand Down
27 changes: 9 additions & 18 deletions packages/gateway/src/features/registration/type-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ import {
isTaskOrTaskHistory,
resourceIdentifierToUUID,
Address,
findLastOfficeFromSavedBundle,
findLastOfficeLocationFromSavedBundle,
notCorrectedHistory,
findResourceFromBundleById,
getUserRoleFromHistory,
SavedOffice
} from '@opencrvs/commons/types'

import { findAssignment } from '@opencrvs/commons/assignment'
import { GQLQuestionnaireQuestion, GQLResolver } from '@gateway/graphql/schema'

import { Context } from '@gateway/graphql/context'
Expand Down Expand Up @@ -1051,23 +1050,15 @@ export const typeResolvers: GQLResolver = {
},
certificates: resolveCertificates,
assignment: async (task, _, context) => {
const assignmentExtension = findExtension(
`${OPENCRVS_SPECIFICATION_URL}extension/regAssigned`,
task.extension
)
const record = context.dataSources.recordsAPI.fetchRecord()
const office = record && findLastOfficeFromSavedBundle(record)

if (assignmentExtension && record) {
const regLastUserExtension = findExtension(
`${OPENCRVS_SPECIFICATION_URL}extension/regLastUser`,
task.extension
)!
const record = context.dataSources.recordsAPI.getRecord()

const practitionerId = resourceIdentifierToUUID(
regLastUserExtension.valueReference.reference
)
if (!record) {
return null
}
const assignment = findAssignment(record)

if (assignment) {
const practitionerId = assignment?.practitioner.id
const user = findResourceFromBundleById<Practitioner>(
record,
practitionerId
Expand All @@ -1077,7 +1068,7 @@ export const typeResolvers: GQLResolver = {
practitionerId: user.id,
firstName: user.name[0].given?.join(' '),
lastName: user.name[0].family,
officeName: office?.name || ''
officeName: assignment?.office.name || ''
}
}

Expand Down

0 comments on commit 6e30787

Please sign in to comment.